memoryjs icon indicating copy to clipboard operation
memoryjs copied to clipboard

ReadMemory stops working at random

Open innosflew opened this issue 5 years ago • 9 comments

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)

innosflew avatar Jan 23 '20 19:01 innosflew

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-- avatar Jan 23 '20 20:01 Rob--

Can you show me the next line of memory too?

Rob-- avatar Jan 23 '20 21:01 Rob--

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

innosflew avatar Jan 23 '20 21:01 innosflew

Here is a bigger pic of it: image

innosflew avatar Jan 23 '20 21:01 innosflew

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?

Rob-- avatar Jan 23 '20 21:01 Rob--

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

innosflew avatar Jan 23 '20 22:01 innosflew

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

Rob-- avatar Jan 27 '20 14:01 Rob--

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

innosflew avatar Jan 29 '20 16:01 innosflew

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-- avatar Feb 07 '20 11:02 Rob--

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

Rob-- avatar Oct 30 '22 16:10 Rob--