RT

解决方案 »

  1.   

    拦截MessageBox
    //Dll部分#include <windows.h>
    #include "detours.h"
    #pragma comment(lib,"detoured.lib")
    #pragma comment(lib,"detours.lib")
    int (WINAPI *pMessageBoxW)(HWND hWnd ,
                           LPCWSTR lpText,
                           LPCWSTR lpCaption,
                           UINT uType) = MessageBoxW;int WINAPI MyMessageBoxW(HWND hWnd ,
      LPCWSTR lpText,
      LPCWSTR lpCaption,
      UINT uType)
    {
    MessageBox(NULL,"MessageBox被拦截","API",MB_OK);
    return pMessageBoxW(hWnd,lpText,lpCaption,uType);
    }void _stdcall myTest()
    {

    }
    BOOL APIENTRY DllMain( HANDLE hModule, 
      DWORD  ul_reason_for_call, 
      LPVOID lpReserved
      )
    {
    int error;
    switch(ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
            {
                DetourTransactionBegin();
                DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)pMessageBoxW, MyMessageBoxW);
                error = DetourTransactionCommit();
    if(NO_ERROR!=error)
    OutputDebugString("错误");
    else
    OutputDebugString("正确");
            }
            break;
        case DLL_PROCESS_DETACH:
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)pMessageBoxW, MyMessageBoxW);
            DetourTransactionCommit();
            break;
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
            break;
    }
        return TRUE;
    }//EXE部分void CTestDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    STARTUPINFO si;
        PROCESS_INFORMATION pi;
    char szpath[MAX_PATH];
    CString str,str1,path;
        ZeroMemory(&si, sizeof(STARTUPINFO));
        ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
        si.cb = sizeof(STARTUPINFO);
        GetCurrentDirectory(MAX_PATH, szpath);
    path.Format("%s",szpath);
    str  = path + "\\" + "testdll.dll";
    str1 = path + "\\" + "detoured.dll";
    MessageBox(str,"",MB_OK);

        if (DetourCreateProcessWithDll(NULL, "C:\\windows\\notepad.exe", NULL,
            NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL,
            &si, &pi, str1, str, NULL))
    {
    MessageBox("","Success",MB_OK);
    }
    }
      

  2.   

    def文件部分
    LIBRARY "testDll.DLL"
    EXPORTS
    myTest
      

  3.   

    好兄弟 我Q 895000080 
    我现在库老是加载失败  是怎么了啊http://topic.csdn.net/u/20100727/10/a5a038f8-791e-4352-a098-2254cf6d73e4.html?78497
    谢9999辈子
      

  4.   

    //拦截socket写日志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);
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s\n", buf);
        fclose(pSendLogFile);
        return pSend(s, buf, len, flags);
    }
     
    int WINAPI MyRecv(SOCKET s, char* buf, int len, int flags)
    {
        fopen_s(&pRecvLogFile, "C:\\RecvLog.txt", "a+");
        fprintf(pRecvLogFile, "%s\n", buf);
        fclose(pRecvLogFile);
        return pRecv(s, buf, len, flags);
    }
    然后照着上面的替换,最后自己在注入.
      

  5.   

    我现在dll加载失败 好郁闷啊
      

  6.   

    我的是VC6 系统XP 要的话留下联系方式 给你发过去参考下?
      

  7.   

    这个 def 文件在哪里?我的工程目录下怎么没
      

  8.   

    在你的工程上 鼠标右键 添加->新建项->代码->模块定义文件(VS2005) VS2005和VS2008差不多
    VC6直接建一个记事本文件 最后保存成def文件
      

  9.   

    DetourCreateProcessWithDll是detours提供的API 作用是Create a new process and load a DLL into it。共同学习
      

  10.   

    先说下那def 放在哪目录,完全COPY你的吗?
    def 文件的作用呢? 可以不要这个文件吗?
    DetourCreateProcessWithDll
    是什么用处能细说下吗
    http://topic.csdn.net/u/20100720/11/fa232f73-f18a-4dac-8338-9aaa3fc75586.html?seed=483682191&r=67200041#r_67200041
    这个帖子是怎么 ?好像里面没用到上面的函数啊?
    奥 这次问题多?回答完结贴了,楼高了
      

  11.   

    def文件放在工程目录下 不用抄我的 我的只是个例子 LIBRARY 后面是你的dll名字 EXPORTS 下面是你要导出的函数名字 可以不用导出文件,因为我用DetourCreateProcessWithDll函数 看别人的帖子说用这个函数最好要有导出函数,所以就加上了。DetourCreateProcessWithDll
    的作用是新建一个进程并把指定的Dll注入。至于你说的那个帖子 也是一种注入的方法,你可以看下windows核心编成 第22章 就明白很多。呵呵 共同学习
      

  12.   

    补充一下 如果你的Dll没有导出函数def文件可以不用
      

  13.   

    (DetourCreateProcessWithDll(NULL, "C:\\windows\\notepad.exe", NULL,
            NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL,
            &si, &pi, str1, str, NULL))第2个参数是干啥用的,是导入的程序的名字?还是别的什么?
      

  14.   


    另外 导出函数 一定要def 吗?我记得有个__declspec(dllexport)
    区别是什么啊
      

  15.   

    DetourCreateProcessWithDll第2个参数是你要注入的程序 我这里以记事本举例
    __declspec(dllexport)和def的区别看下面的连接,我感觉一般情况下用哪个也行
    http://dev.firnow.com/course/3_program/c++/cppxl/2008105/147591.html
      

  16.   

     我要 钩网页统计上网流量 就把 notepad.exe 换成 Internet Explorer吗我桌面有个上网图标,名字叫 Internet Explorer,需要加.exe 吗?
    是用explore.exe 还是Internet Explorer.exe 还是 ?好复杂啊
      

  17.   

    我的系统是XP C:\\Program Files\\Internet Explorer\\iexplore.exe
    要IE的全路径 只写一个iexplore.exe不行
      

  18.   

    我晕 那怎么办呢如果我开了 2个浏览器,会出现2个名字叫iexplore.exe的进程吗?
    会不会2个进程同名?DetourCreateProcessWithDll(NULL, "C:\\windows\\notepad.exe", 
    那参数 到底是进程名字 还是程序 名字,看路径 应该是程序吧
    到底是注入程序 还是注入进程
      

  19.   

    DetourCreateProcessWithDll': identifier not found是怎么了 急啊
      

  20.   

    #include "detours.h"
    #pragma comment(lib,"detoured.lib")
    #pragma comment(lib,"detours.lib")
      

  21.   

    我的联系方式 [email protected]帮我分析下 内存错误啊
    顺便把你的正确代码发给我啊,谢谢!!!