memoryjs

Memory reading and memory writing in NodeJS (via node addon) (finally!)

memoryjs

Node add-on for memory reading and writing! (finally!)

Features

  • open a process
  • close the process (handle)
  • list all open processes
  • list all modules associated with a process
  • find a certain module associated with a process
  • read memory
  • write to memory
  • pattern scanning

TODO: - nothing (suggestions welcome)

Install

This is a Node add-on (last tested to be working on v6.9.1) and therefore requires node-gyp to use.

You may also need to follow these steps.

npm install memoryjs

When using memoryjs, the target process should match the platform architecture of the Node version running. For example if you want to target a 64 bit process, you should try and use a 64 bit version of Node.

You also need to recompile the library and target the platform you want. Head to the memoryjs node module directory, open up a terminal and to run the compile scripts, type:

npm run build32 if you want to target 32 bit processes

npm run build64 if you want to target 64 bit processes

Usage

For a complete example, view index.js and example.js.

Initialise:

var memoryjs = require('memoryjs');
var processName = "csgo.exe";

Processes

Open a process (sync):

var processObject = memoryjs.openProcess(processName);

Open a process (async):

memoryjs.openProcess(processName, function(err, processObject){

});

Get all processes (sync):

var processes = memoryjs.getProcesses();

Get all processes (async):

memoryjs.getProcesses(function(err, processes){

});

See the Documentation section of this README to see what a process object looks like.

Modules

Find a module (sync):

var module = memoryjs.findModule(moduleName, processId);

Find a module (async):

memoryjs.findModule(moduleName, processId, function(err, module){

});

Get all modules (sync):

var modules = memoryjs.getModules(processId);

Get all modules (async):

memoryjs.getModules(processId, function(err, modules){

});

See the Documentation section of this README to see what a module object looks like.

Memory

Read from memory (sync):

memoryjs.readMemory(address, dataType);

Read from memory (async):

memoryjs.readMemory(address, dataType, function(err, result){

});

Write to memory:

memoryjs.writeMemory(address, value, dataType);

See the Documentation section of this README to see what values dataType can be.

Pattern scanning

Pattern scanning (sync):

var offset = memoryjs.findPattern(moduleName, signature, signatureType, patternOffset, addressOffset);

Pattern scanning (async):

memoryjs.findPattern(moduleName, signature, signatureType, patternOffset, addressOffset, function(err, offset){

})

Documentation

Process object:

{  cntThreads: 47,
   szExeFile: "csgo.exe",
   th32ProcessID: 10316,
   th32ParentProcessID: 7804,
   pcPriClassBase: 8 }

Module object:

{ modBaseAddr: 468123648,
  modBaseSize: 80302080,
  szExePath: 'c:\\program files (x86)\\steam\\steamapps\\common\\counter-strike global offensive\\csgo\\bin\\client.dll',
  szModule: 'client.dll',
  th32ProcessID: 10316 }

Data Type:

When using the write or read functions, the data type (dataType) parameter can either be a string and be one of the following:

"int", "dword", "long", "float", "double", "bool", "boolean", "str", "string", "vec3", "vector3"

or can reference constants from within the library:

memoryjs.INT, memoryjs.DWORD, memoryjs.LONG, memoryjs.FLOAT, memoryjs.DOUBLE, memoryjs.BOOL, memoryjs.BOOLEAN, memoryjs.STR, memoryjs.STRING, memoryjs.VEC3, memoryjs.VECTOR3

This is simply used to denote the type of data being read or written.

Vector3 is a data structure of three floats:

var vector = { x: 0.0, y: 0.0, z: 0.0 };
memoryjs.writeMemory(address, vector);

Signature Type:

When pattern scanning, flags need to be raised for the signature types. The signature type parameter needs to be one of the following:

0x0 or memoryjs.NORMAL which denotes a normal signature.

0x1 or memoryjs.READ which will read the memory at the address.

0x2 or memoryjs.SUBSTRACT which will subtract the image base from the address.

To raise multiple flags, use the bitwise OR operator: memoryjs.READ | memoryjs.SUBTRACT.


openProcess(processName[, callback])

opens a process to be able to read from and write to it

  • processName (string) - the name of the process to open
  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • processObject (JSON [process object]) - information about the process

returns process object (JSON) either directly or via the callback


closeProcess()

closes the handle on the opened process


getProcesses([callback])

collects information about all the running processes

  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • processes (array) - array of process object (JSON)

returns an array of process object (JSON) for all the running processes


findModule(moduleName, processId[, callback])

finds a module associated with a given process

  • moduleName (string) - the name of the module to find
  • processId (int) - the id of the process in which to find the module
  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • module (JSON [module object]) - information about the module

returns module object (JSON) either directly or via the callback


getModules(processId[, callback])

gets all modules associated with a given process

  • processId (int) - the id of the process in which to find the module
  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • modules (array) - array of module object (JSON)

returns an array of module object (JSON) for all the modules found


readMemory(address, dataType[, callback])

reads the memory at a given address

  • address (int) - the address in memory to read from
  • dataType (string) - the data type to read into (definitions can be found at the top of this section)
  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • value (any data type) - the value stored at the given address in memory

returns the value that has been read from memory


writeMemory(address, value, dataType[, callback])

writes to an address in memory

  • address (int) - the address in memory to write to
  • value (any data type) - the data type of value must be either number, string or boolean and is the value that will be written to the address in memory
  • dataType (string) the data type of the value (definitions can be found at the top of this section)
  • callback (function) - has one parameter:
    • err (string) - error message (empty if there were no errors)

findPattern(moduleName, signature, signatureType, patternOffset, addressOffset[, callback])

pattern scans memory to find an offset

  • moduleName (string) - the name of the module to pattern scan (module.szModule)
  • signature (string) - the actual signature mask (in the form A9 ? ? ? A3 ?)
  • signatureType (int) - flags for signature types (definitions can be found at the top of this section)
  • patternOffset (int) - offset will be added to the address (before reading, if memoryjs.READ is raised)
  • addressOffset (int) - offset will be added to the address returned
  • callback (function) - has two parameters:
    • err (string) - error message (empty if there were no errors)
    • offset (int) - value of the offset found (will return -1 if the module was not found, -2 if the pattern found no address)

returns the value of the offset found

Related Repositories

memoryjs

memoryjs

Memory reading and memory writing in NodeJS (via node addon) (finally!) ...