Hey Virusman,
Did you ever have compatibility issues with DLL Injection across windows xp and more recent OS's?
I have one player who is using Windows XP, but my Bootstrapper DLL crashes his Game Client.
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReeserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartDotNet, 0, 0, NULL);
break;
case DLL_THREAD_ATTACH:
// CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartDotNet, 0, 0, NULL);
break;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
test = "loaded";
return TRUE;
}
void StartDotNet()
{
HRESULT hr;
ICLRRuntimeHost *pClrHost = NULL;
ICLRMetaHost *pMetaHost = NULL;
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
//MessageBox(NULL, L"CLRCreateInstance Done.", NULL, NULL);
ICLRRuntimeInfo * lpRuntimeInfo = NULL;
hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&lpRuntimeInfo);
//MessageBox(NULL, L"pMetaHost->GetRuntime Done.", NULL, NULL);
ICLRRuntimeHost * lpRuntimeHost = NULL;
hr = lpRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&lpRuntimeHost);
//MessageBox(NULL, L"lpRuntimeInfo->GetInterface Done.", NULL, NULL);
hr = lpRuntimeHost->Start();
//MessageBox(NULL, L"lpRuntimeHost->Start() Done.", NULL, NULL);
DWORD dwRet = 0;
hr = lpRuntimeHost->ExecuteInDefaultAppDomain(
L"RhunDLL.dll",
L"Inject.MainClass", L"DLLMain", L"Injection Worked", &dwRet);
lpRuntimeHost->Release();
}
He has .Net4 installed, and Visual C++ 2010 Redist
I installed a VirtualBox vm with xp, and confirmed the crash.
CreateThread seems to be working for Windows 7, should I be using CreateRemoteThread instead? or Is there something specific to be done for Windows XP compatibility?
Just double checked
Using RemoteThread in the .net code that actually injects the Bootstrapper.
bool bInject(uint pToBeInjected, string sDllPath)
{
IntPtr hndProc = OpenProcess((0x2 | 0x8 | 0x10 | 0x20 | 0x400), 1, pToBeInjected);
if (hndProc == INTPTR_ZERO)
{
return false;
}
IntPtr lpLLAddress = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
if (lpLLAddress == INTPTR_ZERO)
{
return false;
}
IntPtr lpAddress = VirtualAllocEx(hndProc, (IntPtr)null, (IntPtr)sDllPath.Length, (0x1000 | 0x2000), 0X40);
if (lpAddress == INTPTR_ZERO)
{
return false;
}
byte[] bytes = Encoding.ASCII.GetBytes(sDllPath);
if (WriteProcessMemory(hndProc, lpAddress, bytes, (uint)bytes.Length, 0) == 0)
{
return false;
}
if (CreateRemoteThread(hndProc, (IntPtr)null, INTPTR_ZERO, lpLLAddress, lpAddress, 0, (IntPtr)null) == INTPTR_ZERO)
{
return false;
}
CloseHandle(hndProc);
return true;
}