From e193f324a9d054a5fc89274215fae36d73ba3a0b Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:24:09 +1000 Subject: [PATCH 01/10] Update version and dependencies versions --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d2251d1..a1c1253 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "memoryjs", - "version": "3.5.1", + "version": "3.5.2", "description": "Node add-on for memory reading and writing!", "main": "index.js", "scripts": { @@ -33,8 +33,8 @@ }, "homepage": "https://github.com/Rob--/memoryjs#readme", "dependencies": { - "eslint": "^8.5.0", - "eslint-config-airbnb-base": "^12.1.0", - "node-addon-api": "^3.2.1" + "eslint": "^9.4.0", + "eslint-config-airbnb-base": "^15.0.0", + "node-addon-api": "^8.0.0" } } From 701ec2bbe4fe798bf5622ad486b4769524fdeb5a Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:25:11 +1000 Subject: [PATCH 02/10] Fix build script issue --- scripts/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.js b/scripts/install.js index cf65fb5..9077cd8 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -15,7 +15,7 @@ function run(script) { const args = script.split(' ').slice(1); // inherit stdio to print colour (helpful for warnings/errors readability) - const child = spawn(program, args, { stdio: 'inherit' }); + const child = spawn(program, args, { stdio: 'inherit', shell:true }); child.on('close', code => console.log(`Script "${script}" exited with ${code}`)); } From f283a80c09ccf4520f6a0e07c319b26cc0666fe5 Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:27:47 +1000 Subject: [PATCH 03/10] debugger.cc - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/debugger.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/debugger.cc b/lib/debugger.cc index fef5165..8740be0 100644 --- a/lib/debugger.cc +++ b/lib/debugger.cc @@ -25,7 +25,7 @@ bool debugger::detatch(DWORD processId) { } bool debugger::setHardwareBreakpoint(DWORD processId, DWORD64 address, Register reg, int trigger, int size) { - char* errorMessage = ""; + const char* errorMessage = ""; std::vector threads = module::getThreads(0, &errorMessage); if (strcmp(errorMessage, "")) { @@ -166,4 +166,4 @@ bool debugger::handleDebugEvent(DWORD processId, DWORD threadId) { // if (status == DebugContinueStatus::NotHandled) { // return ContinueDebugEvent(processId, threadId, DBG_EXCEPTION_NOT_HANDLED) != 0; // } -} \ No newline at end of file +} From 4581bd251b3784502fda2ba6975c4e8a35dbe6a8 Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:28:20 +1000 Subject: [PATCH 04/10] dll.h - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/dll.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dll.h b/lib/dll.h index 11181bc..c52b5a6 100644 --- a/lib/dll.h +++ b/lib/dll.h @@ -9,7 +9,7 @@ #include namespace dll { - bool inject(HANDLE handle, std::string dllPath, char** errorMessage, LPDWORD moduleHandle) { + bool inject(HANDLE handle, std::string dllPath, const char** errorMessage, LPDWORD moduleHandle) { // allocate space in target process memory for DLL path LPVOID targetProcessPath = VirtualAllocEx(handle, NULL, dllPath.length() + 1, MEM_COMMIT, PAGE_EXECUTE_READWRITE); @@ -53,7 +53,7 @@ namespace dll { return *moduleHandle > 0; } - bool unload(HANDLE handle, char** errorMessage, HMODULE moduleHandle) { + bool unload(HANDLE handle, const char** errorMessage, HMODULE moduleHandle) { HMODULE kernel32 = LoadLibrary("kernel32"); if (kernel32 == 0) { From 408d9a3d84c2a3764bf44f72c658e6c91d6d313b Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:28:48 +1000 Subject: [PATCH 05/10] functions.h - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/functions.h b/lib/functions.h index dea685b..605053a 100644 --- a/lib/functions.h +++ b/lib/functions.h @@ -33,7 +33,7 @@ namespace functions { char readChar(HANDLE hProcess, DWORD64 address); template - Call call(HANDLE pHandle, std::vector args, Type returnType, DWORD64 address, char** errorMessage) { + Call call(HANDLE pHandle, std::vector args, Type returnType, DWORD64 address, const char** errorMessage) { std::vector argShellcode; std::reverse(args.begin(), args.end()); From d23d60c8c9b38a6746ae66dca5f3e89a490daaee Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:29:22 +1000 Subject: [PATCH 06/10] memoryjs.cc - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/memoryjs.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/memoryjs.cc b/lib/memoryjs.cc index 754906b..2799376 100644 --- a/lib/memoryjs.cc +++ b/lib/memoryjs.cc @@ -48,7 +48,7 @@ Napi::Value openProcess(const Napi::CallbackInfo& args) { } // Define error message that may be set by the function that opens the process - char* errorMessage = ""; + const char* errorMessage = ""; process::Pair pair; @@ -125,7 +125,7 @@ Napi::Value getProcesses(const Napi::CallbackInfo& args) { } // Define error message that may be set by the function that gets the processes - char* errorMessage = ""; + const char* errorMessage = ""; std::vector processEntries = Process.getProcesses(&errorMessage); @@ -186,7 +186,7 @@ Napi::Value getModules(const Napi::CallbackInfo& args) { } // Define error message that may be set by the function that gets the modules - char* errorMessage = ""; + const char* errorMessage = ""; std::vector moduleEntries = module::getModules(args[0].As().Int32Value(), &errorMessage); @@ -251,7 +251,7 @@ Napi::Value findModule(const Napi::CallbackInfo& args) { std::string moduleName(args[0].As().Utf8Value()); // Define error message that may be set by the function that gets the modules - char* errorMessage = ""; + const char* errorMessage = ""; MODULEENTRY32 module = module::findModule(moduleName.c_str(), args[1].As().Int32Value(), &errorMessage); @@ -312,7 +312,7 @@ Napi::Value readMemory(const Napi::CallbackInfo& args) { const char* dataType = dataTypeArg.c_str(); // Define the error message that will be set if no data type is recognised - char* errorMessage = ""; + const char* errorMessage = ""; Napi::Value retVal = env.Null(); HANDLE handle = (HANDLE)args[0].As().Int64Value(); @@ -743,7 +743,7 @@ Napi::Value findPattern(const Napi::CallbackInfo& args) { // matching address uintptr_t address = 0; - char* errorMessage = ""; + const char* errorMessage = ""; std::vector modules = module::getModules(GetProcessId(handle), &errorMessage); Pattern.search(handle, modules, 0, pattern.c_str(), flags, patternOffset, &address); @@ -793,7 +793,7 @@ Napi::Value findPatternByModule(const Napi::CallbackInfo& args) { // matching address uintptr_t address = 0; - char* errorMessage = ""; + const char* errorMessage = ""; MODULEENTRY32 module = module::findModule(moduleName.c_str(), GetProcessId(handle), &errorMessage); @@ -854,7 +854,7 @@ Napi::Value findPatternByAddress(const Napi::CallbackInfo& args) { // matching address uintptr_t address = 0; - char* errorMessage = ""; + const char* errorMessage = ""; std::vector modules = module::getModules(GetProcessId(handle), &errorMessage); Pattern.search(handle, modules, baseAddress, pattern.c_str(), flags, patternOffset, &address); @@ -945,7 +945,7 @@ Napi::Value callFunction(const Napi::CallbackInfo& args) { address = args[3].As().Int64Value(); } - char* errorMessage = ""; + const char* errorMessage = ""; Call data = functions::call(handle, parsedArgs, returnType, address, &errorMessage); // Free all the memory we allocated @@ -1030,7 +1030,7 @@ Napi::Value virtualProtectEx(const Napi::CallbackInfo& args) { bool success = VirtualProtectEx(handle, (LPVOID) address, size, protection, &result); - char* errorMessage = ""; + const char* errorMessage = ""; if (success == 0) { errorMessage = "an error occurred calling VirtualProtectEx"; @@ -1135,7 +1135,7 @@ Napi::Value virtualQueryEx(const Napi::CallbackInfo& args) { MEMORY_BASIC_INFORMATION information; SIZE_T result = VirtualQueryEx(handle, (LPVOID)address, &information, sizeof(information)); - char* errorMessage = ""; + const char* errorMessage = ""; if (result == 0 || result != sizeof(information)) { errorMessage = "an error occurred calling VirtualQueryEx"; @@ -1202,7 +1202,7 @@ Napi::Value virtualAllocEx(const Napi::CallbackInfo& args) { LPVOID allocatedAddress = VirtualAllocEx(handle, address, size, allocationType, protection); - char* errorMessage = ""; + const char* errorMessage = ""; // If null, it means an error occurred if (allocatedAddress == NULL) { @@ -1402,7 +1402,7 @@ Napi::Value injectDll(const Napi::CallbackInfo& args) { std::string dllPath(args[1].As().Utf8Value()); Napi::Function callback = args[2].As(); - char* errorMessage = ""; + const char* errorMessage = ""; DWORD moduleHandle = -1; bool success = dll::inject(handle, dllPath, &errorMessage, &moduleHandle); @@ -1463,7 +1463,7 @@ Napi::Value unloadDll(const Napi::CallbackInfo& args) { // find module handle from name of DLL if (args[1].IsString()) { std::string moduleName(args[1].As().Utf8Value()); - char* errorMessage = ""; + const char* errorMessage = ""; MODULEENTRY32 module = module::findModule(moduleName.c_str(), GetProcessId(handle), &errorMessage); @@ -1480,7 +1480,7 @@ Napi::Value unloadDll(const Napi::CallbackInfo& args) { moduleHandle = (HMODULE) module.modBaseAddr; } - char* errorMessage = ""; + const char* errorMessage = ""; bool success = dll::unload(handle, &errorMessage, moduleHandle); if (strcmp(errorMessage, "") && args.Length() != 3) { @@ -1603,4 +1603,4 @@ Napi::Object init(Napi::Env env, Napi::Object exports) { return exports; } -NODE_API_MODULE(memoryjs, init) \ No newline at end of file +NODE_API_MODULE(memoryjs, init) From f8714a28f0e68a18a4b06fbec3edaa4b035f6f2a Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:29:53 +1000 Subject: [PATCH 07/10] module.cc - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/module.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/module.cc b/lib/module.cc index 8d5b52e..6ec1f86 100644 --- a/lib/module.cc +++ b/lib/module.cc @@ -7,12 +7,12 @@ #include "memoryjs.h" DWORD64 module::getBaseAddress(const char* processName, DWORD processId) { - char* errorMessage = ""; + const char* errorMessage = ""; MODULEENTRY32 baseModule = module::findModule(processName, processId, &errorMessage); return (DWORD64)baseModule.modBaseAddr; } -MODULEENTRY32 module::findModule(const char* moduleName, DWORD processId, char** errorMessage) { +MODULEENTRY32 module::findModule(const char* moduleName, DWORD processId, const char** errorMessage) { MODULEENTRY32 module; bool found = false; @@ -36,7 +36,7 @@ MODULEENTRY32 module::findModule(const char* moduleName, DWORD processId, char** return module; } -std::vector module::getModules(DWORD processId, char** errorMessage) { +std::vector module::getModules(DWORD processId, const char** errorMessage) { // Take a snapshot of all modules inside a given process. HANDLE hModuleSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId); MODULEENTRY32 mEntry; @@ -67,7 +67,7 @@ std::vector module::getModules(DWORD processId, char** errorMessa return modules; } -std::vector module::getThreads(DWORD processId, char** errorMessage) { +std::vector module::getThreads(DWORD processId, const char** errorMessage) { HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, processId); THREADENTRY32 mEntry; From e68ee66fee1c3a79014511cee79a07039a4154c5 Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:30:21 +1000 Subject: [PATCH 08/10] - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/module.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/module.h b/lib/module.h index d90ed46..b617e64 100644 --- a/lib/module.h +++ b/lib/module.h @@ -9,9 +9,9 @@ namespace module { DWORD64 getBaseAddress(const char* processName, DWORD processId); - MODULEENTRY32 findModule(const char* moduleName, DWORD processId, char** errorMessage); - std::vector getModules(DWORD processId, char** errorMessage); - std::vector getThreads(DWORD processId, char** errorMessage); + MODULEENTRY32 findModule(const char* moduleName, DWORD processId, const char** errorMessage); + std::vector getModules(DWORD processId, const char** errorMessage); + std::vector getThreads(DWORD processId, const char** errorMessage); }; #endif From 757a12b851e6f2ad125004cc18f755b3d89a7010 Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:30:49 +1000 Subject: [PATCH 09/10] process.cc - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/process.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/process.cc b/lib/process.cc index b493d99..51afba7 100644 --- a/lib/process.cc +++ b/lib/process.cc @@ -12,7 +12,7 @@ using v8::Exception; using v8::Isolate; using v8::String; -process::Pair process::openProcess(const char* processName, char** errorMessage){ +process::Pair process::openProcess(const char* processName, const char** errorMessage){ PROCESSENTRY32 process; HANDLE handle = NULL; @@ -38,7 +38,7 @@ process::Pair process::openProcess(const char* processName, char** errorMessage) }; } -process::Pair process::openProcess(DWORD processId, char** errorMessage) { +process::Pair process::openProcess(DWORD processId, const char** errorMessage) { PROCESSENTRY32 process; HANDLE handle = NULL; @@ -64,7 +64,7 @@ process::Pair process::openProcess(DWORD processId, char** errorMessage) { }; } -std::vector process::getProcesses(char** errorMessage) { +std::vector process::getProcesses(const char** errorMessage) { // Take a snapshot of all processes. HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); PROCESSENTRY32 pEntry; From e8f67d6e944861bf97c2da475d0a1f6cd0deafe4 Mon Sep 17 00:00:00 2001 From: phantomsixthplayer Date: Mon, 3 Jun 2024 13:31:14 +1000 Subject: [PATCH 10/10] process.h - fix type mismatch errors (char*/char** to const char*/const char**) --- lib/process.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/process.h b/lib/process.h index 31a241e..a0b8196 100644 --- a/lib/process.h +++ b/lib/process.h @@ -17,10 +17,10 @@ class process { process(); ~process(); - Pair openProcess(const char* processName, char** errorMessage); - Pair openProcess(DWORD processId, char** errorMessage); + Pair openProcess(const char* processName, const char** errorMessage); + Pair openProcess(DWORD processId, const char** errorMessage); void closeProcess(HANDLE hProcess); - std::vector getProcesses(char** errorMessage); + std::vector getProcesses(const char** errorMessage); }; #endif