Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 迂回钩发送/接收winsock_C++_Winsock_Send_Recv_Detours - Fatal编程技术网

C++ 迂回钩发送/接收winsock

C++ 迂回钩发送/接收winsock,c++,winsock,send,recv,detours,C++,Winsock,Send,Recv,Detours,我正在尝试使用MS Detour从Ultima在线客户端连接发送/接收功能。我在那里找到了一个C++ DLL/注入器源,但它不起作用。dll被注入,但函数没有被钩住。 当注入器启动客户机时,dll抛出3个框,说明它已被注入并钩住了recv/send,但当客户机启动通信时,什么也没有发生 注入器 #include <windows.h> #include <detours.h> #include <cstdio> #pragma comment(lib,"de

我正在尝试使用MS Detour从Ultima在线客户端连接发送/接收功能。我在那里找到了一个C++ DLL/注入器源,但它不起作用。dll被注入,但函数没有被钩住。 当注入器启动客户机时,dll抛出3个框,说明它已被注入并钩住了recv/send,但当客户机启动通信时,什么也没有发生

注入器

#include <windows.h>
#include <detours.h>
#include <cstdio>

#pragma comment(lib,"detours.lib")

int main(int argc, char *argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;

if(!DetourCreateProcessWithDllEx("D:\\UO\\UO Game\\client.exe", 
                                    NULL, NULL, NULL, TRUE, 
                                    CREATE_DEFAULT_ERROR_MODE | CREATE_SUSPENDED,
                                    NULL, "D:\\UO\\UO Game\\", &si, &pi, 
                                    "C:\\Users\\Felipe\\Desktop\\mydll\\Debug\\mydll.dll", NULL))
    printf("Failed");
else
    printf("Success");

ResumeThread(pi.hThread);

//WaitForSingleObject(pi.hProcess, INFINITE);

//CloseHandle(&si);
//CloseHandle(&pi);

return EXIT_SUCCESS;
}
#包括
#包括
#包括
#pragma注释(lib,“detours.lib”)
int main(int argc,char*argv[])
{
STARTUPINFO si;
处理信息;
零内存(&si,sizeof(si));
零内存(&pi,sizeof(pi));
si.cb=sizeof(si);
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=SW_SHOW;
如果(!DetourCreateProcessWithDllEx(“D:\\UO\\UO Game\\client.exe”,
空,空,空,真,
创建默认错误模式创建挂起,
空,“D:\\UO\\UO游戏\\”,&si和pi,
“C:\\Users\\Felipe\\Desktop\\mydll\\Debug\\mydll.dll”,空)
printf(“失败”);
其他的
printf(“成功”);
恢复线程(pi.hThread);
//WaitForSingleObject(pi.hProcess,无限);
//闭柄&si;
//CloseHandle(&pi);
返回退出成功;
}
dll.cpp

#include <cstdio>
#include <windows.h>
#include <detours.h>

#pragma comment(lib,"detours.lib")
#pragma comment(lib,"ws2_32.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, char* buf, int len, int flags) = recv;
int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags);

FILE* pSendLogFile;
FILE* pRecvLogFile;

BOOL msg_once = false;

int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
MessageBoxA(0,"MyRecv",0,0);
return pSend(s, buf, len, flags);
}

int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
{
MessageBoxA(0,"MyRecv",0,0);
return pRecv(s, buf, len, flags);
}

extern "C" __declspec(dllexport) void dummy(void){
return;
}

BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
if (!msg_once)
{
    MessageBoxA(0,"loaded",0,0);
    msg_once = true;
}

if (DetourIsHelperProcess()) {
    return TRUE;
}

if (dwReason == DLL_PROCESS_ATTACH) {
    DetourRestoreAfterWith();

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)pSend, MySend);
    if(DetourTransactionCommit() == NO_ERROR)
        MessageBox(0,"send() detoured successfully","asd",MB_OK);

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)pRecv, MyRecv);
    if(DetourTransactionCommit() == NO_ERROR)
        MessageBox(0,"recv() detoured successfully","asd",MB_OK);
}
else if (dwReason == DLL_PROCESS_DETACH) {
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)pSend, MySend);
    DetourTransactionCommit();

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)pRecv, MyRecv);
    DetourTransactionCommit();
}
return TRUE;
}
#包括
#包括
#包括
#pragma注释(lib,“detours.lib”)
#pragma注释(lib,“ws2_32.lib”)
int(WINAPI*pSend)(sockets,const char*buf,int len,int flags)=发送;
int WINAPI MySend(套接字s、常量字符*buf、int len、int标志);
int(WINAPI*pRecv)(sockets,char*buf,int len,int flags)=recv;
int WINAPI MyRecv(套接字s、字符*buf、int len、int标志);
文件*pSendLogFile;
文件*pRecvLogFile;
BOOL msg_once=错误;
int WINAPI MySend(套接字s、常量字符*buf、int len、int标志)
{
MessageBoxA(0,“MyRecv”,0,0);
返回pSend(s、buf、len、标志);
}
int WINAPI MyRecv(套接字s、字符*buf、int len、int标志)
{
MessageBoxA(0,“MyRecv”,0,0);
返回pRecv(s、buf、len、标志);
}
外部“C”uu declspec(dllexport)无效虚拟(void){
返回;
}
布尔WINAPI DllMain(HINSTANCE hinst、DWORD dwReason、LPVOID保留)
{
如果(!msg_once)
{
MessageBoxA(0,“已加载”,0,0);
msg_once=true;
}
if(迂回过程()){
返回TRUE;
}
if(dwReason==DLL\u进程\u附加){
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
迂回附加(&(PVOID&)pSend,MySend);
if(DetourTransactionCommit()=无错误)
消息框(0,“发送()成功绕道”,“asd”,MB_OK);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
迂回附加(&(PVOID&)pRecv,MyRecv);
if(DetourTransactionCommit()=无错误)
消息框(0,“recv()绕道成功”,“asd”,MB_OK);
}
else if(dwReason==DLL\u进程\u分离){
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
绕道分离(&(PVOID&)pSend,MySend);
DetourTransactionCommit();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
绕道分离(&(PVOID&)pRecv,MyRecv);
DetourTransactionCommit();
}
返回TRUE;
}

是否向对等方发送数据或从对等方接收数据?您确定要挂接的功能是否正确?如果您在没有迂回和断点的调试器中运行它,它们会被调用吗?RetiredInja是对的。例如,挂接的应用程序可能正在调用
WSASend()
/
WSARecv()
。如果数据已发送,则客户端可以毫无问题地进行通信。exe指向发送/接收两个方向。。我将尝试使用WSASend和WSARecv,但我确信应用程序调用recv、send、connect、select、socket和closesocket(我只想要send/recv)刚刚找到了如何正确钩住刚刚替换的:int(WINAPI pSend)(sockets,const char buf,int len,int flags)=send;带有:HMODULE hLib=LoadLibrary(“wsock32.dll”);typedef int(WINAPI SendPtr)(套接字s、const char buf、int len、int标志);SendPtr pSend=(SendPtr)GetProcAddress(hLib,“send”);(与recv相同)无论如何,感谢您的反馈