Search code examples
frida

Print class data member with Frida


I can successfully hook into this getAuthToken method

public class AuthResponse2 extends DataResponse<Data> {
    public static class Data {
        private String mAuthToken;

        public String getAuthToken() {
            return this.mAuthToken;
        }
    }
}

This is my Frida JS script

setImmediate(function() {
    console.log("[*] Starting script");

        Java.perform(function () {
            var Activity = Java.use("com.app.network.AuthResponse2$Data");
            Activity.getAuthToken.overload().implementation = function () {
                console.log(mAuthToken);
                console.log(mAuthToken.toString());
            };
        });

})

But I can't get mAuthToken printed. Not sure what kind of syntax I need to use.

I've tried

this.mAuthToken too, and the following gets printed

"[object Object]"


Solution

  • I would try the following:

    setImmediate(function() {
        console.log("[*] Starting script");
    
            Java.perform(function () {
                var Activity = Java.use("com.app.network.AuthResponse2$Data");
                Activity.getAuthToken.overload().implementation = function () {
                    var mAuthToken = this.getAuthToken(); // use `call` if there are other overloads
                    console.log(mAuthToken);
                    return mAuthToken;
                };
            });
    
    })
    

    This keeps the old method intact (returning a value) and uses the return value of the original method for printing to console.

    I think your original code makes problem because you don't write this.mAuthToken when accessing class members.