Categories
Android

Frida Android Make Toast non-rooted Device

I found it’s tough to understand how to just making simple “Toast” in Android via Frida script. Been search to various articles on how to do Toast, but I’ve faced so many errors, for example:

{'type': 'error', 'description': "Error: makeText(): argument types do not match any of:\n\t.overload('android.content.Context', 'int', 'int')\n\t.overload('android.content.Context', 'java.lang.CharSequence', 'int')\n\t.overload('android.content.Context', 'android.os.Looper', 'java.lang.CharSequence', 'int')", 'stack': "Error: makeText(): argument types do not match any of:\n\t.overload('android.content.Context', 'int', 'int')\n\t.overload('android.content.Context', 'java.lang.CharSequence', 'int')\n\t.overload('android.content.Context', 'android.os.Looper', 'java.lang.CharSequence', 'int')\n
   at pe (frida/node_modules/frida-java-bridge/lib/class-factory.js:549)\n    at frida/node_modules/frida-java-bridge/lib/class-factory.js:951\n    at /script1.js:22\n    at frida/node_modules/frida-java-bridge/lib/vm.js:11\n    at frida/node_modules/frida-java-bridge/index.js:304\n    at /script1.js:24", 'fileName': 'frida/node_modules/frida-java-bridge/lib/class-factory.js', 'lineNumber': 549, 'columnNumber': 1}

Fyi, I already know how to do it in Kotlin or Java code directly into the app. Based on error in this code, I make two assumptions:

1. I’m wrong in calling Context
2. I’m wrong in create makeText(args1, args2, args3)

To ensure we have same environment, in this example, I use the latest Frida version on May 2020 on Non-root Android, Windows 10, Execute it via Python connected to remote server via adb tcp forward 5555. I use real device (not emulator)

Here is script that works :


Java.perform(function () { 
    var context = Java.use('android.app.ActivityThread').currentApplication().getApplicationContext();

    Java.scheduleOnMainThread(function() {
            var toast = Java.use("android.widget.Toast");
            toast.makeText(context, Java.use("java.lang.String").$new("This is works!"), 1).show();
    });

});

In Frida, we shall wrap-up our mind to basic fundamental of software cycle and how to use it. Apparently lack of documentation and examples is really pain here to learn how to use Frida.

Leave a Reply

Your email address will not be published.