@cheatron/native 1.1.0
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/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/eslint.config.js +26 -0
- package/dist/eslint.config.js.map +1 -0
- package/dist/src/handle.d.ts +26 -0
- package/dist/src/handle.d.ts.map +1 -0
- package/dist/src/handle.js +57 -0
- package/dist/src/handle.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +3 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/module.d.ts +22 -0
- package/dist/src/module.d.ts.map +1 -0
- package/dist/src/module.js +55 -0
- package/dist/src/module.js.map +1 -0
- package/dist/src/process.d.ts +30 -0
- package/dist/src/process.d.ts.map +1 -0
- package/dist/src/process.js +104 -0
- package/dist/src/process.js.map +1 -0
- package/dist/src/thread.d.ts +38 -0
- package/dist/src/thread.d.ts.map +1 -0
- package/dist/src/thread.js +137 -0
- package/dist/src/thread.js.map +1 -0
- package/dist/tests/integration/memory.test.d.ts +2 -0
- package/dist/tests/integration/memory.test.d.ts.map +1 -0
- package/dist/tests/integration/memory.test.js +82 -0
- package/dist/tests/integration/memory.test.js.map +1 -0
- package/dist/tests/integration/thread.test.d.ts +2 -0
- package/dist/tests/integration/thread.test.d.ts.map +1 -0
- package/dist/tests/integration/thread.test.js +37 -0
- package/dist/tests/integration/thread.test.js.map +1 -0
- package/dist/tests/setup.d.ts +2 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +3 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/tests/unit/kernel32.test.d.ts +2 -0
- package/dist/tests/unit/kernel32.test.d.ts.map +1 -0
- package/dist/tests/unit/kernel32.test.js +28 -0
- package/dist/tests/unit/kernel32.test.js.map +1 -0
- package/dist/tests/unit/logger.test.d.ts +2 -0
- package/dist/tests/unit/logger.test.d.ts.map +1 -0
- package/dist/tests/unit/logger.test.js +29 -0
- package/dist/tests/unit/logger.test.js.map +1 -0
- package/dist/tests/unit/msvcrt.test.d.ts +2 -0
- package/dist/tests/unit/msvcrt.test.d.ts.map +1 -0
- package/dist/tests/unit/msvcrt.test.js +22 -0
- package/dist/tests/unit/msvcrt.test.js.map +1 -0
- package/dist/tests/unit/process.test.d.ts +2 -0
- package/dist/tests/unit/process.test.d.ts.map +1 -0
- package/dist/tests/unit/process.test.js +27 -0
- package/dist/tests/unit/process.test.js.map +1 -0
- package/dist/tests/unit/thread.test.d.ts +2 -0
- package/dist/tests/unit/thread.test.d.ts.map +1 -0
- package/dist/tests/unit/thread.test.js +35 -0
- package/dist/tests/unit/thread.test.js.map +1 -0
- package/dist/tests/unit/thread_creation.test.d.ts +2 -0
- package/dist/tests/unit/thread_creation.test.d.ts.map +1 -0
- package/dist/tests/unit/thread_creation.test.js +31 -0
- package/dist/tests/unit/thread_creation.test.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cheatron
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @cheatron/native
|
|
2
|
+
|
|
3
|
+
Ergonomic Win32 process and memory management API for Cheatron, powered by [Bun](https://bun.sh/) and [Koffi](https://koffi.dev/).
|
|
4
|
+
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> **64-bit Windows only.** This project exclusively targets 64-bit Windows environments.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Process Management**: Open processes by PID, access the current process, and query memory information.
|
|
11
|
+
- **Memory Operations**: Read and write memory buffers from/to target processes.
|
|
12
|
+
- **Thread Management**: Create local/remote threads, get/set thread context, suspend/resume, and track exit codes.
|
|
13
|
+
- **Module Helper**: Easy access to loaded modules (`kernel32.dll`, `msvcrt.dll`, etc.) and function addresses.
|
|
14
|
+
- **Low-level FFI**: Direct access to `Kernel32Impl` and `MsvcrtImpl` for advanced Win32 API calls.
|
|
15
|
+
- **Safe Handles**: Automatic handle cleanup using `FinalizationRegistry`.
|
|
16
|
+
- **Integrated Logging**: Scoped logging powered by `@cheatron/log`.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bun add @cheatron/native
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Process, currentProcess } from '@cheatron/native';
|
|
28
|
+
|
|
29
|
+
// Open a process by ID
|
|
30
|
+
const proc = Process.open(1234);
|
|
31
|
+
|
|
32
|
+
// Read memory
|
|
33
|
+
const buffer = proc.readMemory(0x10000000n, 1024);
|
|
34
|
+
console.log(buffer.toString('hex'));
|
|
35
|
+
|
|
36
|
+
// Write memory
|
|
37
|
+
proc.writeMemory(0x20000000n, Buffer.from([0x90, 0x90, 0x90]));
|
|
38
|
+
|
|
39
|
+
// Create a thread in the target process
|
|
40
|
+
const thread = proc.createThread(0x30000000n);
|
|
41
|
+
thread.wait();
|
|
42
|
+
console.log(`Thread exited with: ${thread.getExitCode()}`);
|
|
43
|
+
|
|
44
|
+
proc.close();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Core Components
|
|
48
|
+
|
|
49
|
+
### Process
|
|
50
|
+
|
|
51
|
+
The `Process` class provides methods for interacting with Windows processes. Use `Process.open(pid)` or `Process.current()` to get an instance.
|
|
52
|
+
|
|
53
|
+
- `readMemory(address: bigint, size: number): Buffer`
|
|
54
|
+
- `writeMemory(address: bigint, buffer: Buffer): void`
|
|
55
|
+
- `createThread(startAddress: bigint, ...): Thread`
|
|
56
|
+
- `virtualQuery(address: bigint): MemoryBasicInformation`
|
|
57
|
+
|
|
58
|
+
### Thread
|
|
59
|
+
|
|
60
|
+
Manage execution flow within processes.
|
|
61
|
+
|
|
62
|
+
- `suspend() / resume(): number`
|
|
63
|
+
- `getContext(flags?: number): ThreadContext`
|
|
64
|
+
- `setContext(ctx: ThreadContext): void`
|
|
65
|
+
- `getExitCode(): number`
|
|
66
|
+
- `wait(timeoutMs?: number): WaitReturn`
|
|
67
|
+
|
|
68
|
+
### Module
|
|
69
|
+
|
|
70
|
+
Enumerate and interact with loaded DLLs.
|
|
71
|
+
|
|
72
|
+
- `Module.get(name: string): Module`
|
|
73
|
+
- `Module.kernel32 / Module.crt`: Pre-defined instances.
|
|
74
|
+
- `getProcAddress(name: string): bigint`
|
|
75
|
+
|
|
76
|
+
## Advanced FFI
|
|
77
|
+
|
|
78
|
+
For tasks not covered by the ergonomic API, you can use the raw implementations directly:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { Kernel32Impl, MsvcrtImpl } from '@cheatron/native';
|
|
82
|
+
|
|
83
|
+
const hProcess = Kernel32Impl.GetCurrentProcess();
|
|
84
|
+
const ptr = MsvcrtImpl.malloc(1024);
|
|
85
|
+
MsvcrtImpl.free(ptr);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
This project uses [Bun](https://bun.sh/). To run tests on Linux, you need `wine`.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Install dependencies
|
|
94
|
+
bun install
|
|
95
|
+
|
|
96
|
+
# Run tests (runs natively or via wine depending on environment)
|
|
97
|
+
bun test
|
|
98
|
+
|
|
99
|
+
# Build the project
|
|
100
|
+
bun run build
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import prettierConfig from 'eslint-config-prettier';
|
|
5
|
+
export default tseslint.config({ ignores: ['dist', 'node_modules', 'build'] }, {
|
|
6
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
7
|
+
files: ['**/*.{ts,tsx,js,jsx}'],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
ecmaVersion: 2024,
|
|
10
|
+
sourceType: 'module',
|
|
11
|
+
globals: {
|
|
12
|
+
...globals.browser,
|
|
13
|
+
...globals.node,
|
|
14
|
+
},
|
|
15
|
+
parserOptions: {
|
|
16
|
+
project: ['./tsconfig.json'],
|
|
17
|
+
tsconfigRootDir: import.meta.dirname,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
'no-unused-vars': 'warn',
|
|
22
|
+
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
23
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
24
|
+
},
|
|
25
|
+
}, prettierConfig);
|
|
26
|
+
//# sourceMappingURL=eslint.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eslint.config.js","sourceRoot":"","sources":["../eslint.config.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,cAAc,MAAM,wBAAwB,CAAC;AAEpD,eAAe,QAAQ,CAAC,MAAM,CAC5B,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,EAC9C;IACE,OAAO,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC;IAClE,KAAK,EAAE,CAAC,sBAAsB,CAAC;IAC/B,eAAe,EAAE;QACf,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE;YACP,GAAG,OAAO,CAAC,OAAO;YAClB,GAAG,OAAO,CAAC,IAAI;SAChB;QACD,aAAa,EAAE;YACb,OAAO,EAAE,CAAC,iBAAiB,CAAC;YAC5B,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;SACrC;KACF;IACD,KAAK,EAAE;QACL,gBAAgB,EAAE,MAAM;QACxB,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QACpD,oCAAoC,EAAE,MAAM;KAC7C;CACF,EACD,cAAc,CACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WaitReturn, type HANDLE } from '@cheatron/native-bindings';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for Win32 handles
|
|
4
|
+
*/
|
|
5
|
+
export declare class Handle {
|
|
6
|
+
protected _handle: HANDLE;
|
|
7
|
+
constructor(handle: HANDLE, autoClose?: boolean);
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the handle is valid
|
|
10
|
+
*/
|
|
11
|
+
isValid(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Closes the handle
|
|
14
|
+
*/
|
|
15
|
+
close(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Waits for the handle to signal
|
|
18
|
+
* @param timeoutMs Timeout in milliseconds (default: INFINITE)
|
|
19
|
+
*/
|
|
20
|
+
wait(timeoutMs?: number): WaitReturn;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the raw handle
|
|
23
|
+
*/
|
|
24
|
+
get handle(): HANDLE;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAC;AAcnC;;GAEG;AACH,qBAAa,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEd,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,OAAc;IAOrD;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,KAAK;IASL;;;OAGG;IACH,IAAI,CAAC,SAAS,GAAE,MAAiB,GAAG,UAAU;IAS9C;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Kernel32Impl, INFINITE, WaitReturn, } from '@cheatron/native-bindings';
|
|
2
|
+
import { log } from './logger';
|
|
3
|
+
const handleLog = log.child('Handle');
|
|
4
|
+
/**
|
|
5
|
+
* Handle management registry for automatic cleanup
|
|
6
|
+
*/
|
|
7
|
+
const registry = new FinalizationRegistry((handle) => {
|
|
8
|
+
if (handle) {
|
|
9
|
+
Kernel32Impl.CloseHandle(handle);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Base class for Win32 handles
|
|
14
|
+
*/
|
|
15
|
+
export class Handle {
|
|
16
|
+
_handle;
|
|
17
|
+
constructor(handle, autoClose = true) {
|
|
18
|
+
this._handle = handle;
|
|
19
|
+
if (autoClose && handle) {
|
|
20
|
+
registry.register(this, handle, this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the handle is valid
|
|
25
|
+
*/
|
|
26
|
+
isValid() {
|
|
27
|
+
return this._handle !== null && this._handle !== undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Closes the handle
|
|
31
|
+
*/
|
|
32
|
+
close() {
|
|
33
|
+
if (this.isValid()) {
|
|
34
|
+
const h = this._handle;
|
|
35
|
+
this._handle = null;
|
|
36
|
+
registry.unregister(this);
|
|
37
|
+
Kernel32Impl.CloseHandle(h);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Waits for the handle to signal
|
|
42
|
+
* @param timeoutMs Timeout in milliseconds (default: INFINITE)
|
|
43
|
+
*/
|
|
44
|
+
wait(timeoutMs = INFINITE) {
|
|
45
|
+
if (!this.isValid())
|
|
46
|
+
throw new Error('Handle is closed');
|
|
47
|
+
handleLog.debug(`Waiting for handle to signal (Timeout: ${timeoutMs}ms)`);
|
|
48
|
+
return Kernel32Impl.WaitForSingleObject(this._handle, timeoutMs);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the raw handle
|
|
52
|
+
*/
|
|
53
|
+
get handle() {
|
|
54
|
+
return this._handle;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,GAEX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAS,CAAC,MAAM,EAAE,EAAE;IAC3D,IAAI,MAAM,EAAE,CAAC;QACX,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,OAAO,MAAM;IACP,OAAO,CAAS;IAE1B,YAAY,MAAc,EAAE,YAAqB,IAAI;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;YACxB,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACnB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,IAAK,CAAC;YACrB,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC1B,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,YAAoB,QAAQ;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACzD,SAAS,CAAC,KAAK,CAAC,0CAA0C,SAAS,KAAK,CAAC,CAAC;QAC1E,OAAO,YAAY,CAAC,mBAAmB,CACrC,IAAI,CAAC,OAAO,EACZ,SAAS,CACI,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { log } from './logger';
|
|
2
|
+
export * from './thread';
|
|
3
|
+
export * from './process';
|
|
4
|
+
export * from './module';
|
|
5
|
+
export * from './handle';
|
|
6
|
+
export * from '@cheatron/native-bindings';
|
|
7
|
+
export type * from '@cheatron/native-bindings';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,cAAc,2BAA2B,CAAC;AAC1C,mBAAmB,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAEzB,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,uCAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,CAAC,MAAM,GAAG,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type HANDLE, type HMODULE } from '@cheatron/native-bindings';
|
|
2
|
+
import { Handle } from './handle';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a loaded module
|
|
5
|
+
*/
|
|
6
|
+
export declare class Module extends Handle {
|
|
7
|
+
protected _name: string;
|
|
8
|
+
private static _kernel32;
|
|
9
|
+
private static _crt;
|
|
10
|
+
constructor(handle: HMODULE, name: string);
|
|
11
|
+
static get kernel32(): Module;
|
|
12
|
+
static get crt(): Module;
|
|
13
|
+
/**
|
|
14
|
+
* Gets a module handle for the specified module name
|
|
15
|
+
* Automatically detects if the name is ANSI or Unicode
|
|
16
|
+
* @param name Module name (e.g., 'kernel32.dll')
|
|
17
|
+
*/
|
|
18
|
+
static get(name: string): Module;
|
|
19
|
+
getProcAddress(procName: string): HANDLE;
|
|
20
|
+
get name(): string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,OAAO,EACb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC;;GAEG;AACH,qBAAa,MAAO,SAAQ,MAAM;IAChC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IACjC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAS;gBAEhB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM;IAMzC,MAAM,KAAK,QAAQ,IAAI,MAAM,CAK5B;IAED,MAAM,KAAK,GAAG,IAAI,MAAM,CAKvB;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAehC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAQxC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Kernel32Impl, } from '@cheatron/native-bindings';
|
|
2
|
+
import { Handle } from './handle';
|
|
3
|
+
import { log } from './logger';
|
|
4
|
+
const moduleLog = log.child('Module');
|
|
5
|
+
/**
|
|
6
|
+
* Represents a loaded module
|
|
7
|
+
*/
|
|
8
|
+
export class Module extends Handle {
|
|
9
|
+
_name;
|
|
10
|
+
static _kernel32;
|
|
11
|
+
static _crt;
|
|
12
|
+
constructor(handle, name) {
|
|
13
|
+
// Module handles from GetModuleHandle should not be closed with CloseHandle
|
|
14
|
+
super(handle, false);
|
|
15
|
+
this._name = name;
|
|
16
|
+
}
|
|
17
|
+
static get kernel32() {
|
|
18
|
+
if (!this._kernel32) {
|
|
19
|
+
this._kernel32 = this.get('kernel32.dll');
|
|
20
|
+
}
|
|
21
|
+
return this._kernel32;
|
|
22
|
+
}
|
|
23
|
+
static get crt() {
|
|
24
|
+
if (!this._crt) {
|
|
25
|
+
this._crt = this.get('msvcrt.dll');
|
|
26
|
+
}
|
|
27
|
+
return this._crt;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets a module handle for the specified module name
|
|
31
|
+
* Automatically detects if the name is ANSI or Unicode
|
|
32
|
+
* @param name Module name (e.g., 'kernel32.dll')
|
|
33
|
+
*/
|
|
34
|
+
static get(name) {
|
|
35
|
+
moduleLog.debug(`Getting module handle for: ${name}`);
|
|
36
|
+
// Simple ASCII check: any char > 127 means we should use Unicode API
|
|
37
|
+
const isUnicode = Array.from(name).some((char) => char.charCodeAt(0) > 127);
|
|
38
|
+
const handle = isUnicode
|
|
39
|
+
? Kernel32Impl.GetModuleHandleW(name)
|
|
40
|
+
: Kernel32Impl.GetModuleHandleA(name);
|
|
41
|
+
if (!handle) {
|
|
42
|
+
throw new Error(`Failed to get module handle for ${name}`);
|
|
43
|
+
}
|
|
44
|
+
return new Module(handle, name);
|
|
45
|
+
}
|
|
46
|
+
getProcAddress(procName) {
|
|
47
|
+
if (!this.isValid())
|
|
48
|
+
throw new Error('Module handle is closed');
|
|
49
|
+
return Kernel32Impl.GetProcAddress(this._handle, procName);
|
|
50
|
+
}
|
|
51
|
+
get name() {
|
|
52
|
+
return this._name;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAGb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,MAAM;IACtB,KAAK,CAAS;IAChB,MAAM,CAAC,SAAS,CAAS;IACzB,MAAM,CAAC,IAAI,CAAS;IAE5B,YAAY,MAAe,EAAE,IAAY;QACvC,4EAA4E;QAC5E,KAAK,CAAC,MAA2B,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;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,CACT,CAAC;IACJ,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Thread } from './thread';
|
|
2
|
+
import { ThreadCreationFlags, type SecurityAttributes, type MemoryBasicInformation, type HANDLE, type LPVOID, type SIZE_T } from '@cheatron/native-bindings';
|
|
3
|
+
import { Handle } from './handle';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a process handle
|
|
6
|
+
*/
|
|
7
|
+
export declare class Process extends Handle {
|
|
8
|
+
protected _pid: number;
|
|
9
|
+
constructor(handle: HANDLE, pid?: number, autoClose?: boolean);
|
|
10
|
+
static open(pid: number, access?: number): Process;
|
|
11
|
+
readMemory(address: LPVOID, size: number): Buffer;
|
|
12
|
+
read: (address: LPVOID, size: number) => Buffer;
|
|
13
|
+
writeMemory(address: LPVOID, buffer: Buffer): void;
|
|
14
|
+
write: (address: LPVOID, buffer: Buffer) => void;
|
|
15
|
+
createThread(startAddress: LPVOID, parameter?: LPVOID | null, stackSize?: SIZE_T, flags?: ThreadCreationFlags | number, attributes?: SecurityAttributes | LPVOID | null): Thread;
|
|
16
|
+
virtualQuery(address: LPVOID): MemoryBasicInformation;
|
|
17
|
+
query: (address: LPVOID) => MemoryBasicInformation;
|
|
18
|
+
static current(): CurrentProcess;
|
|
19
|
+
get pid(): number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents the current process (singleton)
|
|
23
|
+
*/
|
|
24
|
+
export declare class CurrentProcess extends Process {
|
|
25
|
+
constructor();
|
|
26
|
+
createThread(startAddress: LPVOID, parameter?: LPVOID | null, stackSize?: SIZE_T, flags?: ThreadCreationFlags | number, attributes?: SecurityAttributes | LPVOID | null): Thread;
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const currentProcess: CurrentProcess;
|
|
30
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @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F;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,OAAO;;IAMhC,YAAY,CACnB,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,SAAS,GAAE,MAAoB,EAC/B,KAAK,CAAC,EAAE,mBAAmB,GAAG,MAAM,EACpC,UAAU,CAAC,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI,GAC9C,MAAM;IAIA,KAAK;CAGf;AAID,eAAO,MAAM,cAAc,EAAE,cAU3B,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Thread } from './thread';
|
|
2
|
+
import { Kernel32Impl, ffi, ProcessAccess, ThreadCreationFlags, MEMORY_BASIC_INFORMATION, MBI_SIZE, } from '@cheatron/native-bindings';
|
|
3
|
+
import { Handle } from './handle';
|
|
4
|
+
import { log } from './logger';
|
|
5
|
+
const processLog = log.child('Process');
|
|
6
|
+
/**
|
|
7
|
+
* Represents a process handle
|
|
8
|
+
*/
|
|
9
|
+
export class Process extends Handle {
|
|
10
|
+
_pid;
|
|
11
|
+
constructor(handle, pid, autoClose = true) {
|
|
12
|
+
super(handle, autoClose);
|
|
13
|
+
this._pid = pid ?? Kernel32Impl.GetProcessId(handle);
|
|
14
|
+
}
|
|
15
|
+
static open(pid, access = ProcessAccess.ALL_ACCESS) {
|
|
16
|
+
processLog.debug(`Opening process ${pid} with access ${access}`);
|
|
17
|
+
const handle = Kernel32Impl.OpenProcess(access, 0, pid);
|
|
18
|
+
if (!handle) {
|
|
19
|
+
processLog.warn(`Failed to open process ${pid}`);
|
|
20
|
+
throw new Error(`Failed to open process ${pid}`);
|
|
21
|
+
}
|
|
22
|
+
return new Process(handle, pid);
|
|
23
|
+
}
|
|
24
|
+
readMemory(address, size) {
|
|
25
|
+
if (!this.isValid())
|
|
26
|
+
throw new Error('Process handle is closed');
|
|
27
|
+
const buf = Buffer.alloc(size);
|
|
28
|
+
const success = Kernel32Impl.ReadProcessMemory(this._handle, address, buf, size, null);
|
|
29
|
+
if (!success) {
|
|
30
|
+
processLog.error(`ReadProcessMemory failed at 0x${address.toString(16)}`);
|
|
31
|
+
throw new Error(`ReadProcessMemory failed at 0x${address.toString(16)}`);
|
|
32
|
+
}
|
|
33
|
+
return buf;
|
|
34
|
+
}
|
|
35
|
+
read = this.readMemory;
|
|
36
|
+
writeMemory(address, buffer) {
|
|
37
|
+
if (!this.isValid())
|
|
38
|
+
throw new Error('Process handle is closed');
|
|
39
|
+
const success = Kernel32Impl.WriteProcessMemory(this._handle, address, buffer, buffer.length, null);
|
|
40
|
+
if (!success) {
|
|
41
|
+
processLog.error(`WriteProcessMemory failed at 0x${address.toString(16)}`);
|
|
42
|
+
throw new Error(`WriteProcessMemory failed at 0x${address.toString(16)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
write = this.writeMemory;
|
|
46
|
+
createThread(startAddress, parameter = null, stackSize = 0, flags = ThreadCreationFlags.IMMEDIATE, attributes = null) {
|
|
47
|
+
if (!this.isValid())
|
|
48
|
+
throw new Error('Process handle is closed');
|
|
49
|
+
processLog.debug(`Creating remote thread at 0x${startAddress.toString(16)} (PID: ${this._pid})`);
|
|
50
|
+
const handle = Kernel32Impl.CreateRemoteThread(this._handle, attributes, stackSize, startAddress, parameter, flags, null);
|
|
51
|
+
if (!handle) {
|
|
52
|
+
processLog.error('CreateRemoteThread failed');
|
|
53
|
+
throw new Error('CreateRemoteThread failed');
|
|
54
|
+
}
|
|
55
|
+
return new Thread(handle);
|
|
56
|
+
}
|
|
57
|
+
virtualQuery(address) {
|
|
58
|
+
if (!this.isValid())
|
|
59
|
+
throw new Error('Process handle is closed');
|
|
60
|
+
const buf = Buffer.alloc(MBI_SIZE);
|
|
61
|
+
const result = Kernel32Impl.VirtualQueryEx(this._handle, address, buf, MBI_SIZE);
|
|
62
|
+
if (result === 0) {
|
|
63
|
+
processLog.error(`VirtualQueryEx failed at 0x${address.toString(16)}`);
|
|
64
|
+
throw new Error(`VirtualQueryEx failed at 0x${address.toString(16)}`);
|
|
65
|
+
}
|
|
66
|
+
return ffi.decode(buf, MEMORY_BASIC_INFORMATION);
|
|
67
|
+
}
|
|
68
|
+
query = this.virtualQuery;
|
|
69
|
+
static current() {
|
|
70
|
+
return currentProcess;
|
|
71
|
+
}
|
|
72
|
+
get pid() {
|
|
73
|
+
return this._pid;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Represents the current process (singleton)
|
|
78
|
+
*/
|
|
79
|
+
export class CurrentProcess extends Process {
|
|
80
|
+
constructor() {
|
|
81
|
+
// Current process uses a pseudo-handle that doesn't need closing
|
|
82
|
+
super(Kernel32Impl.GetCurrentProcess(), Kernel32Impl.GetCurrentProcessId());
|
|
83
|
+
}
|
|
84
|
+
createThread(startAddress, parameter, stackSize = 0, flags, attributes) {
|
|
85
|
+
return Thread.create(startAddress, parameter, stackSize, flags, attributes);
|
|
86
|
+
}
|
|
87
|
+
close() {
|
|
88
|
+
this._handle = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Export a pre-initialized instance of the current process (lazy via Proxy)
|
|
92
|
+
let _currentProcess;
|
|
93
|
+
export const currentProcess = new Proxy({}, {
|
|
94
|
+
get(_target, prop, receiver) {
|
|
95
|
+
if (!_currentProcess) {
|
|
96
|
+
_currentProcess = new CurrentProcess();
|
|
97
|
+
}
|
|
98
|
+
return Reflect.get(_currentProcess, prop, receiver);
|
|
99
|
+
},
|
|
100
|
+
getPrototypeOf() {
|
|
101
|
+
return CurrentProcess.prototype;
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
//# 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,EACL,YAAY,EACZ,GAAG,EACH,aAAa,EACb,mBAAmB,E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AAK,CAAC,YAAY,CAAC,iBAAiB,EAAE,EAAE,YAAY,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC9E,CAAC;IAEQ,YAAY,CACnB,YAAoB,EACpB,SAAyB,EACzB,YAAoB,CAAW,EAC/B,KAAoC,EACpC,UAA+C;QAE/C,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAC9E,CAAC;IAEQ,KAAK;QACZ,IAAI,CAAC,OAAO,GAAG,IAAK,CAAC;IACvB,CAAC;CACF;AAED,4EAA4E;AAC5E,IAAI,eAA2C,CAAC;AAChD,MAAM,CAAC,MAAM,cAAc,GAAmB,IAAI,KAAK,CAAC,EAAoB,EAAE;IAC5E,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;QACzB,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,IAAI,cAAc,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IACD,cAAc;QACZ,OAAO,cAAc,CAAC,SAAS,CAAC;IAClC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ThreadCreationFlags, type SecurityAttributes, type ThreadContext, type HANDLE, type LPVOID, type SIZE_T } from '@cheatron/native-bindings';
|
|
2
|
+
import { Handle } from './handle';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a thread handle
|
|
5
|
+
*/
|
|
6
|
+
export declare class Thread extends Handle {
|
|
7
|
+
protected _tid: number;
|
|
8
|
+
constructor(handle: HANDLE, tid?: number, autoClose?: boolean);
|
|
9
|
+
static open(threadId: number, access?: number): Thread;
|
|
10
|
+
static create(startAddress: LPVOID, parameter?: LPVOID | null, stackSize?: SIZE_T, flags?: ThreadCreationFlags | number, attributes?: SecurityAttributes | LPVOID | null): Thread;
|
|
11
|
+
static current(): CurrentThread;
|
|
12
|
+
static currentId(): number;
|
|
13
|
+
suspend(): number;
|
|
14
|
+
resume(): number;
|
|
15
|
+
getContext(flags?: number): ThreadContext;
|
|
16
|
+
setContext(ctx: ThreadContext): void;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the thread exit code
|
|
19
|
+
* @returns Exit code (STILL_ACTIVE means it's still running)
|
|
20
|
+
*/
|
|
21
|
+
getExitCode(): number;
|
|
22
|
+
get tid(): number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Thread states
|
|
26
|
+
*/
|
|
27
|
+
export declare const ThreadState: {
|
|
28
|
+
STILL_ACTIVE: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents the current thread (singleton)
|
|
32
|
+
*/
|
|
33
|
+
export declare class CurrentThread extends Thread {
|
|
34
|
+
constructor();
|
|
35
|
+
close(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare const currentThread: CurrentThread;
|
|
38
|
+
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,mBAAmB,EAGnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC;;GAEG;AACH,qBAAa,MAAO,SAAQ,MAAM;IAChC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,OAAc;IAKnE,MAAM,CAAC,IAAI,CACT,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAgC,GACvC,MAAM;IAUT,MAAM,CAAC,MAAM,CAC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