Let's assume we have a such code snippet:
public class Test {
public void testArrayValue() {
Object[] objects = new Object[1];
fillObject(objects);
Log.d("test", (String)objects[0]);
}
public void fillObject(Object[] objects) {
objects[0] = new String("fillObject str");
}
}
How to hook the fillObject method to change the value of the first element in array passed to method?
Java.perform(function () {
var clazz = Java.use("com.some.package.Test");
clazz.fillObject.overload('[Ljava.lang.Object;').implementation = function(var_0) {
// this won't work :( assigning a string value to var_0[0]
// does not pass it outside the hooked code
//
var stringClass = Java.use("java.lang.String");
var stringInstance = stringClass.$new("Hello World");
var_0[0] = stringInstance
};
});
The output of running hooked code will be "fillObject str", and not "Hello World"