Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

memoryjs

> 包管理
Open source

Read and write process memory in Node.js (Windows API functions exposed via Node bindings)

679 stars0 likes0 views
WebsiteGitHub

About

Read and write process memory in Node.js (Windows API functions exposed via Node bindings)

memoryjs is a an NPM package to read and write process memory!


Features • Getting Started • Usage • Documentation • Debug

Features

  • List all open processes
  • List all modules associated with a process
  • Close process/file handles
  • Find a specific module within a process
  • Read and write process memory (w/big-endian support)
  • Read and write buffers (arbitrary structs)
  • Change memory protection
  • Reserve/allocate, commit or change regions of memory
  • Fetch a list of memory regions within a process
  • Pattern scanning
  • Execute a function within a process
  • Hardware breakpoints (find out what accesses/writes to this address, etc)
  • Inject & unload DLLs
  • Read memory mapped files

TODO:

  • WriteFile support (for driver interactions)
  • Async/await support

Getting Started

Install

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

You may also need to follow these steps to install and setup node-gyp.

bash
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 run one of the following compile scripts:

bash
# will automatically compile based on the detected Node architecture
npm run build

# compile to target 32 bit processes
npm run build32

# compile to target 64 bit processes
npm run build64

Node Webkit / Electron

If you are planning to use this module with Node Webkit or Electron, take a look at Liam Mitchell's build notes here.

Usage

Initialise

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

Processes

  • Open a process
  • Get all processes
  • Close a process (release handle)
javascript
// sync: open a process
const processObject = memoryjs.openProcess(processName);

// async: open a process
memoryjs.openProcess(processName, (error, processObject) => {});

// sync: get all processes
const processes = memoryjs.getProcesses();

// async: get all processes
memoryjs.getProcesses((error, processes) => {});

// close a process (release handle)
memoryjs.closeHandle(handle);

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

Modules

  • Find a module
  • Get all modules
javascript
// sync: find a module
const moduleObject = memoryjs.findModule(moduleName, processId);

// async: find a module
memoryjs.findModule(moduleName, processId, (error, moduleObject) => {});

// sync: get all modules
const modules = memoryjs.getModules(processId);

// async: get all modules
memoryjs.getModules(processId, (error, modules) => {});

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

Memory

  • Read data type from memory
  • Read buffer from memory
  • Write data type to memory
  • Write buffer to memory
  • Fetch memory regions
…

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

Memory Mapped Files

  • Open a named file mapping object
  • Map a view of a file into a specified process
  • Close handle to the file mapping object
javascript
// sync: open a named file mapping object
const fileHandle = memoryjs.openFileMapping(fileName);

// sync: map entire file into a specified process
const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName);

// sync: map portion of a file into a specified process
const baseAddress = memoryjs.mapViewOfFile(processHandle, fileName, offset, viewSize, pageProtection);

// sync: close handle to a file mapping object
const success = memoryjs.closeHandle(fileHandle);

See the Documentation section of this README to see details on the parameters and return values for these functions.

Protection

  • Change/set the protection on a region of memory
javascript
// sync: change/set the protection on a region of memory
const oldProtection = memoryjs.virtualProtectEx(handle, address, size, protection);

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

Pattern Scanning

  • Pattern scan all modules and memory regions
  • Pattern scan a given module
  • Pattern scan a memory region or module at the given base address
…

Function Execution

  • Execute a function in a remote process
javascript
// sync: execute a function in a remote process
const result = memoryjs.callFunction(handle, args, returnType, address);

// async: execute a function in a remote process
memoryjs.callFunction(handle, args, returnType, address, (error, result) => {});

Click here to see what a result object looks like.

Click here for details about how to format the arguments and the return type.

DLL Injection

  • Inject a DLL
  • Unload a DLL by module base address
  • Unload a DLL by module name
…

Hardware Breakpoints

  • Attach debugger
  • Detach debugger
  • Wait for debug event
  • Handle debug event
  • Set hardware breakpoint
  • Remove hardware breakpoint
…

Documentation

Note: this documentation is currently being updated, refer to the Wiki for more information.

Process Object

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

The handle and modBaseAddr properties are only available when opening a process and not when listing processes.

Module Object

javascript
{ 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,
  GlblcntUsage: 2 }

Result Object

javascript
{ returnValue: 1.23,
  exitCode: 2 }

This object is returned when a function is executed in a remote process:

  • returnValue is the value returned from the function that was called
  • exitCode is the termination status of the thread

Data Types

When using the write or read functions, the data type (dataType) parameter should reference a constant from within the library:

Constant Bytes Aliases Range
memoryjs.BOOL 1 memoryjs.BOOLEAN 0 to 1
memoryjs.INT8 1 memoryjs.BYTE, memoryjs.CHAR -128 to 127
memoryjs.UINT8 1 memoryjs.UBYTE, memoryjs.UCHAR 0 to 255
memoryjs.INT16 2 memoryjs.SHORT -32,768 to 32,767
memoryjs.UINT16 2 memoryjs.USHORT, memoryjs.WORD 0 to 65,535
memoryjs.INT32 4 memoryjs.INT, memoryjs.LONG -2,147,483,648 to 2,147,483,647
memoryjs.UINT32 4 memoryjs.UINT, memoryjs.ULONG, memoryjs.DWORD 0 to 4,294,967,295
memoryjs.INT64 8 n/a -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
memoryjs.UINT64 8 n/a 0 to 18,446,744,073,709,551,615
memoryjs.FLOAT 4 n/a 3.4E +/- 38 (7 digits)
memoryjs.DOUBLE 8 n/a 1.7E +/- 308 (15 digits)
memoryjs.PTR 4/8 memoryjs.POINTER n/a
memoryjs.UPTR 4/8 memoryjs.UPOINTER n/a
memoryjs.STR n/a memoryjs.STRING n/a
memoryjs.VEC3 12 memoryjs.VECTOR3 n/a
memoryjs.VEC4 16 memoryjs.VECTOR4 n/a

Notes:

  • all functions that accept an address also accept the address as a BigInt
  • pointer will be 4 bytes in a 32 bit build, and 8 bytes in a 64 bit build.
  • to read in big-endian mode, append _BE to the data type. For example: memoryjs.DOUBLE_BE.
  • when writing 64 bit integers (INT64, UINT64, INT64_BE, UINT64_BE) you will need to supply a BigInt. When reading a 64 bit integer, you will receive a BigInt.

These data types are to used to denote the type of data being read or written.

64 bit integer example:

javascript
const value = memoryjs.readMemory(handle, address, memoryjs.INT64);
console.log(typeof value); // bigint
memoryjs.writeMemory(handle, address, value + 1n, memoryjs.INT64);

Vector3 is a data structure of three floats:

javascript
const vector3 = { x: 0.0, y: 0.0, z: 0.0 };
memoryjs.writeMemory(handle, address, vector3, memoryjs.VEC3);

Vector4 is a data structure of four floats:

javascript
const vector4 = { w: 0.0, x: 0.0, y: 0.0, z: 0.0 };
memoryjs.writeMemory(handle, address, vector4, memoryjs.VEC4);

Generic Structures

If you have a structure you want to write to memory, you can use buffers. For an example on how to do this, view the buffers example.

To write/read a structure to/from memory, you can use structron to define your structures and use them to write or parse buffers.

If you want to read a std::string using structron, the library exposes a custom type that can be used to read/write strings:

javascript
// To create the type, we need to pass the process handle, base address of the
// structure, and the target process architecture (either "32" or "64").
const stringType = memoryjs.STRUCTRON_TYPE_STRING(processObject.handle, structAddress, '64');

// Create a custom structure using the custom type, full example in /examples/buffers.js
const Struct = require('structron');
const Player = new Struct()
  .addMember(string, 'name');

Alternatively, you can use the concentrate and dissolve libraries to achieve the same thing. An old example of this is here.

Protection Type

Protection type is a bit flag DWORD value.

This parameter should reference a constant from the library:

memoryjs.PAGE_NOACCESS, memoryjs.PAGE_READONLY, memoryjs.PAGE_READWRITE, memoryjs.PAGE_WRITECOPY, memoryjs.PAGE_EXECUTE, memoryjs.PAGE_EXECUTE_READ, memoryjs.PAGE_EXECUTE_READWRITE, memoryjs.PAGE_EXECUTE_WRITECOPY, memoryjs.PAGE_GUARD, memoryjs.PAGE_NOCACHE, memoryjs.PAGE_WRITECOMBINE, memoryjs.PAGE_ENCLAVE_THREAD_CONTROL, memoryjs.PAGE_TARGETS_NO_UPDATE, memoryjs.PAGE_TARGETS_INVALID, memoryjs.PAGE_ENCLAVE_UNVALIDATED

Refer to MSDN's Memory Protection Constants for more information.

Memory Allocation Type

Memory allocation type is a bit flag DWORD value.

This parameter should reference a constat from the library:

memoryjs.MEM_COMMIT, memoryjs.MEM_RESERVE, memoryjs.MEM_RESET, memoryjs.MEM_RESET_UNDO

Refer to MSDN's VirtualAllocEx documentation for more information.

Strings

You can use this library to read either a "string", or "char*" and to write a string.

In both cases you

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++cppgame-hackinghackingjavascript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image