bun-memory 1.1.17 → 1.1.19

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
@@ -61,6 +61,7 @@ A `Memory` instance exposes typed helpers for reading and writing process memory
61
61
  scalar and array variants; entries without a pair are scalar-only or array-only.
62
62
 
63
63
  - bool
64
+ - buffer
64
65
  - cString
65
66
  - f32 / f32Array
66
67
  - f64 / f64Array
@@ -45,22 +45,17 @@ if (ClientPtr === undefined) {
45
45
  }
46
46
  // !
47
47
 
48
- const dec = new TextDecoder('utf-8');
49
-
50
- const buffer = Buffer.allocUnsafe(32);
51
- const pointers = [4749947025128n, 4749937696488n, 4749757372648n, 4745786211048n, 4745800086248n, 4748263960808n, 4748274490088n, 4748287459048n, 4747096900328n, 4747107757288n];
52
-
53
48
  console.time('test');
54
49
 
55
- while (true) {
56
- for (const pointer of pointers) {
57
- const cString = cs2.cString(pointer, 32).toString();
50
+ // while (true) {
51
+ // for (const pointer of pointers) {
52
+ // const cString = cs2.cString(pointer, 32).toString();
58
53
 
59
- if (cString.length > 32) {
60
- console.log(cString);
61
- }
62
- }
63
- }
54
+ // if (cString.length > 32) {
55
+ // console.log(cString);
56
+ // }
57
+ // }
58
+ // }
64
59
 
65
60
  console.timeEnd('test');
66
61
 
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.17",
25
+ "version": "1.1.19",
26
26
  "main": "./index.ts",
27
27
  "keywords": [
28
28
  "bun",
package/structs/Memory.ts CHANGED
@@ -261,23 +261,34 @@ class Memory {
261
261
  // Core memory operations
262
262
 
263
263
  /**
264
- * Reads data from the target process memory into a scratch buffer.
265
- * This is a low-level method used internally by the typed read methods.
264
+ * Reads data from the target process memory into the provided scratch buffer and returns that
265
+ * same scratch object (strongly typed). This is a low-level, zero-copy helper used internally by
266
+ * typed readers.
266
267
  *
267
- * @param address - Memory address to read from
268
- * @param scratch - Buffer to store the read data
269
- * @returns This Memory instance for method chaining
270
- * @throws {Win32Error} When the read operation fails
268
+ * @typeParam T - Concrete scratch type extending {@link Scratch} (for example, `Scratch16`,
269
+ * `Scratch32`, a CString scratch, etc.).
270
+ *
271
+ * @param address - Absolute memory address to read from (BigInt).
272
+ * @param scratch - Destination scratch instance to receive the bytes.
273
+ * @returns The same scratch instance you passed in, typed as `T`.
274
+ * @throws {Win32Error} When the underlying `ReadProcessMemory` call fails.
271
275
  *
272
276
  * @todo Research what it will take to add CString to the Scratch type.
273
277
  *
274
278
  * @example
275
- * ```typescript
276
- * const buffer = new Uint8Array(4);
277
- * memory.read(0x12345678n, buffer);
279
+ * ```ts
280
+ * // Strongly typed result based on the scratch you pass in:
281
+ * const s16 = memory.Scratch16;
282
+ * const out16 = memory.read(0x12345678n, s16);
283
+ * ```
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * const myScratch = Buffer.allocUnsafe(64);
288
+ * const out = memory.read(0x1000_2000n, myScratch);
278
289
  * ```
279
290
  */
280
- public read(address: bigint, scratch: Scratch): this {
291
+ public read<T extends Scratch>(address: bigint, scratch: T): T {
281
292
  const lpBaseAddress = address;
282
293
  const lpBuffer = scratch.ptr;
283
294
  const nSize = scratch.byteLength;
@@ -289,7 +300,7 @@ class Memory {
289
300
  throw new Win32Error('ReadProcessMemory', Kernel32.GetLastError());
290
301
  }
291
302
 
292
- return this;
303
+ return scratch;
293
304
  }
294
305
 
295
306
  /**
@@ -306,7 +317,7 @@ class Memory {
306
317
  * memory.write(0x12345678n, buffer);
307
318
  * ```
308
319
  */
309
- private write(address: bigint, scratch: Scratch): void {
320
+ private write(address: bigint, scratch: Scratch): this {
310
321
  const lpBaseAddress = address;
311
322
  const lpBuffer = scratch.ptr;
312
323
  const nSize = scratch.byteLength;
@@ -318,7 +329,7 @@ class Memory {
318
329
  throw new Win32Error('WriteProcessMemory', Kernel32.GetLastError());
319
330
  }
320
331
 
321
- return;
332
+ return this;
322
333
  }
323
334
 
324
335
  // Public read / write methods…