From 17601b582ea425808955499e0bc61d66375cae14 Mon Sep 17 00:00:00 2001 From: Jose Fonseca Date: Fri, 10 Mar 2017 09:02:08 +0000 Subject: inject: Copy DLLs to system dir. --- inject/CMakeLists.txt | 1 + inject/injector.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/inject/CMakeLists.txt b/inject/CMakeLists.txt index e98b077d..51ac327e 100644 --- a/inject/CMakeLists.txt +++ b/inject/CMakeLists.txt @@ -42,6 +42,7 @@ target_link_libraries (injector ${GETOPT_LIBRARIES} devcon psapi + os ) install (TARGETS injector RUNTIME DESTINATION bin) install_pdb (injector DESTINATION bin) diff --git a/inject/injector.cpp b/inject/injector.cpp index 95df0020..925d0a6f 100644 --- a/inject/injector.cpp +++ b/inject/injector.cpp @@ -57,6 +57,7 @@ #endif #include "os_version.hpp" +#include "os_string.hpp" #include "uac.hpp" #include "devcon.hpp" #include "inject.h" @@ -553,7 +554,7 @@ main(int argc, char *argv[]) fprintf(stderr, "IsUserInAdminGroup = %i\n", IsUserInAdminGroup()); fprintf(stderr, "IsRunAsAdmin = %i\n", IsRunAsAdmin()); fprintf(stderr, "IsProcessElevated = %i\n", IsProcessElevated()); - if (0) { + if (!IsProcessElevated()) { // Elevate the process. char szPath[MAX_PATH]; GetModuleFileNameA(NULL, szPath, sizeof szPath); @@ -597,7 +598,29 @@ main(int argc, char *argv[]) return 0; } else { + fprintf(stderr, "info: press any key to exit\n"); atexit((void (*)(void)) getchar); + + os::String injecteeDll = os::getProcessName(); + injecteeDll.trimFilename(); + injecteeDll.join(szDllName); + + char szSystemDir[MAX_PATH]; + GetSystemDirectory(szSystemDir, _countof(szSystemDir)); + + os::String dest = szSystemDir; + dest.join(szDllName); + if (!CopyFileA(injecteeDll.str(), dest.str(), FALSE)) { + fprintf(stderr, "error: failed to copy %s to %s\n", injecteeDll.str(), dest.str()); + exit(1); + } + + dest = szSystemDir; + dest.join("dxgitrace.dll"); + if (!CopyFileA(szDll, dest.str(), FALSE)) { + fprintf(stderr, "error: failed to copy %s to %s\n", szDll, dest.str()); + exit(1); + } } HANDLE hSemaphore = NULL; -- cgit v1.2.3