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

86 篇文章 3 订阅
35 篇文章 0 订阅

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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值