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

How to get all java class fields/methods in frida? #44

Closed
douniwan5788 opened this issue Oct 13, 2017 · 8 comments
Closed

How to get all java class fields/methods in frida? #44

douniwan5788 opened this issue Oct 13, 2017 · 8 comments

Comments

@douniwan5788
Copy link

After dig into source, I finally found the way to get a field which has the same name of a method.

https://github.com/frida/frida-java/blob/82bc59a8389ae62a94e65841b34bb003e03f6518/lib/class-factory.js#L810-L813

public class Test {
    private static int a = 1;
    
    private static int a()
    {
        return 0;
    }
}
'use strict';

if (Java.available) {
    console.log('Java Process!')

    Java.perform(function () {
        var Test = Java.use("Test");

        console.log( Test._a.value );

    });
} else
    console.log("not Java Process!")

My question is:
Is there a way to get all fields/methods of a java class?

@douniwan5788
Copy link
Author

find a way

console.log( Object.getOwnPropertyNames(Test.__proto__).join('\n') );

@wb14123
Copy link

wb14123 commented Jan 18, 2018

I've spent a lot of time to figure out how to get the fields which have the same name of methods. Can we put this in the document?

@wb14123
Copy link

wb14123 commented Jan 18, 2018

BTW, @douniwan5788 are you figuring it out by reading the source code?

@iddoeldor
Copy link
Contributor

iddoeldor commented Apr 23, 2019

find a way

console.log( Object.getOwnPropertyNames(Test.__proto__).join('\n') );

Get Java class methods & members

function describeJavaClass(className) {
  var jClass = Java.use(className);
  console.log(JSON.stringify({
    _name: className,
    _methods: Object.getOwnPropertyNames(jClass.__proto__).filter(m => {
      return !m.startsWith('$') // filter out Frida related special properties
         || m == 'class' || m == 'constructor' // optional
    }), 
    _fields: jClass.class.getFields().map(f => {
      return f.toString()
    })  
  }, null, 2));
}

@0x410c
Copy link

0x410c commented Mar 18, 2020

empty method list
obtain like the fields :

var db1 = Java.use("your.class");
var methodArr = db1.class.getMethods();
for(var m in methodArr)
{
	console.log(methodArr[m]);
}

@KANGOD
Copy link

KANGOD commented Sep 2, 2021

@wb14123

I've spent a lot of time to figure out how to get the fields which have the same name of methods. Can we put this in the document?

Indeed there is one, this._m.value in https://github.com/frida/frida-website/blob/master/_docs/examples/android.md. While it's in Examples section instead of API Reference, I can't say it's well documented.
frida/frida#833 is also the same topic. Maybe a doc PR is needed.

@wb14123
Copy link

wb14123 commented Sep 3, 2021

@KANGOD Yes I added that one to the doc 😄

@mmkhitaryan
Copy link

I think @0x410c meant to use "of" instead of "in".

for(var m of methodArr)

var m inreturns a list of indices instead of objects. Calling 0.class.getMethods() returns error: TypeError: cannot read property 'getMethods' of undefined

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

6 participants