I am having an issue with a JavaScript script to be executed in Frida. In this case, I am intercepting an input from a function where I receive an array of bytes. I need to convert this array to a string, modify it, and then convert it back to an array of bytes before returning the value.
I managed to make the first step work correctly, which is converting the array of bytes into a string and modifying the string. However, the problem arises when I try to convert the string back into an array of bytes; it throws an error. I tried using the Java native function getBytes(), but it gives the error below:
TypeError: not a function
My code is:
//result is byte[]
let StringJava = Java.use("java.lang.String");
var json = StringJava.$new(result);
try {
let arg1 = StringJava.$new(": 0,");
let arg2 = StringJava.$new(": 1000,");
json = json.replace(arg1,arg2);
let newByte = json.getBytes(); //error in line
return newByte;
} catch (error) {
console.log("error:", error);
}
Is there a simple way for me to convert this string back into an array of bytes?