bun-memory 1.1.6 → 1.1.8

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 ADDED
@@ -0,0 +1,81 @@
1
+ # bun-memory
2
+
3
+ High-performance Windows process memory utilities for [Bun](https://bun.sh) using `bun:ffi` and Win32 APIs.
4
+
5
+ ## Features
6
+
7
+ - Built for Bun runtime and Windows 10/11
8
+ - Efficient buffer management for high-speed operations
9
+ - Pattern scanning for offsets \*
10
+ - Read and write memory of Windows processes
11
+
12
+ \* — Feature temporarily disabled
13
+
14
+ ## Requirements
15
+
16
+ - **Bun** (uses `bun:ffi`)
17
+ - **Windows 10/11** (uses `kernel32.dll`)
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ bun add bun-memory
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ See [example/trigger-bot.ts](example/trigger-bot.ts) for a real-world example.
28
+
29
+ ### Basic Example
30
+
31
+ ```ts
32
+ import Memory from 'bun-memory';
33
+
34
+ // Attach to process by name…
35
+ const memory = new Memory('notepad.exe');
36
+ // …or PID
37
+ const memory = new Memory(1234);
38
+
39
+ // Access loaded modules
40
+ const modules = memory.modules;
41
+ const mainModule = modules['notepad.exe'];
42
+ console.log(`Base address: 0x${mainModule.modBaseAddr.toString(16)}`);
43
+ console.log(`Size: ${mainModule.modBaseSize} bytes`);
44
+
45
+ // Read a 32-bit integer
46
+ const value = memory.i32(0x12345678n);
47
+
48
+ // Write a float
49
+ memory.f32(0x12345678n, 3.14159);
50
+
51
+ // Clean up
52
+ memory.close();
53
+ ```
54
+
55
+ ### Pattern Scanning
56
+
57
+ ```ts
58
+ const offset = memory.findPattern('aa??bbccdd??ff', mainModule.modBaseAddr, mainModule.modBaseSize);
59
+ const value = memory.bool(offset + 0x1234n);
60
+ memory.close();
61
+ ```
62
+
63
+ ### Efficient Buffer Reads
64
+
65
+ ```ts
66
+ const scratch = Buffer.allocUnsafe(0xf000);
67
+ const view = new BigUint64Array(scratch.buffer, scratch.byteOffset, 0xf000 / 8);
68
+
69
+ while (true) {
70
+ memory.read(myAddress, scratch); // Updates scratch and view, no allocations
71
+ }
72
+ ```
73
+
74
+ ```ts
75
+ const scratch = Buffer.allocUnsafe(0x100);
76
+ memory.read(myAddress, scratch);
77
+ ```
78
+
79
+ ## Notes
80
+
81
+ - Only works with Bun and Windows.
@@ -1,7 +1,7 @@
1
- import { FFIType, dlopen } from 'bun:ffi';
1
+ import { CString, FFIType, dlopen, ptr } from 'bun:ffi';
2
2
  import { sleep } from 'bun';
3
3
 
4
- import Memory from 'bun-memory';
4
+ import Memory from '../index.ts';
5
5
 
6
6
  // Get the latest client_dll.json and offsets.json from:
7
7
  // https://github.com/a2x/cs2-dumper/tree/main/output
@@ -9,6 +9,10 @@ import Memory from 'bun-memory';
9
9
  import ClientDLLJSON from './offsets/client_dll.json';
10
10
  import OffsetsJSON from './offsets/offsets.json';
11
11
 
12
+ // !
13
+
14
+ // !
15
+
12
16
  const Delay = 2.5;
13
17
 
14
18
  const { random } = Math;
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.6",
25
+ "version": "1.1.8",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",
@@ -74,7 +74,7 @@
74
74
  * ```
75
75
  */
76
76
 
77
- import { ptr, type Pointer } from 'bun:ffi';
77
+ import { type Pointer, ptr } from 'bun:ffi';
78
78
 
79
79
  /**
80
80
  * List of binary view constructor functions whose prototypes will be extended
@@ -236,3 +236,5 @@ constructors.forEach(({ prototype }) => {
236
236
  });
237
237
  }
238
238
  });
239
+
240
+ export {};
package/structs/Memory.ts CHANGED
@@ -439,6 +439,7 @@ class Memory {
439
439
  * @param lengthOrValue - Number of bytes to read (when reading), or `CString` to write (when writing)
440
440
  * @returns `CString` when reading, or this `Memory` instance when writing
441
441
  *
442
+ * @todo Investigate odd behavior when reading strings longer than `lengthOrValue`.
442
443
  * @todo Research and consider alternatives that do not require so many new allocations.
443
444
  *
444
445
  * @example