Rob-- / memoryjs

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

ReadMemory stops working at random #54

Closed innosflew closed 2 years ago

innosflew commented 4 years ago

I'm trying to use memory.js to read the in game data, such as location, of Red Dead Redemption 2, to display it in Discord. My only issue is that the same memory addresses stop working at random after a while.

I checked with Cheat Engine to make sure the addresses haven't changed between gaming sessions and from what I've seen they haven't. The addresses I use still display the same values. Memory.js gives me the following error:

TypeError: unable to read string (no null-terminator found after 1 million chars)
    at Object.readMemory (C:\bots\node_modules\memoryjs\index.js:104:23)
    at test (C:\bots\index.js:42:32)

At line 42 in my code is the ReadMemory function: memoryjs.readMemory(handle, address, memoryjs.STRING)

Rob-- commented 4 years ago

What does the memory at that address look like in Cheat Engine? In the hex display is there a null terminator after the name of the location?

Rob-- commented 4 years ago

Can you show me the next line of memory too?

innosflew commented 4 years ago

The memory address is 7FF60D7CE4F8 and this is what it looks like in Memory Viewer in Cheat Engine: image

innosflew commented 4 years ago

Here is a bigger pic of it: image

Rob-- commented 4 years ago

Replace all the code from L440 to L473 with this:

char value[1000000];
ReadProcessMemory(handle, (LPVOID) address, value, 1000000, NULL);
if (args.Length() == 4) argv[1] = String::NewFromUtf8(isolate, str.c_str());
else args.GetReturnValue().Set(String::NewFromUtf8(isolate, str.c_str()));

Recompile, and see if that works?

Essentially what it's doing right now is reading 1 character at a time continuously until it finds a null terminator (but this is probably a terrible method), and the 4 lines of code above just try to read 1 million chars at once, but it should include a null terminator. So try that and see if it helps?

By the way, I haven't tested this but hopefully it's directly copy-pastable and works without any errors?

innosflew commented 4 years ago

I'm not very well versed in C++ but I modified the file with your suggestion and tried to compile it and it gave me this error: image

Rob-- commented 4 years ago

You aren't compiling it correctly, in the module directory run npm run build32 or npm run build64.

innosflew commented 4 years ago

Oh sorry, I feel stupid now 😅

But anyways, I replaced the code like this: image

And I tried to compile, but I got an error: image

Rob-- commented 4 years ago

Oops it's because the code I gave you was wrong, sorry it's because I just typed it out without testing:

char value[1000000];
ReadProcessMemory(handle, (LPVOID) address, value, 1000000, NULL);
if (args.Length() == 4) argv[1] = String::NewFromUtf8(isolate, value);
else args.GetReturnValue().Set(String::NewFromUtf8(isolate, value));

That should hopefully work!

Rob-- commented 2 years ago

I've since updated the reading/writing of strings, closing the issue for now.