frida issue. hooking static method call

Viewed 2872

I am trying to learn Frida and have experimented with a little so far. Things have mostly worked as thankfully I could find enough examples and tutorials to help me through. However, at this point in time, I am stuck with a very specific task at hand.

So let's say below is the Frida hook I am referring to:

Java.perform(() => {
      const TestClass = Java.use(
        'com.test.TestClass',
      );
      TestClass.testStaticMethod.overload('java.lang.String', 'java.util.Map').implementation = function (
        str,
        map,
      ) {


        console.log('intercept!');
        return this.b(str, map);
      };
      const testStr = Java.use('java.lang.String').$new('test');
      const testMap = Java.use('java.util.HashMap').$new();
 });
 //wait (sleep) 10-15 secs
 Java.perform(() => {
      // test it!   
      TestClass.testStaticMethod(testStr, testMap);
    });

it does NOT output 'intercept!' What could be the reason?

1 Answers

The call to TestClass.testStaticMethod(testStr, testMap); in your script does not execute the hook, but the original un-hooked method. Therefore you will never see the output intercept! when your script is loaded.

The output intercept! will only be generated if the hooked method is executed by the app.

Related