Search code examples
javascriptfrida

Iterate over collection in Frida - Creating an iterator


I'm hooking a Java method in Frida which looks like

public ABC setSomething(Collection<RandObject> things) {
  this.things = new ArrayList(things);
  return this;
}

In javascript, I'm able to log the things parameter and it prints out the RandObjects. I'm also able to do a size() and get the total number of elements inside.

Anything I do to try to iterate over the collection doesn't work. You can't access elements with .get(X) or [X]. I can't do an Array.from since Frida doesn't seem to have that available. I believe I need to create an iterator to properly do this. How can I do that?

I was messing around with trying to instantiate Java.use("java.util.Iterator") but am stuck.


Solution

  • Figured it out:

    var iter = things.iterator();
    while(iter.hasNext()) {
      console.log(iter.next());
    }