Skip to content

Instantly share code, notes, and snippets.

@myzhan
Last active September 28, 2023 01:56
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save myzhan/ab13068463cd7f77b7f06ae561ea853a to your computer and use it in GitHub Desktop.
Save myzhan/ab13068463cd7f77b7f06ae561ea853a to your computer and use it in GitHub Desktop.
Frida android make toast
Java.scheduleOnMainThread(function() {
Toast = Java.use("android.widget.Toast");
var currentApplication = Java.use('android.app.ActivityThread').currentApplication();
var context = currentApplication.getApplicationContext();
Toast.makeText(context,"hello world", Toast.LENGTH_SHORT.value).show();
});
@iddoeldor
Copy link

$ frida -Uf com.app --no-pause
     ____
    / _  |   Frida 12.0.5 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at http://www.frida.re/docs/home/
Spawned `com.app`. Resuming main thread!  
[]-> Java.scheduleOnMainThread(function() {
                                                      Toast = Java.use("android.widget.Toast");
                                                      var currentApplication = Java.use('android.app.ActivityThread').currentApplication();
                                                      var context = currentApplication.getApplicationContext();
                                                      Toast.makeText(context,"hello world", Toast.LENGTH_SHORT.value).show();
                                              });
Error: Not allowed outside Java.perform() callback

@0xE4s0n
Copy link

0xE4s0n commented Dec 24, 2018

It doesn't work! Why?

@pitust
Copy link

pitust commented May 22, 2020

IDK, it works for me

@yodiaditya
Copy link

@0xE4s0n @pitust This is 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(Java.use("android.app.ActivityThread").currentApplication().getApplicationContext(), Java.use("java.lang.String").$new("This is works!"), 1).show();
    });
});

For detail information and debugging, please check https://www.yodiw.com/frida-android-make-toast-non-rooted-device/

@pitust
Copy link

pitust commented May 23, 2020

i know, that is more or less what worked for me

@FourCinnamon0
Copy link

What about hyperlinks and stuff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment