detours2.1 VC6中编译方法及源代码及使用例子及编译好的BIN

来源:互联网 发布:超级优化txt网盘 编辑:程序博客网 时间:2024/06/12 06:03

detours2.1 VC6中编译方法及源代码及使用例子及编译好的BIN


下载地址http://download.csdn.net/detail/chinafe/4424305

http://download.csdn.net/detail/chinafe/4424305


1.在纯VC6环境中新建 win32 static library 项目名设为detours


2.把detours2.1 scr目录中的源文件全部添加到项目


3.在Project->Seting->C/C++->Preprocessor definitions中添加DETOURS_X86


4.打开项目中detoured.cpp把里面DllMain函数名修改为LengFeng(否则使用时会出现DllMain冲突)error LNK2005: _DllMain@12 already defined in ***.obj


5.直接编译就可以生成detours.lib


6.在需要的项目中使用detours.lib和detours.h 就可以了


7.附件中提供了编译好的detours.lib和系统源代码


注意:需要在没有安装SDK的环境编译,如果安装过SDK,请把SDK的顺序调到最后


detour_2.1为源码


detours_bin为BIN


hook_send为例子

2012-7-12 冷风 QQ 121121606

例子代码


下载地址

http://download.csdn.net/detail/chinafe/4424305

#include <windows.h>#include <tchar.h>#include <stdio.h>#include "detours.h"#pragma comment(lib,"detours.lib")static LONG dwSlept = 0;// Target pointer for the uninstrumented Sleep API.//static VOID (WINAPI * TrueSleep)(DWORD dwMilliseconds) = Sleep;// Detour function that replaces the Sleep API.//VOID WINAPI TimedSleep(DWORD dwMilliseconds){    // Save the before and after times around calling the Sleep API.    DWORD dwBeg = GetTickCount();    TrueSleep(dwMilliseconds);    DWORD dwEnd = GetTickCount();    InterlockedExchangeAdd(&dwSlept, dwEnd - dwBeg);}// DllMain function attaches and detaches the TimedSleep detour to the// Sleep target function.  The Sleep target function is referred to// through the TrueSleep target pointer.//BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved){    if (dwReason == DLL_PROCESS_ATTACH) {        DetourRestoreAfterWith();        DetourTransactionBegin();        DetourUpdateThread(GetCurrentThread());        DetourAttach(&(PVOID&)TrueSleep, TimedSleep);        DetourTransactionCommit();    }    else if (dwReason == DLL_PROCESS_DETACH) {        DetourTransactionBegin();        DetourUpdateThread(GetCurrentThread());        DetourDetach(&(PVOID&)TrueSleep, TimedSleep);        DetourTransactionCommit();    }    return TRUE;}


原创粉丝点击