所以我正在尝试制作一个注入器来注入我Detours
用于挂钩游戏客户端的 dll,这很简单,但是有一个问题我不知道出了什么问题,它在 XP 上运行良好Windows Vista+
但在 XP 上运行不正常......这是我的代码
//the injector
#ifndef INJECTOR_H_INCLUDED
#define INJECTOR_H_INCLUDED
#include <windows.h>
class Injector
{
private:
STARTUPINFOA *Startup;
PROCESS_INFORMATION *Process;
char *Directory;
BOOL Start(char *Application);
public:
Injector(char *Directory);
~Injector(void);
BOOL Attach(char *Application, char *Dll);
};
#endif // INJECTOR_H_INCLUDED
#include "Injector.h"
#include <string>
#include <cstdio>
using namespace std;
Injector::Injector(char *Directory)
{
int Size = strlen(Directory) + 1;
Directory = new char[Size];
MoveMemory(Directory, Directory, Size);
Startup = new STARTUPINFOA();
Process = new PROCESS_INFORMATION();
}
Injector::~Injector(void)
{
delete[] Directory;
delete Startup;
delete Process;
}
BOOL Injector::Start(char *Application)
{
char CommandLine[256];
sprintf(CommandLine, "%s\\%s blacknull", Directory, Application);
return CreateProcessA(NULL, CommandLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, NULL, Directory, Startup, Process);
}
BOOL Injector::Attach(char *Application, char *Dll)
{
if(Start(Application))
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Process->dwProcessId);
if(hProcess != NULL)
{
int Length = strlen(Dll) + 1;
LPVOID RemoteMemory = VirtualAllocEx(hProcess, NULL, Length, MEM_COMMIT, PAGE_READWRITE);
if(RemoteMemory != NULL)
{
if(WriteProcessMemory(hProcess, RemoteMemory, Dll, Length, NULL))
{
FARPROC hLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32"), "LoadLibraryA");
HANDLE hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)hLoadLibrary, RemoteMemory, NULL, NULL);
if(hThread != NULL)
{
WaitForSingleObject(hThread, 5000);
VirtualFreeEx(hProcess, RemoteMemory, 0, MEM_RELEASE);
CloseHandle(hProcess);
ResumeThread(Process->hThread);
return TRUE;
}
}
VirtualFreeEx(hProcess, RemoteMemory, 0, MEM_RELEASE);
}
CloseHandle(hProcess);
}
ResumeThread(Process->hThread);
return FALSE;
}
else
{
printf("CreateProcessA failed with the following error: %d\n", GetLastError());
return FALSE;
}
return FALSE;
}
//the main dll with Detours
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "detours.h"
#include <WinSock2.h>
#include <shellapi.h>
HINSTANCE (WINAPI *OriginalShell)(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int nShowCmd) = ShellExecuteA;
HINSTANCE WINAPI DetouredShell(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int nShowCmd)
{
if(strcmp("http://co.91.com/signout/", lpFile) == 0)
{
lpFile = "http://www.google.com";
}
return OriginalShell(hWnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)OriginalShell, DetouredShell);
DetourTransactionCommit();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
两者都是用 VC++2010 构建的,所以它应该可以工作,但在 Windows XP 上它会启动游戏但 dll 没有被注入,我知道这里有什么问题!
编辑:我相信这是因为我的 XP 缺少 MSVCR100D.DLL ,有没有办法让我的 dll 不依赖它?