Rob-- / memoryjs

Read and write process memory in Node.js (Windows API functions exposed via Node bindings)
MIT License
632 stars 86 forks source link

memoryjs not returning BigInt; breaks 64 bit pointers #74

Closed cspotcode closed 2 years ago

cspotcode commented 3 years ago

I'm not certain, but it looks to me like memoryjs is returning JavaScript numbers when getting pointers. 64bit pointers exceed the capacity of a JavaScript number. For that you need to use BigInt. I'm not sure, but I think this means memoryjs needs to somehow return BigInts when reading very large numbers and pointers.

Does this sounds correct? Am I wrong about part of this?

Rob-- commented 2 years ago

Good suggestion, there is Napi support for BigInt, or we could return strings and convert them to BigInt in JS space.

Would need to think about the implementation here, e.g. will everything return BigInt or just certain types. This will be a breaking change, unless it's implemented through a new method e.g. safeReadMemory.

Rob-- commented 2 years ago

147b970 adds support for BigInt for 64 bit integer data types.

When reading and writing the following types, the library will return and require a BigInt:

When reading and writing the following types, the library will return and require a BigInt only if the library is built to target a 64 bit application (so size of pointers is 8 bits, and not 4):

Example:

const value = memoryjs.readMemory(handle, address, memoryjs.INT64);
console.log(typeof value, value); // bigint 10n
memoryjs.writeMemory(handle, address, value + 25n, memoryjs.INT64); // writes 35n