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

Reading an address that is a BigInt throwing errors? #102

Closed pragunvohra closed 1 year ago

pragunvohra commented 1 year ago

Hi Rob,

Fantastic library, thanks for making this!

I'm not sure if I am doing something wrong here, but it looks to me as though although the library is perfectly capable of reading uint64/bigints, it does not seem to accept them as an address for reading.

E.g. calling memoryjs.readMemory(handle, BigInt(0x0), memoryjs.BYTE) seems to throw an error.

Uncaught Error Error: A number was expected
    at readMemory (c:\git\myproject\node_modules\memoryjs\index.js:121:23)

Changing the below in memoryjs.cc ~ line 330 seems to fix it (and updating the corresponding call in memoryjs readMemory's method):

 DWORD64 address = args[1].As<Napi::Number>().Int64Value();

to

 bool lossless = false;
 DWORD64 address = args[1].As<Napi::BigInt>().Int64Value(&lossless);

and in memoryjs's index.js changing readMemory to wrap the value like so:

 return memoryjs.readMemory(handle, BigInt(address), dataType.toLowerCase());

Granted, there are other places that would also need such changes done.

Thank you!

Rob-- commented 1 year ago

Hi @pragunvohra, and thanks! BigInt is only supported for writing and reading 64 bit integers. Adding support for BigInt to be used as memory addresses is on my TODO list now, so I will keep the issue open until then, thanks for raising it :)

Patrick-van-Halm commented 1 year ago

Thanks @pragunvohra I temporarily implemented your fix for BigInt addresses (handy to read pointers) locally. Can't wait till Rob has officially worked this into the project :)

Rob-- commented 1 year ago

Added support for this in f6a0861