1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
bool Testobj::injectDLL(string moduleName)
{
if(!this->gotHandle())
return false;
HANDLE hThread;
void* pLibRemote;
HMODULE hKernel32 = GetModuleHandle("Kernel32");
DWORD hLibModule;
if(!hKernel32)
return false;
pLibRemote = VirtualAllocEx(this->hProcess, NULL, moduleName.size(), MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory( this->hProcess, pLibRemote, (void*)moduleName.c_str(), moduleName.size(), NULL );
hThread = CreateRemoteThread(this->hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) GetProcAddress(hKernel32, "LoadLibraryA"), pLibRemote, 0, NULL);
if(!hThread)
return false;
WaitForSingleObject( hThread, INFINITE );
GetExitCodeThread( hThread, &hLibModule );
CloseHandle( hThread );
VirtualFreeEx( this->hProcess, pLibRemote, moduleName.size(), MEM_RELEASE );
return true;
}
|