bun-memory 1.1.16 → 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/package.json +1 -1
- package/structs/Memory.ts +41 -0
package/package.json
CHANGED
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
|
*
|