bun-memory 1.1.18 → 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/example/trigger-bot.ts +8 -13
- package/package.json +1 -1
- package/structs/Memory.ts +24 -13
package/example/trigger-bot.ts
CHANGED
|
@@ -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
|
-
|
|
57
|
-
|
|
50
|
+
// while (true) {
|
|
51
|
+
// for (const pointer of pointers) {
|
|
52
|
+
// const cString = cs2.cString(pointer, 32).toString();
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
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
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
|
|
265
|
-
* This is a low-level
|
|
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
|
-
* @
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* @
|
|
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
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* memory.
|
|
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:
|
|
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
|
|
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):
|
|
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…
|