frida-java-bridge icon indicating copy to clipboard operation
frida-java-bridge copied to clipboard

Is registerClass broken | not working?

Open snooze6 opened this issue 7 years ago • 1 comments

I was trying to use registerClass function while I realized that it was not working on my actual setup. The code is the following:

Java.perform(function(){
	console.log('Android version:  '+Java.androidVersion);
	console.log('Frida version:    '+Frida.version);
	console.log('Process arch:     '+Process.arch);
	console.log('Process Platform: '+Process.platform);
	var System = Java.use("java.lang.System");
	console.log('Java vm version:  '+System.getProperty("java.vm.version"));
	
	console.log('Trying to register new class...');
	try {
        var Runnable = Java.use('java.lang.Runnable');
        var MyRunnable = Java.registerClass({
            name: 'com.example.MyRunnable',
            implements: [Runnable],
            methods: {
                'run': function() {
                    console.log('Hello!!!');
                }
            }
        });
        // var runnable = MyRunnable.$new();
        // runnable.run();

    } catch (e) {
        console.log("[!] - registerClass error");
		console.log(e);
    }
});

The expected result would be no exceptions everything running fine, but the actual output is

Android version:  8.0.0
Frida version:    11.0.2
Process arch:     arm64
Process Platform: linux
Java vm version:  2.1.0
Trying to register new class...
[!] - registerClass error
Error: java.lang.ClassNotFoundException: Didn't find class "MyRunnable" on path: DexPathList[[zip file "/data/data/com.google.android.deskclock/cache/raw1314848924905500505dex"],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
undefined

I´m using an LG Nexus 5 running Android 8.0.0 (64 bit)

snooze6 avatar May 11 '18 09:05 snooze6

If your phone is dalvik then it won't work. It seems like registerclass is only supported on ART.

TheRealJunior avatar Feb 15 '19 10:02 TheRealJunior