我試圖使用微軟的彎路進行基本掛鉤。我的程序能夠成功運行CreateProcessWithDllEx並注入一個dll。但是,我似乎無法恢復實際的掛鉤程序。我正在使用記事本進行測試,並且可以看到notepad.exe在我的進程列表中運行,但記事本窗口實際上並未出現。CreateProcessWithDLLEx - 掛鉤進程啓動,但無法恢復
我的DLL如下:
#undef UNICODE
#include <cstdio>
#include <windows.h>
#include <detours.h>
#pragma comment(lib, "detours.lib")
typedef void (WINAPI *pFunc)(void);
DWORD WINAPI MyFunc(void);
pFunc FuncToDetour = (pFunc)DetourFindFunction("Winmm.dll", "timeGetTime"); //Set it at address to detour in
//the process
extern "C" __declspec(dllexport)VOID NullExport(VOID)
{
}
INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
{
DisableThreadLibraryCalls(hDLL);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//DetourAttach(&(PVOID&)FuncToDetour, MyFunc);
//DetourTransactionCommit();
}
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)FuncToDetour, MyFunc);
DetourTransactionCommit();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
DWORD WINAPI MyFunc()
{
return 0;
}
我的注射器如下:
#undef _UNICODE
#include "stdafx.h"
#include <cstdio>
#include <windows.h>
#include <detours.h>
int main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
si.cb = sizeof(STARTUPINFO);
WCHAR DirPath[MAX_PATH+1];
wcscpy_s(DirPath, MAX_PATH, L"C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2010\\Projects\\hbotinjector\\Release");
char DLLPath[MAX_PATH+1] = "C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2010\\Projects\\hbotinjector\\Release\\hbotdll.dll";
WCHAR EXE[MAX_PATH+1]={0};
wcscpy_s(EXE, MAX_PATH, L"C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2010\\Projects\\hbotinjector\\Release\\notepad.exe");
STARTUPINFO _StartupInfo;
PROCESS_INFORMATION _Information;
ZeroMemory(&_Information, sizeof(PROCESS_INFORMATION));
if(DetourCreateProcessWithDllEx(EXE, NULL, NULL, NULL, TRUE,
CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED, NULL, DirPath, &_StartupInfo, &_Information,
DLLPath, NULL))
{
MessageBoxA(NULL,"INJECTED", NULL, NULL);
ResumeThread(_Information.hThread);
WaitForSingleObject(_Information.hProcess, INFINITE);
}
else
{
char error[100];
sprintf(error, "%d", GetLastError());
MessageBoxA(NULL, error, NULL, NULL);
}
return 0;
}
我建我的DLL一個.DEF文件,確保有在所需要的功能序號1爲繞道正常工作:
LIBRARY HBOTDLL
EXPORTS
NullExport @1
有沒有人知道是什麼原因引起的過程從不ru nning?作爲一個側面說明,我已經試過它與一個空白的DLL以及它只包含序號1所需的功能,沒有別的,它似乎有相同的結果。
另外,只要在進程列表中顯示notepad.exe進程,我的注入器就會一直運行。這是對WaitForSingleObject的響應,這似乎表明進程已經正確產生。
'ZeroMemory(&_Information,sizeof(PROCESS_INFORMATION));'否看看它在代碼開始時是如何正確完成的,si變量。 – 2012-07-22 20:08:11
你是男人。我不確定爲什麼我已經聲明瞭同一組結構的兩個不同版本。但問題是固定使用原本宣稱結構: 和更改呼叫: \t如果(DetourCreateProcessWithDllEx(EXE,NULL,NULL,NULL,TRUE, \t CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED,NULL,DirPath,&SI,亞太裔, \t DLLPath,NULL)) – emist 2012-07-22 20:17:56