Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: reviewdog
on: [pull_request]
jobs:
biome:
name: runner / Biome
name: Biome Linter
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile
- name: Setup zig
uses: mlugg/setup-zig@v1
run: bun install --frozen-lockfile --ignore-scripts --no-save

- name: Install node-gyp
run: bun add -g node-gyp

- name: Build
run: bun run build.ts
run: bun run build

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -78,7 +78,10 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install dependencies
run: npm install
run: npm ci --ignore-scripts

- name: Install semantic-release plugins
run: npm install @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/npm @semantic-release/github @semantic-release/git

- name: Run semantic-release
run: npx semantic-release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
lib
build
.vscode
.vs
.windsurfrules
Expand Down
10 changes: 9 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
!lib/
!lib/**

# Keep the assets directory and its contents
!assets/
!assets/**

# Keep essential files
!package.json
!README.md
!LICENSE
!CHANGELOG.md
!CHANGELOG.md

# Keep the lock files
!package-lock.json
!bun.lockb
141 changes: 62 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
> ⚠️ **WARNING:**
> This package relies heavily on **Bun's native FFI (`bun:ffi`)** for performance and interacting with system APIs.
> Furthermore, it interacts directly with the Windows API and is therefore **only compatible with Windows**.
>
> Currently, Bun does not provide a polyfill for `bun:ffi` when building for Node.js (`target: 'node'`). Therefore, this package is **only compatible with the Bun runtime** and **will not work** if run directly with Node.js.
>
> While Bun intends to add polyfills for `bun:*` modules in the future to improve Node.js compatibility for bundled code (see [Bundler Docs](https://bun.sh/docs/bundler#target)), this is not yet implemented for `bun:ffi`.
>
> **Requirements:**
> * Bun v1.2.9 or later (required to run the code)

---

<p align="center">
<img alt="Banner" src="assets/banner.png">
<br>
Expand All @@ -32,69 +19,65 @@
</a>
</p>

## Current Status

This package is currently under active development. The following core functions are implemented and available for use:

* `openProcess(processIdentifier: string | number): ProcessObject`: Opens a process by its name or ID.
* `closeProcess(handle: number): void`: Closes an opened process handle.
* `readMemory(handle: number, address: number, dataType: MemoryDataType): number`: Reads memory from a specific address in the target process. **Note:** Currently returns `number` for all types, including strings (returning the address). String content reading is planned.
* `writeMemory(handle: number, address: number, value: MemoryValueType, dataType: MemoryDataType): void`: Writes memory to a specific address in the target process.

The `ProcessObject` object returned by `openProcess` contains information about the opened process:

```typescript
interface ProcessObject {
dwSize: number; // Size of the structure, in bytes
th32ProcessID: number; // Process identifier (PID)
cntThreads: number; // Number of execution threads started by the process
th32ParentProcessID: number; // PID of the parent process
pcPriClassBase: number; // Base priority of threads created by this process
szExeFile: string; // Path to the executable file
handle: number; // Process handle (for read/write operations)
modBaseAddr: number; // Base address of the process's primary module
}
```

More functions are planned for future releases to expand the capabilities of this library.

## Data Types

The `dataType` parameter in `readMemory` and `writeMemory` specifies the type of data to be read or written. It accepts a specific set of string literals defined by the `MemoryDataType` type in TypeScript. The `value` parameter for `writeMemory` should correspond to this type, as defined by `MemoryValueType` (number, string, or boolean).

### Supported Data Type Strings

The following data type strings (and their aliases) are supported:

* **8-bit Signed:** `byte`, `int8`, `char`
* **8-bit Unsigned:** `ubyte`, `uint8`, `uchar`
* **16-bit Signed:** `short`, `int16`
* **16-bit Unsigned:** `ushort`, `uint16`, `word`
* **32-bit Signed:** `int`, `int32`, `long`
* **32-bit Unsigned:** `uint`, `uint32`, `ulong`, `dword`
* **64-bit Signed:** `longlong`, `int64` (uses BigInt)
* **64-bit Unsigned:** `ulonglong`, `uint64` (uses BigInt)
* **Floating Point:** `float` (4 bytes), `double` (8 bytes)
* **Boolean:** `bool` (1 byte, 0 or 1)
* **String:** `string`, `str` (Null-terminated UTF-8)

### TypeScript Type Definitions

```typescript
/** Represents the valid data types for memory operations. */
export type MemoryDataType =
| "byte" | "int8" | "char" // 8-bit signed
| "ubyte" | "uint8" | "uchar" // 8-bit unsigned
| "short" | "int16" // 16-bit signed
| "ushort" | "uint16" | "word" // 16-bit unsigned
| "int" | "int32" | "long" // 32-bit signed
| "uint" | "uint32" | "ulong" | "dword" // 32-bit unsigned
| "float" // 32-bit float
| "double" // 64-bit float
| "longlong" | "int64" // 64-bit signed (Note: JS Number limitations apply)
| "ulonglong" | "uint64" // 64-bit unsigned (Note: JS Number limitations apply)
| "bool"
| "string" | "str"; // Null-terminated string

/** Represents the possible value types corresponding to MemoryDataType. */
export type MemoryValueType = number | string | boolean;
---

## 📖 API References (`src`)

### Main Functions

- **openProcess(processIdentifier: string | number, callback?): Process**
Opens a process by name or ID. Returns the process handle or undefined if not found.

- **closeHandle(handle: number): boolean**
Closes a process handle.

- **getProcesses(callback?): Process[]**
Returns the list of running processes.

- **findModule(moduleName: string, processId: number, callback?): Module | undefined**
Finds a module by name in a process.

- **getModules(processId: number, callback?): Module[]**
Returns the modules loaded by a process.

- **readMemory<T extends DataType>(handle: number, address: number, dataType: T, callback?): MemoryData<T> | undefined**
Reads a value from a process's memory.

- **writeMemory(handle: number, address: number, value: any, dataType: DataType): boolean**
Writes a value to a process's memory.

- **findPattern(...)**
Scans memory patterns (multiple overloads).

- **callFunction(handle: number, args: any[], returnType: number, address: number, callback?): any**
Calls a function in the process's memory.

- **Debugger**
Utility class for process debugging. Main methods: `attach`, `detach`, `setHardwareBreakpoint`, `removeHardwareBreakpoint`, `monitor`.

- **virtualAllocEx, virtualProtectEx, getRegions, virtualQueryEx, injectDll, unloadDll, openFileMapping, mapViewOfFile**
Advanced memory and DLL manipulation functions.

### Main Types and Constants (`types.ts`)

- **type DataType**
Supported data types for memory read/write: `'byte'`, `'int32'`, `'float'`, `'string'`, `'vector3'`, etc.

- **type MemoryData<T extends DataType>**
Maps a `DataType` to its corresponding JS type (`number`, `bigint`, `string`, `{x,y,z}`...)

- **interface Process**
Information about an opened process (PID, handle, etc).

- **interface Module**
Information about a module loaded in a process.

- **type Protection, PageProtection, AllocationType, BreakpointTriggerType**
Auxiliary types for memory flags and protection.

- **const FunctionTypes, SignatureTypes, MemoryAccessFlags, MemoryPageFlags, HardwareDebugRegisters, BreakpointTriggerTypes**
Constants for flags and function types.

---

> See the [`src`](./src) folder for full details and comments on each function/type.
20 changes: 20 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"targets": [
{
"target_name": "native",
"include_dirs" : [
"<!@(node -p \"require('node-addon-api').include\")"
],
"sources": [
"native/memoryprocess.cc",
"native/memory.cc",
"native/process.cc",
"native/module.cc",
"native/pattern.cc",
"native/functions.cc",
"native/debugger.cc"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
}
]
}
121 changes: 0 additions & 121 deletions build.ts

This file was deleted.

Loading
Loading