Detours:下载及编译

下载链接:GitHub - microsoft/Detours: Detours is a software package for monitoring and instrumenting API calls on Windows. It is distributed in source code form.
https://github.com/microsoft/Detours

微软的Detours主页:
Detours - Microsoft Research
https://www.microsoft.com/en-us/research/project/detours/

发现Detours的官方文档不够详细,
而且有人在GitHub上的issus也提到了这个问题:Ununderstandable documents (wiki) · Issue #49 · microsoft/Detours · GitHub
https://github.com/microsoft/Detours/issues/49

开发环境

  1. win10
  2. Visual Studio 17
  3. .Net Framework

步骤

  1. 从github下载zip压缩包,解压
  2. 打开VS 2017的开发人员命令提示符,cd 进入解压目录,运行命令
nmake
  1. 如果报错,就像下面这种情况
    sn.exe not found · Issue #42 · microsoft/Detours · GitHub
    https://github.com/microsoft/Detours/issues/42

sn.exe是.NET Framework里的一个工具,
.NET Framework Tools | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/framework/tools/

如果电脑里有sn.exe,可以把sn.exe所在目录加入环境变量,这样就能在命令行里访问到sn.exe了。

如果电脑里没有sn.exe,就需要下载最新版本的.NET Framework。
下载链接:Download .NET Framework 4.8 | Free official downloads
https://dotnet.microsoft.com/download/dotnet-framework/net48

我下载的是Developer Pack版本的。

在以下目录查找sn.exe,并把sn.exe所在目录加入环境变量中的path

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
C:\Windows\Microsoft.NET
  1. nmake完成之后,
    在“lib.X86”目录获取detours.lib库文件,在“include”目录下获取“detours.h”和“detver.h”两个头文件。

参考链接

  1. 技术分享 - 使用VS2013编译Detours库
    https://www.write-bug.com/article/1939.html
  2. Detours 劫持 - M-Anonymous - 博客园
    https://www.cnblogs.com/M-Anonymous/p/9766343.html
  3. 技术分享 - 基于Detours库HOOK API
    https://www.write-bug.com/article/1805.html

踩过的坑

  1. 编译器
    用VC6编译使用detours的程序可能会出错,
    我用的是VS2017
  2. 无法编译 PVOID&
    PVOID等效于void * —无类型指针
    可以使用:
DetourAttach((void **)&OldMessageBoxW, NewMessageBoxW);

参考链接:https://stackoverflow.com/questions/56305389/ms-detours-detourattach-fails

  1. WINAPI 是这样定义的
    #define WINAPI __stdcall
    __stdcall 是一种函数参数传递压栈顺序和堆栈平衡的约定
    在windows编程中默认的参数传递都是__stdcall方式的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值