Detours 是一个用于在 ARM, ARM64, X86, X64 和 IA64 机器上拦截二进制函数的库。 Detours 最常用来拦截应用程序中的 win32 api 调用,比如添加调试工具。 拦截代码在运行时动态应用。

Detours 将目标函数的前几个指令替换为无条件跳转到用户提供的 detour 函数

它与 WriteProcessMemory 有所不同

区别:

  • WriteProcessMemory 是 Windows API 中的一个函数,用于将数据写入到指定进程的内存空间中。通常情况下,这个函数被用于与进程间通信,比如注入 DLL、修改其他进程的内存内容等。这个函数能够在一定程度上用于修改其他进程的行为,因此在一些涉及软件修改的场景中被使用。
  • Detours 是 Microsoft Research 开发的一种库,用于在 Windows 平台上修改函数调用的行为。它允许开发者截获特定函数的调用,并将其重定向到自定义的函数中,从而实现对目标函数的修改、监视和扩展。Detours 在软件开发中被广泛用于实现各种目的,包括代码注入、API hooking、性能分析等。

结合使用:

  • 在某些情况下,可以将 WriteProcessMemory 和 Detours 结合使用,以实现对其他进程的函数调用的修改和扩展。例如,可以使用 WriteProcessMemory 在目标进程中注入 DLL,然后使用 Detours 修改目标进程的某些函数调用,以实现一些特定的行为,比如游戏作弊、反作弊等。
  • 通常情况下,Detours 会更适合用于修改目标进程内的函数调用,而不是直接修改其内存内容。因此,结合 WriteProcessMemory 和 Detours 使用时,可能会将 Detours 用于修改函数调用,而使用 WriteProcessMemory 用于注入所需的代码或 DLL。

项目上我们将其用于 hook 播放器声音,利用 UDP 将数据传回给我们的软件用于播放和传输

主要用到 DetourCreateProcessWithDllEx

功能:Create a new process and load a DLL into it. Chooses the appropriate 32-bit or 64-bit DLL based on the target process.

它可以根据目标进程自动加载 32-bit DLL 或者 64-bit DLL

方法:

To support both 32-bit and 64-bit applications on a single system, you must create two DLLs. One DLL must contain 32-bit code, the other DLL must contain 64-bit code. The DLLs must reside in the same directory and must have identical names except that the name of the 32-bit DLL should end with "32" and the name of the 64-bit DLL should end with "64". For example, matching DLLs would be named foo32.dll and foo64.dll.

You should use the DetourCreateProcessWithDllEx or DetourCreateProcessWithDlls API to start a process with your DLL. Furthermore, your DLLs must:

Export the DetourFinishHelperProcess API as export ordinal 1.

Call the DetourIsHelperProcess API in your DllMain function. Immediately return TRUE if DetourIsHelperProcess return TRUE.

Call the DetourCreateProcessWithDllEx or DetourCreateProcessWithDlls API instead of DetourCreateProcessWithDll to create new target processes.

文档参考:https://github.com/microsoft/detours/wiki/OverviewHelpers

demo 参考:https://github.com/microsoft/Detours/blob/main/samples/withdll/withdll.cpp

Detours 的使用的更多相关文章

  1. 使用detours实现劫持

    第一步:下载detours3.0,安装detours 第二步:构建库文件,nmake编译 第三步:包含库文件和头文件 #include "detours.h" //载入头文件 #p ...

  2. Microsoft Detours 2.1简介

    http://blog.163.com/qcb_163/blog/static/9545466420117851038971/ Microsoft Detours 2.1简介 2011-08-0817 ...

  3. Detours简介 (拦截x86机器上的任意的win32 API函数)

    Detours 当然是用detours,微软明显高腾讯一筹,同上,至今没失败过.写这种HOOK一定要再写个测试程序,不要直接HOOK你的目的程序,例如QQ,因为这样不方面更灵活的测试.说明一下:Det ...

  4. 运用Detours库hook API(原理是改写函数的头5个字节)

    一.Detours库的来历及下载: Detours库类似于WTL的来历,是由Galen Hunt and Doug Brubacher自己开发出来,于99年7月发表在一篇名为<Detours: ...

  5. Detours信息泄漏漏洞

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  6. Detours修改段属性漏洞

    v:* { } o:* { } w:* { } .shape { }p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-botto ...

  7. Detours HOOK 库 过滤LoadLibraryExW

    Detours HOOK 库 Hook 过滤LoadLibraryExW 一丶简介 1.1 Detours库简介 Detours是微软提供的HOOK库.为我们Hook提供了方便.再也不用手撸 HOOK ...

  8. detours express版本的使用

    原文最早发表于百度空间2012-03-21 一.编译lib 1)拷贝它的src文件夹和system.mak文件到VS的VCVARS32.BAT所在的目录下 2)在命令提示符中运行VCVARS32.BA ...

  9. 丢弃昂贵的Detours Professional 3.0,使用免费强大的EasyHook

    我们要先看看微软官方的著名HOOK库: Detours Professional 3.0 售价:US$9,999.95 功能列表: Detours 3.0 includes the following ...

  10. Detours改动段属性漏洞

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

随机推荐

  1. [转帖]TIKV扩容之刨坑填坑​

    01 背景 某tidb集群收到告警,TIKV 节点磁盘使用率85%以上,联系业务无法快速删除数据,于是想到扩容TIKV 节点,原先TIKV 节点机器都是6TB的硬盘,目前只有3TB的机器可扩,也担心r ...

  2. [转帖]集群监控之 —— ipmi操作指南

    https://www.cnblogs.com/gaoyuechen/p/8506930.html 这两天,配置了一堆500来个节点的大型集群,被ipmi的问题困扰了一天半,到下午16:40,终于解决 ...

  3. [转帖]Intel“革命性”X86s架构,带来哪些颠覆及影响?

    https://www.eet-china.com/mp/a221822.html 英特尔发布了一份新的白皮书(Intel X86-S扩展架构规格),计划简化其处理器指令集架构(ISA).英特尔提供了 ...

  4. [1036]kvm虚拟机访问时提示no route to host分析

    环境 宿主机: IP: 10.110.136.43 版本:Kylin Linux Advanced Server release V10 (Sword) KVM vm: IP: 10.110.136. ...

  5. Linux执行SQLSERVER语句的简单方法

    背景 因为WTF的原因.经常有人让执行各种乱七八槽的删除语句 因为产品支持了10多种数据库. 这个工作量非常复杂. 为了简单起见,想着能够批量执行部分SQL. 其他的都处理过了,但是SQLSERVER ...

  6. Linux上面Shell简单进行数值计算的办法

    1. 自己简单写了一个脚本 来计算 一个服务进程启动的耗时, 精度要求不高 10秒上下就可以. 在程序执行之前和之后的处理 在最前面设置一句time1=`date +%s`在末尾一句设置time2=` ...

  7. sringboot 调试端口启用的写法

    注意 需要在 -jar 的后面加 加在前面貌似没用 $JAVA_HOME/bin/java -Dloader.path=$CAF_MODULE_PATHS -jar -Dspring.profiles ...

  8. 使用Docker快速搭建InnoDB Cluster集群的过程

    感谢 感谢方神的大力帮助,自己对数据库基本一窍不通.只是照葫芦画瓢做出来的. 感谢来自如下两个网站的资料,我进行了一定程度的融合. https://blog.csdn.net/weixin_43972 ...

  9. Asp .Net Core 部署在阿里云Centos上 :使用Docker部署

    参照 https://www.cnblogs.com/xiaxiaolu/p/9973631.html 运行环境 使用SecureCrt连接服务器 1.阿里云ECS 4核 16 GiB 8Mbps 带 ...

  10. windows加壳程序WinLicense与Themida

    反调试提示 开了Procmon.exe之后启动游戏会弹出这个框,这个是程序加壳之后的反外挂,反调试提示框. WinLicense A monitor program has been found ru ...