It would be very cool if Frida allowed you to map raw memory to JavaScript objects (and vice-versa)
Example:
Let's say I have a NativePointer pointing to the following C structure:
struct example {
uint32_t field1;
char* field2;
uint64_t field3;
}
It would be cool if I could just interact with it as a javascript object, by providing Frida with some informations about the structure of such object (similar to what happens with NativeFunction)
let structAddress = new NativePointer("0xdeadbeef");
let structMap = { field1: "uint", field2: "pointer", field3: "ulong" };
let mappedStruct = Frida.FunctionWhichDoesNotExistYet(structAddress, structMap);
console.log("example.field1: " + mappedStruct.field1);
console.log("example.field2: " + mappedStruct.field2);
...
This could be used not only for reading properties, but also for writing (or updating):
mappedStruct.field1 = 420; // This would actually simulate 'structAddress.add(0x0).WriteU32(420)'
mappedStruct.field2 = new NativePointer("0x0"); // This would actually simulate 'structAddress.add(0x4).WritePtr(0x0)'
// ... and so on
Totally agree; this is something I've been thinking about adding at some point. The hard part is figuring out the API. We cannot use an object like in the above example, as the ordering of keys is not well-defined. But we could use an array of tuples perhaps.
As far as I know, any engine which supports ES2015 should be compliant with preserving properties order: https://stackoverflow.com/a/23202095
Regarding Duktape, it seems that they comply with the specification as well, despite not supporting ES2015: https://github.com/svaarala/duktape/issues/1053#issuecomment-258224041
(Sorry for the delay here, I got lost in a context-switch.) Ahh nice! Would be great to design it like that then! Now we just have to figure out the rest of the API 馃槉
Most helpful comment
(Sorry for the delay here, I got lost in a context-switch.) Ahh nice! Would be great to design it like that then! Now we just have to figure out the rest of the API 馃槉