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

global references used in enumerateLoadedClassesArt #312

Open
thushw opened this issue Apr 16, 2024 · 1 comment
Open

global references used in enumerateLoadedClassesArt #312

thushw opened this issue Apr 16, 2024 · 1 comment

Comments

@thushw
Copy link

thushw commented Apr 16, 2024

Thanks so much for this helpful toolset, love what you all do ❤️

I was having some trouble running out of global reference memory table on my android and I'm fairly certain it is to do with the global references being created here ->

function enumerateLoadedClassesArt (callbacks) {

This is the message I get from frida
Abort message: 'JNI ERROR (app bug): global reference table overflow (max=51200)

It happens upon the invocation of Java.enumerateLoadedClassesSync() and running down the execution, it is likely here.
I can see that the references are being re-claimed in the method, but since the memory in the Android is limited, it crashes before reaching

env.deleteGlobalRef(handle);

Is there a way I can increase the memory used for global refs on the android, or is there some work-around?

@thushw
Copy link
Author

thushw commented Apr 17, 2024

I might be able to help with a potential fix - pl let me know if that is ok.
I think, rather than holding on to the class, we can hold on to the name, since that is all we need here :

function enumerateLoadedClassesArt (callbacks) {
    const env = vm.getEnv();

    const classNames = [];
    const addGlobalReference = api['art::JavaVMExt::AddGlobalRef'];
    const vmHandle = api.vm;
    withRunnableArtThread(vm, env, thread => {
      const collectClassNames = makeArtClassVisitor(klass => {
        classHandle = addGlobalReference(vmHandle, thread, klass);
        const className = env.getClassName(classHandle);
        env.deleteGlobalRef(classHandle);
        classNames.push(className);
        return true;
      });

      api['art::ClassLinker::VisitClasses'](api.artClassLinker, collectClassNames);
    });

    try {
      classNames.forEach(className => {
        callbacks.onMatch(className);
      });
    } finally {
    }

    callbacks.onComplete();
  }

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

No branches or pull requests

1 participant