Understand Java to JS type marshalling rules
masterrustFrida automatically converts types between the Java (JNI) and JavaScript runtimes.
Java → JS (Automatic Conversion)
- Primitives:
boolean$\rightarrow$boolean,int/short/byte$\rightarrow$number,long$\rightarrow$BigInt,float/double$\rightarrow$number. - Strings:
java.lang.String$\rightarrow$string. - Arrays: Primitive arrays (
[I,[B, etc.) $\rightarrow$Arrayof numbers. Object arrays $\rightarrow$Arrayof wrappers. - Objects: Most objects are returned as wrappers
{__jptr, __jclass}. You must use.method()or.field.valueto interact with them. - Boxed Types:
Integer,Long, etc., are NOT automatically unboxed. You must call.intValue(),.doubleValue(), etc., to get the primitive value.
JS → Java (Automatic Conversion)
- Primitives: JS
numberorBigIntare automatically converted to the target JNI type. - Strings: JS
stringis converted tojava.lang.String. - Arrays: JS
Arrayis converted to the target Java array type. For primitive arrays, rustFrida uses bulk copying for efficiency. - Autoboxing: If a target signature is a boxed type (e.g.,
Ljava/lang/Integer;), JS primitives are automatically autoboxed usingXxx.valueOf(). - Ambiguity: For overloaded array methods (e.g.,
foo(byte[])vsfoo(int[])), rustFrida scores the JS input array based on whether the elements fit within the target type's range.