bun-memory 1.1.31 → 1.1.33

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.
Files changed (2) hide show
  1. package/README.md +158 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # bun-memory
2
+
3
+ Blazing fast, high-performance Windows process memory manipulation for [Bun](https://bun.sh/).
4
+
5
+ ## Overview
6
+
7
+ `bun-memory` provides fast, allocation-conscious tools for reading and writing memory in external Windows processes. Designed for [Bun](https://bun.sh/) and Windows 10/11, it exposes a single class, `Memory`, with a clear, type-safe API for all common memory operations.
8
+
9
+ ## Features
10
+
11
+ - Attach to processes by name or PID
12
+ - Efficient, allocation-free operations using user-provided buffers (scratches)
13
+ - Module enumeration and pointer chain resolution
14
+ - Pattern search with wildcards (`**` and `??`)
15
+ - Read and write all primitive types, arrays, buffers, and common structures
16
+ - Typed helpers for vectors, matrices, colors, and more
17
+
18
+ ## Requirements
19
+
20
+ - [Bun](https://bun.sh/) runtime
21
+ - Windows 10 or later
22
+
23
+ ## Installation
24
+
25
+ ```sh
26
+ bun add bun-memory
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ❗ **Important**: [Example: Using Scratches (Recommended)](#example-using-scratches-recommended)
32
+
33
+ ```ts
34
+ import Memory from 'bun-memory';
35
+
36
+ // Attach to a process by name
37
+ const cs2 = new Memory('cs2.exe');
38
+
39
+ // Read a float
40
+ const myFloat = cs2.f32(0x12345678n);
41
+
42
+ // Write an int
43
+ cs2.i32(0x12345678n, 42);
44
+
45
+ // Access loaded modules
46
+ const client = cs2.modules['client.dll'];
47
+
48
+ // Clean up
49
+ cs2.close();
50
+ ```
51
+
52
+ ## API Highlights
53
+
54
+ - `follow(address, offsets)` — Follow a pointer chain
55
+ - `read(address, scratch)` — Read memory into a scratch (no allocations)
56
+ - `write(address, scratch)` — Write a scratch to memory
57
+ - Module map: `memory.modules['client.dll']`
58
+ - Typed accessors: `bool`, `f32`, `i32`, `matrix4x4`, `u8`, `u64Array`, `vector3`, etc.
59
+
60
+ See the code and type definitions for full details. All methods are documented with concise examples.
61
+
62
+ ## Example: Efficient Scratch Reuse
63
+
64
+ ```ts
65
+ // Reuse buffers and arrays for fast, allocation-free memory operations
66
+ const buffer = Buffer.allocUnsafe(256);
67
+ void cs2.read(0x12345678n, buffer); // Fills buffer in-place
68
+ // …use buffer…
69
+ ```
70
+
71
+ ```ts
72
+ // Typed arrays work the same way
73
+ const array = new Float32Array(32);
74
+ void cs2.read(0x12345678n, array); // Fills array in-place
75
+ // …use buffer…
76
+ ```
77
+
78
+ ## Example: Pattern Search
79
+
80
+ ```ts
81
+ // Find a byte pattern in memory (supports wildcards: ** and ??)
82
+ const needle = 'deadbeef';
83
+ // const needle = 'de**beef';
84
+ // const needle = 'de????ef';
85
+ const address = cs2.pattern(needle, 0x10000000n, 0x1000);
86
+ if (address !== -1n) {
87
+ console.log(`Found at 0x${address.toString(16)}`);
88
+ }
89
+ ```
90
+
91
+ ## Example: Pointer Chains
92
+
93
+ ```ts
94
+ // Follow a pointer chain to resolve nested addresses
95
+ const address = cs2.follow(0x10000000n, [0x10n, 0x20n]);
96
+ ```
97
+
98
+ ## Example: Searching Memory
99
+
100
+ ```ts
101
+ // Search for a buffer or array in memory
102
+ const needle = Buffer.from([0x01, 0x02, 0x03]);
103
+ // const needle = new Uint8Array([0x01, 0x02, 0x03]);
104
+ // const needle = new Uint32Array([0x012345, 0x123456, 0x234567]);
105
+ // …etc…
106
+ const address = cs2.indexOf(needle, 0x10000000n, 0x1000);
107
+ if (address !== -1n) {
108
+ console.log(`Found at 0x${address.toString(16)}`);
109
+ }
110
+ ```
111
+
112
+ ## Example: Typed Arrays
113
+
114
+ ```ts
115
+ // Read or write arrays of numbers and structures
116
+ const array = cs2.f32Array(0x12345678n, 4); // Float32Array of length 4
117
+ // const array = cs2.u64Array(0x12345678n, 4);
118
+ // const array = cs2.vector3Array(0x12345678n, 4);
119
+ // …etc…
120
+ cs2.i32Array(0x12345678n, new Int32Array([1, 2, 3, 4]));
121
+ cs2.u64Array(0x12345678n, new BigUint64Array([1, 2, 3, 4]));
122
+ cs2.vector3Array(0x12345678n, [{ x: 1, y: 2, z: 3 }]);
123
+ ```
124
+
125
+ ## Example: Using Scratches (Recommended)
126
+
127
+ ```ts
128
+ // Scratches let you reuse buffers and arrays for repeated memory operations
129
+ // This avoids allocations and maximizes performance
130
+ const array = new BigUint64Array(0xf000 / 0x08);
131
+
132
+ while (true) {
133
+ cs2.read(0x10000000n, array); // Updates array without allocations
134
+ for (const element of array) {
135
+ // …use element…
136
+ }
137
+ }
138
+ ```
139
+
140
+ ```ts
141
+ const buffer = Buffer.allocUnsafe(256);
142
+ const array = new Uint64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
143
+
144
+ while (true) {
145
+ cs2.read(0x10000000n, buffer); // Updates both array & buffer without allocations
146
+ for (const element of array) {
147
+ // …use element…
148
+ }
149
+ }
150
+ ```
151
+
152
+ ## Notes
153
+
154
+ - Windows only. Bun runtime required.
155
+
156
+ ---
157
+
158
+ For real-world usage, see [example/trigger-bot.ts](example/trigger-bot.ts).
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.31",
25
+ "version": "1.1.33",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",