Skip to content

Constructing a string array with Frida #255

Description

I'm trying to call a function with Frida that takes a string array as one of its arguments.

public void coolFunction(long value, String[] strArr);

Within Java it gets called like this:

long importantValue = 4L;
String[] importantArr = new String[]{"TEST"};
coolFunction(importantValue, importantArr);

The overload looks like this: .overload('long', '[Ljava.lang.String;')

I could probably create a string array from scratch, but I don't know how to express it in Javascript. What's the Frida equivalent of new String[]{"TEST"}?

Because of that I tried to turn an ArrayList<String> into a String[], which also wasn't successful.

As far as I can tell there are two simple ways to turn ArrayList<String> into String[]:

Attempt #1:

List<String> list = new ArrayList<String>();
list.add("TEST");
String[] stringArray = list.toArray(new String[0]);

If I try to express it with Javascript it looks like this:

var AL_class = Java.use("java.util.ArrayList");
var arrList = AL_class.$new();
arrList.add("TEST");
var stringArray = arrList.toArray(Java.use("[Ljava.lang.String;").$new(0));

This fails with the following error message:

Error: no supported overloads

Attempt #2:

List<String> list = new ArrayList<String>();
list.add("TEST");
Object[] objectArray = list.toArray();
String[] stringArray = (String[]) objectArray;

Javascript:

var AL_class = Java.use("java.util.ArrayList");
var arrList = AL_class.$new();
arrList.add("TEST");
var arrayButAsObject = arrList.toArray();
var stringArray = Java.cast(arrayButAsObject, "[Ljava.lang.String;");

This fails because it assumes that I want to use Javascript's toArray() function.

The solution to this problem is probably very simple but I've been stuck here for quite a while now and can't seem to figure it out. Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions