<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Polymorphic</title>
    <subtitle>Security research, compilers, games, and other things I find interesting.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://polymorphi.cc/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://polymorphi.cc"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-09-19T12:13:38+05:30</updated>
    <id>https://polymorphi.cc/atom.xml</id>
    <entry xml:lang="en">
        <title>Deobfuscating Arxan in Elden Ring</title>
        <published>2026-09-19T12:13:38+05:30</published>
        <updated>2026-09-19T12:13:38+05:30</updated>
        
        <author>
          <name>
            
              teabound
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://polymorphi.cc/blog/arxan-deobfuscation/"/>
        <id>https://polymorphi.cc/blog/arxan-deobfuscation/</id>
        
        <content type="html" xml:base="https://polymorphi.cc/blog/arxan-deobfuscation/">&lt;h1 id=&quot;introduction&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#introduction&quot; aria-label=&quot;Anchor link for: introduction&quot;&gt;Introduction&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;Maybe you, like me, wanted to debug a game that was &lt;em&gt;(without knowing)&lt;&#x2F;em&gt; protected by &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Arxan_Technologies&quot;&gt;Arxan&lt;&#x2F;a&gt; a commercial anti-tamper suite. So naturally, you boot up the game, crack your knuckles, place a breakpoint on an address, and- wait it crashed. Strange, well.. anyways maybe it was a fluke, let&#x27;s try this time with a hardware breakpoint- it crashed again. Ok, fine, let&#x27;s see what&#x27;s going on.&lt;&#x2F;p&gt;
&lt;p&gt;And quickly as an aside: your configuration of Arxan could be different in some ways depending on the game.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;decrypting&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#decrypting&quot; aria-label=&quot;Anchor link for: decrypting&quot;&gt;Decrypting&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;Okay, so one thing we noticed is that we crash when we place a hardware breakpoint. Thanks to &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;momo5502.com&#x2F;posts&#x2F;2022-11-17-reverse-engineering-integrity-checks-in-black-ops-3&#x2F;&quot;&gt;Momo&lt;&#x2F;a&gt; we have an idea of how we should attack this. Can we just set breakpoint on &lt;code&gt;GetThreadContext&lt;&#x2F;code&gt;? Yeah, works like a charm. We continue until the function returns. This seems like a good point to stop and load this up into IDA to see how this anti-debug routine works. We load it into IDA, rebase, go to the return address, and wait?.. it&#x27;s just a bunch of random bytes.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA7F2  dd 7FA51FC9h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA7F6  db 71h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA7F7  db 0E4h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA7F8  dq 9A4230B6ADF4714Ah&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA800  db 95h, 0F2h, 30h, 0D2h, 89h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA805  dq 2FA49E50931EEE54h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.text:00007FF75B7EA80D  db 38h, 0D3h, 10h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Yeah, so part of Arxan&#x27;s suite is the ability to keep some functions encrypted while they&#x27;re not in use, but once invoked will decrypt then re-encrypt afterwards, so even if you dumped the game at runtime these protected functions will still be encrypted. Unfortunately before we can actually get to the deobfuscation part, we&#x27;ll need to decrypt these routines. I&#x27;ll show the process briefly, but this has been extensively documented in the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;me3.help&#x2F;en&#x2F;latest&#x2F;blog&#x2F;posts&#x2F;arxan-reversing-1&#x2F;&quot;&gt;me3 blog&lt;&#x2F;a&gt;, which resulted in &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tremwil&#x2F;dearxan&quot;&gt;dearxan&lt;&#x2F;a&gt;. So, let&#x27;s do that, but before we start: Arxan has &#x27;hooked&#x27; the &lt;code&gt;__security_init_cookie&lt;&#x2F;code&gt; procedure that is ran immediately after the entry point so that it runs some code that makes the &lt;code&gt;.text&lt;&#x2F;code&gt; section RWX among other things.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;stubs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#stubs&quot; aria-label=&quot;Anchor link for: stubs&quot;&gt;Stubs&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;When Arxan obfuscates a routine it creates its own stub that saves the context onto the stack and makes sure the stack is aligned, it looks like this (without obfuscation):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;52                            push    rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 51                         push    r9&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 50                         push    r8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 52                         push    r10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;51                            push    rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50                            push    rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;53                            push    rbx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 53                         push    r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 A0                lea     rsp, [rsp-60h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 1C 24                movupd  [rsp+0A0h+var_A0], xmm3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 54 24 10             movupd  [rsp+0A0h+var_90], xmm2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 4C 24 20             movupd  [rsp+0A0h+var_80], xmm1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 44 24 30             movupd  [rsp+0A0h+var_70], xmm0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 64 24 40             movupd  [rsp+0A0h+var_60], xmm4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 6C 24 50             movupd  [rsp+0A0h+var_50], xmm5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;6A 10                         push    10h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 F7 C4 0F 00 00 00          test    rsp, 0Fh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0F 85 BE DB 3C FE             jnz     loc_7FF756096EE4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;E9 8A 49 3C FE                jmp     loc_7FF75608DCB5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;loc_7FF75608DCB5:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;6A 18                         push    18h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;E9 28 92 00 00                jmp     loc_7FF756096EE4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then it proceeds to call into the actual target routine, and of course when that routine returns it restores the registers and continues. This is important to note because, again, all obfuscated functions are called from a stub, and having the entry point of the obfuscated function is necessary for deobfuscation, more on that in the next section. Nevertheless, to decrypt protected functions we need to find specific stubs that &lt;em&gt;lead to&lt;&#x2F;em&gt; the decryption of those functions. In essence the steps to finding those functions are: find every stub, we can look for &lt;code&gt;test rsp, 0Fh&lt;&#x2F;code&gt;, which works for both obfuscated and unobfuscated stubs, then emulate the stub, then pattern match, once matched log where and what it&#x27;s decrypting, profit.&lt;&#x2F;p&gt;
&lt;p&gt;With that being said, by using a modified version of their &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tremwil&#x2F;dearxan&quot;&gt;library&lt;&#x2F;a&gt; translated to python, I&#x27;m able to decrypt &lt;em&gt;most&lt;&#x2F;em&gt; of the binary statically in IDA, which is important for our next step. Alternatively you can try &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;colaaaaaa123&#x2F;arxan-static-patcher&quot;&gt;arxan-static-patcher&lt;&#x2F;a&gt; out. While I haven&#x27;t tried it personally it&#x27;s a wrapper over dearxan and should accomplish our goals.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;deobfuscation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deobfuscation&quot; aria-label=&quot;Anchor link for: deobfuscation&quot;&gt;Deobfuscation&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;Alright, now equipped with a decrypted binary, let&#x27;s talk about how it&#x27;s obfuscated. Now, we can go back to the return address of the &lt;code&gt;GetThreadContext&lt;&#x2F;code&gt; call, but that would be in the middle of the obfuscated routine, and like I mentioned earlier we can&#x27;t actually recover the full routine from a random starting point in the function, I&#x27;ll explain further in a second. Another thing to note is that if you actually go to the address in IDA you&#x27;ll notice that it&#x27;s just a single basic block, and.. uh.. where is the call to &lt;code&gt;GetThreadContext&lt;&#x2F;code&gt; exactly?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;returned_after_getthreadcontext proc near&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;var_18= qword ptr -18h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;var_10= qword ptr -10h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;var_8= qword ptr -8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rax, [rbp+48h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;test    rax, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     [rsp+var_8], rsi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rsi, offset sub_7FF75B839E83&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;xchg    rsi, [rsp+8+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     [rsp+8+var_10], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     [rsp+10h+var_18], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rax, [rsp+18h+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rcx, offset sub_7FF75B19490A&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cmovnz  rax, rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     [rsp+18h+var_8], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rcx, [rsp+10h+var_18]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mov     rax, [rsp+8+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jmp     [rsp+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So to figure out what&#x27;s going on here let&#x27;s begin from the start of the stub that calls into this routine. We can do this by cross-referencing &lt;code&gt;returned_after_getthreadcontext&lt;&#x2F;code&gt; and its referrer, and cross referencing the referrer&#x27;s referrer, so on and so forth until we get to the stub, you can, of course, automate this with a script and have it print the path. Now that we&#x27;re here let&#x27;s actually go inside of the call to the obfuscated routine and talk about how we can start recovering the original CFG.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;recovering-the-cfg&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#recovering-the-cfg&quot; aria-label=&quot;Anchor link for: recovering-the-cfg&quot;&gt;Recovering the CFG&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;So the way that Arxan works is that, it will obfuscate the instructions in every basic block of a routine, and its control flow. The basic blocks of said routine are scattered throughout the binary. Because of this, the initial appearance of a seemingly normal block of code looks like a procedure to IDA, and will erroneously auto-analyze as one. Now let&#x27;s start with the first block of the routine and figure out how we can find its successor. When it comes to obfuscated stubs it&#x27;s important to realize that they don&#x27;t start off with the context saving, they start off with a few initial blocks first. This in combination with the fact that all basic blocks are scattered is the reason why we need to start from the top of the stub in order to recover the whole function. So let&#x27;s look at the first block see how we can get the successor and then I&#x27;ll explain what&#x27;s going on.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 54 24 F8                mov     [rsp+var_8], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 15 7B B0 6F FB          lea     rdx, loc_7FF7568869A6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 F8                mov     [rsp+8+var_10], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 08                mov     rax, [rsp+10h+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 54 24 08                mov     [rsp+10h+var_8], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 C2                      mov     rdx, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 04 24                   mov     rax, [rsp+10h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 53                         push    r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 8D 1D DD A8 59 00          lea     r11, sub_7FF75B726231&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50                            push    rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 08                mov     rax, [rsp+18h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 5C 24 08                mov     [rsp+18h+var_10], r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 89 C3                      mov     r11, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;58                            pop     rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;C3                            retn&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So this is the first block in the stub. Let&#x27;s trace through the instructions&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 54 24 F8                mov     [rsp+var_8], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 15 7B B0 6F FB          lea     rdx, loc_7FF7568869A6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 F8                mov     [rsp+8+var_10], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 08                mov     rax, [rsp+10h+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 54 24 08                mov     [rsp+10h+var_8], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 C2                      mov     rdx, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 04 24                   mov     rax, [rsp+10h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;so ultimately all this does, is it carefully uses &lt;code&gt;rdx&lt;&#x2F;code&gt; and &lt;code&gt;rax&lt;&#x2F;code&gt; to put &lt;code&gt;0x7FF7568869A6&lt;&#x2F;code&gt; on the stack, at rsp-8, often this does nothing and is never used, however, sometimes it&#x27;s a continuation address. More on that later.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;41 53                         push    r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 8D 1D DD A8 59 00          lea     r11, sub_7FF75B726231&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50                            push    rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 08                mov     rax, [rsp+18h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 5C 24 08                mov     [rsp+18h+var_10], r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 89 C3                      mov     r11, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;58                            pop     rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;C3                            retn&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, and this is important for us, this actually dispatches to the successor. What this does is the same thing we&#x27;ve seen before, but this time it puts &lt;code&gt;0x7FF75B726231&lt;&#x2F;code&gt; at &lt;code&gt;[rsp]&lt;&#x2F;code&gt; and then returns, popping that successor block into &lt;code&gt;rip&lt;&#x2F;code&gt;. With this knowledge acquired we can now recover unconditional jumps, and we&#x27;ll use the &quot;find the last address in the block&quot; heuristic for the recovery. That&#x27;s the general pattern for unconditional jumps, it does some computation at the start of the block, and at the end of the block it computes the next target using a mechanism like how we just saw. There are some variations too, and some exceptions that we will cover later.&lt;&#x2F;p&gt;
&lt;p&gt;Now we can keep using this method to traverse the graph further down until we meet our first conditional jump &lt;em&gt;(note: generally things aren&#x27;t very eventful until the context save block that you&#x27;re about to see, however, sometimes it will place a continuation address on the stack, more on that later)&lt;&#x2F;em&gt;. Let&#x27;s continue on!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 44 24 F8                mov     [rsp+var_8], r8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 14 24                   mov     [rsp+10h+var_10], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 1C 24                   mov     [rsp+18h+var_18], rbx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 4C 24 F8                mov     [rsp+18h+var_20], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 1C 24                   mov     [rsp+28h+var_28], r11&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 0C 24                   mov     [rsp+30h+var_30], r9&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 F8                mov     [rsp+30h+var_38], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 14 24                   mov     [rsp+40h+var_40], r10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 A0                lea     rsp, [rsp-60h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 1C 24                movupd  [rsp+0A0h+var_A0], xmm3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 44 24 10             movupd  [rsp+0A0h+var_90], xmm0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 4C 24 20             movupd  [rsp+0A0h+var_80], xmm1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 6C 24 30             movupd  [rsp+0A0h+var_70], xmm5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 64 24 40             movupd  [rsp+0A0h+var_60], xmm4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;66 0F 11 54 24 50             movupd  [rsp+0A0h+var_50], xmm2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;6A 10                         push    10h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 F7 C4 0F 00 00 00          test    rsp, 0Fh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 6C 24 F8                mov     [rsp+0A8h+var_B0], r13&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 BD 79 7C 28 56 F7 7F 00 00 mov     r13, offset sub_7FF756287C79&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 87 2C 24                   xchg    r13, [rsp+0B0h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 04 24                   mov     [rsp+0B8h+var_B8], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 0C 24                   mov     [rsp+0C0h+var_C0], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 10                mov     rax, [rsp+0C0h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 B9 54 D9 33 56 F7 7F 00 00 mov     rcx, offset sub_7FF75633D954&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 0F 45 C1                   cmovnz  rax, rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 10                mov     [rsp+0C0h+var_B0], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 0C 24                   mov     rcx, [rsp+0C0h+var_C0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 04 24                   mov     rax, [rsp+0B8h+var_B8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FF 64 24 F8                   jmp     [rsp+0A8h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So finally we get to here, and it should look a little familiar, it&#x27;s the exact same template from before where it saves the cpu context onto the stack, the only difference of course being that this is the obfuscated form. But what we care about is the ending of this block.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 F7 C4 0F 00 00 00          test    rsp, 0Fh&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 6C 24 F8                mov     [rsp+0A8h+var_B0], r13&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 BD 79 7C 28 56 F7 7F 00 00 mov     r13, offset sub_7FF756287C79&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 87 2C 24                   xchg    r13, [rsp+0B0h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 04 24                   mov     [rsp+0B8h+var_B8], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 0C 24                   mov     [rsp+0C0h+var_C0], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 10                mov     rax, [rsp+0C0h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 B9 54 D9 33 56 F7 7F 00 00 mov     rcx, offset sub_7FF75633D954&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 0F 45 C1                   cmovnz  rax, rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 10                mov     [rsp+0C0h+var_B0], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 0C 24                   mov     rcx, [rsp+0C0h+var_C0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 04 24                   mov     rax, [rsp+0B8h+var_B8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FF 64 24 F8                   jmp     [rsp+0A8h+var_B0]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is of course a variation of the obfuscation we&#x27;ve been seeing except this time we have a conditional &lt;code&gt;mov&lt;&#x2F;code&gt;, which is predicated on the &lt;code&gt;test&lt;&#x2F;code&gt; in the first line, notice how nothing inbetween the test and the &lt;code&gt;cmov&lt;&#x2F;code&gt; alter the cpu flags. So we can manually trace and see that it&#x27;s conditionally moving &lt;code&gt;0x7FF756287C79&lt;&#x2F;code&gt; or &lt;code&gt;7FF75633D954&lt;&#x2F;code&gt; into a stack slot , and then it jumps to that target at the end of the block. So the heuristic we use is simply if we have a basic block that has a &lt;code&gt;cmov&lt;&#x2F;code&gt; then we take the last two immediates and set those as the successors.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span&gt; find_possible_targets(instructions):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    out&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; instruction&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; instructions:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; instruction.mnemonic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; (iced.Mnemonic.LEA, iced.Mnemonic.MOV):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; is_rip_relative(instruction,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;                # here we match, for example: lea r12, loc_7FF7582A368C.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span&gt; instruction.mnemonic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; iced.Mnemonic.LEA:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instruction.memory_displacement&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;            # we match, for example: mov rcx, offset sub_7FF75B235B57&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;            elif&lt;&#x2F;span&gt;&lt;span&gt; instruction.op1_kind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; (iced.OpKind.IMMEDIATE64, iced.OpKind.IMMEDIATE32,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                   iced.OpKind.IMMEDIATE32TO64):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instruction.immediate(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;        # we want to make sure that the actually leads to code.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; is_executable(v):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            out.append(v)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; out&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; get_last_cmov_condition(instructions)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; len(candidates)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;	# get the last two candidates from the list of possible targets.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    succs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; remove_duplicates([candidates[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;], candidates[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;]])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The final thing we have to look out for is a call to a function. Let&#x27;s continue until we find the call to &lt;code&gt;GetCurrentThread&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;C7 45 30 10 00 10 00          mov     dword ptr [rbp+30h], 100010h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 05 50 A0 C4 FF          mov     rax, cs:GetCurrentThread&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 2C 24                   mov     [rsp+8+var_8], r13&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 8D 2D D2 E6 66 00          lea     r13, sub_7FF75B520C86&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FF 34 24                      push    [rsp+8+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 6C 24 08                mov     [rsp+10h+var_8], r13&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 8B 2C 24                   mov     r13, [rsp+10h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50                            push    rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;C3                            retn&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now this is the general template for all calls to functions. This is the usual push-ret thing that we&#x27;ve seen before, except the minor difference with this one being that it pushes the return address first and then the address of the target function. Where &lt;code&gt;rax&lt;&#x2F;code&gt; contains the successor which is the target function &lt;em&gt;and&lt;&#x2F;em&gt; the return address, &lt;code&gt;0x7FF75B520C86&lt;&#x2F;code&gt;, which is placed right below it. Naturally when the called function returns from execution it will pop the return address placed here into &lt;code&gt;rip&lt;&#x2F;code&gt;. So our heuristic for this is we look for a &lt;code&gt;push &amp;lt;register&amp;gt;&lt;&#x2F;code&gt; followed by a &lt;code&gt;ret&lt;&#x2F;code&gt; if we find that we look what was last moved into the pushed register for the successor, and we just look for the last immediate for the return address.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span&gt; recover_call(instructions):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; len(instructions)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    term&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instructions[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    # the block always ends with a ret.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; term.flow_control&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; iced.FlowControl.RETURN:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    prev&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instructions[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    # the penultimate instruction always, at least as far as I&amp;#39;m aware, is a push.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; prev.mnemonic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; iced.Mnemonic.PUSH&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; or&lt;&#x2F;span&gt;&lt;span&gt; prev.op0_kind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; iced.OpKind.REGISTER:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    # save the register that holds the call target.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    push_reg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; prev.op0_register&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    call_target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return_address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; instruction&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; instructions:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;        # grab the instruction that moves the call target into the pushed register.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; instruction.mnemonic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; iced.Mnemonic.MOV&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; instruction.op0_kind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; iced.OpKind.REGISTER&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; instruction.op0_register&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; push_reg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; is_rip_relative(instruction,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            slot&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instruction.memory_displacement&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; is_iat_slot(slot):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                call_target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; slot         &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;            else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;                # sometimes it&amp;#39;s a pointer to the function.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                ptr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; ida_bytes.get_qword(slot)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;                if&lt;&#x2F;span&gt;&lt;span&gt; is_executable(ptr):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    call_target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; ptr&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;                elif&lt;&#x2F;span&gt;&lt;span&gt; is_executable(slot):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                    call_target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; slot&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;        # grab the instruction that moves the return address into a register.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; instruction.mnemonic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; iced.Mnemonic.LEA&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; is_rip_relative(instruction,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            pret&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; instruction.memory_displacement&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; is_executable(pret):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                return_address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; pret&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; call_target&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span&gt; return_address:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; (call_target, return_address)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; None&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and also something to mention is because of the way Arxan obfuscates code it doesn&#x27;t really have a normal fall-through edge, so when we represent basic blocks we don&#x27;t stop collecting instructions for a block if the branching instruction is a conditional jump, we do it when it&#x27;s an unconditional jump or a ret, etc.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jnz &amp;lt;addr&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;jmp &amp;lt;addr&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;for example.&lt;&#x2F;p&gt;
&lt;p&gt;Now that we understand the gist of how Arxan calculates successor blocks (there is still something we need to touch on soon), let&#x27;s actually try to write a script that will recover the CFG of the function.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot;&gt;First attempt&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;What I tried at first was to use IDA&#x27;s microcode to figure out what the possible successors were. Let me show you the idea with a conditional block. So take this block for example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 45 48                   mov     rax, [rbp+48h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 85 C0                      test    rax, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 24 24                   mov     [rsp+8+var_8], r12&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 BC 93 72 85 5B F7 7F 00 00 mov     r12, offset sub_7FF75B857293&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 44 24 F8                mov     [rsp+8+var_10], rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 44 24 08                mov     rax, [rsp+10h+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4C 89 64 24 08                mov     [rsp+10h+var_8], r12&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;49 89 C4                      mov     r12, rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 04 24                   mov     rax, [rsp+10h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 0C 24                   mov     [rsp+10h+var_10], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 F8                lea     rsp, [rsp-8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 14 24                   mov     [rsp+18h+var_18], rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 4C 24 10                mov     rcx, [rsp+18h+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 BA 3F 87 65 5B F7 7F 00 00 mov     rdx, offset sub_7FF75B65873F&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 0F 45 CA                   cmovnz  rcx, rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 89 4C 24 10                mov     [rsp+18h+var_8], rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 14 24                   mov     rdx, [rsp+18h+var_18]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8B 0C 24                   mov     rcx, [rsp+10h+var_10]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;48 8D 64 24 08                lea     rsp, [rsp+8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FF 64 24 F8                   jmp     [rsp+var_8]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;alright, cool. Now, let&#x27;s look at the microcode (MMAT_LVARS):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1.BLT_2WAY&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1. 1 7FF75AFD34F4  mov    &amp;amp;($sub_7FF75B857293{1}).8, rcx1.8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2. 2 7FF75AFD3503  jz     [ss.2{2}:(rbp0.8+#0x48.8){3}].8, #0.8, @3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2.BLT_1WAY                              &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2. 1 7FF75AFD3503  mov    &amp;amp;($sub_7FF75B65873F).8, rcx1.8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;3.BLT_1WAY                        &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;3. 1 7FF75AFD3523  mov    icall cs.2,rcx1.8&amp;lt;fast:_QWORD rcx0.8,_QWORD rdx0.8&amp;gt; =&amp;gt; __int64 .8, result.8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;it&#x27;s way easier to see what&#x27;s going on here, and on top &lt;em&gt;now&lt;&#x2F;em&gt; we  have 3 blocks in the graph. So if we go to the last block here, and we see what register we&#x27;re calling, we can know what value that register will be depending on which block we came from. This works pretty well, but unfortunately Arxan does many things that will just break the decompiler, or make it so that there are too many variations in the microcode to generically handle this, by using &lt;code&gt;xchg&lt;&#x2F;code&gt;s instead for example, etc. I even tried using different maturities of the microcode for different things, depending on the block, but it was all just too finicky. Man, if only there were another way that was even simpler...&lt;&#x2F;p&gt;
&lt;h2 id=&quot;solution&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#solution&quot; aria-label=&quot;Anchor link for: solution&quot;&gt;Solution&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;I mentioned shortly what I do when describing the obfuscation, and yeah, for most blocks we just use simple heuristics and it seems to work fine. there are cases where they don&#x27;t work though, for example if we only use our simple heuristics we can build the CFG all the way up until this point, for example:
&lt;img src=&quot;&#x2F;images&#x2F;deobfuscating_arxan&#x2F;incomplete.png&quot; alt=&quot;incomplete&quot; &#x2F;&gt;
In this last block there&#x27;s nothing left to glean. That&#x27;s of course because the jump target was placed on the stack further up the CFG:
&lt;img src=&quot;&#x2F;images&#x2F;deobfuscating_arxan&#x2F;resolved.png&quot; alt=&quot;resolved&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;According to our simple static heuristics there&#x27;s nothing we can do here, we&#x27;re going to need more. There&#x27;re quite a few ways to solve this, e.g. using something sophisticated like &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;2603.18355&quot;&gt;Pushan&lt;&#x2F;a&gt;&#x27;s CFG recovery method, or what have you. But for us simply emulating from the entry point to the &quot;unresolved&quot; block, executing its terminator and seeing where RIP is does the trick.&lt;&#x2F;p&gt;
&lt;p&gt;Now, once we combine both these together, we have decently quick and complete CFG recovery.
&lt;img src=&quot;&#x2F;images&#x2F;deobfuscating_arxan&#x2F;full_cfg.png&quot; alt=&quot;full_cfg&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Awesome, and with this alone we can achieve a pretty legible decompilation, so long as we of course fix the terminators of each block to be direct targets, and add &lt;code&gt;call&lt;&#x2F;code&gt; instructions to the &#x27;call&#x27; blocks. Here&#x27;s an example from the decompilation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;&#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v13 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; __readeflags();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ( (v13 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;NtCurrentPeb()-&amp;gt;BeingDebugged ) &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	v22.ContextFlags&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100010&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    CurrentThread &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; GetCurrentThread();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    GetThreadContext(CurrentThread,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;v22);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v22.Dr0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;v22.Dr1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;v22.Dr2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;v22.Dr3 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;        &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Though you&#x27;ll notice scattered throughout the decompilation it will have things like:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v36 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a4;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v35 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v34 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B5D458D;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v33 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v6;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v32 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v7;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v31 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a3;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v29[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF7560011F9&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v8 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v30;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v9 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF756037B44;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;variables assigned which are never read, that&#x27;s just because of the same stack nonsense we&#x27;ve seen before where Arxan will put something on to the stack like a continuation address but in order to do this it uses registers which it stores on to the stack, but in order to preserve them it does the whole song and dance of putting them somewhere for a second and then restoring them later.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-stack&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-stack&quot; aria-label=&quot;Anchor link for: the-stack&quot;&gt;The Stack&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Arxan abuses &lt;code&gt;rsp&lt;&#x2F;code&gt; in its obfuscation, like we&#x27;ve seen before &lt;code&gt;rsp&lt;&#x2F;code&gt; is used for various different things like pushing continuation blocks, in some instances fake continuation blocks, frequently changed mid block, etc. From what I&#x27;ve seen variables are pretty much exclusively referenced through &lt;code&gt;rbp&lt;&#x2F;code&gt;, for example when we call a windows function we pass &lt;code&gt;out&lt;&#x2F;code&gt; parameters relative to &lt;code&gt;rbp&lt;&#x2F;code&gt; rather than &lt;code&gt;rsp&lt;&#x2F;code&gt;.
&lt;img src=&quot;&#x2F;images&#x2F;deobfuscating_arxan&#x2F;stack.svg&quot; alt=&quot;diagram&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;case-study-on-some-anti-debug-routines&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#case-study-on-some-anti-debug-routines&quot; aria-label=&quot;Anchor link for: case-study-on-some-anti-debug-routines&quot;&gt;Case study on some anti-debug routines&lt;&#x2F;a&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;Now that we&#x27;ve created our deobfuscator we can finally investigate what we set out to: let&#x27;s see what made us crash, then we&#x27;ll go over a couple other detections.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;__fastcall func1(__int64 a1, __int64 a2))()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v2;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rbp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v3;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rdi&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v4;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; r10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;result)();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int16 v6;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; kr00_2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v7;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rbp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  bool&lt;&#x2F;span&gt;&lt;span&gt; v8;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; zf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v9;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  bool&lt;&#x2F;span&gt;&lt;span&gt; not_being_debugged;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; zf&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  DWORD64 P1Home;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  int&lt;&#x2F;span&gt;&lt;span&gt; v12;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; ecx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  int&lt;&#x2F;span&gt;&lt;span&gt; v13;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; eax&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;v14)();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v15;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rdx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v16;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rcx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;v17)();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-598h] [rbp-BA8h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  struct&lt;&#x2F;span&gt;&lt;span&gt; _CONTEXT thread_context;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-560h] [rbp-B70h] BYREF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  char *&lt;&#x2F;span&gt;&lt;span&gt;v19;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-88h] [rbp-698h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  _QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;v20;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-80h] [rbp-690h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  HANDLE CurrentThread;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-78h] [rbp-688h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  BOOL v22;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-6Ch] [rbp-67Ch]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v23;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-60h] [rbp-670h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v24;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-58h] [rbp-668h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;v25)();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-50h] [rbp-660h] BYREF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  _QWORD v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;19&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp-48h] [rbp-658h] BYREF&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v27;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+50h] [rbp-5C0h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;v28)();&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+58h] [rbp-5B8h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v29;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+60h] [rbp-5B0h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v30;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+68h] [rbp-5A8h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v31;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+80h] [rbp-590h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  __int64 v32;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+5E8h] [rbp-28h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v27 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v4;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v28 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75BAD9EF6;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;18&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;loc_7FF758176924;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  result &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B4761E9;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;17&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;16&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;loc_7FF756D81948;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;15&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B46A729;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;14&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B4761E9;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;13&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a2;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;11&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; v3;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;12&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B4E30DB;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  v25 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B4E30DB;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span&gt; ( ((&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned&lt;&#x2F;span&gt;&lt;span&gt; __int64)v26 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;F&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v24 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; a1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v23 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v2;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v25 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;sub_7FF75ACA9F5D;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v19 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;char *&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF75B895D6E &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;- *&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int *&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF75604B848;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v17 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; sub_7FF75B895D6E;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v22 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v20 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;v26[(v26[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 24&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v20[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;23&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = *&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF756781EE8;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; check trap flag.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v6 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; __readeflags();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ( (v6 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      goto&lt;&#x2F;span&gt;&lt;span&gt; LABEL_3;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    not_being_debugged &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; NtCurrentPeb()-&amp;gt;BeingDebugged&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    P1Home &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; thread_context.P1Home;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;not_being_debugged )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      P1Home &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF75B19490A&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    thread_context.P1Home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; P1Home;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;not_being_debugged&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      ||&lt;&#x2F;span&gt;&lt;span&gt; (thread_context.ContextFlags&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100010&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          CurrentThread &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; GetCurrentThread(),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          GetThreadContext(CurrentThread,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;thread_context),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          LODWORD(v17)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; v12,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          thread_context.Dr0)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      ||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      ||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      ||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      ||&lt;&#x2F;span&gt;&lt;span&gt; (v20[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;22&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = *&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF756200098, (NtCurrentPeb()-&amp;gt;NtGlobalFlag&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;70&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; == 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;70&lt;&#x2F;span&gt;&lt;span&gt;) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;LABEL_3:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v20[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;22&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = *&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF756200098;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      thread_context.P1Home&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (DWORD64)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;v25;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      report((&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int&lt;&#x2F;span&gt;&lt;span&gt;)v17);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v29;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v29 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1264&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v8 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1264&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v9 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v31;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1264&lt;&#x2F;span&gt;&lt;span&gt;) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        v9 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF756AE7584&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v31 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v9;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v8 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v30 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v9;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    else&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      benign_report(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int *&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF7561297A8);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; (__int64)v28;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      *&lt;&#x2F;span&gt;&lt;span&gt;((_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)v28 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 308&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v13 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1232&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v29 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF75B06AA61&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v28 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v14;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v27 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v15;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v16 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF75B06AA61&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v13 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        v16 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;7FF75B69A753&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      v29 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v16;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; ( v13 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)word_7FF756409A2A &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF755F78F9A;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1248&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL * *&lt;&#x2F;span&gt;&lt;span&gt;(_QWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF7562553B8)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; unk_7FF7564AB10F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  return&lt;&#x2F;span&gt;&lt;span&gt; result;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There is a lot of nonsense like we&#x27;ve mentioned earlier and it&#x27;s possible to clean this up automatically if you lift and optimize™, &lt;em&gt;after&lt;&#x2F;em&gt; we recover the CFG, and do some fixups of course, but for the sake of this article I don&#x27;t believe it&#x27;s necessary. Anyways, manually cleaning it up results in:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;__fastcall func1(__int64 a1, __int64 a2))()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;	&#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; check trap flag.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v6 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; __readeflags();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ( (v6 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      goto&lt;&#x2F;span&gt;&lt;span&gt; LABEL_3;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	not_being_debugged &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; NtCurrentPeb()-&amp;gt;BeingDebugged&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	thread_context.ContextFlags&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; = 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;100010&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	CurrentThread &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; GetCurrentThread(); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	GetThreadContext(CurrentThread,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;thread_context);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;	if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;not_being_debugged &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr0 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr1 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr2 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		||&lt;&#x2F;span&gt;&lt;span&gt; thread_context.Dr3 &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		||&lt;&#x2F;span&gt;&lt;span&gt; (NtCurrentPeb()-&amp;gt;NtGlobalFlag&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp; 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;70&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; == 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;70&lt;&#x2F;span&gt;&lt;span&gt; ) &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;LABEL_3:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;		&#x2F;&#x2F; this will actually report with code 12.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		report((&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int&lt;&#x2F;span&gt;&lt;span&gt;)v17);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	    v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v29;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	    v8 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1264&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;	    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v8 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;	        return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;	else&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;	{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;		&#x2F;&#x2F; this doesn&amp;#39;t do a &amp;quot;real&amp;quot; report, it calls the function with code 8.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		benign_report(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int *&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF7561297A8);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; (__int64)v28;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;		v13 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)(v7 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1232&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;		if&lt;&#x2F;span&gt;&lt;span&gt; ( v13 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;			return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; (__int64 (__fastcall &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)())v32;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;There are a few things we can see immediately. This seems like only really an anti-debug routine, it doesn&#x27;t seem to do anything more than just check if we&#x27;re running a debugger. As for the detections, we can see in this routine they check the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;FLAGS_register&quot;&gt;trap flag&lt;&#x2F;a&gt;, &lt;code&gt;Peb()-&amp;gt;BeingDebugged&lt;&#x2F;code&gt;, &lt;code&gt;Peb()-&amp;gt;NtGlobalFlag&lt;&#x2F;code&gt; which will be &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;unprotect.it&#x2F;technique&#x2F;ntglobalflag&#x2F;&quot;&gt;non-zero&lt;&#x2F;a&gt; if the process was created with a debugger, and if any of the debug registers set (to check for hardware breakpoints). While the routine we&#x27;re looking at here is pretty barebones, the same pattern can be found in other more complex routines.&lt;&#x2F;p&gt;
&lt;p&gt;In another anti-debug routine we can see this, deobfuscated:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;&#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dword_7FF7564D91ED &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;handle &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; AddVectoredExceptionHandler(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;u&lt;&#x2F;span&gt;&lt;span&gt;, sub_7FF75AE050BD);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;CloseHandle((HANDLE)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;DE42345&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;RemoveVectoredExceptionHandler(handle);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;v37 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; RemoveVectoredExceptionHandler(handle);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v37 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&amp;amp; *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)dword_7FF7560947EA &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;!= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;847FEF39&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;	&#x2F;&#x2F; non-detected path.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;report(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;&#x2F;* ... *&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;&#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can see that it registers an exception handler, then immediately closes handle value which will always be invalid (which it must be for this to work), you see normally this would only return a &lt;code&gt;0&lt;&#x2F;code&gt; if the handle is invalid and there&#x27;s no debugger, however, if there&#x27;s a debugger running it will actually invoke the exception handler with the exception code &lt;code&gt;0xC0000008&lt;&#x2F;code&gt;, going to the handler at &lt;code&gt;sub_7FF75AE050BD&lt;&#x2F;code&gt;, which is also obfuscated so here&#x27;s the deobfuscation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;__int64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; __fastcall&lt;&#x2F;span&gt;&lt;span&gt; handler(_EXCEPTION_POINTERS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;a1)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  void *&lt;&#x2F;span&gt;&lt;span&gt;v1;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; rbp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  _UNKNOWN &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;retaddr;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt; &#x2F;&#x2F; [rsp+38h] [rbp+0h]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  retaddr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; v1;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span&gt; ( a1-&amp;gt;ContextRecord-&amp;gt;Dr0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; a1-&amp;gt;ContextRecord-&amp;gt;Dr1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; a1-&amp;gt;ContextRecord-&amp;gt;Dr2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; a1-&amp;gt;ContextRecord-&amp;gt;Dr3 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dword_7FF7564D91ED &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;B8F243D7&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;FFFFFFFF&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  else if&lt;&#x2F;span&gt;&lt;span&gt; ( a1-&amp;gt;ExceptionRecord-&amp;gt;ExceptionCode&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; == 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;C0000008&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dword_7FF7564D91ED &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;B8F243D7&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;FFFFFFFF&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;LL&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  else&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Aha! Okay now if we go back to the routine that sets the handler:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v37 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&amp;amp; *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)dword_7FF7560947EA &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;!= 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;847FEF39&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The decompilation for this is a little misleading, really it&#x27;s just comparing the values of two dwords together, &lt;code&gt;dword_7FF7560947EA&lt;&#x2F;code&gt; and &lt;code&gt;dword_7FF7564D91ED&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;8B 05 88 5B 7D FA             mov     eax, cs:dword_7FF7564D91ED&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;8B 15 7F 11 39 FA             mov     edx, dword ptr cs:dword_7FF7560947EA&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;3B C2                         cmp     eax, edx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The thing is, is that &lt;code&gt;dword_7FF7560947EA&lt;&#x2F;code&gt; is set to &lt;code&gt;0xB8F243D7&lt;&#x2F;code&gt; by default and &lt;code&gt;dword_7FF7564D91ED&lt;&#x2F;code&gt; is set to &lt;code&gt;0x847FEF39&lt;&#x2F;code&gt; by default (which is why IDA shows that value in the decompilation) but is set to 0 earlier on in the function. We can see that if it goes through the handler it will set &lt;code&gt;dword_7FF7564D91ED&lt;&#x2F;code&gt; to the same value making the predicate return false and continuing down the detected path.&lt;&#x2F;p&gt;
&lt;p&gt;And, for fun let&#x27;s go over one more:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  memset(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;heap_entry,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; sizeof&lt;&#x2F;span&gt;&lt;span&gt;(heap_entry));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ProcessHeap &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; GetProcessHeap();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  handle &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; ProcessHeap;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  if&lt;&#x2F;span&gt;&lt;span&gt; ( HeapLock(ProcessHeap) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;HeapWalk(handle,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;heap_entry) )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        HeapUnlock(handle);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        goto&lt;&#x2F;span&gt;&lt;span&gt; exit;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; ( heap_entry.wFlags&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;        break&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    v16 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; HeapUnlock(handle);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; !&lt;&#x2F;span&gt;&lt;span&gt;v16 )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      goto&lt;&#x2F;span&gt;&lt;span&gt; exit;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)((&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;char *&lt;&#x2F;span&gt;&lt;span&gt;)heap_entry.lpData&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; heap_entry.cbData)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; == 0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;ABABABAB&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;      goto&lt;&#x2F;span&gt;&lt;span&gt; detected;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;	&#x2F;&#x2F; remember, not an actual &amp;quot;real&amp;quot; report.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    benign_report(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;unsigned int *&lt;&#x2F;span&gt;&lt;span&gt;)sub_7FF756793758);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;exit:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  *&lt;&#x2F;span&gt;&lt;span&gt;(_DWORD &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;)v9 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;  return&lt;&#x2F;span&gt;&lt;span&gt; v9;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is another &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;anti-debug.checkpoint.com&#x2F;techniques&#x2F;debug-flags.html&quot;&gt;classic&lt;&#x2F;a&gt; anti-debug check.&lt;&#x2F;p&gt;
&lt;p&gt;One more thing to note is that a lot of these checks from as far as I can trace back seem to be on a timer, set with a random interval, one example:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #DDE6CC; background-color: #111111;&quot;&gt;&lt;code data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;float *&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;timer &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;lt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 0.0&lt;&#x2F;span&gt;&lt;span&gt; )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    decrypt_stuff(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;v6);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    anti_debug_check_stuff();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #4A5E42;font-style: italic;&quot;&gt;    &#x2F;&#x2F; ...&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;float *&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;timer &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;= *&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;float *&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;timer &lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; random_range(v5,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt; 30.0&lt;&#x2F;span&gt;&lt;span&gt;, COERCE_DOUBLE(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #72C45E;&quot;&gt;0x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;42700000&lt;&#x2F;span&gt;&lt;span&gt;)).m128_f32[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #C8C0A8;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;];&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h1 id=&quot;conclusion&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#conclusion&quot; aria-label=&quot;Anchor link for: conclusion&quot;&gt;Conclusion&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;The source code for the deobfuscator is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;teabound&#x2F;a8f6383d5572847704c27449e629aade&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Admittedly, the obfuscation itself was a lot more interesting than the anti-debug. There are still other checks that it performs, but the focus really is on the deobfuscation.
Anyways, this is the end of the blog, I hope you enjoyed reading it, because I had a lot of fun on this project. There&#x27;s still a lot more that can be done and I&#x27;m looking forward to improving whatever I can, when I get the chance. If that happens I&#x27;ll be writing a part II! Goodbye!&lt;&#x2F;p&gt;
</content>
        
    </entry>
</feed>
