HOOK Send函数截取游戏数据包

来源:互联网 发布:淘宝网秋冬婴儿服装 编辑:程序博客网 时间:2024/06/04 19:55

前两天写了一个HOOK微软的加密函数然后打Log的Detours的例子,还是不够直观,这次举个简单的例子,其实完全可以应用在不加密的游戏游戏数据分析上,当然当前不加密明文传输的少之又少,此处只为学习方法。

首先在VC下建立一个DLL工程,不需要使用MFC DLL,因为不需要那个框架里面的东西。



然后新增一个源文件,写入相关代码

#include <stdio.h>#include <winsock2.h>#include <windows.h>#include "detours.h"#pragma comment( lib , "ws2_32.lib")#pragma comment( lib , "detours.lib")#pragma comment( lib , "detoured.lib")#ifdef _MANAGED#pragma managed(push, off)#endifint (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;int WINAPI SendEx(SOCKET s, const char* buf, int len, int flags);FILE *pLogFile;int WINAPI SendEx(SOCKET s, const char* buf, int len, int flags){pLogFile = fopen("c:\\SendLog.txt", "a+");    fprintf(pLogFile, "%s\r\n\n", buf);fclose(pLogFile);pLogFile = fopen("c:\\SendBin.txt", "a+");fwrite(buf, sizeof(char), len, pLogFile);fclose(pLogFile);return pSend(s, buf, len, flags);}BOOL APIENTRY DllMain(HMODULE hModule,                      DWORD  ul_reason_for_call,                      LPVOID lpReserved){switch(ul_reason_for_call){case DLL_THREAD_ATTACH:case DLL_PROCESS_ATTACH:{MessageBox(NULL, "Hook Send DLL OK", "Success", MB_OK);DisableThreadLibraryCalls(hModule);DetourTransactionBegin();DetourUpdateThread(GetCurrentThread());DetourAttach(&(PVOID&)pSend, SendEx);if(DetourTransactionCommit() != NO_ERROR){MessageBox(NULL, "Hook Send DLL ERROR", "Error", MB_OK);}}break;case DLL_PROCESS_DETACH:case DLL_THREAD_DETACH:{DetourTransactionBegin();DetourUpdateThread(GetCurrentThread());DetourDetach(&(PVOID&)pSend, SendEx);}break;}    return TRUE;}__declspec(dllexport)LRESULT WINAPI MsgProc(int code, WPARAM wParam, LPARAM lParam){    return(CallNextHookEx(NULL,code,wParam,lParam));}#ifdef _MANAGED#pragma managed(pop)#endif

直接贴整段代码,比上次更好理解,相关的内容已经在上次解释过了,这里就说下之后注入进程的操作。

刚好在11天梯打了一把,就截取WAR3的Send数据包吧,将detoured.dll和生成的dll,HOOKSend.dll拷贝至程序所在目录(这是Detours的要求)。



待游戏开启,WAR3进程启动,可以通过进程注入工具,将HOOKSend.dll注入到进程当中。


注入成功,可以看到代码中写的MessageBox对话框。


下面就跟根据需要跑跑操作,看一下数据包都是什么内容。我没什么需求,认真打场游戏啦,可惜队友秒了....退出看看数据包抓的怎么样了。


嗯,具体内容就不分析了,可以参考相关数据包结构分析。

工程下载:下载


原创粉丝点击