Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency versions, fix build issue and type mismatch errors #120

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<THREADENTRY32> threads = module::getThreads(0, &errorMessage);

if (strcmp(errorMessage, "")) {
Expand Down Expand Up @@ -166,4 +166,4 @@ bool debugger::handleDebugEvent(DWORD processId, DWORD threadId) {
// if (status == DebugContinueStatus::NotHandled) {
// return ContinueDebugEvent(processId, threadId, DBG_EXCEPTION_NOT_HANDLED) != 0;
// }
}
}
4 changes: 2 additions & 2 deletions lib/dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <string>

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);

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace functions {
char readChar(HANDLE hProcess, DWORD64 address);

template <class returnDataType>
Call call(HANDLE pHandle, std::vector<Arg> args, Type returnType, DWORD64 address, char** errorMessage) {
Call call(HANDLE pHandle, std::vector<Arg> args, Type returnType, DWORD64 address, const char** errorMessage) {
std::vector<unsigned char> argShellcode;

std::reverse(args.begin(), args.end());
Expand Down
32 changes: 16 additions & 16 deletions lib/memoryjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<PROCESSENTRY32> processEntries = Process.getProcesses(&errorMessage);

Expand Down Expand Up @@ -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<MODULEENTRY32> moduleEntries = module::getModules(args[0].As<Napi::Number>().Int32Value(), &errorMessage);

Expand Down Expand Up @@ -251,7 +251,7 @@ Napi::Value findModule(const Napi::CallbackInfo& args) {
std::string moduleName(args[0].As<Napi::String>().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<Napi::Number>().Int32Value(), &errorMessage);

Expand Down Expand Up @@ -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<Napi::Number>().Int64Value();
Expand Down Expand Up @@ -743,7 +743,7 @@ Napi::Value findPattern(const Napi::CallbackInfo& args) {

// matching address
uintptr_t address = 0;
char* errorMessage = "";
const char* errorMessage = "";

std::vector<MODULEENTRY32> modules = module::getModules(GetProcessId(handle), &errorMessage);
Pattern.search(handle, modules, 0, pattern.c_str(), flags, patternOffset, &address);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -854,7 +854,7 @@ Napi::Value findPatternByAddress(const Napi::CallbackInfo& args) {

// matching address
uintptr_t address = 0;
char* errorMessage = "";
const char* errorMessage = "";

std::vector<MODULEENTRY32> modules = module::getModules(GetProcessId(handle), &errorMessage);
Pattern.search(handle, modules, baseAddress, pattern.c_str(), flags, patternOffset, &address);
Expand Down Expand Up @@ -945,7 +945,7 @@ Napi::Value callFunction(const Napi::CallbackInfo& args) {
address = args[3].As<Napi::Number>().Int64Value();
}

char* errorMessage = "";
const char* errorMessage = "";
Call data = functions::call<int>(handle, parsedArgs, returnType, address, &errorMessage);

// Free all the memory we allocated
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1402,7 +1402,7 @@ Napi::Value injectDll(const Napi::CallbackInfo& args) {
std::string dllPath(args[1].As<Napi::String>().Utf8Value());
Napi::Function callback = args[2].As<Napi::Function>();

char* errorMessage = "";
const char* errorMessage = "";
DWORD moduleHandle = -1;
bool success = dll::inject(handle, dllPath, &errorMessage, &moduleHandle);

Expand Down Expand Up @@ -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<Napi::String>().Utf8Value());
char* errorMessage = "";
const char* errorMessage = "";

MODULEENTRY32 module = module::findModule(moduleName.c_str(), GetProcessId(handle), &errorMessage);

Expand All @@ -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) {
Expand Down Expand Up @@ -1603,4 +1603,4 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
return exports;
}

NODE_API_MODULE(memoryjs, init)
NODE_API_MODULE(memoryjs, init)
8 changes: 4 additions & 4 deletions lib/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,7 +36,7 @@ MODULEENTRY32 module::findModule(const char* moduleName, DWORD processId, char**
return module;
}

std::vector<MODULEENTRY32> module::getModules(DWORD processId, char** errorMessage) {
std::vector<MODULEENTRY32> 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;
Expand Down Expand Up @@ -67,7 +67,7 @@ std::vector<MODULEENTRY32> module::getModules(DWORD processId, char** errorMessa
return modules;
}

std::vector<THREADENTRY32> module::getThreads(DWORD processId, char** errorMessage) {
std::vector<THREADENTRY32> module::getThreads(DWORD processId, const char** errorMessage) {
HANDLE hThreadSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, processId);
THREADENTRY32 mEntry;

Expand Down
6 changes: 3 additions & 3 deletions lib/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace module {
DWORD64 getBaseAddress(const char* processName, DWORD processId);
MODULEENTRY32 findModule(const char* moduleName, DWORD processId, char** errorMessage);
std::vector<MODULEENTRY32> getModules(DWORD processId, char** errorMessage);
std::vector<THREADENTRY32> getThreads(DWORD processId, char** errorMessage);
MODULEENTRY32 findModule(const char* moduleName, DWORD processId, const char** errorMessage);
std::vector<MODULEENTRY32> getModules(DWORD processId, const char** errorMessage);
std::vector<THREADENTRY32> getThreads(DWORD processId, const char** errorMessage);

};
#endif
Expand Down
6 changes: 3 additions & 3 deletions lib/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -64,7 +64,7 @@ process::Pair process::openProcess(DWORD processId, char** errorMessage) {
};
}

std::vector<PROCESSENTRY32> process::getProcesses(char** errorMessage) {
std::vector<PROCESSENTRY32> process::getProcesses(const char** errorMessage) {
// Take a snapshot of all processes.
HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 pEntry;
Expand Down
6 changes: 3 additions & 3 deletions lib/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PROCESSENTRY32> getProcesses(char** errorMessage);
std::vector<PROCESSENTRY32> getProcesses(const char** errorMessage);
};

#endif
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`));
}
Expand Down