bun-memory 1.0.3 → 1.1.1
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 +42 -39
- package/index.ts +1 -0
- package/package.json +1 -1
- package/structs/Memory.ts +1053 -904
- package/structs/Win32Error.ts +261 -24
package/README.md
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# bun-memory
|
|
2
2
|
|
|
3
|
-
High-performance Windows process memory utilities for [Bun](https://bun.sh) using `bun:ffi` and
|
|
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
|
|
4
13
|
|
|
5
14
|
## Requirements
|
|
6
15
|
|
|
7
|
-
- Bun
|
|
8
|
-
- Windows 10/11 (uses `kernel32.dll`)
|
|
16
|
+
- **Bun** (uses `bun:ffi`)
|
|
17
|
+
- **Windows 10/11** (uses `kernel32.dll`)
|
|
9
18
|
|
|
10
19
|
## Installation
|
|
11
20
|
|
|
@@ -15,62 +24,56 @@ bun add bun-memory
|
|
|
15
24
|
|
|
16
25
|
## Usage
|
|
17
26
|
|
|
18
|
-
### Basic
|
|
27
|
+
### Basic Example
|
|
19
28
|
|
|
20
29
|
```ts
|
|
21
30
|
import Memory from 'bun-memory';
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
// Attach to process by name…
|
|
33
|
+
const memory = new Memory('notepad.exe');
|
|
34
|
+
// …or PID
|
|
35
|
+
const memory = new Memory(1234);
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
// Access loaded modules
|
|
38
|
+
const modules = memory.modules;
|
|
39
|
+
const mainModule = modules['notepad.exe'];
|
|
40
|
+
console.log(`Base address: 0x${mainModule.modBaseAddr.toString(16)}`);
|
|
41
|
+
console.log(`Size: ${mainModule.modBaseSize} bytes`);
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { modBaseAddr: clientBaseAddr, modBaseSize: modBaseSize } = clientDLL;
|
|
43
|
+
// Read a 32-bit integer
|
|
44
|
+
const value = memory.i32(0x12345678n);
|
|
32
45
|
|
|
33
|
-
// Write
|
|
34
|
-
|
|
35
|
-
memory.writeUInt32LE(clientBaseAddr + ammoOffset, 0x270f);
|
|
46
|
+
// Write a float
|
|
47
|
+
memory.f32(0x12345678n, 3.14159);
|
|
36
48
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
console.log('You have %d health…', healthValue); // Your have 100 health…
|
|
49
|
+
// Clean up
|
|
50
|
+
memory.close();
|
|
51
|
+
```
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
const otherOffset = memory.findPattern('aa??bbccdd??ff', clientBaseAddr, clientBaseSize);
|
|
44
|
-
const otherValue = memory.readBoolean(otherOffset + 0x1234n);
|
|
53
|
+
### Pattern Scanning
|
|
45
54
|
|
|
55
|
+
```ts
|
|
56
|
+
const offset = memory.findPattern('aa??bbccdd??ff', mainModule.modBaseAddr, mainModule.modBaseSize);
|
|
57
|
+
const value = memory.bool(offset + 0x1234n);
|
|
46
58
|
memory.close();
|
|
47
59
|
```
|
|
48
60
|
|
|
49
|
-
###
|
|
50
|
-
|
|
51
|
-
Many read methods accept an optional `scratch` `Buffer` to avoid allocations:
|
|
61
|
+
### Efficient Buffer Reads
|
|
52
62
|
|
|
53
63
|
```ts
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
// …
|
|
64
|
+
const scratch = Buffer.allocUnsafe(0xf000);
|
|
65
|
+
const view = new BigUint64Array(scratch.buffer, scratch.byteOffset, 0xf000 / 8);
|
|
58
66
|
|
|
59
67
|
while (true) {
|
|
60
|
-
memory.
|
|
61
|
-
|
|
62
|
-
// …or…
|
|
63
|
-
|
|
64
|
-
memory.readBuffer(myAddress, 0xf000, myScratch); // Also updates myView with no new allocations…
|
|
68
|
+
memory.read(myAddress, scratch); // Updates scratch and view, no allocations
|
|
65
69
|
}
|
|
66
70
|
```
|
|
67
71
|
|
|
68
72
|
```ts
|
|
69
|
-
const
|
|
70
|
-
|
|
73
|
+
const scratch = Buffer.allocUnsafe(0x100);
|
|
74
|
+
memory.read(myAddress, scratch);
|
|
71
75
|
```
|
|
72
76
|
|
|
73
|
-
|
|
77
|
+
## Notes
|
|
74
78
|
|
|
75
|
-
-
|
|
76
|
-
- Windows is the only supported platform.
|
|
79
|
+
- Only works with Bun and Windows.
|
package/index.ts
CHANGED