Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registerClass static method support #339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

5andr0
Copy link

@5andr0 5andr0 commented Oct 2, 2024

With this PR, registerClass supports static methods. This also fixes the bug of not being able to implement static interface methods or static superClass methods.

mkdex now has the ability to add additional access flags like ACC_STATIC to non-constructor methods https://source.android.com/docs/core/runtime/dex-format#access-flags

To make a static method, add isStatic: true in the method object:

Java.scheduleOnMainThread(() => 
{
  Java.registerClass({
    name: 'com.example.MyWeirdTrustManager',
    superClass: SomeBaseClass,
    implements: [X509TrustManager],
    fields: {},
    methods: {
      checkServerTrusted: [{
        isStatic: true,
        returnType: 'void',
        argumentTypes: ['[Ljava.security.cert.X509Certificate;', 'java.lang.String'],
        implementation(chain, authType) {
          console.log('checkServerTrusted A');
        }
      }],
    }
  }
});

I leave it up to you to update the docs and unit tests.

For some reason, when registering a class with static methods from the app start (frida -f) it has to be scheduled on the main thread. Otherwise there will be this error:

Error: java.lang.ClassNotFoundException: Didn't find class "com.example.MyWeirdTrustManager" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system_ext/lib]]
    at t.throwIfExceptionPending (frida/node_modules/frida-java-bridge/lib/env.js:124:1)
    at Proxy.<anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:502:1)
    at Proxy.value (frida/node_modules/frida-java-bridge/lib/class-factory.js:949:1)
    at Proxy.value (frida/node_modules/frida-java-bridge/lib/class-factory.js:954:1)
    at I._make (frida/node_modules/frida-java-bridge/lib/class-factory.js:165:1)
    at I.use (frida/node_modules/frida-java-bridge/lib/class-factory.js:62:1)
    at I.registerClass (frida/node_modules/frida-java-bridge/lib/class-factory.js:275:1)
    at _.registerClass (frida/node_modules/frida-java-bridge/index.js:283:1)

@5andr0
Copy link
Author

5andr0 commented Oct 26, 2024

@oleavr Please include this in the next release! You are doing an awesome job, keep it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant