@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.
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Hacker Disassembler Engine 64 C
3
+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4
+ * All rights reserved.
5
+ *
6
+ */
7
+
8
+ #define C_NONE 0x00
9
+ #define C_MODRM 0x01
10
+ #define C_IMM8 0x02
11
+ #define C_IMM16 0x04
12
+ #define C_IMM_P66 0x10
13
+ #define C_REL8 0x20
14
+ #define C_REL32 0x40
15
+ #define C_GROUP 0x80
16
+ #define C_ERROR 0xff
17
+
18
+ #define PRE_ANY 0x00
19
+ #define PRE_NONE 0x01
20
+ #define PRE_F2 0x02
21
+ #define PRE_F3 0x04
22
+ #define PRE_66 0x08
23
+ #define PRE_67 0x10
24
+ #define PRE_LOCK 0x20
25
+ #define PRE_SEG 0x40
26
+ #define PRE_ALL 0xff
27
+
28
+ #define DELTA_OPCODES 0x4a
29
+ #define DELTA_FPU_REG 0xfd
30
+ #define DELTA_FPU_MODRM 0x104
31
+ #define DELTA_PREFIXES 0x13c
32
+ #define DELTA_OP_LOCK_OK 0x1ae
33
+ #define DELTA_OP2_LOCK_OK 0x1c6
34
+ #define DELTA_OP_ONLY_MEM 0x1d8
35
+ #define DELTA_OP2_ONLY_MEM 0x1e7
36
+
37
+ unsigned char hde64_table[] = {
38
+ 0xa5,0xaa,0xa5,0xaa,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5,
39
+ 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1,
40
+ 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea,
41
+ 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0,
42
+ 0xc0,0xc2,0xc0,0xe6,0x03,0x7e,0x11,0x7e,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab,
43
+ 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92,
44
+ 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90,
45
+ 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b,
46
+ 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,
47
+ 0x5b,0x5b,0x86,0x01,0x01,0x01,0x00,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xa0,
48
+ 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20,
49
+ 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff,
50
+ 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00,
51
+ 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01,
52
+ 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10,
53
+ 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00,
54
+ 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00,
55
+ 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00,
56
+ 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00,
57
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,
58
+ 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00,
59
+ 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40,
60
+ 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43,
61
+ 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
62
+ 0x40,0x40,0x64,0x64,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40,
63
+ 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06,
64
+ 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07,
65
+ 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x00,0x00,
66
+ 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10,
67
+ 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00,
68
+ 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb,
69
+ 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff,
70
+ 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0xff,0x12,0x08,0x00,0x13,0x09,
71
+ 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0xff,0xb2,0xff,
72
+ 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x09,
73
+ 0x00,0xf0,0x02,0x00
74
+ };
@@ -0,0 +1,21 @@
1
+ #include "memory.h"
2
+ #include <system_error>
3
+
4
+ namespace mp {
5
+
6
+ std::vector<std::uint8_t> ReadBytes(HANDLE proc, std::uintptr_t address, std::size_t size) {
7
+ std::vector<std::uint8_t> buf(size);
8
+ SIZE_T read = 0;
9
+ if (!ReadProcessMemory(proc, reinterpret_cast<LPCVOID>(address), buf.data(), size, &read)) {
10
+ throw std::system_error(static_cast<int>(GetLastError()), std::system_category(), "ReadProcessMemory");
11
+ }
12
+ buf.resize(read);
13
+ return buf;
14
+ }
15
+
16
+ bool WriteBytes(HANDLE proc, std::uintptr_t address, const std::uint8_t* data, std::size_t size) {
17
+ SIZE_T written = 0;
18
+ return WriteProcessMemory(proc, reinterpret_cast<LPVOID>(address), data, size, &written) && written == size;
19
+ }
20
+
21
+ } // namespace mp
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+ #include <napi.h>
3
+ #include <windows.h>
4
+ #include <cstdint>
5
+ #include <vector>
6
+
7
+ namespace mp {
8
+
9
+ // Read `size` bytes from `address` in `proc`. Returns bytes actually read.
10
+ // Throws LastError on hard failure (0 bytes && error != PARTIAL).
11
+ std::vector<std::uint8_t> ReadBytes(HANDLE proc, std::uintptr_t address, std::size_t size);
12
+ bool WriteBytes(HANDLE proc, std::uintptr_t address, const std::uint8_t* data, std::size_t size);
13
+
14
+ // Typed helpers
15
+ template <typename T>
16
+ T ReadValue(HANDLE proc, std::uintptr_t address) {
17
+ T out{};
18
+ SIZE_T read = 0;
19
+ if (!ReadProcessMemory(proc, reinterpret_cast<LPCVOID>(address), &out, sizeof(T), &read) || read != sizeof(T)) {
20
+ throw std::system_error(static_cast<int>(GetLastError()), std::system_category(), "ReadProcessMemory");
21
+ }
22
+ return out;
23
+ }
24
+
25
+ template <typename T>
26
+ bool WriteValue(HANDLE proc, std::uintptr_t address, const T& value) {
27
+ SIZE_T written = 0;
28
+ return WriteProcessMemory(proc, reinterpret_cast<LPVOID>(address), &value, sizeof(T), &written) && written == sizeof(T);
29
+ }
30
+
31
+ } // namespace mp
@@ -0,0 +1,43 @@
1
+ #include <napi.h>
2
+ #include "module.h"
3
+
4
+ static Napi::Object Init(Napi::Env env, Napi::Object exports) {
5
+ exports.Set("openProcess", Napi::Function::New(env, mp::OpenProcessSync));
6
+ exports.Set("closeHandle", Napi::Function::New(env, mp::CloseHandleSync));
7
+ exports.Set("listProcesses", Napi::Function::New(env, mp::ListProcessesSync));
8
+ exports.Set("getModules", Napi::Function::New(env, mp::GetModulesSync));
9
+ exports.Set("getRegions", Napi::Function::New(env, mp::GetRegionsSync));
10
+ exports.Set("readValue", Napi::Function::New(env, mp::ReadValueSync));
11
+ exports.Set("writeValue", Napi::Function::New(env, mp::WriteValueSync));
12
+ exports.Set("readBuffer", Napi::Function::New(env, mp::ReadBufferSync));
13
+ exports.Set("writeBuffer", Napi::Function::New(env, mp::WriteBufferSync));
14
+ exports.Set("scan", Napi::Function::New(env, mp::ScanAsync));
15
+ exports.Set("allocMemory", Napi::Function::New(env, mp::AllocMemorySync));
16
+ exports.Set("freeMemory", Napi::Function::New(env, mp::FreeMemorySync));
17
+ exports.Set("protectMemory", Napi::Function::New(env, mp::ProtectMemorySync));
18
+ exports.Set("isWow64", Napi::Function::New(env, mp::IsWow64Sync));
19
+ exports.Set("listThreads", Napi::Function::New(env, mp::ListThreadsSync));
20
+ exports.Set("suspendThread", Napi::Function::New(env, mp::SuspendThreadSync));
21
+ exports.Set("resumeThread", Napi::Function::New(env, mp::ResumeThreadSync));
22
+ exports.Set("readSafe", Napi::Function::New(env, mp::ReadSafeSync));
23
+ exports.Set("flushInstructions", Napi::Function::New(env, mp::FlushInstructionsSync));
24
+ exports.Set("injectDll", Napi::Function::New(env, mp::InjectDllSync));
25
+ exports.Set("ejectDll", Napi::Function::New(env, mp::EjectDllSync));
26
+ exports.Set("queryAddress", Napi::Function::New(env, mp::QueryAddressSync));
27
+ exports.Set("getThreadContext", Napi::Function::New(env, mp::GetThreadContextSync));
28
+ exports.Set("setThreadContext", Napi::Function::New(env, mp::SetThreadContextSync));
29
+ exports.Set("callRemote", Napi::Function::New(env, mp::CallRemoteSync));
30
+ exports.Set("disasmInstructions", Napi::Function::New(env, mp::DisasmInstructionsSync));
31
+ exports.Set("scanValue", Napi::Function::New(env, mp::ScanValueAsync));
32
+ exports.Set("suspendProcess", Napi::Function::New(env, mp::SuspendProcessSync));
33
+ exports.Set("resumeProcess", Napi::Function::New(env, mp::ResumeProcessSync));
34
+ exports.Set("enableDebugPrivilege", Napi::Function::New(env, mp::EnableDebugPrivilegeSync));
35
+ exports.Set("waitForExit", Napi::Function::New(env, mp::WaitForExitAsync));
36
+ exports.Set("findWhatWrites", Napi::Function::New(env, mp::FindWhatWritesAsync));
37
+ exports.Set("hookSteal", Napi::Function::New(env, mp::HookStealSync));
38
+ exports.Set("writeProtectedMemory", Napi::Function::New(env, mp::WriteProtectedMemorySync));
39
+ exports.Set("currentThreadId", Napi::Function::New(env, mp::CurrentThreadIdSync));
40
+ return exports;
41
+ }
42
+
43
+ NODE_API_MODULE(memoryprocess, Init)