hook IE 的send recv函数
各位大神,求助啊!
我现在要hook ie的send和recv函数,想把网页的内容拿下来,dll已经写好了,还写了个将它注入IE的程序,通过IceWorld查看也证明这个Dll也成功的注入IE了,但是我自己的MySend函数不起作用,不知道是为什么。希望有经验的大神们帮忙看看吧。谢啦!
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "stdafx.h"
#include <WinSock.h>
#include <stdio.h>
#include "detours.h"
#pragma comment(lib, "ws2_32.lib")
#pragma comment (lib,"detours.lib")
#pragma comment (lib,"detoured.lib")
int (WINAPI *pSend)(SOCKET s, const char* buf,int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf,int len, int flags);
int (WINAPI *pRecv)(SOCKET s, __out_bcount_part(len, return) __out_data_source(NETWORK) char* buf,int len, int flags) = recv;
int WINAPI MyRecv(SOCKET s, __out_bcount_part(len, return) __out_data_source(NETWORK) char* buf,int len, int flag);
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
FILE *pSendLogFile;
fopen_s(&pSendLogFile, "C: \\SendLog.txt", "a+");
fprintf(pSendLogFile, "%s\n", buf);
MessageBox(NULL,"Error!send","Error in Detours!",MB_OK);
fclose(pSendLogFile);
return pSend(s, buf, len, flags);
}
int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
{
FILE *pRecvLogFile;
fopen_s(&pRecvLogFile, "C: \\RecvLog.txt", "a+");
fprintf(pRecvLogFile, "%s\n", buf);
MessageBox(NULL,"Error!recv","Error in Detours!",MB_OK);
fclose(pRecvLogFile);
return pRecv(s, buf, len, flags);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
int error;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
DetourTransactionBegin();
DetourUpdateThread(::GetCurrentThread());
DetourAttach(&(PVOID&)pSend, MySend);
error = DetourTransactionCommit();
if(NO_ERROR!=error)
{
MessageBox(NULL,"Error!","Error in Detours!",MB_OK);
}
DetourTransactionBegin();
DetourUpdateThread(::GetCurrentThread());
DetourAttach(&(PVOID&)pRecv, MyRecv);
error = DetourTransactionCommit();
if(NO_ERROR!=error)
{
MessageBox(NULL,"Error!","Error in Detours!",MB_OK);
}
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pSend, MySend);
error = DetourTransactionCommit();
MessageBox(NULL,"Detour ends","Prompt!",MB_OK);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pRecv, MyRecv);
error = DetourTransactionCommit();
MessageBox(NULL,"Detour ends","Prompt!",MB_OK);
break;
; }
return TRUE;
}