Skip to content

Commit c40fdf2

Browse files
authored
Migrate to TypeScript and build .node in CI (#29)
* chore(package): update package metadata and repository URLs * refactor(core): use const char* for error messages Replaces char* with const char* for error message parameters and variables in debugger, module, and process components to improve type safety and clarify intent. * chore: remove legacy C++ bindings and JavaScript code * feat: migrate implementation to TypeScript * build: update build tooling and configuration * docs: update README and LICENSE * ci: add GitHub workflows * chore(assets): add banner image * feat: add TypeScript examples * chore: remove source and config files Deleted the following files as part of repository cleanup: - .gitattributes - build.ts - bun.lock - src/index.ts - src/memory.ts - src/memoryprocess.d.ts - src/process.ts * fix(ci): add --no-save to bun install in release workflow Update the GitHub Actions release workflow to use 'bun install --frozen-lockfile --ignore-scripts --no-save' for dependency installation. This ensures no changes are written to lockfiles during CI.
1 parent 3e0921e commit c40fdf2

31 files changed

+4521
-1949
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: reviewdog
22
on: [pull_request]
33
jobs:
44
biome:
5-
name: runner / Biome
5+
name: Biome Linter
66
runs-on: ubuntu-latest
77
permissions:
88
contents: read

.github/workflows/release.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
2929
bun-version: latest
3030

3131
- name: Install dependencies
32-
run: bun install --frozen-lockfile
33-
34-
- name: Setup zig
35-
uses: mlugg/setup-zig@v1
32+
run: bun install --frozen-lockfile --ignore-scripts --no-save
33+
34+
- name: Install node-gyp
35+
run: bun add -g node-gyp
3636

3737
- name: Build
38-
run: bun run build.ts
38+
run: bun run build
3939

4040
- name: Upload artifact
4141
uses: actions/upload-artifact@v4
@@ -78,7 +78,10 @@ jobs:
7878
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7979

8080
- name: Install dependencies
81-
run: npm install
81+
run: npm ci --ignore-scripts
82+
83+
- name: Install semantic-release plugins
84+
run: npm install @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/npm @semantic-release/github @semantic-release/git
8285

8386
- name: Run semantic-release
8487
run: npx semantic-release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
lib
3+
build
34
.vscode
45
.vs
56
.windsurfrules

.npmignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
!lib/
66
!lib/**
77

8+
# Keep the assets directory and its contents
9+
!assets/
10+
!assets/**
11+
812
# Keep essential files
913
!package.json
1014
!README.md
1115
!LICENSE
12-
!CHANGELOG.md
16+
!CHANGELOG.md
17+
18+
# Keep the lock files
19+
!package-lock.json
20+
!bun.lockb

README.md

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
> ⚠️ **WARNING:**
2-
> This package relies heavily on **Bun's native FFI (`bun:ffi`)** for performance and interacting with system APIs.
3-
> Furthermore, it interacts directly with the Windows API and is therefore **only compatible with Windows**.
4-
>
5-
> 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.
6-
>
7-
> 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`.
8-
>
9-
> **Requirements:**
10-
> * Bun v1.2.9 or later (required to run the code)
11-
12-
---
13-
141
<p align="center">
152
<img alt="Banner" src="assets/banner.png">
163
<br>
@@ -32,69 +19,65 @@
3219
</a>
3320
</p>
3421

35-
## Current Status
36-
37-
This package is currently under active development. The following core functions are implemented and available for use:
38-
39-
* `openProcess(processIdentifier: string | number): ProcessObject`: Opens a process by its name or ID.
40-
* `closeProcess(handle: number): void`: Closes an opened process handle.
41-
* `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.
42-
* `writeMemory(handle: number, address: number, value: MemoryValueType, dataType: MemoryDataType): void`: Writes memory to a specific address in the target process.
43-
44-
The `ProcessObject` object returned by `openProcess` contains information about the opened process:
45-
46-
```typescript
47-
interface ProcessObject {
48-
dwSize: number; // Size of the structure, in bytes
49-
th32ProcessID: number; // Process identifier (PID)
50-
cntThreads: number; // Number of execution threads started by the process
51-
th32ParentProcessID: number; // PID of the parent process
52-
pcPriClassBase: number; // Base priority of threads created by this process
53-
szExeFile: string; // Path to the executable file
54-
handle: number; // Process handle (for read/write operations)
55-
modBaseAddr: number; // Base address of the process's primary module
56-
}
57-
```
58-
59-
More functions are planned for future releases to expand the capabilities of this library.
60-
61-
## Data Types
62-
63-
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).
64-
65-
### Supported Data Type Strings
66-
67-
The following data type strings (and their aliases) are supported:
68-
69-
* **8-bit Signed:** `byte`, `int8`, `char`
70-
* **8-bit Unsigned:** `ubyte`, `uint8`, `uchar`
71-
* **16-bit Signed:** `short`, `int16`
72-
* **16-bit Unsigned:** `ushort`, `uint16`, `word`
73-
* **32-bit Signed:** `int`, `int32`, `long`
74-
* **32-bit Unsigned:** `uint`, `uint32`, `ulong`, `dword`
75-
* **64-bit Signed:** `longlong`, `int64` (uses BigInt)
76-
* **64-bit Unsigned:** `ulonglong`, `uint64` (uses BigInt)
77-
* **Floating Point:** `float` (4 bytes), `double` (8 bytes)
78-
* **Boolean:** `bool` (1 byte, 0 or 1)
79-
* **String:** `string`, `str` (Null-terminated UTF-8)
80-
81-
### TypeScript Type Definitions
82-
83-
```typescript
84-
/** Represents the valid data types for memory operations. */
85-
export type MemoryDataType =
86-
| "byte" | "int8" | "char" // 8-bit signed
87-
| "ubyte" | "uint8" | "uchar" // 8-bit unsigned
88-
| "short" | "int16" // 16-bit signed
89-
| "ushort" | "uint16" | "word" // 16-bit unsigned
90-
| "int" | "int32" | "long" // 32-bit signed
91-
| "uint" | "uint32" | "ulong" | "dword" // 32-bit unsigned
92-
| "float" // 32-bit float
93-
| "double" // 64-bit float
94-
| "longlong" | "int64" // 64-bit signed (Note: JS Number limitations apply)
95-
| "ulonglong" | "uint64" // 64-bit unsigned (Note: JS Number limitations apply)
96-
| "bool"
97-
| "string" | "str"; // Null-terminated string
98-
99-
/** Represents the possible value types corresponding to MemoryDataType. */
100-
export type MemoryValueType = number | string | boolean;
22+
---
23+
24+
## 📖 API References (`src`)
25+
26+
### Main Functions
27+
28+
- **openProcess(processIdentifier: string | number, callback?): Process**
29+
Opens a process by name or ID. Returns the process handle or undefined if not found.
30+
31+
- **closeHandle(handle: number): boolean**
32+
Closes a process handle.
33+
34+
- **getProcesses(callback?): Process[]**
35+
Returns the list of running processes.
36+
37+
- **findModule(moduleName: string, processId: number, callback?): Module | undefined**
38+
Finds a module by name in a process.
39+
40+
- **getModules(processId: number, callback?): Module[]**
41+
Returns the modules loaded by a process.
42+
43+
- **readMemory<T extends DataType>(handle: number, address: number, dataType: T, callback?): MemoryData<T> | undefined**
44+
Reads a value from a process's memory.
45+
46+
- **writeMemory(handle: number, address: number, value: any, dataType: DataType): boolean**
47+
Writes a value to a process's memory.
48+
49+
- **findPattern(...)**
50+
Scans memory patterns (multiple overloads).
51+
52+
- **callFunction(handle: number, args: any[], returnType: number, address: number, callback?): any**
53+
Calls a function in the process's memory.
54+
55+
- **Debugger**
56+
Utility class for process debugging. Main methods: `attach`, `detach`, `setHardwareBreakpoint`, `removeHardwareBreakpoint`, `monitor`.
57+
58+
- **virtualAllocEx, virtualProtectEx, getRegions, virtualQueryEx, injectDll, unloadDll, openFileMapping, mapViewOfFile**
59+
Advanced memory and DLL manipulation functions.
60+
61+
### Main Types and Constants (`types.ts`)
62+
63+
- **type DataType**
64+
Supported data types for memory read/write: `'byte'`, `'int32'`, `'float'`, `'string'`, `'vector3'`, etc.
65+
66+
- **type MemoryData<T extends DataType>**
67+
Maps a `DataType` to its corresponding JS type (`number`, `bigint`, `string`, `{x,y,z}`...)
68+
69+
- **interface Process**
70+
Information about an opened process (PID, handle, etc).
71+
72+
- **interface Module**
73+
Information about a module loaded in a process.
74+
75+
- **type Protection, PageProtection, AllocationType, BreakpointTriggerType**
76+
Auxiliary types for memory flags and protection.
77+
78+
- **const FunctionTypes, SignatureTypes, MemoryAccessFlags, MemoryPageFlags, HardwareDebugRegisters, BreakpointTriggerTypes**
79+
Constants for flags and function types.
80+
81+
---
82+
83+
> See the [`src`](./src) folder for full details and comments on each function/type.

binding.gyp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "native",
5+
"include_dirs" : [
6+
"<!@(node -p \"require('node-addon-api').include\")"
7+
],
8+
"sources": [
9+
"native/memoryprocess.cc",
10+
"native/memory.cc",
11+
"native/process.cc",
12+
"native/module.cc",
13+
"native/pattern.cc",
14+
"native/functions.cc",
15+
"native/debugger.cc"
16+
],
17+
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
18+
}
19+
]
20+
}

build.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)