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 · 7 comments
Closed

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

douniwan5788 opened this issue Oct 13, 2017 · 7 comments

Comments

@douniwan5788
Copy link

@douniwan5788 douniwan5788 commented Oct 13, 2017

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

@douniwan5788 douniwan5788 commented Oct 13, 2017

find a way

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

Loading

@wb14123
Copy link

@wb14123 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?

Loading

@wb14123
Copy link

@wb14123 wb14123 commented Jan 18, 2018

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

Loading

@iddoeldor
Copy link
Contributor

@iddoeldor 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));
}

Loading

@0x410c
Copy link

@0x410c 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]);
}

Loading

@KANGOD
Copy link

@KANGOD 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.

Loading

@wb14123
Copy link

@wb14123 wb14123 commented Sep 3, 2021

@KANGOD Yes I added that one to the doc 😄

Loading

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

Successfully merging a pull request may close this issue.

None yet
5 participants