// Android Intent Monitor — logs all intents, deeplinks, exported component calls
// Usage: frida -U -f com.target.app -l intent-monitor.js --no-pause

Java.perform(function() {
    // --- Intent creation/actions ---
    try {
        var Intent = Java.use('android.content.Intent');
        Intent.setAction.implementation = function(action) {
            if (action) console.log('[INTENT] setAction: ' + action);
            return this.setAction(action);
        };
        Intent.setData.implementation = function(uri) {
            if (uri) console.log('[INTENT] setData (deeplink): ' + uri.toString());
            return this.setData(uri);
        };
        Intent.putExtra.overload('java.lang.String', 'java.lang.String').implementation = function(k, v) {
            console.log('[INTENT EXTRA] ' + k + ' = ' + v);
            return this.putExtra(k, v);
        };
        Intent.getData.implementation = function() {
            var data = this.getData();
            if (data) console.log('[INTENT DATA] ' + data.toString());
            return data;
        };
    } catch(e) {}

    // --- Activity navigation ---
    try {
        var Activity = Java.use('android.app.Activity');
        Activity.startActivity.overload('android.content.Intent').implementation = function(intent) {
            var action = intent.getAction ? intent.getAction() : '?';
            var data = intent.getData ? intent.getData() : null;
            console.log('[startActivity] action=' + action + (data ? ' data=' + data : ''));
            return this.startActivity(intent);
        };
        Activity.startActivityForResult.overload('android.content.Intent', 'int').implementation = function(intent, req) {
            console.log('[startActivityForResult] requestCode=' + req + ' intent=' + intent.toString());
            return this.startActivityForResult(intent, req);
        };
    } catch(e) {}

    // --- Broadcast intents ---
    try {
        var Context = Java.use('android.content.ContextWrapper');
        Context.sendBroadcast.overload('android.content.Intent').implementation = function(intent) {
            console.log('[sendBroadcast] ' + intent.toString());
            return this.sendBroadcast(intent);
        };
    } catch(e) {}

    // --- Content Provider access ---
    try {
        var ContentResolver = Java.use('android.content.ContentResolver');
        ContentResolver.query.overload(
            'android.net.Uri', '[Ljava.lang.String;',
            'android.os.Bundle', 'android.os.CancellationSignal'
        ).implementation = function(uri, proj, sel, cancel) {
            console.log('[ContentProvider] query: ' + uri.toString());
            return this.query(uri, proj, sel, cancel);
        };
    } catch(e) {}

    console.log('[RTExit] Intent monitor loaded.');
});
