bun-memory 1.1.16 → 1.1.18

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
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.16",
25
+ "version": "1.1.18",
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
  *