So here's my injection code:
CODE
BOOL InjectIntoProcess(TCHAR* szExeName, TCHAR* szDllName)
{
TCHAR szProcessName[MAX_PATH];
TCHAR szDllNameAndPath[MAX_PATH];
DWORD aProcesses[1024], cb, cProcesses;
HANDLE hProcess = NULL;
HMODULE hMod = NULL;
UINT i = 0;
// Get the full path to the DLL for later use
GetCurrentDirectory(MAX_PATH, szDllNameAndPath);
wcscat(szDllNameAndPath, _T("\\"));
wcscat(szDllNameAndPath, szDllName);
// Get the list of process identifiers
if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cb))
return FALSE;
// Calculate how many process identifiers were returned
cProcesses = cb / sizeof(DWORD);
// Get the name and process identifier for each process
for(i = 0; i < cProcesses; i++)
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, aProcesses[i]);
if(hProcess)
{
if(EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cb))
{
GetModuleBaseNameW(hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR));
}
if(wcscmp(wcslwr(szProcessName), szExeName) == 0)
{
// We found the process, inject our DLL
if(DetourContinueProcessWithDllW(hProcess, szDllNameAndPath))
{
return TRUE;
}
}
}
CloseHandle(hProcess);
}
return FALSE;
}
Now we can inject a DLL as easily as this:
CODE
if(InjectIntoProcess(_T("et.exe"), _T("hax.dll")))
{
_tprintf(_T("Injection successful!\n"));
}
else {
_tprintf(_T("Injection failed.\n"));
}
And you can use a loop to check when to inject.
reflink: http://www.gamereversal.com/index.php?act=Print&client=printer&f=21&t=13