Skip to content
Advertisement

Frida Casting object to List of Strings

I have been trying to print out the contents of a list when hooking an android app with Frida but am not having any luck.

The object I want to hook in Java looks like this

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;

public final class Hello extends HelloParent{

    @JsonIgnore
    public final List sampleList;

}

There aren’t any getters for this public object so I have to resort to using another object (Let’s call the object “Bye”)’s method (byeMethodB) to monitor this value.

This is what my frida-script looks like:

setTimeout(function() {

    Java.perform(function(){
        
        Java.use("Bye").byeMethodA.implementation = function(){

            try{
                //Returns a Hello object
                var helloObject = Java.cast(this.byeMethodB(),Java.use("Hello"))
                printListContent(Java.cast(helloObject.sampleList,Java.use("java.util.List"))))
            }catch(err){
                console.log(err)
            }
        }

    })
},1000)

function printListContent(list){

    var listIter = list.iterator()
    while(listIter.hasNext()){
        console.log(listIter.next())
    }

}

Without casting the “helloObject.sampleList” object to a list, the output looks like this:

[object Object]

So I am sure it is not null

If I cast using Java.cast(helloObject.sampleList,Java.use("java.util.List")),

I get the following error:

java.util.List

I have also tried:

Java.cast(helloObject.sampleList,Java.use("java.util.List<>"))

java.util.List<>

(I am pretty sure its a String) Java.cast(helloObject.sampleList,Java.use("java.util.List<String>"))

java.util.List

Java.cast(helloObject.sampleList,Java.use("java.util.List<java.lang.String>"))

java.util.List<java.lang.String>

Java.cast(helloObject.sampleList,Java.use("[String"))

[LString

Java.cast(helloObject.sampleList,Java.use("[Ljava.lang.String"))

[Ljava.lang.String

It is not going well at all. Would appreciate some help

Advertisement

Answer

In Frida accessing fields is not identical as in Java. If you execute helloObject.sampleList in Frida you are getting the JavaScript object that describes the field, not the field value itself.

If you want the field value you have to execute helloObject.sampleList.value.

Therefore the following code should work:

Java.cast(helloObject.sampleList.value, Java.use("java.util.List"));

Generics only exists at compile time but frida is working at run-time. Therefore java.util.List<> and the other class names with angle bracket will never work.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement