だから、ゲームクライアントをフックするために使用する私のdllを注入するインジェクターを作ろうとしていDetours
ます、それは簡単です、しかし私はそれがうまくいくのに何が間違っているのかわからないという問題がありWindows Vista+
ます...これが私のコード
//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が挿入されていません。Idkここで何が問題になっていますか。
編集:それは私のXPにMSVCR100D.DLLがないためだと思いますが、dllがそれに依存しないようにする方法はありますか?