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. [转帖]一次ORA-3136的处理

    https://oracleblog.org/working-case/deal-with-ora3136/ 最近收到一个告警,用户说数据库无法连接,但是从监控上看,oracle的后台进程已经侦听进程 ...

  2. [转帖]你应该知道的Shell 脚本的经典十三问

    https://blog.csdn.net/wangzhicheng987/article/details/131031344 1. 为何叫做shell? 我们知道计算机的运作不能离开硬件,但使用者却 ...

  3. [转帖]Linux的tmpfs和ramfs

    tmpfs tmpfs是一种虚拟内存文件系统, 它的存储空间在VM里面,现在大多数操作系统都采用了虚拟内存管理机制, VM(Virtual Memory) 是由Linux内核里面的VM子系统管理. V ...

  4. [转帖]vm内核参数之缓存回收drop_caches

    注:本文分析基于3.10.0-693.el7内核版本,即CentOS 7.4 1.关于drop_caches 通常在内存不足时,我们习惯通过echo 3 > /proc/sys/vm/drop_ ...

  5. [转帖]Linux性能测试之unixbench

    https://www.modb.pro/db/487945 大家好,昨天为大家带来了一篇关于在Linux下性能测试的文章<性能测试之LTP>,今天继续为大家推荐系列工具之unixbenc ...

  6. Oracle Linux7 与Oracle Linux8 下载rpm包的位置

    Oracle Linux 7 http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/index.html 索引页 http://yum.or ...

  7. 2022 倒带 - NutUI

    作者:京东零售 于明明 前言 时光飞逝,流年似水,让我们倒带 2022,回首这跌宕起伏一年走过的 "升级之路". NutUI 表现如何? 成绩单等着您打分! 2022 是 NutU ...

  8. 给你一颗“定心丸”——记一次由线上事故引发的Log4j2日志异步打印优化分析

    一.内容提要 自知是人外有人,天外有天,相信对于Log4j2的异步日志打印早有老师或者同学已是熟稔于心,优化配置更是信手拈来,为了防止我在这里啰里八嗦的班门弄斧,我先将谜底在此公布:log4j2.as ...

  9. 解决Edge浏览器提示“此网站已被人举报不安全”

    今天下午微软旗下的 Microsoft Edge 浏览器将百度搜索的跳转域名 (*.baidu.com/link?url=*) 封杀,百度搜索首页可以打开,但搜索任何关键词点击搜索结果都会被拦截. 当 ...

  10. LeetCode刷题日记 2020/03/25

    力扣刷题继续! 题目:计算三维形体表面积 题干 在 N * N 的网格上,我们放置一些 1 * 1 * 1  的立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在对应单元格 (i ...