Reputation: 31
I am trying to figure out how to read a public unmodifiableList
field of a Java class with Frida.
Here is the class I have:
public final class MyClass {
public final String myString;
public final List myList;
public MyClass() {
this.myString = "Hello!";
this.myList = Collections.unmodifiableList({ "this_is_a_string" });
}
}
and here is the JS Frida code I am using to extract the two fields:
Java.perform(function() {
function onField(instance) {
const fields = instance.getClass().getDeclaredFields();
for(var i = 0; i < fields.length; i++) {
const value = fields[i].get(instance);
if(fields[i].getName() == "myString") {
// This correctly prints "Hello!".
console.log("myString: " + value);
} else if(fields[i].getName() == "myList") {
for(var j = 0; j < value.length; i++) {
// This prints out a blank line, as opposed to "this_is_a_string".
console.log(value[j]);
}
}
}
}
Java.choose("com.myapp.MyClass", { onField: onField, onComplete: function() {} })
});
The problem is that I cannot access any methods or fields of the unmodifiableList (size() and indexing included.). How can I read from this list?
Upvotes: 0
Views: 1905
Reputation: 31
The problem was solved with the usage of Java.cast
.
// ...
var list = Java.cast(value, Java.use("java.util.List"));
Upvotes: 3