From 082a96c61c34d3fbc9cb4ca826c9815de391e1f6 Mon Sep 17 00:00:00 2001 From: J <41439659+daeds1dog@users.noreply.github.com> Date: Sat, 10 Apr 2021 07:06:33 +0300 Subject: [PATCH] Fix incorrect path format for LoadLibraryA --- main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index b25688d..5a8d641 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #define BUFSIZE 1024 @@ -27,14 +28,18 @@ int main(int argc, char **argv) { // Format passed down to loader to pass to process. std::stringstream args; - args << target_binary_abs_path.string(); + args << "\"" + target_binary_abs_path.string() + "\""; bool reading_args = false; for (int i = 2; i < argc; ++i) { if (!reading_args) { if (std::string(argv[i]) != "-args") { std::filesystem::path abs_dll_path = std::filesystem::absolute(std::filesystem::path(argv[i])); - dlls.push_back(abs_dll_path.string()); + std::string abs_dll_path_string = abs_dll_path.string(); + + // Needs to be converted to this format for Windows. + abs_dll_path_string = std::regex_replace(abs_dll_path_string, std::regex("\\\\"), "/"); + dlls.push_back(abs_dll_path_string); continue; } reading_args = true; @@ -54,18 +59,16 @@ int main(int argc, char **argv) { &process_info)) { std::list pages; for (std::string dll_name : dlls) { - - LPVOID page = - VirtualAllocEx(process_info.hProcess, nullptr, BUFSIZE, - MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); - pages.push_back(page); + LPVOID page = VirtualAllocEx( + process_info.hProcess, nullptr, BUFSIZE, + MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (page == nullptr) { std::cerr << "VirtualAllocEx error: " << GetLastError() << std::endl; return -1; } if (WriteProcessMemory(process_info.hProcess, page, - dll_name.c_str(), sizeof(dll_name), + dll_name.c_str(), dll_name.length(), nullptr) == 0) { std::cerr << "WriteProcessMemory error: " << GetLastError() << std::endl;