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

The library can't read memory for me can someone help me figure it out? #103

Closed Patrick-van-Halm closed 1 year ago

Patrick-van-Halm commented 1 year ago

process.js

import memoryjs from "memoryjs";
export class Process {
    #handle
    #modules

    constructor(processName) {
        this.#handle = memoryjs.openProcess(processName);
        if(!this.#handle) throw new Error("process not found");

        this.#modules = memoryjs.getModules(this.#handle.th32ProcessID);
    }

    PID() {
        return this.#handle.th32ProcessID;
    }

    read(address, datatype) {
        return memoryjs.readMemory(this.#handle, address, datatype);
    }
}

index.js

import { Process } from "./process.js";
import memoryjs from "memoryjs";

let process = new Process("F1_22.exe");
console.log(process.PID());
console.log(0x16991C388)
console.log(process.read(0x16991C388, memoryjs.INT32));

Error

$ node .
16224
6066127752
E:\Documents\Projects\node-memory\node_modules\memoryjs\index.js:49
    return memoryjs.readMemory(handle, address, dataType.toLowerCase());
                    ^

Error: A number was expected
    at Object.readMemory (E:\Documents\Projects\node-memory\node_modules\memoryjs\index.js:49:21)
    at Process.read (file:///E:/Documents/Projects/node-memory/process.js:29:25)
    at file:///E:/Documents/Projects/node-memory/index.js:7:21
    at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
error Command failed with exit code 1.

Node version: v14.15.0

I did rebuild the binaries.

I also tried to run the library with node 16.18.0 (LTS), this results in a different error

Error: Error in native callback
    at Object.readMemory (E:\Documents\Projects\node-memory\node_modules\memoryjs\index.js:49:21)
    at Process.read (file:///E:/Documents/Projects/node-memory/process.js:29:25)
    at file:///E:/Documents/Projects/node-memory/index.js:8:21
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
error Command failed with exit code 1.
Rob-- commented 1 year ago

Hi, please refer to the read me.

memoryjs.openProcess returns a process object:

{ dwSize: 304,
  th32ProcessID: 10316,
  cntThreads: 47,
  th32ParentProcessID: 7804,
  pcPriClassBase: 8,
  szExeFile: "csgo.exe",
  modBaseAddr: 1673789440,
  handle: 808 }

You need to use the handle property from openProcess and pass it to the readMemory function:

const processObject = memoryjs.openProcess(processName);
this.#handle = processObject.handle;
Patrick-van-Halm commented 1 year ago

Hi, please refer to the read me.

memoryjs.openProcess returns a process object:

{ dwSize: 304,
  th32ProcessID: 10316,
  cntThreads: 47,
  th32ParentProcessID: 7804,
  pcPriClassBase: 8,
  szExeFile: "csgo.exe",
  modBaseAddr: 1673789440,
  handle: 808 }

You need to use the handle property from openProcess and pass it to the readMemory function:

const processObject = memoryjs.openProcess(processName);
this.#handle = processObject.handle;

Ahhh okay then I completely missed that my bad