Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reading BigInt pointer #114

Open
alorodri opened this issue Sep 5, 2023 · 6 comments
Open

Error reading BigInt pointer #114

alorodri opened this issue Sep 5, 2023 · 6 comments

Comments

@alorodri
Copy link

alorodri commented Sep 5, 2023

Hello!

In this code, it fails to read the memory from the first pointer, when it sums the offset and tries to readMemory again the new address. Elden Ring is a x64 game, I compiled memoryjs with build64 and I had no problem getting the first ptr value. The problem comes with the second readMemory call, because the first returns a BigInt, then when I call again I must pass an address that is a BigInt, and then it shows me that error:

C:\Users\alope\source\repos\electronTestWindows\node_modules\memoryjs\index.js:49
    return memoryjs.readMemory(handle, address, dataType.toLowerCase());
                    ^

Error: Error in native callback
    at Object.readMemory (C:\Users\alope\source\repos\electronTestWindows\node_modules\memoryjs\index.js:49:21)
    at readMemory (C:\Users\alope\source\repos\electronTestWindows\test.js:16:26)
    at Object.<anonymous> (C:\Users\alope\source\repos\electronTestWindows\test.js:24:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.17.1

Some useful data:

Object process

{
  dwSize: 304,
  th32ProcessID: 30796,
  cntThreads: 97,
  th32ParentProcessID: 32248,
  pcPriClassBase: 8,
  szExeFile: 'eldenring.exe',
  handle: 564,
  modBaseAddr: 2061870039768
}

That's my code:

const memoryjs = require("memoryjs");

function readMemory() {
  const processName = "eldenring.exe";
  const offset1 = 0x3cd4d88;
  const offset2 = 0x94;

  const processObject = memoryjs.openProcess(processName);
  const baseAddress = processObject.modBaseAddr;
  const ptrToValue = memoryjs.readMemory(
    processObject.handle,
    baseAddress + offset1,
    memoryjs.PTR
  );

  const value = memoryjs.readMemory(
    processObject.handle,
    ptrToValue + BigInt(offset2),
    memoryjs.INT64
  );
  console.log(value);
}

readMemory();

Thanks in advance!

@Danovich
Copy link

Hey @alorodri,

I have the same error, did you manage to figure it out?
If I pass BigInt to func it fails even though it should support it @Rob-- .

all functions that accept an address also accept the address as a BigInt

@alorodri
Copy link
Author

alorodri commented Oct 23, 2023

Hey @alorodri,

I have the same error, did you manage to figure it out? If I pass BigInt to func it fails even though it should support it @Rob-- .

all functions that accept an address also accept the address as a BigInt

Hey @Danovich ! Besides idk if it's the correct solution, I've been able to manage it casting the address to Number before passing it again to the readMemory function.

@Danovich
Copy link

@alorodri and the data you get from readMemory is correct? Converting bigint to number is sketchy as you can go over the MAX_SAFE_INTEGER and lose accuracy...

@alorodri
Copy link
Author

@alorodri and the data you get from readMemory is correct? Converting bigint to number is sketchy as you can go over the MAX_SAFE_INTEGER and lose accuracy...

In my case it worked and I got the value I was searching for, but seems it loses accuracy and can result in errors if the Number is > 2^54 or something like that.

@Danovich
Copy link

@Rob-- any updates on this issue?

@Rob--
Copy link
Owner

Rob-- commented Mar 29, 2024

Hi, will fix this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants