1

I'm trying to hook some function in an class it works fine but I want to view one argumant that is an class instance and this class has field that is String type, but when I try to get this field I get some really weird type instead of the string

Here is the code: var someclass = Java.use('com.myapp.classes.someclass.a');

// String (Object, String, Boolean)
someclass.getData.overload('com.myapp.classes.ClassContext', 
        'java.lang.String', 'java.lang.Boolean').implementation = function (a, b, c) {

    console.log('com.myapp.classes.ClassContext.stringify: ', 
        JSON.stringify(a.fieldWithStringData), '\r\n');
}

But instead of string I get some weird object when I used JSON.stringify on this object I got string like this (pretty printed for this question):

{
    "_p": ["<instance: com.myapp.classes.ClassContext>", 2, {
            "className": "java.lang.String",
            "name": "Ljava/lang/String;",
            "type": "pointer",
            "size": 1,
            "defaultValue": "0x0"
        }, "0xa3144614", "0xc2aaa8b0", "0xc2aace70"]
}

What is this object and how to get actual string from it, can some one help?

Robert
  • 39,162
  • 17
  • 99
  • 152
SiriusED
  • 11
  • 1
  • In your title you wrote `hooking native method` but your hook is for a Java method. If you want to hook the native implementation of a method the hook looks different. Also keep in mind that when accessing a field in Java it is recommended to prepend an underscore `_` see https://stackoverflow.com/a/60467285/150978 for details. – Robert Feb 04 '22 at 16:47

1 Answers1

1

You can use like this: a.fieldWithStringData.value

Serhat
  • 396
  • 1
  • 5
  • 13