#include <windows.h>
#include <cstdio>
#include <tchar.h>
BOOL EATHook(LPCTSTR szDllName, LPCTSTR szFunName, LPVOID NewFun) {
DWORD addr = 0;
DWORD index = 0;
DWORD dwProtect;
SIZE_T dwWritten = 0;
HMODULE hMod = LoadLibrary(szDllName);
if (NULL == hMod)
return(FALSE);
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hMod;
PIMAGE_OPTIONAL_HEADER pOptHeader = (PIMAGE_OPTIONAL_HEADER)((PBYTE)hMod + pDosHeader->e_lfanew + 24);
PIMAGE_EXPORT_DIRECTORY pExpDes = (PIMAGE_EXPORT_DIRECTORY)((PBYTE)hMod + pOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
PULONG pAddressOfFunctions = (PULONG)((PBYTE)hMod + pExpDes->AddressOfFunctions);
PULONG pAddressOfNames = (PULONG)((PBYTE)hMod + pExpDes->AddressOfNames);
PUSHORT pAddressOfNameOrdinals = (PUSHORT)((PBYTE)hMod + pExpDes->AddressOfNameOrdinals);
for (int i = 0; i < pExpDes->NumberOfNames; ++i) {
index = pAddressOfNameOrdinals[i];
LPCTSTR pFuncName = (LPTSTR)((PBYTE)hMod + pAddressOfNames[i]);
if (!_tcscmp((LPCTSTR)pFuncName, szFunName)) {
addr = pAddressOfFunctions[index];
break;
}
}
VirtualProtect(&pAddressOfFunctions[index], 0x1000, PAGE_READWRITE, &dwProtect);
pAddressOfFunctions[index] = (DWORD)NewFun - (DWORD)hMod;
WriteProcessMemory(GetCurrentProcess(), &pAddressOfFunctions[index], (LPCVOID)((LPDWORD)NewFun - (LPDWORD)hMod), 8, &dwWritten);
VirtualProtect(&pAddressOfFunctions[index], 0x1000, dwProtect, &dwProtect);
return(TRUE);
}
int WINAPI MyMessageBox(
HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
) {
_tprintf("Hello, world!\n");
return(0);
}
typedef int (WINAPI* LPFNMESSAGEBOX)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
int _tmain() {
EATHook("USER32.dll", "MessageBoxA", MyMessageBox);
HMODULE hDll = GetModuleHandle("USER32.dll");
LPFNMESSAGEBOX lpMessageBox = (LPFNMESSAGEBOX)GetProcAddress(hDll, "MessageBoxA");
if (NULL == lpMessageBox)
return(-1);
lpMessageBox(NULL, "Hello, EAT Hook", "Info", MB_OK);
return(0);
}
2. 我想问一下,如果我在64位下远程线程注入,希望突破SESSION0隔离,能够注入到比如explorer.exe等系统服务进程里面该怎么办?
我用ZwCreateThreadEx注入发现要么注入成功但没反应,要么就是注入成功进程崩溃(explorer.exe的时候),要么就直接失败。(已获取Debug权限)。该怎么做呢,这到底是什么问题?
3. 远程线程注入时而成功时而失败这正常吗??
4. Windows下WDK编程有什么好的书推荐吗? 我在看<Windows驱动编程详解>,虽然WDM式驱动还用,但很老的DDK开发包现在都不用了。有什么更好一点的入门书籍吗? 谢谢。
谢谢各位的查看和帮助!!