// Find the name of the DLL and inject it. BOOL Inject( LPPROCESS_INFORMATION ppi ) { DWORD len; WCHAR dll[MAX_PATH]; int type; #if (MYDEBUG > 0) if (GetModuleFileNameEx( ppi->hProcess, NULL, dll, lenof(dll) )) DEBUGSTR( L"%s", dll ); #endif type = ProcessType( ppi ); if (type == 0) return FALSE; len = GetModuleFileName( NULL, dll, lenof(dll) ); while (dll[len-1] != '\\') --len; #ifdef _WIN64 wsprintf( dll + len, L"ANSI%d.dll", type ); if (type == 32) InjectDLL32( ppi, dll ); else InjectDLL64( ppi, dll ); #else wcscpy( dll + len, L"ANSI32.dll" ); InjectDLL32( ppi, dll ); #endif return TRUE; }
// Inject code into the target process to load our DLL. void Inject( LPPROCESS_INFORMATION pinfo, LPPROCESS_INFORMATION lpi, DWORD dwCreationFlags ) { int type = ProcessType( pinfo ); if (type != 0) { #ifdef _WIN64 if (type == 32) { hDllNameType[0] = '3'; hDllNameType[1] = '2'; InjectDLL32( pinfo ); } else { hDllNameType[0] = '6'; hDllNameType[1] = '4'; InjectDLL64( pinfo ); } #else #ifdef W32ON64 if (type == 64) { TCHAR args[64]; STARTUPINFO si; PROCESS_INFORMATION pi; wcscpy( hDllNameType, L".exe" ); wsprintf( args, L"errout -P%lu:%lu", pinfo->dwProcessId, pinfo->dwThreadId ); ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); if (CreateProcess( hDllName, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi )) { WaitForSingleObject( pi.hProcess, INFINITE ); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } wcscpy( hDllNameType, L"32.dll" ); } else #endif InjectDLL32( pinfo ); #endif } if (!(dwCreationFlags & CREATE_SUSPENDED)) ResumeThread( pinfo->hThread ); if (lpi) { memcpy( lpi, pinfo, sizeof(PROCESS_INFORMATION) ); } else { CloseHandle( pinfo->hProcess ); CloseHandle( pinfo->hThread ); } }
// Inject code into the target process to load our DLL. void Inject( LPPROCESS_INFORMATION pinfo, LPPROCESS_INFORMATION lpi, DWORD dwCreationFlags ) { int type = ProcessType( pinfo ); if (type != 0) { WCHAR dll[MAX_PATH]; #ifdef _WIN64 DWORD len = GetModuleFileName( GetModuleHandleA( "ANSI64.dll" ), dll, lenof(dll) ); if (type == 32) { dll[len-6] = '3'; dll[len-5] = '2'; InjectDLL32( pinfo, dll ); } else { InjectDLL64( pinfo, dll ); } #else GetModuleFileName( GetModuleHandleA( "ANSI32.dll" ), dll, lenof(dll) ); InjectDLL32( pinfo, dll ); #endif } if (!(dwCreationFlags & CREATE_SUSPENDED)) ResumeThread( pinfo->hThread ); if (lpi) { memcpy( lpi, pinfo, sizeof(PROCESS_INFORMATION) ); } else { CloseHandle( pinfo->hProcess ); CloseHandle( pinfo->hThread ); } }