@memoryprocess/bindings 0.0.0-stage → 0.0.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/binding.gyp +46 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +27 -0
- package/dist/memoryprocess.node +0 -0
- package/dist/native.d.ts +128 -0
- package/native/hde/LICENSE-minhook.txt +81 -0
- package/native/hde/hde64.c +538 -0
- package/native/hde/hde64.h +113 -0
- package/native/hde/pstdint.h +39 -0
- package/native/hde/table64.h +74 -0
- package/native/memory.cc +21 -0
- package/native/memory.h +31 -0
- package/native/memoryprocess.cc +43 -0
- package/native/module.cc +1720 -0
- package/native/module.h +55 -0
- package/native/pattern.cc +304 -0
- package/native/process.cc +113 -0
- package/native/process.h +36 -0
- package/package.json +49 -4
- package/README.md +0 -3
package/binding.gyp
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "memoryprocess",
|
|
5
|
+
"include_dirs": [
|
|
6
|
+
"<!@(node -p \"require('node-addon-api').include\")"
|
|
7
|
+
],
|
|
8
|
+
"sources": [
|
|
9
|
+
"native/memoryprocess.cc",
|
|
10
|
+
"native/process.cc",
|
|
11
|
+
"native/memory.cc",
|
|
12
|
+
"native/module.cc",
|
|
13
|
+
"native/pattern.cc",
|
|
14
|
+
"native/hde/hde64.c"
|
|
15
|
+
],
|
|
16
|
+
"defines": [
|
|
17
|
+
"NAPI_DISABLE_CPP_EXCEPTIONS",
|
|
18
|
+
"NAPI_VERSION=<(napi_build_version)"
|
|
19
|
+
],
|
|
20
|
+
"conditions": [
|
|
21
|
+
["OS==\"win\"", {
|
|
22
|
+
"msvs_settings": {
|
|
23
|
+
"VCCLCompilerTool": {
|
|
24
|
+
"ExceptionHandling": 1,
|
|
25
|
+
"AdditionalOptions!": [ "-flto=thin", "-flto=full", "-flto" ]
|
|
26
|
+
},
|
|
27
|
+
"VCLibrarianTool": {
|
|
28
|
+
"AdditionalOptions!": [ "-flto=thin", "-flto=full", "-flto" ]
|
|
29
|
+
},
|
|
30
|
+
"VCLinkerTool": {
|
|
31
|
+
"AdditionalOptions!": [ "-flto=thin", "-flto=full", "-flto", "/opt:lldltojobs=<(lto_jobs)" ]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}]
|
|
35
|
+
],
|
|
36
|
+
# Node 26 official builds ship thin-LTO flags (-flto=thin, /opt:lldltojobs)
|
|
37
|
+
# that MSVC cannot link. The '%' lets these defaults be overridden but
|
|
38
|
+
# neutralises them when Node reports them enabled.
|
|
39
|
+
"variables": {
|
|
40
|
+
"enable_lto%": "false",
|
|
41
|
+
"enable_thin_lto%": "false",
|
|
42
|
+
"lto_jobs%": ""
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
// src/native.ts
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const __dir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const candidates = [
|
|
8
|
+
join(__dir, "memoryprocess.node"),
|
|
9
|
+
join(__dir, "..", "dist", "memoryprocess.node"),
|
|
10
|
+
join(__dir, "..", "build", "Release", "memoryprocess.node")
|
|
11
|
+
];
|
|
12
|
+
const native = (() => {
|
|
13
|
+
let lastErr;
|
|
14
|
+
for (const path of candidates) try {
|
|
15
|
+
return require(path);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
lastErr = e;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return require("node-gyp-build")(join(__dir, ".."));
|
|
21
|
+
} catch (e) {
|
|
22
|
+
lastErr = lastErr ?? e;
|
|
23
|
+
}
|
|
24
|
+
const detail = lastErr instanceof Error ? `: ${lastErr.message}` : "";
|
|
25
|
+
throw new Error(`memoryprocess native addon failed to load (run \`bun run build\`)${detail}`);
|
|
26
|
+
})();
|
|
27
|
+
export { native };
|
|
Binary file
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
interface Native {
|
|
2
|
+
openProcess(nameOrPid: string | number, access?: number): {
|
|
3
|
+
handle: number;
|
|
4
|
+
pid: number;
|
|
5
|
+
};
|
|
6
|
+
closeHandle(handle: number): boolean;
|
|
7
|
+
listProcesses(): {
|
|
8
|
+
pid: number;
|
|
9
|
+
name: string;
|
|
10
|
+
}[];
|
|
11
|
+
getModules(handle: number, pid: number): {
|
|
12
|
+
base: number;
|
|
13
|
+
size: number;
|
|
14
|
+
path: string;
|
|
15
|
+
}[];
|
|
16
|
+
getRegions(handle: number): {
|
|
17
|
+
baseAddress: number;
|
|
18
|
+
size: number;
|
|
19
|
+
protection: number;
|
|
20
|
+
type: number;
|
|
21
|
+
}[];
|
|
22
|
+
readValue(handle: number, address: number, type: string): number | bigint;
|
|
23
|
+
writeValue(handle: number, address: number, type: string, value: number | bigint): boolean;
|
|
24
|
+
readBuffer(handle: number, address: number, size: number): Buffer;
|
|
25
|
+
writeBuffer(handle: number, address: number, data: Buffer): boolean;
|
|
26
|
+
scan(pid: number, pattern: string, opts?: {
|
|
27
|
+
start?: number;
|
|
28
|
+
end?: number;
|
|
29
|
+
onlyReadable?: boolean;
|
|
30
|
+
}): Promise<bigint[]>;
|
|
31
|
+
scanValue(pid: number, needle: Uint8Array, opts?: {
|
|
32
|
+
start?: number;
|
|
33
|
+
end?: number;
|
|
34
|
+
onlyWritable?: boolean;
|
|
35
|
+
alignment?: number;
|
|
36
|
+
}): Promise<bigint[]>;
|
|
37
|
+
allocMemory(handle: number, size: number, protection: number, nearAddress?: number): bigint;
|
|
38
|
+
freeMemory(handle: number, address: number): boolean;
|
|
39
|
+
protectMemory(handle: number, address: number, size: number, protection: number): number;
|
|
40
|
+
isWow64(handle: number): boolean;
|
|
41
|
+
listThreads(pid: number): number[];
|
|
42
|
+
suspendThread(tid: number): boolean;
|
|
43
|
+
resumeThread(tid: number): boolean;
|
|
44
|
+
readSafe(handle: number, address: number, size: number): Buffer;
|
|
45
|
+
flushInstructions(handle: number, address: number, size: number): boolean;
|
|
46
|
+
injectDll(pid: number, dllPath: string, timeoutMs?: number): boolean;
|
|
47
|
+
ejectDll(pid: number, moduleBase: number): boolean;
|
|
48
|
+
queryAddress(handle: number, address: number): {
|
|
49
|
+
baseAddress: number;
|
|
50
|
+
allocationBase: number;
|
|
51
|
+
size: number;
|
|
52
|
+
protection: number;
|
|
53
|
+
state: number;
|
|
54
|
+
type: number;
|
|
55
|
+
} | null;
|
|
56
|
+
getThreadContext(tid: number): {
|
|
57
|
+
rip: bigint;
|
|
58
|
+
rsp: bigint;
|
|
59
|
+
rbp: bigint;
|
|
60
|
+
dr0: bigint;
|
|
61
|
+
dr1: bigint;
|
|
62
|
+
dr2: bigint;
|
|
63
|
+
dr3: bigint;
|
|
64
|
+
dr6: bigint;
|
|
65
|
+
dr7: bigint;
|
|
66
|
+
eflags: bigint;
|
|
67
|
+
} | null;
|
|
68
|
+
setThreadContext(tid: number, ctx: Partial<Record<'rip' | 'rsp' | 'rbp' | 'dr0' | 'dr1' | 'dr2' | 'dr3' | 'dr6' | 'dr7' | 'eflags', number | bigint>>): boolean;
|
|
69
|
+
callRemote(pid: number, fnAddress: number | bigint, param: number | bigint, timeoutMs?: number): number | null;
|
|
70
|
+
disasmInstructions(handle: number, address: number, count: number): {
|
|
71
|
+
offset: number;
|
|
72
|
+
length: number;
|
|
73
|
+
relative: boolean;
|
|
74
|
+
}[];
|
|
75
|
+
/**
|
|
76
|
+
* Walk instructions at `address` until `minBytes` are covered, then
|
|
77
|
+
* RELOCATE position-relative operands (rel32 branch/call immediates,
|
|
78
|
+
* RIP-relative disp32) so the stolen bytes are correct when executed from
|
|
79
|
+
* `stubAddr` (must be within rel32 range of `address`). External rel8/16
|
|
80
|
+
* branches (incl. LOOP/JECXZ) can't be widened — refused `HOOK_RELOCATE`,
|
|
81
|
+
* like MinHook; rel8/16 internal (target inside the stolen window) and
|
|
82
|
+
* all non-relative instructions copy verbatim. Without `stubAddr` any
|
|
83
|
+
* position-relative instruction is refused (inspection mode).
|
|
84
|
+
* Throws `HOOK_STEAL`/`HOOK_RELOCATE` — returns the relocated bytes.
|
|
85
|
+
*/
|
|
86
|
+
hookSteal(handle: number, address: number, minBytesOrOpts?: number | {
|
|
87
|
+
minBytes?: number;
|
|
88
|
+
stubAddr?: number | bigint;
|
|
89
|
+
}, stubAddr?: number | bigint): {
|
|
90
|
+
length: number;
|
|
91
|
+
bytes: Buffer;
|
|
92
|
+
original: Buffer;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Per-region VirtualProtectEx→write→restore across the whole write span —
|
|
96
|
+
* records each region's real old protection before writing, restores each
|
|
97
|
+
* individually. `restored=false` means part of the span is left weakened.
|
|
98
|
+
*/
|
|
99
|
+
writeProtectedMemory(handle: number, address: number, buffer: Buffer, protection?: number): {
|
|
100
|
+
ok: boolean;
|
|
101
|
+
restored: boolean;
|
|
102
|
+
protected: boolean;
|
|
103
|
+
};
|
|
104
|
+
/** Current thread id (TID) — used to refuse self-suspend. */
|
|
105
|
+
currentThreadId(): number;
|
|
106
|
+
suspendProcess(pid: number): boolean;
|
|
107
|
+
resumeProcess(pid: number): boolean;
|
|
108
|
+
enableDebugPrivilege(): boolean;
|
|
109
|
+
waitForExit(pid: number, timeoutMs?: number): Promise<number | null>;
|
|
110
|
+
findWhatWrites(pid: number, address: number | bigint, size: number, timeoutMs: number, maxHits: number): Promise<{
|
|
111
|
+
rip: bigint;
|
|
112
|
+
tid: number;
|
|
113
|
+
threadContext: {
|
|
114
|
+
rip: bigint;
|
|
115
|
+
rsp: bigint;
|
|
116
|
+
rbp: bigint;
|
|
117
|
+
dr0: bigint;
|
|
118
|
+
dr1: bigint;
|
|
119
|
+
dr2: bigint;
|
|
120
|
+
dr3: bigint;
|
|
121
|
+
dr6: bigint;
|
|
122
|
+
dr7: bigint;
|
|
123
|
+
eflags: bigint;
|
|
124
|
+
};
|
|
125
|
+
}[]>;
|
|
126
|
+
}
|
|
127
|
+
export declare const native: Native;
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
MinHook - The Minimalistic API Hooking Library for x64/x86
|
|
2
|
+
Copyright (C) 2009-2017 Tsuda Kageyu.
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions
|
|
7
|
+
are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
17
|
+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
18
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
|
19
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
|
|
27
|
+
================================================================================
|
|
28
|
+
Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov.
|
|
29
|
+
================================================================================
|
|
30
|
+
Hacker Disassembler Engine 32 C
|
|
31
|
+
Copyright (c) 2008-2009, Vyacheslav Patkov.
|
|
32
|
+
All rights reserved.
|
|
33
|
+
|
|
34
|
+
Redistribution and use in source and binary forms, with or without
|
|
35
|
+
modification, are permitted provided that the following conditions
|
|
36
|
+
are met:
|
|
37
|
+
|
|
38
|
+
1. Redistributions of source code must retain the above copyright
|
|
39
|
+
notice, this list of conditions and the following disclaimer.
|
|
40
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
41
|
+
notice, this list of conditions and the following disclaimer in the
|
|
42
|
+
documentation and/or other materials provided with the distribution.
|
|
43
|
+
|
|
44
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
45
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
46
|
+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
47
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
|
48
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
49
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
50
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
51
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
52
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
53
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
54
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
55
|
+
|
|
56
|
+
-------------------------------------------------------------------------------
|
|
57
|
+
Hacker Disassembler Engine 64 C
|
|
58
|
+
Copyright (c) 2008-2009, Vyacheslav Patkov.
|
|
59
|
+
All rights reserved.
|
|
60
|
+
|
|
61
|
+
Redistribution and use in source and binary forms, with or without
|
|
62
|
+
modification, are permitted provided that the following conditions
|
|
63
|
+
are met:
|
|
64
|
+
|
|
65
|
+
1. Redistributions of source code must retain the above copyright
|
|
66
|
+
notice, this list of conditions and the following disclaimer.
|
|
67
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
68
|
+
notice, this list of conditions and the following disclaimer in the
|
|
69
|
+
documentation and/or other materials provided with the distribution.
|
|
70
|
+
|
|
71
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
72
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
73
|
+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
74
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
|
75
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
76
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
77
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
78
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
79
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
80
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
81
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|