admin管理员组

文章数量:1435859

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.

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.

Share Improve this question asked Jun 17, 2022 at 12:04 user19358595user19358595 1
  • Another trick when calling a function is not to let Frida chose the correct overload but instead define the overloaded function to be called (targetMethod = ) and then targetMethod.call it as shown in this example: stackoverflow./a/65969575/150978 – Robert Commented Jun 17, 2022 at 17:31
Add a ment  | 

1 Answer 1

Reset to default 5

Instead of trying to construct a java.util.List and then convert it to an array I would use the Frida function Java.array and directly construct a Java String array:

var javaStringArray = Java.array('java.lang.String', [ "Test" ]);

本文标签: javascriptConstructing a string array with FridaStack Overflow