Code:
// Launch button handler
std::string DoLaunch(const char*, CButton*)
{
SetStatus(RGB(0,0,255), "Attempting injection.");
// Make sure the DLL exists
TCHAR tszHookPath[MAX_PATH] = {0};
if(GetFileAttributes(_tfullpath(tszHookPath, DllName.c_str(), MAX_PATH)) == 0xFFFFFFFF)
{
SetStatus(RGB(255,0,0), "Couldn't find DLL!");
return std::string();
}
STARTUPINFO WoWSi;
PROCESS_INFORMATION WoWPi;
ZeroMemory(&WoWSi, sizeof(WoWSi));
WoWSi.cb = sizeof(WoWSi);
ZeroMemory(&WoWPi, sizeof(WoWPi));
TCHAR Path[MAX_PATH] = {0};
DWORD BuffSize = MAX_PATH;
HKEY WoWKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\Blizzard Entertainment\World of Warcraft\",0,KEY_READ,&WoWKey);
RegQueryValueEx(WoWKey,"InstallPath",NULL,NULL,(LPBYTE)Path,&BuffSize);
std::string WoWPath = Path;
WoWPath.append("WoW.exe -console");
std::string WoWCurrentDir = "WoW.exe -console";
if (!CreateProcess(NULL,(LPSTR)WoWCurrentDir.c_str(),NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&WoWSi,&WoWPi))
{
if (!CreateProcess(NULL,(LPSTR)WoWPath.c_str(),NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&WoWSi,&WoWPi))
{
SetStatus(RGB(255,0,0), "Process creation failed!");
return std::string();
}
}
// Inject the dll
DWORD ForceLibrary(CHAR* szLibraryPath,PROCESS_INFORMATION* pProcInfo);
DWORD ForceLibRet = ForceLibrary(_tfullpath(NULL, DllName.c_str(), MAX_PATH),&WoWPi);
if (!ForceLibRet)
{
SetStatus(RGB(255,0,0), "Injection failed!");
TerminateProcess(WoWPi.hProcess,0);
return std::string();
}
else
{
ResumeThread(WoWPi.hThread);
}
// Injection succeeded (hopefully) if we get here
SetStatus(RGB(0,255,0),"Injection succeeded!");
return std::string();
}
Code is pretty disgusting at the moment. My apologies. Only because its something I hacked together quickly without care because I'm rewriting the loader from scratch in a few days.