bun-memory 1.1.21 → 1.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,171 +1,121 @@
1
1
  # bun-memory
2
2
 
3
- High-performance Windows process memory utilities for [Bun](https://bun.sh) using `bun:ffi` and
4
- Win32 APIs.
3
+ Blazing fast, high-performance Windows process memory manipulation for Bun.
5
4
 
6
- ## Features
5
+ ## Overview
6
+
7
+ `bun-memory` provides fast, allocation-conscious tools for reading and writing memory in external Windows processes. Designed for Bun and Windows 10/11, it exposes a single class, `Memory`, with a clear, type-safe API for all common memory operations.
7
8
 
8
- - Built for Bun runtime and Windows 10/11
9
- - Efficient buffer management for high-speed operations
10
- - Pattern scanning for offsets \*
11
- - Read and write memory of Windows processes
9
+ ## Features
12
10
 
13
- \* Feature temporarily disabled
11
+ - Attach to processes by name or PID
12
+ - Read and write all primitive types, arrays, buffers, and common structures
13
+ - Efficient, allocation-free operations using user-provided buffers (scratches)
14
+ - Module enumeration and pointer chain resolution
15
+ - Typed helpers for vectors, matrices, colors, and more
14
16
 
15
17
  ## Requirements
16
18
 
17
- - **Bun** (uses `bun:ffi`)
18
- - **Windows 10/11** (uses `kernel32.dll`)
19
+ - Bun runtime
20
+ - Windows 10 or later
19
21
 
20
22
  ## Installation
21
23
 
22
- ```bash
24
+ ```sh
23
25
  bun add bun-memory
24
26
  ```
25
27
 
26
- ## Usage
27
-
28
- See [example/trigger-bot.ts](example/trigger-bot.ts) for a real-world example for Counter-Strike 2.
29
-
30
- ### Basic Example
28
+ ## Quick Start
31
29
 
32
30
  ```ts
33
31
  import Memory from 'bun-memory';
34
32
 
35
- // Attach to process by name
36
- const memory = new Memory('cs2.exe');
37
- // …or PID…
38
- const memory = new Memory(1_234);
33
+ // Attach to a process by name
34
+ const cs2 = new Memory('cs2.exe');
39
35
 
40
- // Access loaded modules…
41
- const modules = memory.modules;
36
+ // Read a float
37
+ const myFloat = cs2.f32(0x12345678n);
42
38
 
43
- const client = modules['client.dll'];
39
+ // Write an int
40
+ cs2.i32(0x12345678n, 42);
41
+
42
+ // Access loaded modules
43
+ const client = cs2.modules['client.dll'];
44
+
45
+ // Clean up
46
+ cs2.close();
47
+ ```
44
48
 
45
- console.log(`Base: 0x%s — Size: %d bytes…`, client.base.toString(16), client.size);
49
+ ## API Highlights
46
50
 
47
- const address = memory.follow(client.base + 0x12345678n, [0x10n, 0x20n, 0x30n]);
51
+ - `follow(address, offsets)` Follow a pointer chain
52
+ - `read(address, scratch)` — Read memory into a scratch (no allocations)
53
+ - `write(address, scratch)` — Write a scratch to memory
54
+ - Module map: `memory.modules['client.dll']`
55
+ - Typed accessors: `bool`, `f32`, `i32`, `matrix4x4`, `u8`, `u64Array`, `vector3`, etc.
48
56
 
49
- // Read a 32-bit integer…
50
- const value = memory.i32(address);
57
+ See the code and type definitions for full details. All methods are documented with concise examples.
51
58
 
52
- // Write a float…
53
- memory.f32(address, 3.14159);
59
+ ## Example: Efficient Buffer Reuse
54
60
 
55
- // Clean up…
56
- memory.close();
61
+ ```ts
62
+ const buffer = Buffer.allocUnsafe(256);
63
+ cs2.read(0x12345678n, buffer); // Fills buffer in-place
64
+ // …use buffer…
57
65
  ```
58
66
 
59
- ### API Follow / Read / Write
60
-
61
- Low-level helpers for pointer resolution and raw, allocation-free memory transfers. Use these when you need maximum control or want to reuse your own scratches.
62
-
63
- - follow
64
- - read
65
- - write
66
-
67
- ### API — Typed Reads / Writes
68
-
69
- A `Memory` instance exposes typed helpers for reading and writing process memory. Pairs indicate
70
- scalar and array variants; entries without a pair are scalar-only or array-only.
71
-
72
- - bool
73
- - buffer
74
- - cString
75
- - f32 / f32Array
76
- - f64 / f64Array
77
- - i16 / i16Array
78
- - i32 / i32Array
79
- - i64 / i64Array
80
- - i8 / i8Array
81
- - matrix3x3
82
- - matrix3x4
83
- - matrix4x4
84
- - networkUtlVector
85
- - qAngle / qAngleArray
86
- - quaternion / quaternionArray
87
- - u16 / u16Array
88
- - u32 / u32Array
89
- - u64 / u64Array
90
- - u8 / u8Array
91
- - vector2 / vector2Array
92
- - vector3 / vector3Array
93
- - vector4 / vector4Array
94
-
95
- ### Efficient Reads / Writes Using Scratches
96
-
97
- There are many ways to use `scratch`es. Scratches are great for avoiding allocation costs by reusing
98
- a preexisting array, buffer, string, etc.
67
+ ## Example: Pointer Chains
99
68
 
100
69
  ```ts
101
- const handles = new Uint32Array(0x100);
70
+ const address = cs2.follow(0x10000000n, [0x10n, 0x20n]);
71
+ ```
102
72
 
103
- while (true) {
104
- try {
105
- memory.read(myAddress, handles); // Updated handles, no allocations…
106
-
107
- // Do something with your handles…
108
- for (const handle of handles) {
109
- //
110
- }
111
- } finally {
112
- continue;
113
- }
73
+ ## Example: Searching Memory
74
+
75
+ ```ts
76
+ const needle = Buffer.from([0x48, 0x8b, 0x05]);
77
+ const address = cs2.indexOf(needle, 0x10000000n, 0x1000);
78
+ if (address !== -1n) {
79
+ console.log(`Found at 0x${address.toString(16)}`);
114
80
  }
115
81
  ```
116
82
 
117
83
  ```ts
118
- const buffer = Buffer.allocUnsafe(0xf000); // Use buffer as a scratch…
119
- const pointers = new BigUint64Array(scratchBuffer.buffer, scratchBuffer.byteOffset, 0xf000 / 8);
120
-
121
- while (true) {
122
- try {
123
- memory.read(myAddress, buffer); // Updates buffer and pointers, no allocations…
124
-
125
- // Do something with your pointers…
126
- for (const pointer of pointers) {
127
- // Read a 32 length string at pointer…
128
- const myString = memory.cString(pointer, 32).toString();
129
-
130
- // …
131
- }
132
- } finally {
133
- continue;
134
- }
84
+ const needle = new Uint32Array([0x01, 0x02, 0x03]);
85
+ const address = cs2.indexOf(needle, 0x10000000n, 0x1000);
86
+ if (address !== -1n) {
87
+ console.log(`Found at 0x${address.toString(16)}`);
135
88
  }
136
89
  ```
137
90
 
138
- ### Searching Memory
139
-
140
- #### `findPattern`
141
-
142
- Pattern scanning is temporarily disabled but will return shortly.
143
-
144
- #### `indexOf`
145
-
146
- Find the first occurrence of a byte sequence within a memory range and return the absolute address (`bigint`) of the first match, or `-1n` when not found. Accepts any Scratch-compatible input (`Buffer`, `TypedArray`, `DataView`, `ArrayBuffer`, or `SharedArrayBuffer`). No region or protection checking is performed; ensure the range is readable before calling.
91
+ ## Example: Typed Arrays
147
92
 
148
93
  ```ts
149
- // Attach…
150
- const memory = new Memory('cs2.exe');
94
+ const array = cs2.f32Array(0x12345678n, 4); // Float32Array of length 4
95
+ cs2.i32Array(0x12345678n, new Int32Array([1, 2, 3, 4]));
96
+ ```
151
97
 
152
- // Get the loaded client.dll…
153
- const client = cs2.modules['client.dll'];
98
+ ## Example: Using Scratches (Recommended)
154
99
 
155
- // Choose any Scratch type for the needle (bytes are matched exactly as laid out in memory).
156
- const needle = Buffer.from([0x48, 0x8b, 0x05, 0x00, 0x00, 0x00, 0x00]);
157
- // const needle = new Uint8Array([0x48, 0x8B, 0x05, 0x00, 0x00, 0x00, 0x00]);
158
- // const needle = new Uint32Array([0xDEADBEEF, 0x11223344]);
159
- // const needle = new DataView(Uint8Array.from([0xde, 0xad, 0xbe, 0xef]).buffer);
100
+ Scratches let you reuse buffers and typed arrays for repeated memory operations, avoiding unnecessary allocations and maximizing performance. This is the most efficient way to read or write large or frequent data.
160
101
 
161
- // Search client.dll for the byte sequence…
162
- const addeess = memory.indexOf(needle, client.base, client.size);
102
+ ```ts
103
+ const buffer = Buffer.allocUnsafe(256);
104
+ const array = new Uint64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
163
105
 
164
- if (address !== -1n) {
165
- console.log(`Found at 0x${address.toString(16)}`);
106
+ while (true) {
107
+ cs2.read(0x10000000n, buffer); // Updates array & buffer without allocations
108
+ for (const element of array) {
109
+ // …use element…
110
+ }
166
111
  }
167
112
  ```
168
113
 
169
114
  ## Notes
170
115
 
171
- - Only works with Bun and Windows.
116
+ - Pattern scanning is temporarily disabled.
117
+ - Windows only. Bun runtime required.
118
+
119
+ ---
120
+
121
+ For real-world usage, see [example/trigger-bot.ts](example/trigger-bot.ts).
@@ -34,6 +34,10 @@ const { dwEntityList, dwGlobalVars, dwLocalPlayerController, dwLocalPlayerPawn }
34
34
  [K in keyof (typeof OffsetsJSON)['client.dll']]: bigint;
35
35
  };
36
36
 
37
+ const a: bigint[] = [1n];
38
+
39
+ console.log(typeof a);
40
+
37
41
  // Open a handle to cs2.exe…
38
42
  const cs2 = new Memory('cs2.exe');
39
43
 
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "url": "git://github.com/obscuritysrl/bun-memory.git"
23
23
  },
24
24
  "type": "module",
25
- "version": "1.1.21",
25
+ "version": "1.1.23",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",