javascriptjavaandroidreverse-engineeringfrida

Why Frida (Inject) doesn't hook getPackageInfo and other methods?


I am having problems creating a script in JavaScript for Frida. I want to hook the getPackageInfo method in order to log when it is called in the console, i have overloaded the old and the new version of it using this code:

    jPM = Java.use('android.content.pm.PackageManager');
    jPM.getPackageInfo.overload('java.lang.String','int').implementation=(pname,f)=>{
        console.warn("Called => getPackageInfo ("+f+")");
        return jPM.getPackageInfo.call(this,pname,f);
    }
    jPM.getPackageInfo.overload('android.content.pm.VersionedPackage','int').implementation=(vp,f)=>{
        console.warn("Called => getPackageInfo [API level 33] ("+f+")");
        return jPM.getPackageInfo.call(this,vp,f);
    }

When i try to run the script I don't get any error, but I don't get any log in the console. I am sure that the method that is being called is the first, because it's signature is this in smali:

Landroid/content/pm/PackageManager;->getPackageInfo(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;

I can't understand what am I doing wrong, if i use the same code to hook other methods it works. Please help me


Solution

  • I have solved this by using android.app.ApplicationPackageManager instead of android.content.pm.PackageManager.

    Thanks to @Robert for giving me the link to this example code: https://codeshare.frida.re/@limyout/test/