<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-CN">
  <title>LeviMC's blog</title>
  <subtitle>Everything about development</subtitle>
  <id>https://levimc.org/blog/</id>
  <link href="https://levimc.org/blog/"/>
  <link href="https://levimc.org/blog/atom.xml" rel="self"/>
  <updated>2024-08-11T09:51:07+08:00</updated>
  <author><name>LeviMC</name></author>
  <entry>
    <title>通过Patch修复BDS的空包刷屏问题</title>
    <id>https://levimc.org/blog/2024/08/11/fix-empty-packet-spam-by-patch/</id>
    <link href="https://levimc.org/blog/2024/08/11/fix-empty-packet-spam-by-patch/"/>
    <published>2024-08-11T09:51:07+08:00</published>
    <updated>2024-08-11T09:51:07+08:00</updated>
    <author><name>ShrBox</name><uri>https://github.com/ShrBox</uri></author>
    <category term="Bedrock Dedicated Server"/>
    <category term="LeviLamina"/>
    <summary>本文将介绍我通过LeviLamina以及libhat通过Patch的方式解决Bedrock Dedicated Server(以下简称BDS)中服务端收到空包会在控制台刷ATTENTION! Received EMPTY UDP packet - potential UDP…</summary>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;Mojang已经在1.21.20.03中修复了此问题&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;本文将介绍我通过&lt;a href=&quot;https://github.com/LiteLDev/LeviLamina&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;LeviLamina&lt;/a&gt;以及&lt;a href=&quot;https://github.com/BasedInc/libhat&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;libhat&lt;/a&gt;通过Patch的方式解决Bedrock Dedicated Server(以下简称BDS)中服务端收到空包会在控制台刷&lt;code&gt;ATTENTION! Received EMPTY UDP packet - potential UDP ports scanning.&lt;/code&gt;的问题。&lt;/p&gt;
&lt;h2 id=&quot;起因&quot;&gt;起因&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2024/08/11/fix-empty-packet-spam-by-patch/#起因&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;在BDS的早期版本中，存在着非常多的严重的远程崩服漏洞，空包崩服就是其中一种，自某个版本后Mojang便修复了此漏洞，但同时又在RakNet中拉了一坨&lt;code&gt;printf&lt;/code&gt;来提醒使用者服务器收到了空包，但这又导致了另一个问题，就是攻击者可以通过频繁地发送空包来造成主线程堵塞。此问题已经由社区向反馈差不多一年时间了，Mojang仍然没有在公开的BDS版本中修复此问题，鉴于前些日子官方和MCC合作的活动服务器是由BDS+ScriptAPI驱动的，但活动服中并无此问题，由此可见Mojang早就知道BDS有这个问题，但却迟迟不修复。于是，我们只能自己动手来修复这一问题。&lt;/p&gt;
&lt;h2 id=&quot;寻找printf函数所在位置&quot;&gt;寻找&lt;code&gt;printf&lt;/code&gt;函数所在位置&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2024/08/11/fix-empty-packet-spam-by-patch/#寻找printf函数所在位置&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;首先编写一个发送空包到BDS端口的脚本，这里选择使用Python。&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;py&quot; data-lines=&quot;11&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Python&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; socket&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;s &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; socket&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;AF_INET&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; socket&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;SOCK_DGRAM&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;i &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; i &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 10000&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; # 发送10000个空包到BDS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    s&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;sendto&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k6&quot;&gt;        &quot;&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        (&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 19132&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    i &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; i &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;将脚本保存为&lt;code&gt;empty.py&lt;/code&gt;。&lt;br&gt;
然后通过Visual Studio打开/挂载BDS进程，选用其它调试器例如x64dbg也可以。&lt;br&gt;
运行此脚本：&lt;code&gt;py empty.py&lt;/code&gt;&lt;br&gt;
此时在控制台观察到大量的&lt;code&gt;ATTENTION! Received EMPTY UDP packet - potential UDP ports scanning.&lt;/code&gt;输出，通过Visual Studio或其它调试器暂停主线程，我们可以看到如下堆栈：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;6&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ntdll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;NtWaitForSingleObject&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    KernelBase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;WaitForSingleObjectEx&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    bedrock_server&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;exe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;UpdateNetworkLoop&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;thread_start&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__cdecl&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    kernel32&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;BaseThreadInitThunk&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;	ntdll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;RtlUserThreadStart&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;嗯？似乎没有看到任何有关输出流的调用？没关系，让我们再试一次。&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;19&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;	ntdll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;NtWriteFile&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    KernelBase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;WriteFile&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;write_text_ansi_nolock&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;_write_nolock&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;_write_internal&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;write_buffer_nolock&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;common_flush_and_write_nolock&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_stdio_output&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;stream_output_adapter&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;write_character_without_count_update&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_stdio_output&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;output_processor&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_stdio_output&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;stream_output_adapter&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_stdio_output&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;standard_base&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_stdio_output&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;stream_output_adapter&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__crt_seh_guarded_call&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;::&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;lambda_d854c62834386a3b23916ad6dae2782d&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;,&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x26;,&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;__stdio_common_vfprintf&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    bedrock_server&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;exe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    bedrock_server&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;exe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RNS2_Berkley&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;RecvFromLoopInt&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    bedrock_server&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;exe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RNS2_Berkley&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;RecvFromLoop&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ucrtbase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;thread_start&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;__cdecl&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    kernel32&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;BaseThreadInitThunk&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    ntdll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;RtlUserThreadStart&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;这次我们得到了我们想要的东西，我们看到了我们期望的&lt;code&gt;printf&lt;/code&gt;，以及&lt;code&gt;printf&lt;/code&gt;在&lt;code&gt;RakNet::RNS2_Berkley::RecvFromLoopInt(void)&lt;/code&gt;中调用的有效信息，现在，我们可以打开IDA或其它同类型的反编译软件来具体查看&lt;code&gt;RakNet::RNS2_Berkley::RecvFromLoopInt(void)&lt;/code&gt;中&lt;code&gt;printf&lt;/code&gt;的具体位置了。&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;48&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RNS2_Berkley&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;RecvFromLoopInt&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RNS2_Berkley&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;  // 略...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  while&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; !*((&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_BYTE &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 260&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    v5 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *((&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 30&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v5 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;      v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (*(&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;__int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__fastcall &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;**)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; const&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(*(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v5 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 24i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;             v5&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k6&quot;&gt;             &quot;D:&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;_work&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;handheld&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;src-deps&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;raknet&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;raknet&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;RakNetSocket2.cpp&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k3&quot;&gt;             388i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;      v7 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;      if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;      {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;        // 略...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;        if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v12 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;          // 略...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;          if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v14 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;            (*(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__fastcall &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;**)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; const&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(*(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v14 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 16i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;              v14&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;              v7&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k6&quot;&gt;              &quot;D:&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;_work&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;handheld&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;src-deps&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;raknet&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;raknet&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;RakNetSocket2.cpp&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k3&quot;&gt;              408i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k8&quot;&gt;          printf&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;  ATTENTION! Received EMPTY UDP packet - potential UDP ports scanning.&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\n\n&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // 找到Mojang拉的屎了&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;        else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;          v13 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *((&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 30&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;          if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v13 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;            (*(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__fastcall &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;**)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(*(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v13 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 8i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v13&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v7&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;LocklessUint32_t&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;Decrement&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;RakNet&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;RNS2_Berkley &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)((&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 256&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v18 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; _InterlockedExchangeAdd&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0xFFFFFFFF&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;      (**(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__fastcall &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;***)(&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; signed&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int32 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*))&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;      if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; _InterlockedExchangeAdd&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0xFFFFFFFF&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;        (*(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__fastcall &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;**)(&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;volatile&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; signed&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int32 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*))(*(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 8i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v18&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  return&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;通过IDA伪代码，我们可以看到Mojang确确实实在&lt;code&gt;RecvFromLoopInt&lt;/code&gt;里面拉了坨大的，现在我们要做的事就是Patch掉这坨了。&lt;br&gt;
切换到IDA View，右键选择&lt;strong&gt;Synchrnoize with&lt;/strong&gt;-&gt;&lt;strong&gt;Pseudocode-A&lt;/strong&gt;，我们就可以看到罪魁祸首的汇编了：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;asm&quot; data-lines=&quot;4&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;GAS&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k8&quot;&gt;loc_14232424B&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;lea&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;     rcx&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;, aAttentionRecei &lt;/span&gt;&lt;span class=&quot;k5&quot;&gt;; &quot;\n\n  ATTENTION! Received EMPTY UDP pac&quot;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;    printf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;jmp&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;     short loc_1423242B9&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;我们需要将&lt;code&gt;lea&lt;/code&gt;和&lt;code&gt;call&lt;/code&gt;给Patch为空字节，接下来切换到Hex View，同样右键选择&lt;strong&gt;Synchrnoize with&lt;/strong&gt;-&gt;&lt;strong&gt;Pseudocode-A&lt;/strong&gt;，我们就找到了罪魁祸首的16进制：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;text&quot; data-lines=&quot;1&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Text Only&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;48 8D 0D 9E DB B7 00 E8 D9 EB FD FF&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;通过levilamina和libhat进行patch&quot;&gt;通过LeviLamina和libhat进行Patch&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2024/08/11/fix-empty-packet-spam-by-patch/#通过levilamina和libhat进行patch&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;现在就是我们通过LeviLamina和libhat来大展拳脚的时候了&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;17&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;libhat/Scanner.hpp&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;libhat/Signature.hpp&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;ll/api/memory/Memory.h&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; consoleSpamPatch&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;     funcBegin &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;LL_RESOLVE_SYMBOL&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;?RecvFromLoopInt@RNS2_Berkley@RakNet@@IEAAIXZ&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    constexpr&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; pattern   &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; hat&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;compile_signature&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;48 8D 0D 9E DB B7 00 E8 D9 EB FD FF&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;           result    &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; hat&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;find_pattern&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;funcBegin&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; funcBegin &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0x250&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; pattern&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (!&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;has_result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;())&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;        std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;cout &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt; &quot;Can't find signature for RecvFromLoopInt&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; patchLocation &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    size_t&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;     patchLength   &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 12&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    ll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;memory&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;modify&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;patchLocation&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; oatchLength&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&amp;#x26;]()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;        std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;memset&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;patchLocation&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0x90&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; /* nop */&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; oatchLength&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;我们也可以改用模糊匹配，将一些可能会变动的字节改为&lt;code&gt;??&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;17&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;libhat/Scanner.hpp&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;libhat/Signature.hpp&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k0&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;ll/api/memory/Memory.h&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; consoleSpamPatch&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;     funcBegin &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;LL_RESOLVE_SYMBOL&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;?RecvFromLoopInt@RNS2_Berkley@RakNet@@IEAAIXZ&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    constexpr&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; pattern   &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; hat&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;compile_signature&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;48 8D 0D ?? ?? ?? 00 E8 ?? ?? FD FF&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;           result    &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; hat&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;find_pattern&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;funcBegin&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; funcBegin &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0x250&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; pattern&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (!&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;has_result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;())&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;        std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;cout &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt; &quot;Can't find signature for RecvFromLoopInt&lt;/span&gt;&lt;span class=&quot;kb&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; patchLocation &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    size_t&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;     patchLength   &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 12&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    ll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;memory&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;modify&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;patchLocation&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; oatchLength&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&amp;#x26;]()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;        std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;memset&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;patchLocation&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0x90&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; /* nop */&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; oatchLength&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;将代码嵌入Mod中，然后将Mod安装进带有LeviLamina的服务端中。&lt;br&gt;
重新执行发送空包的Python脚本，服务器的控制台无事发生，就证明我们的Patch已经生效了。&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>使用机器学习检测杀戮光环</title>
    <id>https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/</id>
    <link href="https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/"/>
    <published>2023-07-31T14:03:00+08:00</published>
    <updated>2023-07-31T14:03:00+08:00</updated>
    <author><name>PA733</name><uri>https://github.com/PA733</uri></author>
    <category term="Bedrock Dedicated Server"/>
    <category term="LiteLoaderBDS"/>
    <summary>本文将介绍一种基于机器学习的反作弊思路，它利用玩家的行为数据来训练一个神经网络模型，从而有效地识别出作弊的玩家。</summary>
    <content type="html">&lt;p&gt;本文将介绍一种基于机器学习的反作弊思路，它利用玩家的行为数据来训练一个神经网络模型，从而有效地识别出作弊的玩家。&lt;/p&gt;
&lt;h2 id=&quot;引言&quot;&gt;引言&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#引言&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;杀戮光环简介&quot;&gt;杀戮光环简介&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#杀戮光环简介&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;杀戮光环是一种外挂，它可以让玩家自动攻击周围的实体（其他玩家、怪物等）。杀戮光环的检测一直是一个难题，因为杀戮光环的行为和正常玩家的行为非常相似。&lt;br&gt;
目前市面上的杀戮光环检测方法主要有以下几种：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;基于行为的检测：分析玩家的攻击频率、攻击间隔等指标。&lt;/li&gt;
&lt;li&gt;基于数据包的检测：分析玩家攻击数据包的间隔等特征。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;传统方法有一些局限性，比如容易受到网络延迟的影响，或者被一些高级的外挂绕过。&lt;/p&gt;
&lt;h2 id=&quot;特征分析&quot;&gt;特征分析&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#特征分析&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;玩家行为&quot;&gt;玩家行为&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#玩家行为&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;玩家攻击时，通常要先瞄准目标，再点击鼠标。&lt;br&gt;
但杀戮光环不需要瞄准，它通过发送攻击数据包，来快速攻击周围的实体。&lt;br&gt;
因此，分析玩家看的方向和玩家攻击的实体的方向，有多大的偏差，即可判断玩家是否用了杀戮光环。&lt;br&gt;
在实战中，我们发现这个偏差与玩家的攻击距离有关，因此接下来我们将同时收集角度和距离的特征。&lt;/p&gt;
&lt;h3 id=&quot;数据收集&quot;&gt;数据收集&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#数据收集&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;借助LiteLoaderBDS SDK，使用以下代码，即可获取到玩家的视线向量：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;4&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;Event&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;PlayerAttackEvent&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;([](&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; Event&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;PlayerAttackEvent&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;&amp;#x26;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; ev&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    Vec3&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerLookDir &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; ev&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;mPlayer&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;getHeadLookVector&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;随后使用以下代码计算玩家到实体的向量和距离：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;7&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;Event&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;PlayerAttackEvent&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;([](&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; Event&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;PlayerAttackEvent&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;&amp;#x26;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; ev&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    Vec3&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEyeLoc &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; ev&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;mPlayer&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;getCameraPos&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    Vec3&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; entityLoc &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; ev&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;mTarget&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;getPos&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    Vec3&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEntityDir &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; entityLoc &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEyeLoc&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    double&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEntityDist &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEntityDir&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; true&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;接着，我们计算出夹角：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;2&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; cosAngle &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerEntityDir&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;angle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;playerLookDir&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; angle &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; acos&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;cosAngle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;至此，我们已经获得了关键数据。&lt;/p&gt;
&lt;h3 id=&quot;数据可视化&quot;&gt;数据可视化&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#数据可视化&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;将数据导入至MATLAB，使用以下代码，即可绘制出玩家攻击距离和玩家攻击角度的散点图：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;matlab&quot; data-lines=&quot;7&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Text Only&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;%% Read the csv files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;vanillaData = readmatrix('data.desktop.vanilla.csv');&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;horionData = readmatrix('data.desktop.horion.csv');&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;%% Plot the data in a scatter plot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;scatter(vanillaData, 'g');&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;scatter(horionData, 'r', 'x');&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://levimc.org/blog/images/2023/07/31/3RwnGp9VqgZby8t.jpg&quot; alt=&quot;MATLAB绘制的散点图&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot;&gt;&lt;br&gt;
观察发现，两类数据有着较明显的区别。其中，原版客户端对应点分布于图像左下角；而杀戮光环对应点分布较散。&lt;/p&gt;
&lt;h2 id=&quot;模型训练&quot;&gt;模型训练&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#模型训练&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;神经网络的选择&quot;&gt;神经网络的选择&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#神经网络的选择&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;在本次案例中，我们选择了DNN神经网络，原因如下：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;DNN网络在大量数据的情况下表现较好。在Minecraft中，玩家攻击数据收集成本较低。&lt;/li&gt;
&lt;li&gt;DNN网络可以较容易地移植到C++上，减小开发难度。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;神经网络训练&quot;&gt;神经网络训练&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#神经网络训练&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;读入数据后，我们使用以下MATLAB代码创建一个DNN神经网络：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;matlab&quot; data-lines=&quot;1&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Text Only&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;net = patternnet(hiddenLayerSize);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;接着，开始训练：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;matlab&quot; data-lines=&quot;1&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Text Only&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;net = train(net, P_train, T_train);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;在实战中，测试集报告的分类准确度达到了87%，符合预期。&lt;/p&gt;
&lt;h2 id=&quot;实践&quot;&gt;实践&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#实践&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;神经网络移植&quot;&gt;神经网络移植&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#神经网络移植&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;使用MATLAB中的&lt;code&gt;save&lt;/code&gt;函数，我们可以保存训练好的模型的权重等数据。&lt;br&gt;
在C++中实现相关逻辑后，即可用于新数据的分类：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;11&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; DNN&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt;&amp;#x26;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; X&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;    // ===== SIMULATION ========&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;    // Dimensions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    int&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Q &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; X&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;    // Input 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Xp1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; mapminmax_apply&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; x1_step1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k5&quot;&gt;    // Layer 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    double&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; a1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; logsigApply&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;matlab&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;matrixAddition&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;matlab&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;repmat&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Q&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; matlab&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;matrixMultiply&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;LW1_1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Xp1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; a1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;检测实现&quot;&gt;检测实现&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#检测实现&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;使用 “特征分析”-“数据收集” 章节中，我们收集到玩家的攻击数据，即可进行分类：&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;4&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; playerData &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;playerData&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;playerEntityDist&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;playerData&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;angle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; results &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; DNN&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;playerData&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;神经网络返回数据分类为1的概率。&lt;/p&gt;
&lt;h2 id=&quot;总结与展望&quot;&gt;总结与展望&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#总结与展望&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;主要贡献&quot;&gt;主要贡献&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#主要贡献&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;机器学习在游戏中的主要贡献如下：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;我们只需要找到玩家行为的量化方法，即可进行异常检测。&lt;/li&gt;
&lt;li&gt;如果外挂进行了升级，借助机器学习较高的灵活性与可扩展性，我们可以通过增加数据量或数据维度的方式，及时地做出应对。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;未来的发展方向&quot;&gt;未来的发展方向&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#未来的发展方向&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;反作弊作为一种保证玩家游戏公平的手段，能够帮助广大服主建立良好的游玩体验，提高用户的满意度和留存率。&lt;br&gt;
但随着作弊手段的日益进步与玩家需求的变化，反作弊也面临着新的挑战与机遇，未来的发展方向主要有以下几个方面：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;机器学习的引入。机器学习能带来更高的检测率与更低的误报率，并及时对新兴作弊手段进行响应。&lt;/li&gt;
&lt;li&gt;更多判定角度。反作弊可引入更多的玩家特征信息进行判断，进一步增强反作弊能力。&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;致谢&quot;&gt;致谢&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/31/machine-learning-killaura-detect/#致谢&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;感谢 &lt;a href=&quot;https://github.com/LiteLDev/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;LiteLDev&lt;/a&gt; 的各位，他们开发出的LiteLoaderBDS极大地简化了数据采集与分析的难度。&lt;br&gt;
感谢 &lt;a href=&quot;https://github.com/Futrime&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Futrime&lt;/a&gt; ，他对本实践提出了很多建设性的意见。&lt;br&gt;
感谢 &lt;a href=&quot;https://github.com/ShrBox&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;ShrBox&lt;/a&gt; 和 &lt;a href=&quot;https://github.com/dofes&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Dofes&lt;/a&gt; ，他们为本项目的推广提供了很大的帮助。&lt;br&gt;
感谢 &lt;a href=&quot;https://github.com/KawaiiNahida&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;KawaiiNahida&lt;/a&gt;、&lt;a href=&quot;https://github.com/Redbeanw44602&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Redbeanw44602&lt;/a&gt;和&lt;a href=&quot;https://github.com/RimuruChan&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;RimuruChan&lt;/a&gt; ，他们为我的开发给予了精神上的鼓励与支持。&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>蜂巢崩服问题的解决</title>
    <id>https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/</id>
    <link href="https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/"/>
    <published>2023-07-26T18:28:00+08:00</published>
    <updated>2023-07-26T18:28:00+08:00</updated>
    <author><name>Dofes</name><uri>https://github.com/Dofes</uri></author>
    <category term="Bedrock Dedicated Server"/>
    <category term="LiteLoaderBDS"/>
    <summary>记录一下BDS有关BlockEventDispatcherToken::unregister的一个崩服问题</summary>
    <content type="html">&lt;p&gt;记录一下BDS有关BlockEventDispatcherToken::unregister的一个崩服问题&lt;/p&gt;
&lt;h3 id=&quot;起因&quot;&gt;起因&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/#起因&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;当初有人反馈,大型服务器在长期运行的时候,在关服的时候会出现崩服问题(0xc0000005错误),而崩服很显然,会导致地图损失等问题, &lt;del&gt;再加上当初闲得无聊&lt;/del&gt; ,就着手开展了对这个的研究.&lt;/p&gt;
&lt;h3 id=&quot;研究&quot;&gt;研究&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/#研究&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;details&gt;  
&lt;summary&gt;当时的崩服Log: &lt;/summary&gt;  
&lt;div class=&quot;kit-code&quot; data-lang=&quot;bash&quot; data-lines=&quot;8&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;Bash&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k8&quot;&gt;......&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.138&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.138&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Last Assembly: &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.138&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;   0x7FF7CCAA92BE --&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; mov rax, &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;rcx+0x08&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.138&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.138&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; Stacktrace: &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;2023-06-07 06:00:49.169&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; [&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt;   #0 at pc 0x7FF7CCAA9230 bedrock_server_mod.exe -&gt; BlockEventDispatcherToken::unregister+0x8E&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k8&quot;&gt;......&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/details&gt;  
&lt;p&gt;很明显的看到和BlockEventDispatcherToken有关, 所以显而易见的得去ida里看这个函数的问题&lt;br&gt;
但是由于一系列问题,最初是并没有定位到出问题的本质的 &lt;del&gt;(菜)&lt;/del&gt;&lt;/p&gt;
&lt;p&gt;后续,在多次定位后无果,尝试去探寻一下这个的复现方法,于是在调用堆栈里发现这个的调用和BlockBreakSensorComponent有关,而这个又和数据驱动的&lt;a href=&quot;https://learn.microsoft.com/en-us/minecraft/creator/reference/content/entityreference/examples/entitycomponents/minecraftcomponent_block_sensor?view=minecraft-bedrock-stable&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;minecraft:block_sensor&lt;/a&gt;有关.&lt;br&gt;
查阅可知,这个组件和蜜蜂,猪灵的攻击仇恨有关,具体就是蜂箱和金块之类的方块被破坏时,蜜蜂这些拥有该组件的实体会对破坏者产生敌意,并攻击破坏者.&lt;br&gt;
那这个为什么又会导致崩服呢?问题来到了实体上面.&lt;br&gt;
根据经验,这种情况一般是实体销毁导致的问题,于是,笔者便开始了测试,尝试在本地复现该问题.&lt;br&gt;
经过多次测试,发现利用蜂蜜快速死亡+反复生成的情况下,stop可以导致崩服,而且复现概率很高.&lt;/p&gt;
&lt;p&gt;在查阅ida的反汇编后,得到BlockEventDispatcherToken::unregister的逻辑如下:&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;47&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; __fastcall&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; BlockEventDispatcherToken&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;unregister&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;BlockEventDispatcherToken&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  unsigned&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // r8d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  _QWORD&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // r9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  __int64&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v4&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // rdx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  __int64&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v5&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // rcx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  __int64&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // rax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  __int64&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v7&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // rcx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  unsigned&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; int&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v8&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k5&quot;&gt; // [rsp+20h] [rbp-18h] BYREF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v3 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)*((&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v8 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v4 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v5 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;__int64 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                 +&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 16&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                 *&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ((&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0x100000001B3i64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                   *&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (((&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 24&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ^&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0x100000001B3i64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                                                    *&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;BYTE2&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ^&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0x100000001B3i64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                                                                  *&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ((&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0x100000001B3i64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;                                                                    *&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ((&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unsigned&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; __int8&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;^&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0xCBF29CE484222325ui64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ^&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt; BYTE1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)))))))&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v5&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v4 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    goto&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt; LABEL_7&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;  v7 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v5&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 16&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    while&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v7 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;      v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_QWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 8&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;      if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v1 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 16&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;        goto&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt; LABEL_8&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;LABEL_7:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt; 0i64&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;LABEL_8:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; !&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;    v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v4 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;_Hash&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;_Umap_traits&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unique_ptr&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;ListenerInfo&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;_Uhash_compare&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;equal_to&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;allocator&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; const&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unique_ptr&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;ListenerInfo&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;&gt;,&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;_Erase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;      v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;      &amp;#x26;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;v8&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  *(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;_DWORD &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;*)&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;而问题出现在&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;1&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;v6 &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; v3&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;于是,很显然,这与v3有关&lt;/p&gt;
&lt;h3 id=&quot;修复&quot;&gt;修复&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/#修复&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;在恢复了BlockEventDispatcherToken的结构后,发现其拥有两个成员&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;4&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; BlockEventDispatcherToken&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  ListenerHandle&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  BlockEventDispatcher&lt;/span&gt;&lt;span class=&quot;k4&quot;&gt; *&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;而BlockEventDispatcher也有一个成员&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;3&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; BlockEventDispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;  std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unordered_map&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; std&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;unique_ptr&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;ListenerInfo&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;很明显,从v3上分析,崩服问题和umap逃不了关系.&lt;br&gt;
于是,在unregister伪代码的研究下,我们得到了正常情况下,BlockEventDispatcherToken::unregister的大致逻辑&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;8&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:1ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; BlockEventDispatcherToken&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;unregister&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; !=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; it &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt; this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;it &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt; this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;ka&quot;&gt;        this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;erase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;ka&quot;&gt;    this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;于是,我们大致知道了问题的所在,便可以着手修复工作了.&lt;/p&gt;
&lt;p&gt;由于该问题的特殊性,引起该问题的本身就是内存回收和销毁的问题,而笔者并没有权限对源码进行阅读和查看,基于Windows平台本身在线程死亡后,便会自行清理,于是该问题的最容易解决的方案也就很明显了.&lt;br&gt;
笔者采用了直接对BlockEventDispatcherToken::unregister进行hook,自行实现了上面的伪代码中的清理部分的功能, 并且为了方便和稳定,在关服状态下便不主动对listeners进行回收,防止因为关服回收内存时候dispatcher出现问题.&lt;/p&gt;
&lt;div class=&quot;kit-code&quot; data-lang=&quot;cpp&quot; data-lines=&quot;15&quot; data-linenos=&quot;&quot; style=&quot;--kit-gutter:2ch&quot;&gt;&lt;div class=&quot;kit-code-head&quot;&gt;&lt;span class=&quot;kit-code-title&quot; data-kit-code-title=&quot;&quot;&gt;C++&lt;/span&gt;&lt;button type=&quot;button&quot; class=&quot;kit-code-copy&quot; data-kit-copy=&quot;&quot; aria-label=&quot;复制代码&quot; title=&quot;复制代码&quot; data-copied-label=&quot;已复制&quot;&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-copy&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h9v1H5zM5 3h1v1H5zM13 3h1v7h-1zM2 4h9v1H2zM2 5h1v8H2zM10 5h1v8h-1zM4 6h5v1H4zM4 8h4v1H4zM11 9h3v1h-3zM4 10h5v1H4zM2 12h9v1H2z&quot;/&gt;&lt;/svg&gt;&lt;svg class=&quot;kit-pixel-icon kit-icon-done&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M12 3h2v1h-2zM11 4h3v1h-3zM10 5h3v1h-3zM9 6h3v1H9zM2 7h2v1H2zM8 7h3v1H8zM2 8h3v1H2zM7 8h3v1H7zM3 9h6v1H3zM4 10h4v1H4zM5 11h2v1H5z&quot;/&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt;&lt;pre class=&quot;shiki kit-shiki&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k8&quot;&gt;TInstanceHook&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;?unregister@BlockEventDispatcherToken@@QEAAXXZ&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;BlockEventDispatcherToken&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;  if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; !=&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;ll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;globalRuntimeConfig&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;serverStatus&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; ==&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt; ll&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k9&quot;&gt;LLServerStatus&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;Stopping&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k1&quot;&gt;      logger&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k6&quot;&gt;&quot;BlockEventDispatcherToken::unregister ignore unregister when server stopping&quot;&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;ka&quot;&gt;      this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;      return&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k9&quot;&gt;    auto&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt; it &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt; this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    if&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;it &lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;ka&quot;&gt; this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;ka&quot;&gt;        this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;dispatcher&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;listeners&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k8&quot;&gt;erase&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k1&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;ka&quot;&gt;    this&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;k7&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt; -&lt;/span&gt;&lt;span class=&quot;k3&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k4&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;k2&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;k2&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;总结&quot;&gt;总结&lt;a class=&quot;kit-anchor&quot; href=&quot;https://levimc.org/blog/2023/07/26/original-fix-BeeCrash/#总结&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;&gt;&lt;svg viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot; height=&quot;16&quot; shape-rendering=&quot;crispEdges&quot; aria-hidden=&quot;true&quot; fill=&quot;currentColor&quot;&gt;&lt;path d=&quot;M5 2h2v2h3V2h2v2h2v2h-2v3h2v2h-2v2h-2v-2H7v2H5v-2H3V9h2V6H3V4h2zm2 4v3h3V6z&quot;/&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;该问题的出现和修复其实并没有那么快速,前期因为经验不足而走错了方向.&lt;br&gt;
但是,该问题的出现也让笔者对BDS的内存管理方面有了更深的认识,也算是有点收获了.&lt;/p&gt;</content>
  </entry>
</feed>
