Rob-- / memoryjs

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

Confusion about using pointers. #42

Closed ChristianTucker closed 2 years ago

ChristianTucker commented 5 years ago

I'm a little new to all of this, so please excuse my ignorance if I'm doing something wrong. I have a game that I'm going to call "game.exe" and the offset to the local player, and then a list of offsets that I want to obtain data for.

Here's what reading from this data looks like in C++

float GetHealth() {
    auto address = *(DWORD*)(BASE_ADDRESS + LOCAL_PLAYER_OFFSET);
    return *(float*)(address + OFFSET_HEALTH);
}

Here is what I'm trying the memoryjs

mjs.readMemory(process.handle, (baseAddress + localPlayerAddress) + healthOffset, mjs.FLOAT, (err, value) => {
        // ...
})

Printing these values out to hex shows up like this:

Base address: 1150000
Local player offset: 2f457fc
Health offset: 2280e0
Base + Local Player 40957fc
Health address: 42bd8dc

This is of-course being printed with .toString(16)

Not really sure what I'm doing wrong, as it grabs the correct value in C++ but not in memoryjs (I'm probably doing something wrong).

Rob-- commented 5 years ago

Read ‘baseAddress + localPlayerAddress’ as DWORD. Then read that value + healthOffset as float.

ChristianTucker commented 5 years ago

So, here's what I came up with (and tried before making this issue)

memoryjs.openProcess("League of Legends.exe", (error, process) => {
    if(error) return console.error(error); 
    if(!process.szExeFile) return console.error("Failed to open handle, szExeFile not found.");
    const baseAddress = process.modBaseAddr;
    const oLocalPlayer = 0x2F457FC; 
    const oHealth = 0x0DE8;
    const pointer = memoryjs.readMemory(process.handle, baseAddress + oLocalPlayer, memoryjs.DWORD); 
    const health = memoryjs.readMemory(process.handle, pointer + oHealth, memoryjs.FLOAT); 
    console.log("Health:", health);
});

This prints a value of 1.0062128199535909e-31 which is definitely wrong, as it should be 586. Reading directly in C++ reflects this with a value of 586.xxxxxxxxxxx.

This value also changes every time I query the memory, even though my health is not changing.

Just trying this out for fun

jlanio commented 5 years ago

solved the problem?

p410n3 commented 5 years ago

So, here's what I came up with (and tried before making this issue)

memoryjs.openProcess("League of Legends.exe", (error, process) => {
    if(error) return console.error(error); 
    if(!process.szExeFile) return console.error("Failed to open handle, szExeFile not found.");
    const baseAddress = process.modBaseAddr;
    const oLocalPlayer = 0x2F457FC; 
    const oHealth = 0x0DE8;
    const pointer = memoryjs.readMemory(process.handle, baseAddress + oLocalPlayer, memoryjs.DWORD); 
    const health = memoryjs.readMemory(process.handle, pointer + oHealth, memoryjs.FLOAT); 
    console.log("Health:", health);
});

This prints a value of 1.0062128199535909e-31 which is definitely wrong, as it should be 586. Reading directly in C++ reflects this with a value of 586.xxxxxxxxxxx.

This value also changes every time I query the memory, even though my health is not changing.

Just trying this out for fun

If I am not mistaken, LoL runs 32 bit. Did you run npm run build32 ?

Just a shot in the blue. I cannot see anything majorly wrong with the code itself.

EDIT: try to make pointer and health use let and not const. I have had some problems with that in the past.

p410n3 commented 4 years ago

Oh additionally, all of that may even be caused by some anti cheat fuckery.

Rob-- commented 2 years ago

Closing, please comment if you still need help.

Notes: