3

I'm able to sucessfully hook into an Android method using Frida, but I am trying to find out who is calling that method. I can find that out if I can rewrite the method with Frida to print the stacktrace when the method gets called. I've tried a few things, but all of them have had some sort of error. This is the latest thing I have tried.

setImmediate(function() {
 console.log("[*] Starting script");
 Java.perform(function () {
 var Activity = Java.use("com.package.MyClass");
 Activity.getUpdates.overload('boolean', 'java.lang.String', 'java.lang.String').implementation = function (v1, v2, v3) {
 console.log("v1: " + v1);
 console.log("v2: " + v2);
 console.log("v3: " + v3);
 Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new())
 };
 });
})

This is resulting in the following error

Error: Not allowed outside Java.perform() callback
 at d (frida/node_modules/frida-java/index.js:86)
 at frida/node_modules/frida-java/index.js:366
 at [anon] (repl1.js:11)
 at input:1

Any idea how I can achieve this?

asked Jan 27, 2018 at 21:56

2 Answers 2

20

I fixed it by using this:

Java.perform(function() {
 console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()))
});

It is necessary to add an additional Java.perform call

answered Jan 30, 2018 at 12:26
Sign up to request clarification or add additional context in comments.

5 Comments

Have you used Frida with Python bindings?
Yes, I'm new to Frida, is there a difference? Do you need additional code? I used it with Frida server and Frida gadget
there is another issue which I've been stuck for 2 weeks or so, I thought maybe you know how to deal with it. Have you used reactor while using Frida with Python?
no, sorry I haven't used reactor yet. Maybe open a new question here
I have posted a new question about a new problem. Can you please take a look at it too? stackoverflow.com/questions/48772800/…
1
var stack = Java.use("java.lang.Exception").$new().getStackTrace();
 for (var i = 0; i < stack.length; i++) {
 console.log(stack[i].toString());
 }
answered Sep 17, 2024 at 7:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.