Home > OS >  remove element from list while overload function with Frida
remove element from list while overload function with Frida

Time:05-17

I debug an android application with Frida and I overload function that return java.util.List<SomeObject>

I want to remove the first element from List that the function is return.

How can I do that please?

Java.perform(function x() {
    
    var my_class = Java.use("a.b");
    my_class.c.overload().implementation = function () { 
        var s= this.c(); // THE FUNCTION RETURN java.util.List<SomeObject>
        //HERE I WANT TO REMOVE THE FIRST ELEMENT IN S
        return s;
        
    };
});

Here is c function:

public List<SomeObject> c() {
        return this.c;
    }

CodePudding user response:

First you have to cast the variable s to java.util.List, then you can call methods on it or use it as argument, e.g. to create a new List.

The following code works if the List c() returns is mutable:

let s = this.c(); 
let list = Java.cast(s, Java.use("java.util.List"));
list.remove(0);
return list;

If the returned List is immutable you need to create a new mutable array and the delete then first element:

let s = this.c(); 
let list = Java.cast(s, Java.use("java.util.List"));
let newList = Java.use("java.util.ArrayList").$new(list);
newList.remove(0);
return newList;

Mutable Lists are e.g. ArrayList, LinkedList. Immutable are e.g. created by List.of(...) Arrays.asList(...), by wraping a list with Collections.unmodifiableList() or usually by stream/lambda expressions.

  • Related