@cheatron/native 1.1.0 → 1.2.1
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 +17 -4
- package/dist/{src/handle.d.ts → handle.d.ts} +4 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/{src/handle.js → handle.js} +3 -3
- package/dist/handle.js.map +1 -0
- package/dist/{src/index.d.ts → index.d.ts} +8 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/{src/index.js → index.js} +7 -2
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js.map +1 -0
- package/dist/module.d.ts +38 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +106 -0
- package/dist/module.js.map +1 -0
- package/dist/msvcrt-ext.d.ts +20 -0
- package/dist/msvcrt-ext.d.ts.map +1 -0
- package/dist/msvcrt-ext.js +120 -0
- package/dist/msvcrt-ext.js.map +1 -0
- package/dist/native-fn.d.ts +73 -0
- package/dist/native-fn.d.ts.map +1 -0
- package/dist/native-fn.js +214 -0
- package/dist/native-fn.js.map +1 -0
- package/dist/pattern.d.ts +36 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +79 -0
- package/dist/pattern.js.map +1 -0
- package/dist/process.d.ts +104 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +402 -0
- package/dist/process.js.map +1 -0
- package/dist/scan-result.d.ts +54 -0
- package/dist/scan-result.d.ts.map +1 -0
- package/dist/scan-result.js +128 -0
- package/dist/scan-result.js.map +1 -0
- package/dist/scanner.d.ts +22 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +116 -0
- package/dist/scanner.js.map +1 -0
- package/dist/thread.d.ts.map +1 -0
- package/dist/{src/thread.js → thread.js} +1 -1
- package/dist/thread.js.map +1 -0
- package/package.json +3 -2
- package/dist/eslint.config.d.ts +0 -3
- package/dist/eslint.config.d.ts.map +0 -1
- package/dist/eslint.config.js +0 -26
- package/dist/eslint.config.js.map +0 -1
- package/dist/src/handle.d.ts.map +0 -1
- package/dist/src/handle.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/logger.d.ts.map +0 -1
- package/dist/src/logger.js.map +0 -1
- package/dist/src/module.d.ts +0 -22
- package/dist/src/module.d.ts.map +0 -1
- package/dist/src/module.js +0 -55
- package/dist/src/module.js.map +0 -1
- package/dist/src/process.d.ts +0 -30
- package/dist/src/process.d.ts.map +0 -1
- package/dist/src/process.js +0 -104
- package/dist/src/process.js.map +0 -1
- package/dist/src/thread.d.ts.map +0 -1
- package/dist/src/thread.js.map +0 -1
- package/dist/tests/integration/memory.test.d.ts +0 -2
- package/dist/tests/integration/memory.test.d.ts.map +0 -1
- package/dist/tests/integration/memory.test.js +0 -82
- package/dist/tests/integration/memory.test.js.map +0 -1
- package/dist/tests/integration/thread.test.d.ts +0 -2
- package/dist/tests/integration/thread.test.d.ts.map +0 -1
- package/dist/tests/integration/thread.test.js +0 -37
- package/dist/tests/integration/thread.test.js.map +0 -1
- package/dist/tests/setup.d.ts +0 -2
- package/dist/tests/setup.d.ts.map +0 -1
- package/dist/tests/setup.js +0 -3
- package/dist/tests/setup.js.map +0 -1
- package/dist/tests/unit/kernel32.test.d.ts +0 -2
- package/dist/tests/unit/kernel32.test.d.ts.map +0 -1
- package/dist/tests/unit/kernel32.test.js +0 -28
- package/dist/tests/unit/kernel32.test.js.map +0 -1
- package/dist/tests/unit/logger.test.d.ts +0 -2
- package/dist/tests/unit/logger.test.d.ts.map +0 -1
- package/dist/tests/unit/logger.test.js +0 -29
- package/dist/tests/unit/logger.test.js.map +0 -1
- package/dist/tests/unit/msvcrt.test.d.ts +0 -2
- package/dist/tests/unit/msvcrt.test.d.ts.map +0 -1
- package/dist/tests/unit/msvcrt.test.js +0 -22
- package/dist/tests/unit/msvcrt.test.js.map +0 -1
- package/dist/tests/unit/process.test.d.ts +0 -2
- package/dist/tests/unit/process.test.d.ts.map +0 -1
- package/dist/tests/unit/process.test.js +0 -27
- package/dist/tests/unit/process.test.js.map +0 -1
- package/dist/tests/unit/thread.test.d.ts +0 -2
- package/dist/tests/unit/thread.test.d.ts.map +0 -1
- package/dist/tests/unit/thread.test.js +0 -35
- package/dist/tests/unit/thread.test.js.map +0 -1
- package/dist/tests/unit/thread_creation.test.d.ts +0 -2
- package/dist/tests/unit/thread_creation.test.d.ts.map +0 -1
- package/dist/tests/unit/thread_creation.test.js +0 -31
- package/dist/tests/unit/thread_creation.test.js.map +0 -1
- /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
- /package/dist/{src/logger.js → logger.js} +0 -0
- /package/dist/{src/thread.d.ts → thread.d.ts} +0 -0
package/dist/process.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Thread } from './thread';
|
|
2
|
+
import { Kernel32Impl, ffi, ProcessAccess, ThreadCreationFlags, MEMORY_BASIC_INFORMATION, MBI_SIZE, MemoryProtection, MemoryState, MemoryFreeType, } from '@cheatron/native-bindings';
|
|
3
|
+
import { Handle } from './handle';
|
|
4
|
+
import { log } from './logger';
|
|
5
|
+
import { Scanner } from './scanner';
|
|
6
|
+
import { Pattern } from './pattern';
|
|
7
|
+
import { ScanResult, ScanEntry } from './scan-result';
|
|
8
|
+
const processLog = log.child('Process');
|
|
9
|
+
/**
|
|
10
|
+
* Represents a process handle
|
|
11
|
+
*/
|
|
12
|
+
export class Process extends Handle {
|
|
13
|
+
_pid;
|
|
14
|
+
memory;
|
|
15
|
+
constructor(handle, pid, autoClose = true) {
|
|
16
|
+
super(handle, autoClose);
|
|
17
|
+
this._pid = pid ?? Kernel32Impl.GetProcessId(handle);
|
|
18
|
+
this.memory = new ProcessMemory(this);
|
|
19
|
+
}
|
|
20
|
+
static open(pid, access = ProcessAccess.ALL_ACCESS) {
|
|
21
|
+
processLog.debug(`Opening process ${pid} with access ${access}`);
|
|
22
|
+
const handle = Kernel32Impl.OpenProcess(access, 0, pid);
|
|
23
|
+
if (!handle) {
|
|
24
|
+
processLog.warn(`Failed to open process ${pid}`);
|
|
25
|
+
throw new Error(`Failed to open process ${pid}`);
|
|
26
|
+
}
|
|
27
|
+
return new Process(handle, pid);
|
|
28
|
+
}
|
|
29
|
+
createThread(startAddress, parameter = null, stackSize = 0, flags = ThreadCreationFlags.IMMEDIATE, attributes = null) {
|
|
30
|
+
if (!this.isValid())
|
|
31
|
+
throw new Error('Process handle is closed');
|
|
32
|
+
processLog.debug(`Creating remote thread at 0x${ffi.address(startAddress).toString(16)} (PID: ${this._pid})`);
|
|
33
|
+
const handle = Kernel32Impl.CreateRemoteThread(this._handle, attributes, stackSize, startAddress, parameter, flags, null);
|
|
34
|
+
if (!handle) {
|
|
35
|
+
processLog.error('CreateRemoteThread failed');
|
|
36
|
+
throw new Error('CreateRemoteThread failed');
|
|
37
|
+
}
|
|
38
|
+
return new Thread(handle);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Finds pattern matches in a specific memory range.
|
|
42
|
+
* Configure limit on the Pattern: `.limit(1)` for first match only.
|
|
43
|
+
*/
|
|
44
|
+
*findPatternInRangeGenerator(pattern, start, size, module) {
|
|
45
|
+
const end = start + BigInt(size);
|
|
46
|
+
let current = start;
|
|
47
|
+
try {
|
|
48
|
+
while (current < end) {
|
|
49
|
+
const mbi = this.memory.query(current);
|
|
50
|
+
const regionBase = BigInt(mbi.BaseAddress);
|
|
51
|
+
const regionSize = BigInt(mbi.RegionSize);
|
|
52
|
+
const regionEnd = regionBase + regionSize;
|
|
53
|
+
const isReadable = mbi.State === MemoryState.COMMIT &&
|
|
54
|
+
!(mbi.Protect & MemoryProtection.GUARD) &&
|
|
55
|
+
!!(mbi.Protect & pattern.protect);
|
|
56
|
+
if (isReadable) {
|
|
57
|
+
const scanStart = current > regionBase ? current : regionBase;
|
|
58
|
+
const scanEnd = end < regionEnd ? end : regionEnd;
|
|
59
|
+
const scanSize = Number(scanEnd - scanStart);
|
|
60
|
+
if (scanSize >= pattern.length) {
|
|
61
|
+
for (const ptr of Scanner.scan(scanStart, scanSize, pattern)) {
|
|
62
|
+
yield new ScanEntry(ptr, module);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (regionEnd <= current)
|
|
67
|
+
break;
|
|
68
|
+
current = regionEnd;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Range partially unmapped or error
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
findPatternInRange(signature, start, size, module) {
|
|
76
|
+
const pattern = signature instanceof Pattern ? signature : new Pattern(signature);
|
|
77
|
+
if (pattern.protect === 0)
|
|
78
|
+
pattern.defaultProtect();
|
|
79
|
+
return new ScanResult(this.findPatternInRangeGenerator(pattern, start, size, module), pattern);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Finds pattern matches in all committed readable memory of the process.
|
|
83
|
+
* Configure limit and protect filter on the Pattern object.
|
|
84
|
+
*/
|
|
85
|
+
*findPatternGenerator(pattern) {
|
|
86
|
+
let address = 0n;
|
|
87
|
+
const maxAddress = 0x7fffffffffffn;
|
|
88
|
+
try {
|
|
89
|
+
while (address < maxAddress) {
|
|
90
|
+
const mbi = this.memory.query(address);
|
|
91
|
+
const isReadable = mbi.State === MemoryState.COMMIT &&
|
|
92
|
+
!(mbi.Protect & MemoryProtection.GUARD) &&
|
|
93
|
+
!!(mbi.Protect & pattern.protect);
|
|
94
|
+
if (isReadable) {
|
|
95
|
+
const regionResult = this.findPatternInRange(pattern, BigInt(mbi.BaseAddress), Number(mbi.RegionSize));
|
|
96
|
+
yield* regionResult;
|
|
97
|
+
}
|
|
98
|
+
const nextAddress = BigInt(mbi.BaseAddress) + BigInt(mbi.RegionSize);
|
|
99
|
+
if (nextAddress <= address)
|
|
100
|
+
break;
|
|
101
|
+
address = nextAddress;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Loop finished
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
findPattern(signature) {
|
|
109
|
+
const pattern = signature instanceof Pattern ? signature : new Pattern(signature);
|
|
110
|
+
// Ensure protect mask is set before filtering regions
|
|
111
|
+
if (pattern.protect === 0)
|
|
112
|
+
pattern.defaultProtect();
|
|
113
|
+
return new ScanResult(this.findPatternGenerator(pattern), pattern);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Finds pattern matches across specified modules (default: all static modules).
|
|
117
|
+
* Each entry in the result is tagged with its source module.
|
|
118
|
+
* Configure limit and protect filter on the Pattern object.
|
|
119
|
+
*/
|
|
120
|
+
*findPatternFromModulesGenerator(pattern, moduleNames) {
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
122
|
+
const { Module } = require('./module');
|
|
123
|
+
for (const name of moduleNames) {
|
|
124
|
+
try {
|
|
125
|
+
const mod = Module.get(name);
|
|
126
|
+
yield* mod.findPattern(pattern);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
processLog.warn(`findPatternFromModules: Failed to process module ${name}: ${err}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
findPatternFromModules(signature, moduleNames = []) {
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
135
|
+
const { STATIC_MODULES } = require('./module');
|
|
136
|
+
if (this._pid !== Kernel32Impl.GetCurrentProcessId()) {
|
|
137
|
+
throw new Error('Module scanning is only supported for the current process');
|
|
138
|
+
}
|
|
139
|
+
if (moduleNames.length === 0) {
|
|
140
|
+
moduleNames = Object.values(STATIC_MODULES);
|
|
141
|
+
}
|
|
142
|
+
const pattern = signature instanceof Pattern ? signature : new Pattern(signature);
|
|
143
|
+
return new ScanResult(this.findPatternFromModulesGenerator(pattern, moduleNames), pattern);
|
|
144
|
+
}
|
|
145
|
+
static current() {
|
|
146
|
+
return currentProcess;
|
|
147
|
+
}
|
|
148
|
+
get pid() {
|
|
149
|
+
return this._pid;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Represents the current process (singleton)
|
|
154
|
+
*/
|
|
155
|
+
export class CurrentProcess extends Process {
|
|
156
|
+
constructor() {
|
|
157
|
+
// Current process uses a pseudo-handle that doesn't need closing
|
|
158
|
+
super(Kernel32Impl.GetCurrentProcess(), Kernel32Impl.GetCurrentProcessId());
|
|
159
|
+
this.memory = new CurrentProcessMemory(this);
|
|
160
|
+
}
|
|
161
|
+
createThread(startAddress, parameter, stackSize = 0, flags, attributes) {
|
|
162
|
+
return Thread.create(startAddress, parameter, stackSize, flags, attributes);
|
|
163
|
+
}
|
|
164
|
+
close() {
|
|
165
|
+
this._handle = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Export a pre-initialized instance of the current process (lazy via Proxy)
|
|
169
|
+
let _currentProcess;
|
|
170
|
+
export const currentProcess = new Proxy({}, {
|
|
171
|
+
get(_target, prop, receiver) {
|
|
172
|
+
if (!_currentProcess) {
|
|
173
|
+
_currentProcess = new CurrentProcess();
|
|
174
|
+
}
|
|
175
|
+
return Reflect.get(_currentProcess, prop, receiver);
|
|
176
|
+
},
|
|
177
|
+
getPrototypeOf() {
|
|
178
|
+
return CurrentProcess.prototype;
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
/**
|
|
182
|
+
* Manages memory operations for a given process handle.
|
|
183
|
+
*/
|
|
184
|
+
export class ProcessMemory {
|
|
185
|
+
process;
|
|
186
|
+
// eslint-disable-next-line no-unused-vars
|
|
187
|
+
constructor(process) {
|
|
188
|
+
this.process = process;
|
|
189
|
+
}
|
|
190
|
+
read(address, size) {
|
|
191
|
+
if (!this.process.isValid())
|
|
192
|
+
throw new Error('Process handle is closed');
|
|
193
|
+
const buf = Buffer.alloc(size);
|
|
194
|
+
const success = Kernel32Impl.ReadProcessMemory(this.process.handle, address, buf, size, null);
|
|
195
|
+
if (!success) {
|
|
196
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
197
|
+
processLog.error(`ReadProcessMemory failed at 0x${addrHex}`);
|
|
198
|
+
throw new Error(`ReadProcessMemory failed at 0x${addrHex}`);
|
|
199
|
+
}
|
|
200
|
+
return buf;
|
|
201
|
+
}
|
|
202
|
+
readMemory = this.read;
|
|
203
|
+
write(address, buffer) {
|
|
204
|
+
if (!this.process.isValid())
|
|
205
|
+
throw new Error('Process handle is closed');
|
|
206
|
+
const success = Kernel32Impl.WriteProcessMemory(this.process.handle, address, buffer, buffer.length, null);
|
|
207
|
+
if (!success) {
|
|
208
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
209
|
+
processLog.error(`WriteProcessMemory failed at 0x${addrHex}`);
|
|
210
|
+
throw new Error(`WriteProcessMemory failed at 0x${addrHex}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
writeMemory = this.write;
|
|
214
|
+
readInt8(address) {
|
|
215
|
+
return this.read(address, 1).readInt8(0);
|
|
216
|
+
}
|
|
217
|
+
writeInt8(address, value) {
|
|
218
|
+
const buf = Buffer.alloc(1);
|
|
219
|
+
buf.writeInt8(value, 0);
|
|
220
|
+
this.write(address, buf);
|
|
221
|
+
}
|
|
222
|
+
readUInt8(address) {
|
|
223
|
+
return this.read(address, 1).readUInt8(0);
|
|
224
|
+
}
|
|
225
|
+
writeUInt8(address, value) {
|
|
226
|
+
const buf = Buffer.alloc(1);
|
|
227
|
+
buf.writeUInt8(value, 0);
|
|
228
|
+
this.write(address, buf);
|
|
229
|
+
}
|
|
230
|
+
readInt16(address) {
|
|
231
|
+
return this.read(address, 2).readInt16LE(0);
|
|
232
|
+
}
|
|
233
|
+
writeInt16(address, value) {
|
|
234
|
+
const buf = Buffer.alloc(2);
|
|
235
|
+
buf.writeInt16LE(value, 0);
|
|
236
|
+
this.write(address, buf);
|
|
237
|
+
}
|
|
238
|
+
readUInt16(address) {
|
|
239
|
+
return this.read(address, 2).readUInt16LE(0);
|
|
240
|
+
}
|
|
241
|
+
writeUInt16(address, value) {
|
|
242
|
+
const buf = Buffer.alloc(2);
|
|
243
|
+
buf.writeUInt16LE(value, 0);
|
|
244
|
+
this.write(address, buf);
|
|
245
|
+
}
|
|
246
|
+
readInt32(address) {
|
|
247
|
+
return this.read(address, 4).readInt32LE(0);
|
|
248
|
+
}
|
|
249
|
+
writeInt32(address, value) {
|
|
250
|
+
const buf = Buffer.alloc(4);
|
|
251
|
+
buf.writeInt32LE(value, 0);
|
|
252
|
+
this.write(address, buf);
|
|
253
|
+
}
|
|
254
|
+
readUInt32(address) {
|
|
255
|
+
return this.read(address, 4).readUInt32LE(0);
|
|
256
|
+
}
|
|
257
|
+
writeUInt32(address, value) {
|
|
258
|
+
const buf = Buffer.alloc(4);
|
|
259
|
+
buf.writeUInt32LE(value, 0);
|
|
260
|
+
this.write(address, buf);
|
|
261
|
+
}
|
|
262
|
+
readInt64(address) {
|
|
263
|
+
return this.read(address, 8).readBigInt64LE(0);
|
|
264
|
+
}
|
|
265
|
+
writeInt64(address, value) {
|
|
266
|
+
const buf = Buffer.alloc(8);
|
|
267
|
+
buf.writeBigInt64LE(value, 0);
|
|
268
|
+
this.write(address, buf);
|
|
269
|
+
}
|
|
270
|
+
readUInt64(address) {
|
|
271
|
+
return this.read(address, 8).readBigUInt64LE(0);
|
|
272
|
+
}
|
|
273
|
+
writeUInt64(address, value) {
|
|
274
|
+
const buf = Buffer.alloc(8);
|
|
275
|
+
buf.writeBigUInt64LE(value, 0);
|
|
276
|
+
this.write(address, buf);
|
|
277
|
+
}
|
|
278
|
+
readFloat(address) {
|
|
279
|
+
return this.read(address, 4).readFloatLE(0);
|
|
280
|
+
}
|
|
281
|
+
writeFloat(address, value) {
|
|
282
|
+
const buf = Buffer.alloc(4);
|
|
283
|
+
buf.writeFloatLE(value, 0);
|
|
284
|
+
this.write(address, buf);
|
|
285
|
+
}
|
|
286
|
+
readDouble(address) {
|
|
287
|
+
return this.read(address, 8).readDoubleLE(0);
|
|
288
|
+
}
|
|
289
|
+
writeDouble(address, value) {
|
|
290
|
+
const buf = Buffer.alloc(8);
|
|
291
|
+
buf.writeDoubleLE(value, 0);
|
|
292
|
+
this.write(address, buf);
|
|
293
|
+
}
|
|
294
|
+
readString(address, length, encoding = 'utf8') {
|
|
295
|
+
const buf = this.read(address, length);
|
|
296
|
+
// Trim null byte if exists at the end
|
|
297
|
+
const nullIdx = buf.indexOf(0);
|
|
298
|
+
if (nullIdx !== -1) {
|
|
299
|
+
return buf.toString(encoding, 0, nullIdx);
|
|
300
|
+
}
|
|
301
|
+
return buf.toString(encoding);
|
|
302
|
+
}
|
|
303
|
+
writeString(address, value, encoding = 'utf8') {
|
|
304
|
+
const buf = Buffer.from(value + '\0', encoding);
|
|
305
|
+
this.write(address, buf);
|
|
306
|
+
}
|
|
307
|
+
query(address) {
|
|
308
|
+
if (!this.process.isValid())
|
|
309
|
+
throw new Error('Process handle is closed');
|
|
310
|
+
const buf = Buffer.alloc(MBI_SIZE);
|
|
311
|
+
const result = Kernel32Impl.VirtualQueryEx(this.process.handle, address, buf, MBI_SIZE);
|
|
312
|
+
if (result === 0) {
|
|
313
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
314
|
+
processLog.error(`VirtualQueryEx failed at 0x${addrHex}`);
|
|
315
|
+
throw new Error(`VirtualQueryEx failed at 0x${addrHex}`);
|
|
316
|
+
}
|
|
317
|
+
return ffi.decode(buf, MEMORY_BASIC_INFORMATION);
|
|
318
|
+
}
|
|
319
|
+
virtualQuery = this.query;
|
|
320
|
+
/**
|
|
321
|
+
* Allocates memory in the process.
|
|
322
|
+
*/
|
|
323
|
+
alloc(size, address = null, allocationType = MemoryState.COMMIT | MemoryState.RESERVE, protection = MemoryProtection.READWRITE) {
|
|
324
|
+
if (!this.process.isValid())
|
|
325
|
+
throw new Error('Process handle is closed');
|
|
326
|
+
const result = Kernel32Impl.VirtualAllocEx(this.process.handle, address, size, allocationType, protection);
|
|
327
|
+
if (!result) {
|
|
328
|
+
processLog.error(`VirtualAllocEx failed (PID: ${this.process.pid}, size: ${size})`);
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Frees memory in the process.
|
|
334
|
+
*/
|
|
335
|
+
free(address, size = 0, freeType = MemoryFreeType.RELEASE) {
|
|
336
|
+
if (!this.process.isValid())
|
|
337
|
+
throw new Error('Process handle is closed');
|
|
338
|
+
const result = Kernel32Impl.VirtualFreeEx(this.process.handle, address, size, freeType);
|
|
339
|
+
if (!result) {
|
|
340
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
341
|
+
processLog.error(`VirtualFreeEx failed at 0x${addrHex}`);
|
|
342
|
+
}
|
|
343
|
+
return !!result;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Changes the memory protection of a region of memory.
|
|
347
|
+
*/
|
|
348
|
+
protect(address, size, newProtect) {
|
|
349
|
+
if (!this.process.isValid())
|
|
350
|
+
throw new Error('Process handle is closed');
|
|
351
|
+
const oldProtectBuf = Buffer.alloc(4);
|
|
352
|
+
const result = Kernel32Impl.VirtualProtectEx(this.process.handle, address, size, newProtect, oldProtectBuf);
|
|
353
|
+
if (!result) {
|
|
354
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
355
|
+
processLog.error(`VirtualProtectEx failed at 0x${addrHex}`);
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
return oldProtectBuf.readUInt32LE(0);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Optimizes memory operations natively for the current running process.
|
|
363
|
+
*/
|
|
364
|
+
export class CurrentProcessMemory extends ProcessMemory {
|
|
365
|
+
alloc(size, address = null, allocationType = MemoryState.COMMIT | MemoryState.RESERVE, protection = MemoryProtection.READWRITE) {
|
|
366
|
+
const result = Kernel32Impl.VirtualAlloc(address, size, allocationType, protection);
|
|
367
|
+
if (!result) {
|
|
368
|
+
processLog.error(`VirtualAlloc failed (size: ${size})`);
|
|
369
|
+
}
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
free(address, size = 0, freeType = MemoryFreeType.RELEASE) {
|
|
373
|
+
const result = Kernel32Impl.VirtualFree(address, size, freeType);
|
|
374
|
+
if (!result) {
|
|
375
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
376
|
+
processLog.error(`VirtualFree failed at 0x${addrHex}`);
|
|
377
|
+
}
|
|
378
|
+
return !!result;
|
|
379
|
+
}
|
|
380
|
+
protect(address, size, newProtect) {
|
|
381
|
+
const oldProtectBuf = Buffer.alloc(4);
|
|
382
|
+
const result = Kernel32Impl.VirtualProtect(address, BigInt(size), newProtect, oldProtectBuf);
|
|
383
|
+
if (!result) {
|
|
384
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
385
|
+
processLog.error(`VirtualProtect failed at 0x${addrHex}`);
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
return oldProtectBuf.readUInt32LE(0);
|
|
389
|
+
}
|
|
390
|
+
query(address) {
|
|
391
|
+
const buf = Buffer.alloc(MBI_SIZE);
|
|
392
|
+
const result = Kernel32Impl.VirtualQuery(address, buf, MBI_SIZE);
|
|
393
|
+
if (result === 0) {
|
|
394
|
+
const addrHex = ffi.address(address).toString(16).toUpperCase();
|
|
395
|
+
processLog.error(`VirtualQuery failed at 0x${addrHex}`);
|
|
396
|
+
throw new Error(`VirtualQuery failed at 0x${addrHex}`);
|
|
397
|
+
}
|
|
398
|
+
return ffi.decode(buf, MEMORY_BASIC_INFORMATION);
|
|
399
|
+
}
|
|
400
|
+
virtualQuery = this.query;
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,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C,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACjE,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YAChE,UAAU,CAAC,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,wBAAwB,CAA2B,CAAC;IAC7E,CAAC;IAEQ,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC;CACpC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Pattern } from './pattern';
|
|
2
|
+
/**
|
|
3
|
+
* A single pattern match entry.
|
|
4
|
+
* Stores the decoded numeric address (bigint) of the match.
|
|
5
|
+
* Call `toAddress()` to retrieve it — consistent with how ffi.address() works.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ScanEntry {
|
|
8
|
+
readonly address: bigint;
|
|
9
|
+
readonly module?: import('./module').Module;
|
|
10
|
+
constructor(address: bigint, module?: import('./module').Module);
|
|
11
|
+
toAddress(): bigint;
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result of a pattern scan operation.
|
|
16
|
+
* Lazily evaluates the underlying generator and caches findings.
|
|
17
|
+
* Supports taking matches one-by-one or materializing the full result.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const result = currentProcess.findPattern('55 8B EC');
|
|
21
|
+
* const firstMatch = result.first(); // Scans until 1 match is found
|
|
22
|
+
* const allMatches = result.all(); // Fully exhausts the generator up to pattern config limit
|
|
23
|
+
*/
|
|
24
|
+
export declare class ScanResult implements Iterable<ScanEntry> {
|
|
25
|
+
readonly pattern: Pattern;
|
|
26
|
+
private generator;
|
|
27
|
+
private _cached;
|
|
28
|
+
private _isExhausted;
|
|
29
|
+
constructor(iterable: Iterable<ScanEntry>, pattern: Pattern);
|
|
30
|
+
/**
|
|
31
|
+
* Evaluates the generator up to 'n' elements and caches them internally.
|
|
32
|
+
*/
|
|
33
|
+
private pump;
|
|
34
|
+
/** Gets the first match and stops scanning further unless requested again. */
|
|
35
|
+
first(): ScanEntry | undefined;
|
|
36
|
+
/** Gets up to N matches. Scans only as much memory as needed. */
|
|
37
|
+
take(n: number): ScanEntry[];
|
|
38
|
+
/** Evaluates the scan fully, up to the pattern's configured limit. */
|
|
39
|
+
all(): ScanEntry[];
|
|
40
|
+
/** Shortcut to strictly evaluate the scan based on the limit and return the array. */
|
|
41
|
+
get entries(): ScanEntry[];
|
|
42
|
+
/** Number of matched entries (fully evaluates scan). */
|
|
43
|
+
get length(): number;
|
|
44
|
+
/** All matched addresses directly derived from entries. */
|
|
45
|
+
get addresses(): bigint[];
|
|
46
|
+
/** Combines another ScanResult efficiently. */
|
|
47
|
+
merge(other: ScanResult): ScanResult;
|
|
48
|
+
/**
|
|
49
|
+
* Lazily iterates over available entries, fetching from the scan engine only when needed.
|
|
50
|
+
* Bound efficiently by the limit configured on the `Pattern`.
|
|
51
|
+
*/
|
|
52
|
+
[Symbol.iterator](): Iterator<ScanEntry>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=scan-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan-result.d.ts","sourceRoot":"","sources":["../src/scan-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;GAIG;AACH,qBAAa,SAAS;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,UAAU,EAAE,MAAM,CAAC;gBAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,UAAU,EAAE,MAAM;IAK/D,SAAS,IAAI,MAAM;IAInB,QAAQ,IAAI,MAAM;CAMnB;AAED;;;;;;;;;GASG;AACH,qBAAa,UAAW,YAAW,QAAQ,CAAC,SAAS,CAAC;IACpD,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,YAAY,CAAS;gBAEjB,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO;IAK3D;;OAEG;IACH,OAAO,CAAC,IAAI;IAWZ,8EAA8E;IAC9E,KAAK,IAAI,SAAS,GAAG,SAAS;IAK9B,iEAAiE;IACjE,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE;IAK5B,sEAAsE;IACtE,GAAG,IAAI,SAAS,EAAE;IAWlB,sFAAsF;IACtF,IAAI,OAAO,IAAI,SAAS,EAAE,CAEzB;IAED,wDAAwD;IACxD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,2DAA2D;IAC3D,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;IAED,+CAA+C;IAC/C,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAUpC;;;OAGG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC;CAuB1C"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single pattern match entry.
|
|
3
|
+
* Stores the decoded numeric address (bigint) of the match.
|
|
4
|
+
* Call `toAddress()` to retrieve it — consistent with how ffi.address() works.
|
|
5
|
+
*/
|
|
6
|
+
export class ScanEntry {
|
|
7
|
+
address;
|
|
8
|
+
module;
|
|
9
|
+
constructor(address, module) {
|
|
10
|
+
this.address = address;
|
|
11
|
+
this.module = module;
|
|
12
|
+
}
|
|
13
|
+
toAddress() {
|
|
14
|
+
return this.address;
|
|
15
|
+
}
|
|
16
|
+
toString() {
|
|
17
|
+
const addressString = '0x' + this.address.toString(16).toUpperCase();
|
|
18
|
+
return this.module
|
|
19
|
+
? `${this.module.toString()}+${addressString}`
|
|
20
|
+
: addressString;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Result of a pattern scan operation.
|
|
25
|
+
* Lazily evaluates the underlying generator and caches findings.
|
|
26
|
+
* Supports taking matches one-by-one or materializing the full result.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const result = currentProcess.findPattern('55 8B EC');
|
|
30
|
+
* const firstMatch = result.first(); // Scans until 1 match is found
|
|
31
|
+
* const allMatches = result.all(); // Fully exhausts the generator up to pattern config limit
|
|
32
|
+
*/
|
|
33
|
+
export class ScanResult {
|
|
34
|
+
pattern;
|
|
35
|
+
generator;
|
|
36
|
+
_cached = [];
|
|
37
|
+
_isExhausted = false;
|
|
38
|
+
constructor(iterable, pattern) {
|
|
39
|
+
this.pattern = pattern;
|
|
40
|
+
this.generator = iterable[Symbol.iterator]();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Evaluates the generator up to 'n' elements and caches them internally.
|
|
44
|
+
*/
|
|
45
|
+
pump(n) {
|
|
46
|
+
while (!this._isExhausted && (n === undefined || this._cached.length < n)) {
|
|
47
|
+
const res = this.generator.next();
|
|
48
|
+
if (res.done) {
|
|
49
|
+
this._isExhausted = true;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._cached.push(res.value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Gets the first match and stops scanning further unless requested again. */
|
|
57
|
+
first() {
|
|
58
|
+
this.pump(1);
|
|
59
|
+
return this._cached[0];
|
|
60
|
+
}
|
|
61
|
+
/** Gets up to N matches. Scans only as much memory as needed. */
|
|
62
|
+
take(n) {
|
|
63
|
+
this.pump(n);
|
|
64
|
+
return this._cached.slice(0, n);
|
|
65
|
+
}
|
|
66
|
+
/** Evaluates the scan fully, up to the pattern's configured limit. */
|
|
67
|
+
all() {
|
|
68
|
+
const limit = this.pattern.maxResults;
|
|
69
|
+
if (limit > 0) {
|
|
70
|
+
this.pump(limit);
|
|
71
|
+
return this._cached.slice(0, limit);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.pump();
|
|
75
|
+
return [...this._cached];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Shortcut to strictly evaluate the scan based on the limit and return the array. */
|
|
79
|
+
get entries() {
|
|
80
|
+
return this.all();
|
|
81
|
+
}
|
|
82
|
+
/** Number of matched entries (fully evaluates scan). */
|
|
83
|
+
get length() {
|
|
84
|
+
return this.all().length;
|
|
85
|
+
}
|
|
86
|
+
/** All matched addresses directly derived from entries. */
|
|
87
|
+
get addresses() {
|
|
88
|
+
return this.all().map((e) => e.address);
|
|
89
|
+
}
|
|
90
|
+
/** Combines another ScanResult efficiently. */
|
|
91
|
+
merge(other) {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
93
|
+
const me = this;
|
|
94
|
+
const combined = function* () {
|
|
95
|
+
yield* me.all(); // Yields cached/evaluated from this
|
|
96
|
+
yield* other.all(); // Yields cached/evaluated from other
|
|
97
|
+
};
|
|
98
|
+
return new ScanResult(combined(), this.pattern);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Lazily iterates over available entries, fetching from the scan engine only when needed.
|
|
102
|
+
* Bound efficiently by the limit configured on the `Pattern`.
|
|
103
|
+
*/
|
|
104
|
+
*[Symbol.iterator]() {
|
|
105
|
+
const limit = this.pattern.maxResults;
|
|
106
|
+
let yielded = 0;
|
|
107
|
+
// First yield already evaluated results
|
|
108
|
+
for (const cachedEntry of this._cached) {
|
|
109
|
+
if (limit > 0 && yielded >= limit)
|
|
110
|
+
return;
|
|
111
|
+
yield cachedEntry;
|
|
112
|
+
yielded++;
|
|
113
|
+
}
|
|
114
|
+
// Now evaluate fresh parts if needed
|
|
115
|
+
while (!this._isExhausted && (limit === 0 || yielded < limit)) {
|
|
116
|
+
const res = this.generator.next();
|
|
117
|
+
if (res.done) {
|
|
118
|
+
this._isExhausted = true;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this._cached.push(res.value);
|
|
122
|
+
yield res.value;
|
|
123
|
+
yielded++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=scan-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan-result.js","sourceRoot":"","sources":["../src/scan-result.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACX,OAAO,CAAS;IAChB,MAAM,CAA6B;IAE5C,YAAY,OAAe,EAAE,MAAkC;QAC7D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,QAAQ;QACN,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACrE,OAAO,IAAI,CAAC,MAAM;YAChB,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,aAAa,EAAE;YAC9C,CAAC,CAAC,aAAa,CAAC;IACpB,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACL,OAAO,CAAU;IACzB,SAAS,CAAsB;IAC/B,OAAO,GAAgB,EAAE,CAAC;IAC1B,YAAY,GAAG,KAAK,CAAC;IAE7B,YAAY,QAA6B,EAAE,OAAgB;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,I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I,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;gBACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAC7B,MAAM,GAAG,CAAC,KAAK,CAAC;gBAChB,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Pattern } from './pattern';
|
|
2
|
+
/**
|
|
3
|
+
* Memory scanning utility
|
|
4
|
+
*/
|
|
5
|
+
export declare class Scanner {
|
|
6
|
+
/**
|
|
7
|
+
* Scans local memory for a pattern using a generator.
|
|
8
|
+
* Yields each matched address as a decoded bigint.
|
|
9
|
+
*
|
|
10
|
+
* @param base Memory address to start from
|
|
11
|
+
* @param size Total size of the memory region to scan
|
|
12
|
+
* @param pattern Pattern to search for
|
|
13
|
+
* @param chunkSize Size of each scan chunk (default: 1MB)
|
|
14
|
+
*/
|
|
15
|
+
static scan(base: bigint, size: number, pattern: Pattern, chunkSize?: number): Generator<bigint>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper method to scan a specific memory chunk with wildcards.
|
|
18
|
+
* Yields decoded bigint addresses.
|
|
19
|
+
*/
|
|
20
|
+
private static scanChunkWildcard;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC;;GAEG;AACH,qBAAa,OAAO;IAClB;;;;;;;;OAQG;IACH,MAAM,CAAE,IAAI,CACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,SAAS,GAAE,MAAoB,GAC9B,SAAS,CAAC,MAAM,CAAC;IAuFpB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAE,iBAAiB;CA2BlC"}
|