Closed cspotcode closed 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
.
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:
memoryjs.INT64
, memoryjs.UINT64
, memoryjs.INT64_BE
, memoryjs.UINT64_BE
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):
memoryjs.PTR
, memoryjs.POINTER
, memoryjs.UPTR
, memoryjs.UPOINTER
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
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?