bun-memory 1.1.15 → 1.1.17

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
@@ -125,24 +125,35 @@ while (true) {
125
125
  }
126
126
  ```
127
127
 
128
- ```ts
129
- const scratch = Buffer.allocUnsafe(0x100);
130
- memory.read(myAddress, scratch);
131
- ```
128
+ ### Searching Memory
132
129
 
133
- ```ts
134
- const scratch = new Uint32Array(0x10);
135
- memory.read(myAddress, scratch);
136
- ```
137
-
138
- ### Pattern Scanning
130
+ #### `findPattern`
139
131
 
140
132
  Pattern scanning is temporarily disabled but will return shortly.
141
133
 
134
+ #### `indexOf`
135
+
136
+ 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.
137
+
142
138
  ```ts
143
- const offset = memory.findPattern('aa??bbccdd??ff', mainModule.modBaseAddr, mainModule.modBaseSize);
144
- const value = memory.bool(offset + 0x1234n);
145
- memory.close();
139
+ // Attach…
140
+ const memory = new Memory('cs2.exe');
141
+
142
+ // Get the loaded client.dll…
143
+ const client = cs2.modules['client.dll'];
144
+
145
+ // Choose any Scratch type for the needle (bytes are matched exactly as laid out in memory).
146
+ const needle = Buffer.from([0x48, 0x8b, 0x05, 0x00, 0x00, 0x00, 0x00]);
147
+ // const needle = new Uint8Array([0x48, 0x8B, 0x05, 0x00, 0x00, 0x00, 0x00]);
148
+ // const needle = new Uint32Array([0xDEADBEEF, 0x11223344]);
149
+ // const needle = new DataView(Uint8Array.from([0xde, 0xad, 0xbe, 0xef]).buffer);
150
+
151
+ // Search client.dll for the byte sequence…
152
+ const addeess = memory.indexOf(needle, client.base, client.size);
153
+
154
+ if (address !== -1n) {
155
+ console.log(`Found at 0x${address.toString(16)}`);
156
+ }
146
157
  ```
147
158
 
148
159
  ## Notes
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.15",
25
+ "version": "1.1.17",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",
package/structs/Memory.ts CHANGED
@@ -429,6 +429,47 @@ class Memory {
429
429
  return this;
430
430
  }
431
431
 
432
+ /**
433
+ * Reads a raw byte buffer from memory or writes a raw byte buffer to memory.
434
+ *
435
+ * When reading, exactly `length` bytes are copied from `address` into a new `Buffer`.
436
+ * Bytes are returned exactly as laid out in memory—no decoding, alignment, or transformation
437
+ * is applied. When writing, the contents of `value` are copied to `address` verbatim.
438
+ *
439
+ * @param address - Memory address to read from or write to
440
+ * @param lengthOrValue - Number of bytes to read (when reading), or `Buffer` to write (when writing)
441
+ * @returns `Buffer` when reading, or this `Memory` instance when writing
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * // Read 16 bytes from memory
446
+ * const bytes = memory.buffer(0x12345678n, 16);
447
+ *
448
+ * // Write a 4-byte patch (NOP sled, for example)
449
+ * const patch = Buffer.from([0x90, 0x90, 0x90, 0x90]);
450
+ * memory.buffer(0x12345678n, patch);
451
+ * ```
452
+ */
453
+ public buffer(address: bigint, length: number): Buffer;
454
+ public buffer(address: bigint, value: Buffer): this;
455
+ public buffer(address: bigint, lengthOrValue: number | Buffer): Buffer | this {
456
+ if (typeof lengthOrValue === 'number') {
457
+ const length = lengthOrValue;
458
+
459
+ const scratch = Buffer.allocUnsafe(length);
460
+
461
+ this.read(address, scratch);
462
+
463
+ return scratch;
464
+ }
465
+
466
+ const value = lengthOrValue;
467
+
468
+ this.write(address, value);
469
+
470
+ return this;
471
+ }
472
+
432
473
  /**
433
474
  * Reads a NUL-terminated C string from memory or writes a NUL-terminated C string to memory.
434
475
  *