From da7f50bc2d0255a1a46ef1c75973a8343c21a7c9 Mon Sep 17 00:00:00 2001 From: BarehSolok <96950043+Fanixtar@users.noreply.github.com> Date: Sun, 19 Jun 2022 12:55:37 +0700 Subject: [PATCH] Wait for injector thread to end and release unnecessary data --- injector/src/injector.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/injector/src/injector.cpp b/injector/src/injector.cpp index e3dcb0c..fb431a5 100644 --- a/injector/src/injector.cpp +++ b/injector/src/injector.cpp @@ -81,10 +81,14 @@ static bool LoadLibraryInject(HANDLE hProc, const std::string& dllpath) VirtualFreeEx(hProc, pDLLPath, 0, MEM_RELEASE); return false; } - CloseHandle(hThread); - // TODO: Add waiting for thread end and release unneccessary data. - // VirtualFreeEx(hProc, pDLLPath, 0, MEM_RELEASE); + // Waiting for thread end and release unnecessary data. + if (WaitForSingleObject(hThread, 2000) == WAIT_OBJECT_0) { + // ILog("[DLL Injection] Remote thread ended successfully.\n"); + VirtualFreeEx(hProc, pDLLPath, 0, MEM_RELEASE); + } + + CloseHandle(hThread); ILog("[DLL Injection] Successfully LoadLibraryA injection.\n"); return true;