Arxan is the code protection that ships inside the Call of Duty executables. It does not stop you from reading the game's code. Its job is to notice when that code has been changed, and to make the consequences hard to trace back to the change.
This is an account of taking that system apart in Modern Warfare (2019), and then taking it out, told in the order it happened. It starts with a memory dump and an emulator, because that is what I started with. It ends with ten versions of the game running their start-up side by side with their cleaned twins. In between are the places where I was wrong in a way that says something about the protection: a routine that cannot be skipped, a check that is there to fail, and a cleaned build that passed seven hundred comparisons and would not open its window.
If you want the mechanism before the story, the section after this introduction is the whole protection on one page. The rest of the post covers, in order:
- the 730 routines Arxan adds to the game, and what each kind does;
- how a checksum guard works, instruction by instruction, and what it does when the checksum is wrong, which is not a crash;
- how code is repaired, decrypted and hidden again while the game runs;
- how it looks for a debugger, and what it does not look for;
- one structural weakness, and a way to use it that changes no code at all;
- how the shipped file is encrypted, and how to decrypt it without running it;
- what the protection did to the entry point, and what runs before the game's first instruction;
- what the program still needs from the protection, and what it takes to export an image that runs without it;
- how to know that such an image is right: an emulator used as a measuring instrument, a real start, and what a memory dump can and cannot tell you.
Everything about the running process was established by executing Arxan's own machine code in an emulator. Nothing is inferred from watching the game crash. Everything about the file was then re-implemented from what the emulator showed, and checked byte for byte: against the emulated routines, against memory dumps of the running game, and in the end against a second, a third and a tenth build that none of it had been fitted to.
I have kept the order in which things were found, wrong turns included where they taught me something. Each section says what I looked at, what came back, and what question that raised, because the route is more reusable than the addresses.
Part of the idea came from Maurice Heumann's Reverse Engineering Integrity Checks in Black Ops 3, which follows one of this protection's checksum checks in an older title.
The developed PoC projects are available at IDARETW/MWHook and IDARETW/MWDec for further analysis and experimentation.
Arxan on one page
Before the story, the mechanism, stated flat. Everything in this section is shown later with the listing and the numbers behind it.
What it does to the executable. Arxan runs after the linker. It appends a code section of its own, about 100 MB here, and then treats the game's code as raw material:
- it cuts game functions into pieces, moves many of the pieces into its own section, and joins them with jumps;
- it rewrites branches, calls, returns and stack instructions in a small set of disguised spellings, so that no disassembler follows them;
- it splices 730 small routines of its own into game functions, each reached through an obfuscated call;
- it encrypts both code sections, and leaves everything the Windows loader reads in the clear.
On disk. The file is a valid PE whose code is ciphertext. There is one cipher: XTEA in output-feedback mode, a single keystream XORed over 1.3 million fragments that fit between the relocated pointers. The key, the starting block and the list of fragments are stored in the file in plain bytes.
At start-up. The entry point is the compiler's, with its first call redirected through three routines. The first TLS callback and every exported function carry the same three. They make every section writable and executable, decrypt the code, and copy the import pointers into a second import table that a tenth of the game's call sites still use.
While the game runs. The 730 routines are of four kinds:
- writers (554) overwrite code from encoded copies they carry: some repair bytes that should not have changed, and some produce functions that are stored as noise and exist only while they are needed. Every such function has a second writer that overwrites it with noise again;
- checksum guards (106) hash ranges of code, write the digest into a slot in the code section, and compare it with an expected value. Most of what they hash is the protection itself;
- clocks (52) sample time, and gate how often the guards do their work;
- debugger probes come in a bundle of six, stamped into the image 294 times.
When something is wrong. Nothing crashes where the check is. A guard that fails overwrites its own return address with a value that lands exactly 1 GiB above a real address, or leaves a wrong number in a state word that some unrelated function later adds to its stack pointer. Fifty-three checks elsewhere in the game's code read the values the guards publish, and their failing path computes a return address from a table of wrong ones.
Why it cannot simply be cut out. A routine spliced into a function is not a detour on the way to somewhere. The code around it pushes three plausible addresses, and the routine replaces all three while it runs: the place where the function continues exists only as three writes inside the routine. Skip the routine and the function continues in the middle of some other function. And some checks are placed before the guard that satisfies them, so that the program depends on their failing first.
What it does not have. No bytecode virtual machine. No key derived from the machine or the run. No anti-debugging beyond the six probes, and no code that asks what protection a page has. Everything it knows is a constant in the file, which is what makes the rest of this post possible.
How this is laid out
This article is the whole argument, with the listings and the numbers that carry it. Four more articles in this series, the appendices, hold the long tails: every step, every count, and the cases that went sideways.
| in this article | in full | |
|---|---|---|
| The running process | routines, guards, the failed check, writers, debugger probes, the weakness | here |
| The file on disk | the cipher, the entry point, functions that stay encrypted, strings | Appendix A |
| Taking the protection out | what the program needs, why a routine cannot be skipped, the rewrites | Appendix B |
| Doing it without an emulator | how every table is read from the shipped file alone | Appendix C |
| Checking the result | emulated comparison, a real start, memory dumps, the emulated start | Appendix D |
Scope
The target is an archived build of the game, 1.51.2 from January 2022, studied offline on my own machine. This post covers Arxan only. The game also carries an anti-cheat with an obfuscation of its own; it appears here where the protection touches it, it is left exactly as shipped, and nothing in this post takes it apart. This is not a guide to cheating or to running a game you do not own.
Two limits apply throughout, and I repeat them where they matter. The mitigation at the end of the first part is proven against Arxan's real code in emulation and by a native test of the implementation, and it has been run in real starts of the game, where it corrected a guard that had found five changed bytes; the guards that hash the game's own code did not run in those starts, so for them the proof is still the emulator. The cleaned images of the last part were compared with their protected originals in an emulator, function by function and from the entry point into main, on ten versions of the game; one of them was also started as a real process.
Part 1: The running process
Method: run it where it cannot fight back
I started with what I had, which was a memory dump of the running game. The usual way to study an integrity check is to put a hardware breakpoint on some code and wait for something to read it. That needs a live process, and it shows one check at a time. I did not want one check at a time. I wanted to know what every routine the protection added does, so I took the dump and executed its routines in an emulator.
The dump is a 693 MB snapshot with the code already unpacked. Map it lazily into Unicorn at its recorded base, give it a stack and a fake TEB and PEB, point rip at a routine, and record three things:
- every data read that lands in an executable section;
- every write that does;
- where control ends up.
This works far better than it has any right to. The first guard I tried ran to completion with no hand-built state: 53,178 basic blocks, one loop that read 16,982 bytes of code, three 4-byte writes into the code section, and a clean return.
The reason is in Arxan's design. Each routine computes the image base from its own address, reads its tables out of the code section, and keeps its state in its own stack frame. It has to be self-contained, because it must work no matter which game function it is spliced into. The same property makes every routine runnable in isolation.
Two details matter for repeatable results. Routines that call Windows need small models of the handful of APIs they use. And rdtsc has to be pinned to a chosen value, because some routines branch on the timestamp.
With that in place, an experiment is cheap: run a routine, change one byte, run it again, and compare everything.
730 routines, one calling convention
Arxan's routines are entered through an obfuscated call. It is easy to recognise:
push 0x18 ; how many bytes the return thunk will drop
sub rsp, 8 ; 48 81 EC 08 00 00 00 - a scratch slot, in the long encoding
lea rsp, [rsp-8] ; --+
mov [rsp], rbp ; | push <return thunk>
lea rbp, [rip+R] ; |
xchg [rsp], rbp ; --+
push rbp ; --+
lea rbp, [rip+G] ; | push <routine>
xchg [rsp], rbp ; --+
ret ; "call" G, which returns to R
The return address and the target are both planted on the stack with lea/xchg, so no call instruction and no direct reference to the routine exists. The routine G preserves the non-volatile registers and returns to the thunk R, which restores the saved context.
Where the thunk goes after that is not written in the thunk. Its last transfers go through three stack slots that the routine filled in while it ran. The third holds the address of the code that continues the game function, starting with whatever instruction the splice displaced. Those three slots come back when the protection is taken out, because they decide what it takes to remove a routine.
Chains of these stubs are spliced into game functions. In the case traced end to end below, the function's first five bytes are a jmp into the chain, and its original first instruction sits in the last thunk.
There are 730 stubs in the image, and each calls a different routine. Once one of them ran, I ran all of them and sorted them by what they did. That gives four kinds:
| Kind | Count | What it does |
|---|---|---|
| Writer | 554 | Copies, repairs or decrypts code. More than half write eight bytes or fewer. |
| Checksum guard | 106 | Reads code as data, publishes a digest, compares it with an expected value. |
| Clock | 52 | Samples the system time. |
| Other | 8 | Includes the debugger probes. |
(Three more did not finish inside the instruction budget, and seven faulted on state the emulator does not model.)
Control flow inside every routine is cut into chunks of a few instructions, scattered over a 100 MiB section that Arxan appends to the executable. Chunks are joined by jmp rel32 or by computed transfers:
movabs rbp, <target A> ; planted on the stack
...
movabs rax, <target B>
cmove rbx, rax ; choose between A and B
...
jmp qword ptr [rsp-8]
That last form is a conditional branch. A disassembler sees an indirect jump and stops; an emulator just follows it.
Anatomy of a checksum guard
A guard is an ordinary function with an rbp frame. It does seven things.
1. Find the image
There are no relocations and no imports involved:
mov rax, [rip+...] ; 0x140000000, the link-time image base
mov [rbp+0x28], rax
lea rax, [rip-...] ; my own address, right now
mov rax, [rip+...] ; my own address at link time
neg rax
add rax, [rbp+0x30] ; load delta
add rax, [rbp+0x28] ; runtime base
2. Decode what to hash
The ranges are a LEB128 stream of (gap, length) pairs stored in the code section. Each range starts where the previous one ended, plus the gap. The stream ends when the start reaches 0xFFFFFFFF. For the larger guards the stream is TEA-encrypted with a per-guard key and decrypted first.
The ranges are sparse. The guard above hashes 16,982 bytes in 83 ranges. Many ranges are a single byte, or exactly five bytes (one jmp rel32). The gaps skip everything that legitimately changes while the game runs.
3. Hash the code
This loop is the only place where code is read as data:
movzx eax, byte ptr [rax] ; one byte of code
xor eax, [rbp+0x60]
... ; h = (h ^ b) * 0x01000193
That is FNV-1a with a non-standard seed. Two other hashes are in use:
- a rotate-and-add over dwords (
h += rol(w, r); r = (h ^ r) & 31) with a byte tail; - full SHA-1, with its round constants split across two tables and XORed together at run time.
4. Hash the relocations
A second list names the pointers that lie inside the hashed ranges. Each is read, converted back to its link-time value, and folded into the hash. The digest therefore does not depend on where the image was loaded.
5. Publish the digest
lea rdx, [rip+slot]
mov [rdx+rcx*4], eax ; 89 04 8A
add dword ptr [rbp+0x70], -1
The guard copies its digest, one dword per iteration, into a slot in the code section: a few dead bytes between two chunks. There are 184 of these stores in this image.
Most of these slots are write-only. About one in nine is read back later, by unrelated code, in the form slot + c1 - c2 == 0, where c2 - c1 is the expected digest. The published value is a second opinion, taken far from the guard.
6. Compare
The guard keeps two adjacent pointers in its frame. One points at the digest it just computed, on its stack. The other points at the expected digest, a table of one or five dwords in the code section.
mov rdx, [rbp+0x40] ; computed
mov rbx, [rbp+0x48] ; expected
mov eax, [rdx+rax*4]
mov edx, [rbx+rcx*4]
cmp eax, edx
The comparison reads the stack copy, not the published one. Changing eax at the store in step 5 changes what is published and nothing else.
7. Act
On a match the guard performs one more store, refreshing a state word elsewhere in the code section, and returns to its thunk. What it does on a mismatch gets its own section.
What the guards cover
Only the two executable sections are ever hashed. .rdata, .data and the import table never are.
Coverage is lopsided. Measured over the guards that could be emulated:
| Bytes hashed | Share | |
|---|---|---|
| The game's own code | about 465 KB | 0.4% |
| Arxan's appended section | about 11.3 MB | 10.9% |
The guards mostly guard each other:
- 40 of 105 guard entry points lie inside some other guard's ranges.
- A third of the expected-digest words do.
- A quarter of the publish instructions do, and at least 29 of the 106 guards hash one or more of them. An inline hook on a publish instruction is itself a modification that other guards see.
- About 2 MB is hashed by two or three guards at once.
- No publish slot lies inside any hashed range. Guards do not chain by hashing each other's results.
One more property follows from the next section but belongs here. Run against the dump, 36 of the 106 guards compute a digest that does not match. Every one of them hashes code that the writer routines decrypt just before use and encrypt again afterwards. The dump caught those functions at rest. Such a guard only passes when it runs at the right moment in the sequence: after the writer that prepares its code, and before the one that hides it again.
What a failed check does
This was the experiment I had wanted the emulator for. Take a guard that passes. Flip one bit in one byte it hashes. Run it again and compare the path, the writes, the registers and where it returns.
Inside the hash, nothing changes except the value. The first difference is after the comparison. Of 65 guards tested, 55 respond the same way:
mov eax, [rip+K] ; a constant; for this guard 0x448E92B0
mov eax, eax
add rax, [rbp+0x20] ; + runtime image base
mov rcx, [rbp+0x28]
sub rcx, 8
mov [rcx], rax ; my own return address := base + K
mov eax, 1
The guard overwrites its own return address, skips the state refresh, and returns normally. The fault happens on the ret, in the guard's epilogue, at an address 1 GiB above the image, with a stack that no longer records who called.
Where bit 30 comes from
Crashes caused by this response always have the form valid code address + 0x40000000. It looks like a flag bit. It is not.
K is stored in the code as 0x1_4000_0000 + rva: a link-time virtual address, against the preferred image base. About 3,000 such constants are embedded in the code, with no relocation entry. Truncate one to 32 bits and you get rva + 0x40000000. Add the real runtime base, as the failure path does, and you land exactly 1 GiB above a real address.
No instruction ever sets bit 30. It is what remains of 0x140000000 after a rebase that is done wrong on purpose.
The rva is not the guard's legitimate return address. It is the place in game code where the guard chain was spliced in. In the case I could run end to end, that is the first five bytes of the protected function.
The quieter responses
Not every guard poisons its return.
- Four of the 65 return to their thunk normally and simply skip the state refresh they perform on success.
- A separate failure helper overwrites a state word with a scrambled copy of its correct value:
y = x ^ (x >> 2).
State words are consumed elsewhere. This is one consumer, in a return thunk:
mov edx, [rip+D] ; the state word
add edx, [rip+A]
xor edx, [rip+B]
add rsp, rdx ; zero when D is right
add rsp, [rsp+8]
pop rdx
jmp body
With the right value, (D + A) ^ B is zero and the instruction does nothing. With the scrambled value it is 0x1150787F: the stack pointer moves 277 MiB. The next stack access faults, and the exception cannot be delivered, because there is no stack to build the frame on.
The same word is also tested by a conditional branch somewhere else entirely.
So the check and the penalty are separated in both space and time. The guard that detects a change does not crash. It leaves a wrong number behind, and a different function, later, uses it.
A poisoned return cannot be undone afterwards
My first idea for living with a poisoned return was to treat it as recoverable: catch the execute fault, subtract 0x40000000 from rip, continue. The emulator shows what that does.
One guard protects a function whose entry is still the five-byte jmp into its guard chain. Start at that entry with known registers and a marker for a return address, and see whether execution reaches the function's body.
| Run | Reaches the body |
rsp vs entry |
Registers | Return address |
|---|---|---|---|---|
| Clean | yes | 0 | all preserved | intact |
| One byte flipped | no, faults at entry + 0x40000000
|
−416 |
rax, rcx, rdx clobbered |
gone |
| Flipped, fault redirected to the unbiased address | never | −416 per attempt | clobbered | gone |
| Same, all clocks advanced 10 s per attempt | never | −416 per attempt | clobbered | gone |
The unbiased address is the entry of the protected function, which is the jump into the guard chain. The guard runs again, fails again, and returns to the same poisoned address.
Every attempt leaves 416 bytes of dead frame behind, because the guard never unwound, and the argument registers hold whatever the guard left in them. Advancing every clock the routines can read changes nothing, so this is not a schedule waiting to expire. A 1 MiB stack lasts about 2,520 attempts.
The response is not a detour that can be stepped around. By the time the fault happens, the state needed to continue is already gone.
Writers: repair and decryption
Guards are a seventh of the routines. Three quarters are writers.
They are built around about 340 copies of one small memcpy: a dword loop and a byte tail. The same helper is used three ways.
- Read. Copy code into a stack buffer, eight bytes at a time.
-
Repair. Write a range back to the bytes it should hold. The good bytes come from an encoded copy in the protection's own section, the stash, decoded a dword at a time with a key hidden in filler bytes between instructions. The ranges are another LEB128
(gap, length)stream. - Decrypt. The same operation, pointed at a function that is not yet code.
Fifty-nine game functions are stored unreadable and produced on demand, and so are the entries of a family of much smaller subroutines. The chapter on the file takes that mechanism apart, including the part that is easy to get wrong: a writer never reads what it overwrites.
On disk the picture is starker. All but 235 of the game's 29,329 code pages are noise, and the file has to unpack itself before its first instruction can run. That is where the next chapter starts.
Two facts about how the writes happen matter later:
- One start-up routine walks the image with
VirtualQueryandVirtualProtectand makes every section readable, writable and executable. - After that, no routine changes page protection around its own writes. It just writes.
For anyone placing a hook: ordinary function prologues are not rewritten, but anything inside an on-demand function will be overwritten the next time its writer runs.
Clocks and scheduling
The 52 clock routines read interrupt time and system time straight from KUSER_SHARED_DATA, with no API call.
Guards have scheduling gates in front of their hash loops: counters stored in the code section, and timestamps. A guard does not hash every time it is reached. Presumably this keeps megabytes of hashing from costing a frame. It also means the moment a change is noticed is not the moment it was made.
Debugger probes
Everything Arxan does that looks outward at the process is one bundle of six probes, stamped into the image 294 times:
| Probe | How "no debugger" is established |
|---|---|
PEB.BeingDebugged |
the byte is zero |
NtQueryInformationProcess(ProcessDebugObjectHandle) |
the query fails with "port not set" |
CloseHandle(0x12345) under a vectored handler |
the invalid-handle exception a debugger would cause never arrives |
ud2 under a vectored handler |
the handler runs and steps over it |
int 2Dh under a vectored handler |
the handler runs |
int3 under SetUnhandledExceptionFilter
|
the filter runs, which only happens with no debugger attached |
One instance, run end to end:
- It picks a probe from
rdtsc % 5. It assembles therdtscon the fly, storing90 90 0F 31into the code section and then executing it. - For the query it calls
LoadLibraryA("ntdll.dll")andGetProcAddress(..., "NtQueryInformationProcess"), then frees the library again. Both strings are built on the stack from two XOR pads and wiped after use. They are the only two protected strings in the whole protection. - When the query reports a debug object, the routine answers with the same poisoned return the checksum guards use. There is one response primitive for everything.
The vectored handlers exist only for the duration of a probe: registered first in the chain, removed straight after. They read CONTEXT.Rax and Rip and nothing else. Arming a hardware breakpoint or setting PEB.BeingDebugged changes the outcome of none of the exception probes. They test that exceptions are delivered to the process, not what the debug registers hold.
That has a consequence for tool authors. A first-chance handler that swallows illegal-instruction or breakpoint exceptions breaks these probes, and the probe then reports a debugger that is not there.
What it does not do
Searched for and not found in Arxan's code:
- thread hiding;
-
NtGlobalFlagor heap-flag checks; - timing checks (every
rdtscfeeds a random gate; none is subtracted from another); - debug-register inspection;
- kernel-debugger checks;
- process, window or module enumeration;
- reads of system DLL code;
- direct system calls.
Its whole API vocabulary is nine functions: Add- and RemoveVectoredExceptionHandler, SetUnhandledExceptionFilter, CloseHandle, GetCurrentProcess, LoadLibraryA, GetProcAddress, FreeLibrary and NtQueryInformationProcess. The imported ones are reached with push rax; ret, never with a call.
A weakness: every guard publishes before it judges
By now the options had narrowed. Hooks are code, and code is what the guards hash. The response cannot be undone after the fact. That left the moment in between, and I went back to the guard's seven steps to look for it.
Step 5 happens before step 6. Every guard writes its digest into the code section before it compares. A write is something a process can be notified about without changing any code.

Figure 1. A guard publishes its digest into a code page before it compares. A page fault on that one store is enough to see the guard's frame at the right moment.
Two things make that usable. Sections are made writable once, at start-up. And Arxan's routines cannot notice a change afterwards: nothing in their nine-function vocabulary queries or sets page protection. So take the pages that hold the 184 publish slots (171 pages) and set them back to read-and-execute. Nothing in the image is modified. The next time a guard publishes, the store faults, and the handler sees a live guard frame at exactly the right moment:
-
rcxis the index andeaxis the computed digest word. - Scan the frame for the two adjacent pointers from step 6: one outside the image whose dword at that index equals
eax, followed by one into an executable section. That is the guard's own{computed*, expected*}pair. - If the expected word differs, write it over the computed word on the guard's stack and put it in
eax. - Complete the store by hand, skip the three-byte instruction, and continue.
The guard goes on to compare two equal values. It takes its normal pass path, performs its state refresh, and returns to its thunk. Everything downstream sees a guard that passed, because the guard itself believes it passed.
The correction itself is the obvious one for a checksum guard: replace the computed checksum with the expected one in the guard's own context. What is unusual is the delivery, a page fault instead of a patch. Because no code byte changes, there is nothing for any other guard to notice.
The core of the handler:
if (is_site(rip) && page_protected(destination))
{
const auto index = static_cast<uint32_t>(context.Rcx);
const auto computed = static_cast<uint32_t>(context.Rax);
uint32_t value = computed;
uint32_t* computed_ptr = nullptr;
const uint32_t* expected_ptr = nullptr;
if (find_context(context.Rbp, index, computed, computed_ptr, expected_ptr))
{
const uint32_t expected = expected_ptr[index];
if (expected != computed)
{
computed_ptr[index] = expected; // what the guard is about to compare
context.Rax = expected;
value = expected;
}
}
store_through(destination, &value, 4); // the write the guard asked for
context.Rip = rip + 3; // past mov [rdx+rcx*4], eax
return EXCEPTION_CONTINUE_EXECUTION;
}
Other stores land on those pages too: writer routines, and the guards' own state refreshes. The handler completes plain mov stores from the instruction bytes and lets anything more exotic run once with the page writable.
Proof by emulation
The emulator can model this faithfully, because the handler needs nothing a real one would not have: the instruction bytes at rip, the registers, and readable memory. Pages are write-protected inside Unicorn, the write fault is handed to a Python port of the handler, and the guard's real code runs on either side of it.
For every guard that passes on the dump, four runs from its real call stub: clean, one byte flipped, and both again with the protection armed.
| Guards | |
|---|---|
| Tested | 65 |
| Flipped byte is in code the guard verifies | 59 |
| ...detected with no mitigation | 59 of 59 (55 poisoned return, 4 withheld refresh) |
| ...armed: same outcome as the clean run | 59 of 59 |
| Flipped byte is in the guard's own range table | 3 (the guard decodes garbage and never publishes, armed or not) |
| Flipped byte has no visible effect | 3 |
| Clean code, armed: same outcome as unarmed | 65 of 65 |
"Same outcome" means the same return thunk, the same stack pointer, every general register equal, and every code slot the routine wrote holding the same final value.
The handler corrected one digest word for 40 guards and five for 19 (the SHA-1 family). It never failed to identify the context.
The function-entry experiment from earlier, with the protection armed:
| Run | Reaches the body |
rsp vs entry |
Registers | Handler |
|---|---|---|---|---|
| Clean | yes | 0 | all preserved | digest 0x73008F99 matched |
| One byte flipped | yes | 0 | all preserved |
0x73009799 corrected to 0x73008F99
|
The handler knows no addresses. It finds the publish stores by their instruction bytes, so the same experiment can be put to a build it was never looked at on. In 1.20, a build twenty months older, there are 200 stores of that shape, 166 of them with their slot named by the lea in front, on 168 pages. Ten functions whose path runs through a guard that passes were each run three ways with the protection's routines executing: clean, with one bit flipped in one code byte the guard hashes, and flipped with the correction applied at the store.
| 1.20, ten functions | |
|---|---|
flipped: ends at the function's own entry + 0x40000000
|
10 |
| flipped and corrected: ends where the clean run ends, in the same state | 10 |
The first of them is the function at 0x15A7200. With the byte at 0x14DD8F1 flipped, its guard leaves five digest words wrong and the run ends on a fetch from image + 0x415A7200. With the correction, five words are corrected and the run ends at the instruction the clean one ends at. It is the same poisoned return, with the same missing bit of 0x140000000, in a build from May 2020.
The handler also exists as native code. Its test builds a routine with the guard's exact publish-and-compare shape in a buffer, confirms that the routine detects a wrong digest on its own, then arms the protection and confirms that the routine can no longer tell.
In the running game
Then I put the native handler into a real start of the shipped 1.20, loaded inside the game process before the protection's start-up has run. Its own scan of the running image finds the 200 stores and names all 200 slots: the 34 that have no lea in front of the store are named by the lea that ends the block whose jump lands on it. That makes 200 pages to protect.
The first start ended at 18.6 seconds on a write fault in a byte-copy loop of the protection, one page past a protected one. The start-up pass copies code into the game's pages one byte at a time, and it runs straight across page boundaries. Completing a store at the end of a protected page had left the page after it read-only too, and that page was not one of the 200. The whole image is writable at that point, so the loop's next byte there faulted with nobody to handle it. A protected page has to give every neighbour back exactly the protection it had.
The same copy pass is also what the handler costs. It writes through almost every page that holds a slot. Armed as soon as the stores were decrypted, the handler completed about 700,000 of its single-byte stores before the splash screen, and the game window came up eight seconds late. Armed once the slot pages have stopped changing, which is about two and a half seconds later, it completes about 52,000, and the splash and the window come up when they do without it. In the menus it goes on completing 2,000 to 4,000 unrelated stores a second, which I estimate at about 3% of one core.
The running process also has a moment the dump never showed. From about five seconds into the start, runs of the code pages cannot be read at all, and a scan that reads the sections from end to end faults. So the scan walks only the pages that can be read, and the handler only ever takes write access away: a page the program has made inaccessible is left that way.
The handler logs each store the first time it publishes. Fifty stores first publish after the splash. The emulator had reached 27 of them, and what those guards read says what they hash: every one hashes the protection's own section, one of them a single run of 6.6 MB, and none hashes the game's code. The guards that do hash the game's code, up to 16.4 MB of it, did not run in the menus at all.
The last test was a change for them to find. Right at the splash, I overwrote five bytes of that 6.6 MB run with the bytes an inline hook writes, E9 and a 32-bit displacement, and put them back ten seconds later.
| 1.20, shipped, five hook bytes in hashed code | handler off | handler armed |
|---|---|---|
| what followed | a poisoned return 0.86 s later | a guard published five wrong words 3.3 s later; all five corrected |
| the process | crashed at 14.3 s, before its window | splash and window on time, still running at 90 s |
| publishes seen | — | 171 matched, 5 corrected, none without a context |
It was not the guard I had picked from the emulator that caught it. Another guard, one the emulator had never reached, hashes the same bytes and ran first. Coverage overlaps, and the handler does not need to know which guard it is.
This build cannot reach its online services, and it quits on its own after one to two minutes, with the handler armed or not, so every start was compared with one without it.
The handler carries no table, so I started ten other versions the same way, from September 2019 to the newest: each build's own shipped executable, run on 1.20's game data, gets as far as its splash screen before it meets data that is not its own. The store shape is in every one of them, and every store has its slot named:
| version | stores with their slot | pages |
|---|---|---|
| 0.01.2 | 166 | 167 |
| 1.07.0 | 170 | 170 |
| 1.20 | 200 | 200 |
| 1.23.2 | 200 | 200 |
| 1.30.0 | 201 | 200 |
| 1.31.5 | 201 | 204 |
| 1.39.3 | 202 | 200 |
| 1.41.2 | 202 | 200 |
| 1.51.2 | 184 | 176 |
| 1.64.0 | 185 | 184 |
| 1.69.0 | 183 | 182 |
Where guards published before a build gave up, every digest was already right: 87 publishes in 0.01.2, 17 in 1.23.2. 1.69.0 stops before its splash on 1.20's data, armed or not.
Limits
- In the running game it has been put to one change, in the menus. The guards that ran there and that the emulator reached hash the protection's own section. The guards that hash the game's own code did not run in the menus, so for those the correction is still shown only in the emulator.
- Only 65 of the 106 guards could be tested against a clean baseline. The rest hash on-demand code that was at rest in the dump. They publish with the same instruction the mitigation keys on.
- The 730 stubs reach 101 of the 184 publish instructions. How the guards behind the other 83 are entered is not known. The mitigation covers them by their instruction shape; the tests do not.
- Five routines publish with a different instruction and are not covered.
- It does not address the debugger probes. Those are a separate mechanism with the same response.
- There is a window. While the handler has a page writable to complete a store, another thread's publish to the same page goes through unseen.
- It costs something. The protection keeps writing to the pages that hold slots, and every such store is a fault. At start-up that is avoided by arming late; in the menus it is a few thousand faults a second.
Part 2: The file on disk
A file that cannot be read
By this point I had a working model of the protection in a running process, and all of it had come from one memory dump. A dump is one moment of a program that keeps rewriting itself. It could not tell me how the process had got into that state, and it is not something to hand to a disassembler and trust. The file that produces the process is a different object: 297 MB on disk against 693 MB mapped, and almost none of its code can be read.
So the second stretch of the work started from the shipped file, with the aim of arriving at the running image without ever running anything. The method stayed the same, with one more step at the end:
- look at the bytes and ask the smallest question they raise;
- answer it by running Arxan's own code in the emulator;
- replace the emulation with a plain re-implementation, and check that against the memory dump.
The last step is what turns an observation into a tool, and the tool grew one question at a time. It is a static decryptor I called mwdec: it reads a file and writes a file, and it never loads or runs the game.
I began with the obvious comparison: the shipped executable and the memory dump, mapped by RVA, section by section.
| section | size | entropy on disk | equal to the running image |
|---|---|---|---|
.text (game) |
120.1 MB | 7.991 | 3.67% |
.rdata |
5.3 MB | 5.936 | 99.7% |
.data |
460.8 MB (mostly zero-fill) | 0.260 | n/a, written at run time |
.pdata |
1.5 MB | 7.198 | 100.0% |
.rsrc, .reloc, _RDATA
|
1.8 MB | 5.5 to 7.5 | 100% |
.text (protection) |
103.9 MB | 7.959 | 11.08% |
Eight bits per byte is what random data measures. Both code sections are ciphertext, and nothing else is. The headers, the import directory, the relocation table, the TLS directory, the exception directory and the resources are all in the clear. Windows can map this file, relocate it, bind its imports, register its unwind data and call its TLS callbacks with no help from the protection. Only the code is locked, and the loader never needs to read code.

Figure 2. The shipped file. Everything the Windows loader reads is plain; the two code sections are ciphertext except for the few islands the first instructions need.
What has to be readable
A file whose code is entirely ciphertext cannot start, so my next question was what the first executed instruction is, and whether it can be read. The loader calls TLS callbacks first, then the entry point. On disk the entry point is nine plaintext bytes followed by noise:
070D9224 48 83 EC 28 sub rsp, 28h
070D9228 E8 9E ED A2 FA call 01B07FCB
070D922D ... ; ciphertext
The TLS directory lists six callbacks. Five begin with bytes that decode to nothing. The first begins with jmp 01A274F7. Both targets are readable, and they contain the same thing: fourteen register pushes, sixteen XMM saves, a stack alignment, and then the call stub every routine is entered through. The code that unlocks the file is not special. It is ordinary Arxan routines, reached through the ordinary stub, stored in plaintext.
Comparing the file with the dump for long runs that already agree shows how much plaintext there is: 233 runs of 256 bytes or more in the game's code, 901 KB in total, and two large islands in the protection's section, 4.4 MB at 0x25A8CA90 and a 4.8 MB tail that holds, among other things, the relocation table.
How do you relocate ciphertext?
The image is built for 0x140000000 and loaded somewhere else, and the loader fixes that by adding the difference to every address stored in the image. The relocation table lists 422,110 such places: 34,282 inside the game's code and 251,874 inside the protection's.
That raised a question I had to answer before going any further, because it looks impossible for an encrypted file. The loader adds a number to eight bytes of ciphertext, before any decryption has run, and decrypting afterwards would give garbage at every one of those places. Looking at the sites directly settled it. At each relocation site inside the code sections, the eight bytes on disk are a readable link-time pointer, and the bytes on either side are noise. The encryption steps around every relocation. So whatever decrypts this file must have a list of what to skip, and that list has at least 286,000 holes in it.
One keystream, cut into 1.3 million pieces
With two readable entry stubs I could start the file in the emulator the way the loader would: map the disk file section by section, point every import at a stub that logs the call, and call TLS callback 0 with the loader's arguments.
The first thing it does is ask Windows for access: GetSystemInfo, then a VirtualQuery and a VirtualProtect for the headers and each of the nine sections, every one asking for PAGE_EXECUTE_READWRITE. That is 21 API calls, and there are no others for the rest of the callback. Then the bytes start changing, front to back, and sampling the instruction pointer shows the emulator in two small loops: a byte-by-byte copy, and a longer loop that is plaintext on disk and can simply be read.
mov eax,[rbp+1Ch] ; shl eax,4
mov edx,[rbp+1Ch] ; shr edx,5 ; xor eax,edx ; add eax,[rbp+1Ch] ; ((v1<<4) ^ (v1>>5)) + v1
mov edx,[rbp+20h] ; and edx,3 ; mov rcx,[rbp] ; mov edx,[rcx+rdx*4] ; key[sum & 3]
add edx,[rbp+20h] ; xor eax,edx ; add eax,[rbp+18h] ; mov [rbp+18h],eax ; v0 += ...
mov eax,[rbp+14h] ; add eax,[rbp+20h] ; mov [rbp+20h],eax ; sum += delta
... shr edx,0Bh ; and edx,3 ; key[(sum>>11) & 3]
add dword [rbp+24h],1 ; cmp [rbp+24h],[rbp+10h] ; jb loop ; rounds
Two shifts by 4 and 5, a key word chosen by the low two bits of a running sum, then the same again with bits 11 and 12. This is the XTEA block function, in the encipher direction. Knowing the block function is not knowing the cipher, though. The question that decides everything is what goes into it and what happens to what comes out, and a hook at the head of the loop and another at its tail, logging the frame for the first 600 blocks, answers it.
| parameter | value | where it is stored |
|---|---|---|
| key | 7B7006CF 0F833A93 A21A3354 13F7BA9F |
RVA 0x23BF3897, plaintext |
| sum increment | 0x9E3779B9 |
immediate |
| rounds | 64 | immediate |
| first input block | E8B9C3BC A0A8028D |
RVA 0x26D860DC, plaintext |
The inputs are the surprise. Every block's input is the previous block's output. No block ever takes its input from the image. And each byte the copy loop stores is the byte that was already at that address, XORed with the next byte of the block outputs taken in order. So the cipher never touches the code. It enciphers its own 8-byte state over and over, and the successive states are a keystream that is XORed into the image:
S(0) = the stored block
S(i+1) = XTEA(S(i))
plaintext = ciphertext XOR (S(1) || S(2) || S(3) || ...)
That is output-feedback mode, and it has three consequences. Encryption and decryption are the same operation. It is strictly sequential: block n cannot be computed without the n − 1 before it. And position is everything: the keystream carries no trace of where it is being applied, so the right list of addresses in the wrong order makes every byte after the first mistake wrong.
The list
The keystream ran straight across the boundary between two separate destination ranges without restarting, so the one thing still missing is the list of ranges, in order. The store log gives its first entries: 16 bytes at 0x1000, then 28 at 0x7004, 28 at 0xD014, 28 at 0x13024.
A checksum guard describes what it hashes as a stream of LEB128 (gap, length) pairs. If the bootstrap uses the same encoding, its list begins with 80 20 10 (gap 0x1000, length 16) followed by F4 BF 01 1C repeated. I searched the file for those bytes and got one hit, at RVA 0x25A8CA90: the first byte of the 4.4 MB plaintext island. Decoded from there the list is 2,774,020 bytes long and has 1,324,188 ranges covering 208,856,213 bytes: 96.69% of the game's code section, 89.15% of the protection's, and under 22,000 bytes spread across the data sections. It ends with a gap that moves a 32-bit cursor to exactly 0xFFFFFFFF.
The most common gap is 8 bytes, and of 23,166 eight-byte gaps sampled, 21,997 sit exactly on a relocation site. That is the answer to the relocation question. The code is not encrypted as a block with exceptions. It is encrypted as 1.3 million fragments that fit between the things the loader has to touch, and the list also steps over the plaintext islands, the key, the starting block, and itself.
Key, starting block, round count and list are all plaintext in the file. Nothing is derived from the machine, the time or the process. So the first version of mwdec did exactly one thing: it ran one XTEA keystream across all 1.3 million ranges in order, 26,107,027 blocks, in 4.1 seconds, where the emulator needs about fifteen minutes for the same work. Rebased to the dump's load address and compared:
| section | entropy before | after | equal to the running image before | after |
|---|---|---|---|---|
.text (game) |
7.991 | 6.916 | 3.67% | 99.05% |
.text (protection) |
7.959 | 6.743 | 11.08% | 96.25% |
Because the keystream is positional, this is stronger than the percentages suggest. One wrong range anywhere in the list would have turned everything after it into noise. Agreement at the far end of the second section means all 1.3 million ranges are right. What still differs, 5.0 MB in 75,253 places, turns out not to be "still encrypted" at all, and the section on memory dumps near the end comes back to it.
What the protection did to the entry point
With the code decrypted I wanted to read the entry paths instead of emulating them. That still took a tool, because no path is contiguous. Each is a trail of one or two instructions at a time, scattered across both code sections and joined by jumps, and the jumps themselves are disguised. Three spellings have to be undone before a path becomes a listing, and they matter for everything that follows.
; "jmp X"
lea rsp,[rsp-8] ; mov [rsp],rbp ; lea rbp,[rip+X] ; xchg [rsp],rbp
lea rsp,[rsp+8] ; jmp [rsp-8]
; "jne B", falling through to A
push rbp ; movabs rbp,A ; xchg [rsp],rbp ; push A
push rcx ; push rdx
mov rcx,[rsp+10h] ; movabs rdx,B ; cmovne rcx,rdx ; mov [rsp+10h],rcx
pop rdx ; pop rcx ; ret
; "call G", returning to R
push R ; push G ; ret ; each push built as above
The first hides the target of a jump from anything that looks for E9 or FF 25. The second replaces a conditional branch with a conditional move between two absolute addresses, followed by a ret, so a disassembler following control flow sees no branch at all. It is also where the quarter of a million relocations in the protection's section come from: movabs rbp, A holds a full 64-bit address, so the loader has to fix it up, so it needs a relocation entry, so the bootstrap's list has to step around it. 250,178 of the 251,874 are movabs immediates.
Followed through those idioms with a small symbolic stack, the entry point reads:
070D9224 sub rsp, 28h
070D9228 call 01B07FCB
070D922D nop
28DDA0B6 add rsp, 28h
28DDA0D3 jmp 070D90B0
Anyone who has looked at an MSVC binary will recognise mainCRTStartup: sub rsp, 28h ; call __security_init_cookie ; add rsp, 28h ; jmp __scrt_common_main_seh. The tail is untouched, apart from being moved into the protection's section. The call is where the protection got in. It no longer goes to __security_init_cookie. It goes to a thunk that saves the full context three times over and makes three calls:
01B07FCB ; save context: 14 registers, 16 XMM; align stack
031206B6 call 0043907D
; restore, save, align
27714CFC call 258DC3DA
; restore, save, align
27850B16 call 285C23FC
; restore
2863455F jmp 070DD5F0 ; compares a global with 2B992DDFA232h: __security_init_cookie
So the protection did not write an entry point. It took the compiler's and redirected its first call through a thunk that runs three routines and then tail-jumps to the original callee. That also explains the nine plaintext bytes: sub rsp,28h and the call are the only two instructions of the entry point that can execute before decryption.
TLS callback 0 begins with the same three calls and then continues into its own first instruction. So do all 203 exported functions of the executable. With the entry point and the callback that makes 205 doors and 615 call chains: whichever way into the image is used first, the code behind it has been decrypted by the time it runs. None of the six TLS callbacks is the protection's own; they belong to the game and its anti-cheat, and the protection treats them like any other function it covers.
Run one at a time on the statically decrypted image, the three routines are:
| routine | API calls | what it does to memory |
|---|---|---|
0x43907D |
GetSystemInfo, then VirtualQuery and VirtualProtect for the headers and each section |
makes everything read-write-execute, then reads one byte and writes it back at the start of every 4 KB page: 169,353 pages |
0x258DC3DA |
none | the XTEA pass over 1,324,188 ranges |
0x285C23FC |
none | copies 667 pointers from .idata to the start of .rdata
|
Nothing in the start-up path puts the page protections back. From here on every Arxan routine simply writes to code, which is why no writer routine ever calls VirtualProtect, and why the weakness of the first part works at all.
The third routine is the one a static decryptor would miss. The file has two import address tables. The PE import directory describes one in .idata, a section the protection added, and that is the table the Windows loader fills in. The original table is still at the very start of .rdata, but no directory entry mentions it. Counting indirect calls in the decrypted game code shows both in use: 10,015 call [rip+d] go through the loader's table and 1,226 through the original. Nine call sites in ten were rewritten, and the rest would jump through slots holding whatever the linker left there. The third routine keeps them working by walking two range lists in step, in the same LEB128 encoding as everything else, and copying the loader's pointers across, one run per imported DLL. The odd run out is the protection's own: a 33rd import descriptor, a second KERNEL32.DLL with exactly two functions, AddVectoredExceptionHandler and RemoveVectoredExceptionHandler, which the debugger probes need and the game does not import.
One more detail closes the start-up. If the callback and the entry point both make the same three calls, the second caller must not decrypt again, since XORing the keystream in twice would re-encrypt the image. Each routine keeps a flag, and keeps it somewhere that looks like nothing: CC bytes between functions, which it zeroes when it has run. Comparing the memory left by a complete emulated run of the callback with the static result, the two code sections differ in 25 bytes out of 224,083,968: those flags, two state dwords, the final keystream state where the starting block was, and the first word of the XTEA key, which the decryptor overwrites on its way out. A memory dump of the running game therefore holds neither the key nor the starting block. Everything needed to decrypt the file is in the file, and after start-up it is nowhere else.
Functions that stay encrypted
After the bootstrap, 251 of the game's 29,329 code pages are still noise. They belong to 59 functions, the largest of them 454 KB: the functions the first part called decrypted on demand. I went looking for their key the way one usually finds a key: take one decrypted value and walk back to where it came from. I ran a writer that was known to produce the function at 0x387DEC0, logged every read and write, and looked at the instruction that produced its first four bytes, 55 48 8B EC.
2583A98F mov rax, [rbp+68h] ; a pointer that starts at 0x2500ACF2
2583A993 mov eax, [rax] ; e = 0x17A80096
2583A995 xor eax, [rip+...] ; K = the dword at 0x415D1D = 0xFB2348C3
2583A99F mov [rdx], eax ; -> a 4-byte buffer, then memcpy to the function
2583A9A1 add qword ptr [rbp+68h], 4
0x17A80096 ^ 0xFB2348C3 = 0xEC8B4855. That is the code. What is missing from this listing is more interesting than what is in it: the writer never reads the function. The pointer walks through a block of data in the protection's own section, half a gigabyte of address space away from the function it is producing.
So I had been asking the wrong question. This is not decryption in the usual sense, and the function has no key. The noise that fills it at rest is not transformed into code. It is thrown away. Each writer carries its own encoded copy of the bytes it will write, a stash, and overwrites the target with the decoded copy. One experiment confirmed it: I filled every target range with random bytes before running the writers, and the result was identical.
Scanning both code sections for the shape of that decode block finds every variant of it. There are four, and in each e is the next dword of the stash, p the next four bytes of output, and K a single dword hidden in the filler bytes between two fragments of scattered code.
| variant | decode step |
|---|---|
| xor | p = e ^ K |
| subtract | p = K - e |
| autokey |
p = e ^ k ; k += p, with k starting as K
|
| multiply-rotate |
a = rol(a, b & 31) ; p = e - a*b ; b = ~p ^ b, with a starting as K and b as K & 31
|
Where the output goes is a range list in the usual encoding. So a writer is completely described by four addresses and a variant: range list, stash, key, and which step to use. None of the four depends on anything at run time.
Layers, and pairs
Run one at a time, some writers still produced noise, with the right model and the right key. The function at 0x471CCF0 showed why. Two writers are involved, and the first does not write code at all: it writes 8,000 bytes into the protection's own section, at exactly the address the second uses as its stash. Some writers exist only to prepare another writer's stash, and from the file there is one more level than the memory dump shows, because two large stashes had already been rewritten by the time the dump was taken. Up to three steps separate the file from a function, and every one is a function of bytes in the file.

Figure 3. From the file to a function: the bootstrap keystream uncovers a feeder's stash, the feeder decodes that into a writer's stash, and the writer overwrites the function with the decoded copy. A twin with the same range list overwrites it with noise again.
A function that is produced on demand is also taken away again. For every on-demand range a second routine exists, with the same range list and a stash of its own, whose output is noise: hiding a function is one more overwrite from an encoded copy, and the copy happens to be ciphertext. So writers come in pairs, and a memory dump shows each range in whichever state the last of the two left it. Telling the two apart on the at-rest file is a measurement: run every routine once, and compare the entropy of what it writes with the entropy of what is there.
| the routine writes | the image holds | routines | bytes | what they are |
|---|---|---|---|---|
| about 8.0 bits per byte | 5.6 to 6.7 | 75 | 1,101,492 | re-encryptors: they turn code the image already has into noise |
| 4.4 to 5.9 | 7.2 to 8.0 | 15 | 17,717 | decryptors whose output the image does not have yet |
| 7.6 to 7.8 | 7.5 to 7.8 | 7 | 4,928 | re-encryptors of the ranges in the row above |
In all, the table for this build has 100 writers: 12 that prepare stashes and 88 that produce code. Applied in order to the statically decrypted file, they leave 6 of 29,329 pages of game code above 7.2 bits per byte, where a dump of the game that was actually running has 254. Two independent routes to the 59 functions, one from the file and one from the dump, agree on 883,737 of 883,737 bytes.
A protected range is not only code
The writer that taught me the most was one I thought I already had. Its stash and key were known, and its range list looked known as well: nine ranges, to the byte what the checksum guard for that function hashes. Laid over those nine ranges, the decoded stash came out as code in seven places and as this in the last two:
247A940F 2E 78 68 61 73 68 00 00 63 6F 6C 6C 69 73 69 6F .xhash..collisio
25FC7169 61 69 6D 00 70 61 73 73 74 68 72 6F 75 67 68 2D aim.passthrough-
Text, where the real routine leaves a function prologue. Plain text is not what a wrong key looks like. The stream is right and landing in the wrong place, which means a range is missing in front of it. The image holds three lists that begin with the same seven ranges: one with nine entries and two with ten, and the extra one is 10,760 bytes in .rdata. With the ten-range list the last two ranges become code and the block in .rdata becomes 619 strings, the names of animation states, stored as noise at rest. A writer can carry data along with its function, and the guard that watches the function hashes the writer's list with the data left out.
Much later, on build 1.30.0, the same thing turned up at a larger scale, as a comparison between two images that would not come out equal: one list covering 48,843 bytes of functions and 51,128 bytes of .rdata holding 2,797 names (yaw, movetype, fov, start_aim, goalradius...), where the functions are the ones that register those names, each a long run of lea rcx,[rip+name] ; call ; mov [rip+slot],eax. A strings dump of the file does not show the names, and neither does a search for code that refers to them, because the references are in the same ciphertext. That writer also defeats the simple way of telling a decryptor from its twin, since code that is one address load after another is mostly displacement bytes: 34% common code bytes, halfway between code (58% and up) and noise (20%). Entropy settles it, at 5.7 bits per byte against 8.0. Nothing that is still encrypted has two bits of slack per byte.
The most thorough hiding in the image is a family of 76 small subroutines near 0xAF8E10. At rest each entry is five bytes of noise. Decrypted, the five bytes are a jmp into the protection's section, where the body lives; the exception directory has no record for it; and the chain in front of each body runs a re-encryptor that hides the entry of another member of the family. The running process keeps closing the family behind itself as it goes.
Strings
Text is hidden three ways, and two are Arxan's. The protection needs two names at run time, ntdll.dll and NtQueryInformationProcess, and stores neither: each of 544 sites carries two byte arrays inside a code section, and the name is their XOR. Every site has its own pair of pads, so no two share a byte even though they produce the same nine or twenty-five characters. The second is the name tables that travel with their functions, above. The third is the game engine's own and much larger: 17,205 strings in .data, each an 8-byte key, a length, a flag byte and the text XORed with the key, decrypted in place by an inlined getter on first use. Because the key travels with the blob the file alone is enough, and the dump gives a direct check: the game had decrypted 9,144 of them by the time it was taken, and all 9,144 match. One detail is pleasing. 402 of those strings are referred to only from inside on-demand functions (dw_match_id, teamsValidated, winningTeamIndex), so in a memory dump they look unused, because the code that uses them is noise. They also say something about what was thought worth the extra layer.
Part 3: Taking the protection out
What removal has to mean
A decrypted file still contains all of Arxan. Every routine is there, every call chain, every disguised jump, the injected start-up path and the second import table. Once I could read the file, the next thing I wanted was the same program without any of that in it.
This is usually called devirtualizing, but this build has no bytecode virtual machine to undo. What it has is the list in the previous paragraph, and each item needs a different kind of removal. I started by writing down what the program would miss if the protection were simply deleted, because by now it depends on it in three ways.
- Decrypted bytes. Covered already: both layers are static.
- The start-up path. Two of the three start-up routines do work the program needs. One makes memory writable. One fills the second import table.
- Published state. A checksum guard writes its digest into a slot inside a code section before it compares, and other code reads those slots later.
Everything else is protection for its own sake: the comparisons, the debugger probes, the clocks, the repair writes. So removal is not deletion. For the start-up path, the program needs the function the thunk was hiding, and one import table instead of two. For published state, it needs the values the guards would have written, at the moment they would have written them. Only then can the routines stop running. Appendix B has every step in full; what follows is the shape of each and the thing that made it harder than it looks.
The start-up path
The instruction after the last of the three start-up chains is a jump to the function the entry point's call originally named. So the fix is to write that address back.
| site | shipped | restored |
|---|---|---|
entry point, 0x70D9228
|
call 0x1B07FCB (thunk, three routines) |
call 0x70DD5F0 (__security_init_cookie) |
TLS callback 0, 0xA80D10
|
jmp 0x1A274F7 (three routines, then the body) |
jmp 0x2776055E (the body) |
The third start-up routine existed to copy 667 pointers into the old import table for the instructions that still use it. Those instructions can be made to stop needing it: add the distance between an old slot and its twin in the loader's table to each instruction's displacement. Finding them takes a little care, because a four-byte pattern is not an instruction. Scanning for any 32-bit field that would land on a copied slot if it were a RIP-relative displacement gives 1,485 candidates, and each is kept only if some instruction start in the eleven bytes before it decodes to an instruction whose displacement is exactly that field. 1,251 survive: 1,226 call, 21 jmp and 4 mov. Executed one at a time in the emulator, 1,251 of 1,251 go to the DLL and function their original named.
With the image stored decrypted and one import table, none of the three routines has anything left to do, and a chain around a routine that does nothing saves a set of registers and restores the same set. Each of the 615 chains at the 205 doors is replaced by a five-byte jmp from its first instruction to the instruction after its last. One thing does change: a chain that does not save the flags leaves the flags of its own stack-alignment arithmetic behind. Following the code after each exit until every status flag is either overwritten or read shows that nothing reads them. All 615 exits have dead flags.
A routine cannot be skipped
The start-up path had come out so cleanly that I expected the 730 routines spliced into game code to be the same case, and I tried the same thing: write ret at a routine's entry and run the code around it. Here is one such place, in a game function at 0x7013EBC, with the idioms resolved.
07013EBC push 25842E17 ; push 27FEF75C ; ret
27FEF75C push 040F51A4 ; push 041011FF ; ret
041011FF push 03FEB276 ; push 00B03667 ; ret
00B03667 ; save context: 11 registers, 16 XMM
; align stack
24F7F1E3 push 250A7A89 ; push 250326B2 ; ret ; call the routine
250A7A89 ; restore context
250A7B27 ret
Three "calls" are nested around the chain before it starts, so three return addresses lie on the stack above the saved registers. After the chain restores its context it executes ret, which takes the innermost of them, 0x3FEB276. With the routine replaced by ret, that is where the emulator ends up:
03FEB276 mov r9, [rsp+48h]
03FEB27B add r9, 0E5h
03FEB282 mov [rsp+0B0h], r9
03FEB28A movzx eax, byte ptr [r9]
This is the middle of an unrelated function, entered with a stack that is not its own. The other two addresses are no better: one is a jmp in the middle of some other function, and one is inside a routine of the protection. I repeated the experiment on 60 chains spread over the 730 and got the same answer 60 times. None arrives anywhere the game function could continue.
So the real routine does something the chain depends on, and it is not in any register, because the chain restores those. I ran the chain with the real routine and compared the stack afterwards. Three qwords above the chain's saved registers have changed.
| slot | pushed by the construct | written by the routine | what is there |
|---|---|---|---|
| first | 0x3FEB276 |
0x2335316 |
ret |
| second | 0x40F51A4 |
0x416FDBF |
ret |
| third | 0x25842E17 |
0x26D01BE3 |
mov dword ptr [rsp+58h], 8, then more of the game function |
The three addresses the construct pushes are decoys. The routine overwrites all three before it returns. The chain's own ret then goes to a ret, which goes to another ret, which goes to the third address, and that one is the next piece of the game function.

Figure 4. A routine spliced into a game function. The construct pushes three plausible addresses, the routine replaces all three while it runs, and the chain's return falls through two bare returns into the real continuation.
This holds for every one of the 730. On its success path a routine in game code is not called on the way to somewhere. It is the way: the place where the function continues exists only as three writes inside the routine, and nothing in the calling construct names it. A disassembler that resolves every idiom perfectly and then follows the constants it found walks into a decoy. So does a patch that removes the routine or makes it return early. And it puts the failed check of the first part in a different light. A guard that fails does not need a separate mechanism to send the program somewhere wrong. It only has to write something else into slots it was going to write anyway.
Fifty-three bytes
Since those three writes are everything the calling code needs, a routine can be replaced by a function that performs them and nothing else.
lea rdx, [rsp+8] ; the caller's frame, as the routine addresses it
mov rax, [rdx+8] ; the alignment push: 10h or 18h
shr rax, 3
add rax, idx ; first slot, in qwords
lea rcx, [rip+T2] ; mov [rdx+rax*8+10h], rcx
lea rcx, [rip+T1] ; mov [rdx+rax*8+8], rcx
lea rcx, [rip+T0] ; mov [rdx+rax*8], rcx
ret
It is 53 bytes, position independent, and fits in the routine's own first instructions. The order of the three stores is not free. Some chains save only twelve registers, and in those rax, rcx and rdx come back to the game holding whatever the routine last put in them: a slot index, the address of a ret, a stack address. To be indistinguishable from the routine, the replacement has to leave the same leftovers. Each of the 730 chains was run twice in the emulator, from the instruction that calls the routine to the continuation, once with the real routine and once with the 53 bytes, and compared on rip, rsp, all sixteen general registers, the flags and the live stack. All 730 pairs end in the same state.
The three addresses came from one emulated run of each routine, watching what it writes above its own frame. Seven hundred and thirty emulated runs is a workable way to build a table for one build. It stopped being workable the moment there was a second build, and the next chapter is about what replaced it.
Values the guards leave behind
The second thing the program needs from the routines is state. Searching both code sections for instructions that read anything a routine publishes, and discarding the instructions the routines themselves execute, leaves very little: a few dozen short sequences, all of one family.
mov ecx, [P] ; a published value
add ecx, [A]
xor ecx, [B] ; or sub
add rsp, rcx ; zero when P is what a clean run leaves there
The variants end in a conditional jump or a cmov between two addresses instead of the add rsp. All of them compute one number from a published value and two constants of their own, and all are harmless only when that number is zero. The value each one needs therefore follows from its own constants: (P + A) ^ B = 0 gives P = B − A. For 25 of the values the publisher was found and run in the emulator, a guard or the start-up decryptor, and in 25 of 25 what it writes is exactly what the arithmetic asks for. Read through the joining jumps the protection cuts its code with, the count later turned out to be the same in every build I looked at: 53 checks on 40 published dwords.
What such a check does with a value it does not like is worth seeing once, because it is the failed guard again with no routine in sight. This one is from build 1.20.
01433F05 mov edx, [rip-634FF7h] ; the published value
171529D7 add edx, [rip+1E07CC5h]
171529DD sub edx, [rip-135AD529h]
171529E3 je 16F2D3FC ; zero: carry on
17EC344D and rdx, 3
17EC3451 shl rdx, 3
148761F1 push rdx
148761FA lea rdx, [rip-13B376ACh] ; a table of four qwords
15B32D9D add rdx, [rsp]
15B32DA1 mov rdx, [rdx] ; one of them, chosen by the wrong value
15B32DA4 xor rdx, [rip-14DF4236h]
15B32DAB push rdx
18931927 lea rdx, [rip-3Ah]
1893192E add rdx, [rsp]
18931932 sub rdx, [rip-183F72Ch]
18931939 push rdx
159DF04D ret ; and gone
There is no error branch. The two low bits of the wrong result pick one of four constants, and arithmetic on it becomes a return address. Decoded for one such check in build 1.30.0, the four table entries are link-time addresses in the game's code, and what the path does with them is a rebase by hand done with two anchors that are not the same place, so every entry lands 0x466A27B short of where it points: the middle of an instruction in an unrelated function three times out of four, and 38 MB below the image the fourth. It is the same family as the return that is off by a gigabyte, an address computed correctly except for one term, so that nothing in the crash looks like a decision.
The natural conclusion is that the 40 values can be stored in the file, and that every check then has one outcome and can be folded into a jump. That is what I did first, and every comparison I ran in the emulator agreed with it. It is wrong, and the reason only showed when a cleaned build was started for real; that story comes two chapters on. The rule that came out of it: a published value has a before and an after. Only values that hold from the start are written into the file. Where a guard publishes a value at run time, its construct stays, its replacement stores the value at the moment the guard would have, and the checks that read it are left exactly as they are, both branches.
Folding, straightening, and where it stops
At this point I had an image with 730 replacement functions in it. It runs without the protection, but it does not look like it. Every chain is still there, saving and restoring up to fourteen registers and sixteen XMM registers around 53 bytes that write three constants.
Those 53 bytes are simple enough to reason about without running them. Give the symbolic stack that resolves push R ; push G ; ret one more rule, "this routine stores these three addresses in these three slots", and it can evaluate a whole construct from its first instruction: the nested pushes, the chain, the three writes, the chain's ret into a ret, into another ret, into the continuation.
; shipped
07013EBC push 25842E17 ; push 27FEF75C ; ret ; and everything after it
; exported
07013EBC jmp 26D01BE3
26D01BE3 mov dword ptr [rsp+58h], 8
26D01BEB mov dword ptr [rsp+44h], 0FFFFFFF8h
Three wrapped calls, a context save, a routine and a context restore fold into one direct jump to the next piece of the game function. Often the continuation of one routine is the first instruction of another construct, and the evaluation carries on through it: the chains in game code group into 311 such nests, each running between one and five routines before it lets the function go on.
A jump is not quite the same thing as the nest it replaces, and the difference has to be shown harmless before the fold is allowed. The routine leaves values in rax, rcx and rdx, and a chain that does not save those hands them to the game; after a fold they hold whatever they held before. That is the same only if nothing reads them before writing them, so from each fold target the code is followed on every path, into callees, until each such register is written or read. The same walk is done for each status flag. Then every fold was checked against the real routine: the emulator runs the shipped construct from its first instruction, with the protection's routine executing in full, until it reaches the fold's target, and the two sides are compared on every register that is live there. They did not all get there in one pass. In the first, 49 of 309 gave nothing to compare, because the real routine ended in an illegal instruction or a breakpoint: two of the six debugger probes, chosen by the timestamp. Run again with a different pinned timestamp, 47 of the 49 went through, and the last two only needed time, 167 and 87 seconds of emulation.
Straightening the jumps
The three idioms that had to be resolved to read the entry point are everywhere, and for an exported image they have to be resolved and written back. That needs a definition of where code is. The walk that supplies it starts from everything the file itself calls an entry: 127,967 records of the exception directory, 56,756 relocated pointers in the data sections that point into code, the entry point, the TLS callbacks, the exports, the unwind handlers. From there it follows every direct branch, resolves every idiom into the branch it stands for, and follows that too.
Two things nearly hid a large part of the code from it. Code is not only in the code sections: the protection's pieces in section padding have to be walked like the rest. And the compiler's switch dispatch does not end in jmp rcx in this build. It ends in
mov [rsp-8], rcx
lea rsp, [rsp-8]
lea rsp, [rsp+8]
jmp [rsp-8]
which pushes rcx, pops nothing, and jumps to what it pushed. A walk that treats jmp [rsp-8] as an unknown destination stops there and never sees a single case. Reading those four instructions as jmp rcx brought 4,520 jump tables and every block behind them into the walk.
In the code the walk reaches there are 184,254 disguised branches, and each is replaced at its first instruction by what it means.
| idiom | replacement | bytes |
|---|---|---|
jmp X |
jmp X |
5 |
jcc B, else A
|
jcc B ; jmp A |
11 |
call G, return to R
|
call G ; jmp R |
10 |
The replacement has to fit where the idiom was, and an idiom is rarely in one place: its instructions are spread over several chunks joined by jmp rel32. It also has to be safe to overwrite. A chunk may be rewritten only if nothing else enters it: no branch from live code into its interior, no lea or movabs of an address inside it, no exception record that starts in the middle of it. And one piece of bookkeeping is easy to miss. Every movabs in a conditional idiom carried a 64-bit address, so every one has an entry in the relocation table. If the instruction goes and its entry stays, the loader adds the load offset to eight bytes in the middle of whatever is there now. Each rewrite also deletes the relocation entries under it: 164,289 of the 422,110 the file started with.
With the branches rewritten I expected jmp [rsp-8] to have disappeared from live code. Nearly 7,000 were still there, and grouping them by the instructions in front showed why. They are not branches. They are compiler epilogues in which every stack instruction has been written as a pair: lea rsp,[rsp-8] ; mov [rsp],r for push r, mov r,[rsp] ; lea rsp,[rsp+8] for pop r, lea rsp,[rsp+8] ; jmp [rsp-8] for ret, often with a joining jump between the two halves. There are close to 114,000 of them. None changes what the program does, and they are not the protection's logic. But they are its handwriting, and they are most of the reason a function in this build is hard to read.
A no-op with a hole in it
One number had been nagging at the end of every run: a handful of function pieces, four to ten a build, that still read as noise after both layers were off. I had been carrying them as "still encrypted", and that was wrong. Held against a memory dump of the running game they are byte for byte the same. No writer has them in its list. And read as instructions from their first byte, most of them are this:
00001010 pushfq
00001011 push rbx
00001012 movabs rbx, 0EFECB3E81FEBAEF6h ; 48 BB F6 AE EB 1F E8 B3 EC EF
0000101C call 00001016 ; back into that immediate, onto the bytes EB 1F
00001021 add rsp, 3E10h ; never executed: a believable epilogue,
00001028 pop rbp ; then a few random bytes
00001029 ret
00001037 pop rbx ; the call's return address, thrown away
00001038 xor ebx, 0DC7421E6h
0000103E pop rbx
0000103F popfq
00001040 call 00AF27C0 ; the function goes on
The flags and one register are saved. The register is loaded with a constant whose middle two bytes are EB 1F. The call goes back, into the middle of that instruction, where EB 1F is a short jump over what follows. What it lands on throws the return address away, does a little more arithmetic on the scratch register, and puts the register and the flags back. Between thirty-four and forty-seven bytes, and nothing has changed. What it is for is the stretch nobody executes: a disassembler reading straight through meets add rsp ; pop rbp ; ret, decides the function has ended, and decodes the random bytes after it as the start of the next one. It also explained why a walk that follows every call and every fall-through had been reaching bytes that could not be code.
| constructs | bytes they occupy | |
|---|---|---|
| a build of the game that was never protected | 0 | |
| 0.01.2 | 12,578 | about 0.6 MB |
| 1.20 | 19,064 | about 0.9 MB |
| 1.51.2 | 23,674 | about 1.1 MB |
| 1.69.0 | 22,429 | about 1.1 MB |
Every one of them is in the game's own code, and the protection's section has none. The fifty variants differ in the order of the two pushes, the register and the arithmetic. Removing them takes less trust than the branches did, because the claim is so narrow. Each candidate is checked instruction by instruction: the pushes are exactly the flags and one register, everything in between writes only that register and the flags, the pops undo the pushes in order, and no arithmetic comes after either has been put back. All 19,064 and all 23,674 pass. Six hundred of them, at least one of every variant, were then run in the emulator from random registers and flags, and at the end everything is as it was. Each becomes a two-byte jump over itself, and the bytes behind it are filled with int3 unless some branch encoded anywhere in the image could land in them, which keeps a few hundred as they are.
The construct changes between versions, and the two ends of the range spell it differently. The oldest builds save only the register:
push rbx
sub ebx, 3D1EEB6Bh ; immediate bytes 6B EB 1E 3D
call <back onto EB 1E>
... ; never executed
pop rbx ; the return address
movabs rbx, ...
pop rbx ; no popfq: the flags keep what the sub left
Here the construct is not a no-op. The sub changes the flags and nothing puts them back, so it can only go where the flags it leaves are never looked at. For each of these I followed every path forward from the construct until all six status flags had been written: by an instruction that sets them, or by a call or a ret, across which the Windows x64 convention keeps no flags. A path that reads a flag first, takes an indirect jump or runs too long keeps its construct. On 0.01.2 all 12,578 come out clean, 12,568 of them at an instruction that writes the flags and ten at a call. The newest build goes the other way and adds something between the two pops: a nop of any length, an xchg or mov of a register with itself at 64 or 16 bits, or lea r64, [r64]. All of these change nothing, and I accept only those. The 32-bit forms are left out on purpose, because writing a 32-bit register clears its upper half. That is what 21,751 of 1.69.0's constructs look like, and it raises the number of shapes from fifty to two hundred. The same emulator check holds for both forms, with the flags left out of the comparison for the older one, whose flags are covered by the proof above.
In 1.51.2 four of the ten pieces were this construct. The other six are what is left where a function used to be. Each begins with a jmp into the protection's section, where the function's body now lives, and what follows in the old address range is fragments of the protection's own code or bytes nothing executes; one record begins a byte early, in front of such a jump. The largest, 806 bytes that recur in five versions, is noise in the running game too: guards hash it and no writer writes it. None of them is something a decryptor would produce. Each is, byte for byte, what the running game holds.
Each kind of rewrite has its own proof of the same shape: the shipped form and its replacement, run from the same random state, compared on everything afterwards. Idioms that are byte for byte the same shape share one proof, so the runs cover one of every shape and a random sample of the rest: 42,717 runs for the branches, 24,610 for the pairs, no difference.
Where the walk ends
Every rewrite rests on one definition: code is what the walk reaches. I took an inventory of the game's code section after the rewrite to see where that definition runs out. Close to seven megabytes of the game's code section are neither reached nor touched, and decoded from the right offsets, part of it is ordinary code. Grouped by the exception record around it, almost all of it lies in a handful of enormous records, the largest covering eight megabytes. These belong to the game's anti-cheat, whose blocks end in a register jump with a destination computed at run time. A walk follows direct branches, idioms and jump tables. It does not follow a computed jump, and resolving those is outside the scope of this post.
Arxan did not stop there. It treated that code like any other: its idioms run all through it, and pieces of it were moved into the protection's section. That is why the edge matters. "Not reached" cannot be read as "dead", and a rewrite is safe only when every way into the rewritten bytes is known. So the code behind the computed jumps is found without walking to it. A compiler emits blocks back to back, so the byte after an instruction that never falls through is where the next block would begin; every such byte the walk did not reach is decoded as a candidate block and accepted when every instruction is one a compiler writes for user-mode code and the block ends cleanly. Accepted blocks are not rewritten. They become the roots of a second walk with a different rule, keep: everything it reaches stays byte for byte, nothing it executes, reads or branches to is wiped, and a patch already planned over a byte it walks is taken back.
The price is stated in that walk's own numbers. Inside it, exactly as shipped, are about 61,000 disguised branches, 60,000 stack pairs and 344 routine call sites. The protection's handwriting stays in the code the walk could not prove it understood.
Two things about that edge are worth being exact about. The first is whose obfuscation the computed jumps are. A build of the same game that was never protected, linked two weeks before 1.20, already has these functions in this form: its largest exception records are 3.1 MB, 1.7 MB and 0.75 MB, where the protected 1.20 has 3.1, 2.2 and 1.9 MB. The flattening was in the code before Arxan saw it. Arxan's part is what it lays over everything alike: moved blocks, disguised branches, junk constructs, and the routines it splices in. That is also why this post leaves those functions exactly as shipped and does not take their dispatch apart: it belongs to the game's anti-cheat, not to the protection.
The second is how much of Arxan's own writing stays behind because of it, in code the walk does reach. For the ten versions of the last chapter:
| version | disguised branches left as shipped | routine call sites left in live code | routine replacements kept in place |
|---|---|---|---|
| 0.01.2 | 686 | 62 | 630 |
| 1.07.0 | 729 | 67 | 630 |
| 1.23.2 | 795 | 69 | 611 |
| 1.30.0 | 1,281 | 74 | 1,009 |
| 1.31.5 | 1,220 | 83 | 1,214 |
| 1.39.3 | 1,397 | 86 | 1,199 |
| 1.41.2 | 993 | 76 | 1,088 |
| 1.51.2 | 1,449 | 75 | 908 |
| 1.64.0 | 1,442 | 78 | 932 |
| 1.69.0 | 1,404 | 78 | 907 |
Against the fifty to two hundred thousand branches rewritten in each of those versions, about one in a hundred is left, and every routine a kept call site reaches has its three-write replacement, so none of the protection's routines runs.
What is left
For 1.51.2, the exported image has 72,268,708 bytes filled with int3, in 236,561 ranges, and its relocation table goes from 422,110 entries to 208,359. The protection's section tells the story in three numbers: 7.96 bits per byte as shipped, 6.71 decrypted, 2.48 exported. About 32 of its 104 MB still hold something: game code the protection moved there, the kept blocks, rewritten instructions, data that live instructions read, and the relocation table itself, which the protection keeps in its own section. The protection's own import descriptor stays as well, because the kept code still contains debugger probes that load its two slots, and whether any path the game takes still reaches one of them is a question about computed jumps that the walk cannot answer.
Part 4: A second build
How much of it was the build?
Everything so far was measured on one build, with an emulator and a memory dump at hand, and by now the tables behind the removal had been filled in one emulated routine at a time. I did not know how much of what I had was Arxan and how much was 1.51.2. The honest test was a build none of it had been fitted to, so I took an older one, 1.20 from May 2020, and resolved to use nothing but the shipped file. Appendix C follows every step. The short version is that each table the protection uses is either named by plain compiled code or pinned down by the file's own structure, and the emulator had been a slow way of reading what was written down all along.
The cipher's three parameters
On 1.51.2 the bootstrap's list was found by watching the cipher store its first few ranges. It can be found without watching anything, because the file says where some of its entries must be. The cipher steps around every relocated qword, so between two relocation sites that lie close together the list has to contain gap 8, length (distance − 8). I took six consecutive entries of the file's own relocation table, encoded the six pairs as LEB128, and searched the file for those bytes. A hit is somewhere in the middle of the list, with the cursor at that point known. And LEB128 reads backwards without ambiguity, since a value ends at a byte with the top bit clear and the top-bit-set bytes in front of it are its own. So the list can be walked back, value by value, to the gap that equals the whole remaining cursor, which is its beginning.
The key and the starting block I first found by position: both must be readable before anything is decrypted, so the cipher must skip them, and no relocation explains those skips. Trying every 16-byte island with every 8-byte island on the head of the stream, and scoring the output by how much of it looks like compiled code, takes a few seconds and leaves one pair standing at 54% to 59% against 23% for the runner-up.
Then the oldest build I have, 0.01.2 from September 2019, broke that search and in doing so showed a shorter one. No pair of its islands decrypts anything. But the constant 9E3779B9 occurs exactly once in the file, in code the protection has to leave readable, since it is the code that makes everything else readable:
13A0885F mov dword ptr [rbp+10h], 40h ; 64 cycles
13A08866 mov dword ptr [rbp+14h], 9E3779B9h
13A0886D lea rax, [rip+88134Dh] ; 14289BC1, the key
13A08874 mov [rbp], rax
13A08878 lea rax, [rip-11CBE387h] ; 01D4A4F8, the starting block
13A0887F mov [rbp+8], rax
The starting block of that build is not in the protection's section at all, which is why no pair matched. And these instructions are the same, frame offsets included, in 1.03, 1.20 and 1.51.2. The cipher's set-up is plain compiled code that names its cycle count, its key and its starting block. I had built a clever search for something the file states outright.
Every list, and every writer
The backward reading that found the bootstrap's list finds all the others, because every list in the protection ends the same way: with a gap that carries the cursor from somewhere inside the image to 0xFFFFFFFF. A gap that large is always five LEB128 bytes, and the last of them is 0D, 0E or 0F. Every five-byte value of that shape is a possible ending, and the walk back from it either arrives at a list's first value or falls apart within a few steps. On 1.51.2 that turns 105,690 candidates into 310 lists in about a second, the bootstrap's and all 100 writers' among them: the table I had built by emulation, one routine at a time, given up by the file to a scan.
A writer needs three more things: its stash, its key and its encoding. My first attempt at the key was brute force, since a key is one dword and a dword can be exhausted. It taught me something I would not have found otherwise. For a multiply-rotate stash, trying all 2^32 keys prints the right one with 76.7% of the decoded bytes common code bytes against 27.5% for the runner-up. For an autokey stash it prints a wrong key and reports that 1.4 billion keys, a third of all there are, decode the first 80 bytes to something that passes for code. The reason is in the arithmetic: p = e ^ k ; k += p. Bit 0 of the next k is bit 0 of e whatever k was, bit 1 then depends only on bit 0, and so on up. The running key forgets where it started within 32 words. An autokey stash is readable without its key, apart from its first lines.
Brute force was the wrong tool all the same, and the answer was again in the code. Every writer is an instance of one compiled routine, and three instruction shapes name its parameters.
| what | how the writer names it |
|---|---|
| stash | lea rax,[rip+S] ; mov [rbp+68h],rax |
| list | lea rax,[rip+L] ; mov [rbp+48h],rax ; mov eax,1 ; test eax,eax |
| key, xor |
xor eax,[rip+K] ; mov rdx,[rbp+78h] ; mov [rdx],eax, in the loop |
| key, subtract |
add eax,[rip+K] ; mov rdx,[rbp+78h] ; mov [rdx],eax, in the loop |
| key, autokey |
mov eax,[rip+K] ; mov [rbp+8Ch],eax, before the set-up |
| key, multiply-rotate | mov eax,[rip+K] ; mov [rbp+88h],eax ; mov eax,[rip+K] ; and eax,1Fh |
The frame offsets differ between builds, so the shapes are what to match. Matching them takes the same care as everything else in this image, because the protection cuts the routine into pieces: the instructions have to be read as a stream, joining jumps followed and disguised ones resolved. With all four parameters in hand each candidate row is simply decoded, and what comes out says what the row is: code that differs from what is in place is a decryptor, code identical to what is in place is a repair writer, noise is a twin or a writer that prepares another's stash.
The oldest build had one more lesson. After everything, 233 pages of its game code were still unreadable, nearly all in the ranges of a single list of 2.7 MB. The image holds that list three times: one copy named by a writer that decodes to noise, one by a guard, and one that nothing in either code section refers to. The writer that should use the third copy seemed not to exist. It does. Its set-up is in the last page of .pdata, in the padding the linker leaves after the table of unwind records. The reference search had only looked where code is supposed to be. Reading every read-only section as a place code may be took the unreadable pages of that build from 233 to 1, and the one is hashing code whose constants are as dense as noise.
The check was the first build again. With every parameter read from the file and nothing taken from the emulator, the decrypted image of 1.51.2 differs from the earlier one in 0 of 297,288,240 bytes.
The way back is a constant
The removal leaned on two things the calling code does not contain: where each routine sends its caller, and what the guards publish. On 1.51.2 both had been measured by running every routine. Running hundreds of routines again for every build was one way to go on. The other was to ask where a routine gets its three addresses from, so I put the question to the file: where else does one of those addresses occur?
Once. Every one of the three addresses of every routine is in the image exactly once, as an absolute qword with a relocation entry, sitting alone between pieces of code. One instruction loads the qword, and what follows is the end of the routine:
25F7BB85 mov rcx, [rip-0DE7068h] ; the qword at 25194B24: the continuation
25F7BB8C mov [rdx+rax*8], rcx
28D0EF2E mov rax, [rip-73AD73h] ; another qword: a small number, the slot
28D0EF35 mov rdx, [rbp+170h] ; the caller's frame
28D0EF3C mov rcx, [rip-27394568h] ; the address of a ret
28D0EF43 mov [rdx+rax*8], rcx
Both inputs of each store are constants. Walking every routine from its entry and collecting those stores gives the same three addresses as the 730 measured runs, 730 times, in a few seconds, and adds the one routine the measurement had never reached.
1.20 was the test of whether that is the protection or the build, and at first it looked like the build: not one store of that form in 613 routines. Grouping every indexed qword store in the image by the instructions before it showed the same store written by an older version of the protection, in two spellings, addressed from the routine's own frame and placed at the start of the routine where 1.51.2 has it in the epilogue. What all versions share is the part worth matching: a qword store with a scaled index, whose value was just loaded from a qword holding an address in the image. Entered in the emulator the way their chains enter them, 595 of 1.20's 613 routines returned having written exactly the three qwords the table has, and the other 18 ran out of time having written the continuation and nothing else.
The published values never needed a guard at all. A check does arithmetic on the published dword with two constants of its own and uses the result in a way that only works when it is zero, so the value the guard has to have published is B − A, and it is sitting in the check. Collected that way, the 40 values of 1.51.2 are the same file, byte for byte, as the one made from the guards' emulated runs.
1.20 without its protection
With those tables read from the file, the whole removal ran on a build it had never been fitted to: 613 routine replacements, 537 start-up chains skipped, 275 of 275 constructs folded to a jump, 56,302 disguised branches rewritten, 55 of 55 checks folded, 65 MB wiped, and no function piece left that reads as noise.
Those are counts, and counts were not enough. Compared against the protected image in the emulator, function by function from the same state, the first export was wrong in two places. One function returned in the protected image and jumped out of the image in the export: its path goes through a check whose first instruction is separated from the rest by a joining jump, so the value it reads had not been recognised. The other stopped at an int3: a return thunk that lives in the padding of a data section, whose address is only ever pushed and never jumped to, had not been recognised as code, and what it leads to had been wiped. Both were fixed, and then the comparison read 107 of 116 targeted functions and 599 of 600 sampled ones equal, the rest out of time, none different.
By every measure I had, the 1.20 export was right. So it was time to do the one thing an emulator cannot do for a file, and start it.
Part 5: Finding out whether it is right
An emulator as a measuring instrument
A cleaned file is a claim about a program: that it does what the protected one does. Each kind of rewrite had been proven on its own, in isolation. That leaves the question of whether the pieces fit, and I wanted an answer that did not depend on my understanding of any single piece.
The comparison I settled on needs a reference that still has its protection, running. That is the decrypted image in the emulator with every routine executing and each checksum guard held on its success path. The candidate is the exported file, run as it is. What a function does, as far as the rest of the world can tell, is the sequence of calls it makes to Windows and the state it leaves. So both sides are entered at the same function with the same registers, stack and memory, both are stopped at every import call, and the call, its arguments, the stack pointer and the non-volatile registers are recorded. Calls the reference makes while one of the protection's routines is on its stack are left out, because the candidate has no routines. The two sequences must be equal, and when both runs end the same way, so must the return value, the registers, every changed byte of every data section and the heap.
Getting the reference to behave took longer than building the comparison, and most of what went wrong said something about the protection. The best example is a function that, run alone in the reference six times, returned three times and stopped at an int 2Dh debugger probe the other three, with every rdtsc in the image pinned to a fixed value. Two instruction traces of it are identical for 568 instructions and differ at the next one, which is a probe bundle assembling its own rdtsc:
25854E37 lea rdx, [rip+11D1F23h] ; 26A26D61
25854E3E mov eax, [rip-23C3D778h]
25854E44 xor eax, [rip-23CE1C47h] ; eax = 310F9090
25854E4A mov [rdx], eax
25854E4C jmp 26A26D61
26A26D61 nop ; nop ; rdtsc ; at rest: lea rdx, [rsp]
26A26D65 jmp 273F0874
273F0874 mov [rbp+130h], eax
In the file those four bytes are a harmless lea, so a scan of the image for the opcode does not find them, and the timestamp that picks the probe came from the host. The reference now watches writes into code for the opcode and pins those too.
One function shows what the filter on routine calls hides. At 0x5FB33E0 both sides make one call of their own, GetLastError. The reference makes seven more while routines are on its stack: LoadLibraryA, GetProcAddress, GetCurrentProcess, NtQueryInformationProcess, FreeLibrary, AddVectoredExceptionHandler, CloseHandle. That is a debugger-probe bundle running in the middle of a game function. The export makes none of those calls and ends in the same state.
The results on 1.51.2:
| functions run | how many | equal | no verdict | different |
|---|---|---|---|---|
| the entry path | 1 | 1 | 0 | 0 |
| every function that reaches a routine call site, a folded nest or a folded check | 170 | 161 | 9 | 0 |
| a random sample of function entries | 3,000 | 2,987 | 13 | 0 |
| a second sample, with arguments full of pointers | 3,000 | 2,940 | 60 | 0 |
Every "no verdict" is the reference running out of time: a routine in the middle of hashing megabytes of code is slow in an emulator. 1,111 of the 6,089 equal runs went all the way to the function's return. The rest stopped at the same instruction in the same state on both sides, usually at a pointer the invented arguments could not satisfy. That is the limit of this kind of comparison, and I understood it less well than I thought. An emulator with invented arguments walks the first stretch of a function and seldom its depths, and what the table says is that no path it could take tells the two images apart.
Started for real
The Windows loader is the one reader of the file the emulator never plays. So the 1.20 export was started once as a process, from the game's folder, under its own file name.
The loader had no complaint. It mapped the image, applied the 175,973 relocations the export keeps, bound every import from the one import table that is left, and called the three TLS callbacks. Forty-four modules were in the process and the C runtime was running the program's static initialisers when, a second after the start, the process tried to execute address 0.
Windows kept a dump, and the first surprise was that the fault had nothing to do with anything I had changed. The faulting call is call qword ptr [rsp+1EC8h] in static initialiser 30 of 6,442, through a local variable that held an address in private memory, and next to it the frame held CreateFileW, GetFileSize, VirtualAlloc and three pointers that look like the arrays of an export directory. That initialiser reads gdi32.dll from disk, lays it out as a second image of its own, and calls the copy's GdiDllInitialize. To watch it do so the emulator needed something it had never had, a module list and the real DLL files mapped around the image, and given those the function runs the same twenty-one calls in both images to the same end. On a current Windows that export is a jump through a delay-load slot, and Windows will not resolve a delay-load import for an image it has never heard of. It is a failure of this build on a Windows six years younger than it, in bytes the export leaves exactly as shipped, and the protected file takes the same twenty-one steps to it. With a handler in the process that recognises that one fault, the shipped file shows its splash screen after ten seconds and its window after fourteen.
The export, in the same folder under the same name, did three other things, a different one from start to start. Each was a rule I had wrong.
One function, 256 ways through
The first was an int3, a wiped byte, executed inside static initialiser 39. The dump has the path: push rax ; ret with rax = 0x3DD537, and at that address
3DD532 90 66 2B 16 76 junk
3DD537 E9 8C C3 96 15 jmp 15D498C8
3DD53C 48 BD 28 78 ... junk
A disassembler that starts at 0x3DD532 reads nop ; sub dx,[rsi] ; jbe … and never sees the jump, and nothing in the image names 0x3DD537: no lea, no pointer, no branch. The address is arithmetic. The function is a state machine, the protection has moved its blocks into its own section and left a five-byte jmp block at each block's old address, and the dispatcher computes which of those addresses to go to. A walk that follows branches finds the blocks the dispatcher's direct branches reach and no others, and I had wiped the rest as unreachable.
Why had the emulator never seen it? The initialiser opens like this:
159E7776 rdtsc
159E7778 shl rdx, 20h
159E777C or rax, rdx
159E777F movzx r8d, al
159E7783 imul eax, r8d, 1807h
159E778A cmp eax, 0C0380h ; a binary search on the product follows
It takes the low byte of the timestamp counter and picks one of up to 256 paths with it. Three real starts took three paths. My emulator's counter was pinned so that two images would see the same values, and its first read always ended in zero. I had made the comparison repeatable and, in the same stroke, blind to 255 of 256 ways through this function.
A computed jump cannot be followed, but it has to land on something, and what it lands on is still a jump the file spells out. So the rule became a search instead of a walk: in every byte the walk did not read and no rewrite wipes, a jmp, call or jcc encoded at any offset whose target is a wiped byte keeps that target, and a second walk keeps what the target reaches. Build 1.20 has 1,651 of these and 799 pointers of the same kind, and keeping their targets costs 150 KB of the 65 MB that was wiped.
A value has a before
The second ending was the strange one: exit code 0 after a second and a half, no fault, no window. Started in the emulator from its entry point, with the loader's TLS block, the TLS callbacks and all 6,442 initialisers run in order, the export does the same thing, and the log shows where: WinMain makes no call at all. Its first lines, with the disguises taken off:
mov eax, [P]
add eax, [A]
xor eax, [B]
je skip ; equal: nothing to do
mov eax, [17EEB5BDh] ; a 1, stored between two instructions of the protection
mov [flag], eax
skip: mov eax, [flag]
test eax, eax
je return_zero
...
<a guard's construct> ; publishes P
P is one of the 40 dwords a guard publishes, and the first three instructions are one of the 53 checks. Everything I had said about checks holds here except the one thing I had assumed: that a check exists to be passed. The protected image, run from its entry point in the same emulator with its routines really executing, arrives at WinMain with P still holding the value it has in the file. The check fails, the failing branch sets the flag, the flag lets WinMain continue, and the very next construct is the guard that publishes P. From then on P is right, and the other check that reads it, one whose failing branch is the poisoned return, passes.
The order is deliberate. A check placed before its guard cannot pass in the shipped program, so its failing branch is ordinary control flow, and the program depends on it. Whoever supplies the guard's value in advance, by patching the dword or by answering the check, turns that branch off. There is no crash to investigate afterwards. WinMain returns zero, the C runtime runs the destructors, and the process ends politely.

Figure 5. A check placed before the guard that publishes its value. In the shipped program the first check fails every time, and its failing branch is the way forward. A cleaned file that stores the value ahead of time turns that branch off.
So a published value is not a constant of the file. It has a before and an after, and the moment between them is the guard's construct running. The removal changed to match. Only values that hold from the start are written into the file. A construct whose routine publishes is not a jump in disguise any more: it stays as shipped, nothing is rewritten to land past it, and the routine's replacement gains one instruction in front of its three stack writes,
mov dword ptr [rip+P], 671CF959h ; ten bytes, no register, no flag
so the value appears when the guard would have run. Checks that read such a value are left exactly as they are, both branches.
That last sentence I learned from the third ending. With the fold merely withdrawn after planning, the game drew its window and then reported Fatal Error … 0xc0000005 itself. A snapshot of the process with the box still up has the faulting thread's context on its stack: a ret popping 0x19C8E1FCDFD36281, with the alignment words 10h and 18h above it. That is the poisoned return of a check, live. The check's guard had never run, because a jump I had written earlier was aimed at the end of the chain of jumps after another check and looked straight through the guard to its continuation. Deciding that a construct stays has to come before any jump target is computed.
A window
With the three rules in place the counts for 1.20 read differently, and more honestly: 258 of 275 constructs folded and 17 left in place because their guard publishes a value; 31 of 55 checks folded and 24 left as shipped, both branches. The export was then started four more times. Each time: the splash screen at five seconds, the game's window at nine, a hundred threads and five gigabytes of working set a minute later, and the same name lookups the shipped file makes at that point, where both wait for a back end that was not running. The export gets there sooner than the shipped file does, by the four seconds the shipped file spends decrypting itself.
Much later, after the junk constructs had been taken out as well (19,064 more rewrites in this build), I did not take the emulator's word for it a second time. A fresh export of 1.20 went through the comparison, 398 of 411 functions equal and none different, then the start in the emulator, 6,450 of 6,450 stretches the same, and then one more real start: the splash two seconds after the process began, the game's window drawing by the fourteenth second, the same name lookups, no fault and no error event, and still running when I stopped it after seventy-five seconds.
Seven hundred emulated function comparisons had found nothing wrong with the earlier export, and they were right about what they compared. What they could not see is what needs a history: code that only a computed jump reaches, chosen by a counter, and an order of events that spans a function boundary.
From the entry point, in the emulator
So the comparison grew a second form, and it is the one I trust most now. Start both images where Windows starts them and let each run: the TLS callbacks with the arguments the loader gives them, the entry point, the C runtime, every static initialiser in table order with the state the earlier ones left, and on into main until the program does nothing but wait for threads a one-thread emulator will never give it. The run is cut into stretches, one per callback and per initialiser, and a stretch is the same in both images when it made the same API calls with the same text and got the same answers.
| build | TLS callbacks | stretches | the same in both | API calls up to the wait | routines entered, protected side |
|---|---|---|---|---|---|
| 1.07.0 | 1 | 6,294 | 6,294 | 2,681 | 14 |
| 1.20 | 3 | 6,450 | 6,450 | 4,855 | 20 |
| 1.30.0 | 3 | 6,539 | 6,539 | 4,942 | 24 |
| 1.69.0 | 6 | 6,950 | 6,950 | 5,785 | 154 |
Getting past 1.20 meant playing more of Windows, because the game's start-up asks more of it in each generation, and an emulator that answers "success" and writes nothing sends both images down the same wrong path. 1.30.0 reads a system DLL from disk through NtCreateFile and NtReadFile and then executes the syscall instruction itself, with a service number it has just read out of that file; an emulator that steps over syscall hands back a null pointer as success, and both images die on it at initialiser 43 of 6,539. 1.69.0 loads the number and jumps to the syscall ; ret at the end of a stub inside the loaded ntdll. Answered from the same table the program reads, both go through. That code is the game's and its anti-cheat's, and I treated it as a black box: the emulator answers what it asks and looks no further.
The last obstacle was the protection's own. In 1.69.0 the path through main enters 154 of its routines before the first wait, against two dozen in the older builds, and one of them is a debugger probe:
call AddVectoredExceptionHandler ; (1, handler at 1AADBE1A)
1FD56508 mov [rbp+78h], rax ; the handle, for the removal afterwards
...
1FD5651D lea rax, [rbp+68h]
1FD56521 ud2
1FD56523 jmp 1C9A1730
A processor that executes ud2 raises an exception, and on a machine with no debugger Windows hands it to the handler registered a moment earlier. The handler sets a flag through the rax it finds in the context, moves the context's rip past the instruction, and asks to continue. So the emulator has to be Windows for one more thing: build the exception record and the context below the stack, enter the handler, and on "continue" load the registers from what the handler left. One exception is delivered on the way into 1.69.0's main, the handler answers it, and the protected image arrives at the same wait as the cleaned one after the same 5,785 calls.
What a function entered cold cannot tell you
Running the function comparison over many builds produced a steady trickle of functions that differed, and almost every one turned out to be a property of entering a function with no history. They are worth listing because the protection is what makes each of them visible.
- A check at the door. A function entered cold can meet a check before the guard that publishes its value has run. The protected image then dies on the check's failing path, a jump through four wrong addresses, and the cleaned one dies somewhere else, because that table is the failing path's alone and a program that works never reads it. Where the value is one a kept routine publishes at run time, both images fail the same check, each through its own wrong address.
- The protection opens and closes its own code. Pieces of the protection sit in the unused tail of data sections, and one was different after a run: 168 bytes that one routine writes as readable instructions and a later one covers with noise again. That is a writer and its twin bracketing one use of a piece of protection code. A cleaned image has nobody left to close it.
- Routines leave their registers on the stack. When the game builds a 16-byte structure on the stack and stores it whole, the two bytes of padding the compiler never initialised are whatever was there, and in the protected run that is two bytes of a register a routine saved. Fill the stack below the function with another value, run the cleaned side again, and exactly those bytes change with it.
- The protection is 90 megabytes of plausible neighbours. A function given filler for arguments can index a table with it and land in the protection's section, where the protected side reads protection code and the cleaned side reads what replaced it. Run the function again with different filler, and an address that was computed from it moves, while one the code names stays where it was.
- Not every record is a function. The exception directory has records that begin in the middle of one of the protection's constructs, some of them on a 16-byte boundary by chance. A record whose unwind data is chained to another is a later piece of a function, not an entry.
Each of those is now recognised by what happened on the path, not by how the path ended, and each gets its own verdict instead of "different".
What a memory dump holds
A dump of the running game is the other way to get this code out from under its protection, so it was worth holding one against the cleaned file, address for address. A dump made with Scylla is the image as Windows laid it out: its header names the address the game was loaded at, here 0x7FF6D7950000, and its pointers are relocated to that address. Read both by RVA and they agree on where everything is. For 1.51.2:
| at the same RVA in both | same | of |
|---|---|---|
| sections | 9 | 9 |
| function records in the exception directory | 127,967 | 127,967 |
| pointers in read-only data, each side's base subtracted | 78,973 | 78,973 |
| bytes of game code | 117,293,940 (97.6%) | 120,134,656 |
| bytes of game code with the dump moved by 16 bytes | 4.5% |
97.6% against 4.5% leaves no doubt about the addresses. The 2.4% is the interesting part. 1.57 MB of it is what the removal rewrote. The rest is code the removal never touched, and there it is the dump that differs from the decrypted image: 1.28 MB of noise at 7.7 bits per byte, scattered through functions that are otherwise readable.
Whose noise it is can be asked of the writers. Decode every writer the image has, the ones that decrypt and the ones that do not, and hold each one's output against the dump:
| of the 1,475,362 code bytes where the dump is not the decrypted image | bytes |
|---|---|
| exactly what one writer writes, over 115,632 ranges | 805,560 |
| exactly what three other writers write | 194,164 |
| exactly what smaller writers write | 4,734 |
| inside a writer's ranges, in another state | 224,770 |
| in no writer's ranges | 246,134 |
None of those writers decrypts anything. What each of them writes is noise: they are the half of each pair that hides. The largest does not hide functions. Its 115,632 ranges average seven bytes, so it punches holes, a few bytes at a time, across the whole code section, and a dump taken while the game runs has every hole that had not been filled in again at that moment.
A second dump of the same build, made by another tool at another time, shows how much the moment matters.
| the same build, two dumps | taken early | taken late |
|---|---|---|
| pages of game code present | 12,845 of 29,329 | 29,329 of 29,329 |
| bytes identical to the decrypted image, in the pages present | 99.6% | 98.8% |
| of the bytes writers decrypt, still encrypted | 99.2% | 17.5% |
| noise a hiding writer left | under 8,000 bytes | 1,004,458 bytes |
The early one is the game seconds into its life: the outer layer off, almost nothing opened yet, nothing hidden again yet.
A dump of the last version, 1.69.0, caught an earlier moment still, and I only noticed because its numbers looked wrong. Its addresses agree with the cleaned file like all the others, section for section and record for record, but only two thirds of its code bytes do. Held against the shipped file instead, the reason is a single address. The game's code is decrypted up to 0x54DE87A, and from the next byte on the dump is the shipped file's ciphertext, byte for byte, to the end of the section and through the whole of the protection's section behind it. The dumper stopped the process 73% of the way through the bootstrap's pass. A keystream that has to be applied in order leaves exactly this picture when it is interrupted: everything before one byte, nothing after it.
So a dump is one moment of a program that keeps most of itself readable and a moving part of itself not. It has the right addresses and the wrong bytes in about a megabyte of places, and which places depends on when it was taken. The file, decrypted from its own tables, has no moment.
Ten versions
The last thing I did was run the whole removal, with every check above, on versions spread across the life of the game, from the September 2019 build to the last one. Nothing in the tools knows any of them. Each row is one shipped executable taken through decryption, removal and export, then compared with its protected original function by function, started in the emulator from its entry point beside it, and held against a memory dump of the same version where I had one.
| version | routines | junk constructs removed | functions compared | equal | out of time or no verdict | different | start: stretches | the same | memory dump |
|---|---|---|---|---|---|---|---|---|---|
| 0.01.2 | 551 | 12,578 | 396 | 383 | 13 | 0 | 6,181 | 6,181 | none to compare |
| 1.07.0 | 567 | 12,868 | 402 | 391 | 11 | 0 | 6,294 | 6,294 | none to compare |
| 1.23.2 | 616 | 18,538 | 410 | 396 | 14 | 0 | 6,505 | 6,505 | none to compare |
| 1.30.0 | 621 | 20,774 | 411 | 396 | 15 | 0 | 6,539 | 6,539 | none to compare |
| 1.31.5 | 621 | 20,730 | 411 | 397 | 14 | 0 | 6,551 | 6,551 | same addresses |
| 1.39.3 | 625 | 21,085 | 411 | 394 | 17 | 0 | 6,027 | 6,027 | same addresses |
| 1.41.2 | 626 | 21,183 | 412 | 393 | 19 | 0 | 6,032 | 6,032 | none to compare |
| 1.51.2 | 734 | 23,674 | 407 | 392 | 15 | 0 | 6,463 | 6,463 | same addresses |
| 1.64.0 | 744 | 23,341 | 408 | 393 | 15 | 0 | 6,995 | 6,995 | same addresses |
| 1.69.0 | 735 | 22,429 | 406 | 392 | 14 | 0 | 6,950 | 6,950 | same addresses |
Ten of ten export. No function differs in any of them, and every stretch of every start is the same in both images, between six and seven thousand stretches a version. The functions without a verdict are the ones where the protected side ran out of emulated time, plus one to four per version that fell into the cold-entry cases above. Where I had a memory dump of the version, every section, every function record and every pointer in read-only data sits at the same address in the dump as in the cleaned file.
The table also shows how little the protection moved in two and a half years. The routine count grows from 551 to 744 and the code around it more than doubles, but every one of these versions has the same 53 checks on 40 published values, the same three start-up calls at every door, and the same three writes inside every routine.
Part 6: Looking back
The tool
What came out of all this is one static tool, mwdec, and it is smaller than the story. It reads a shipped executable and never loads or runs the game. From the file alone it finds the bootstrap cipher's parameters and its list, every writer with its stash, key and encoding, both import tables, the three addresses each routine writes and the values the checks need, and it produces one of two things.
The first is a decrypted image, for a disassembler: every byte readable, every string in plain text, and the protection still in it, inert, because its start-up flags are unset and its guards would be hashing code that is no longer in the state they expect. On 1.51.2 that takes under six seconds, four of them the keystream.
The second is the cleaned image, meant to stand on its own. The removal is kept apart from the writing of the file: the analysis produces plans, each a list of byte patches, relocation entries to delete and ranges to fill with int3, and the exporter only applies plans. That keeps every decision inspectable, since a plan can be printed, compared with another, or applied alone to see which one a difference comes from. Planning is the slow part, a walk of 27 million instructions several times over. Everything runs in one process from the shipped file, nothing kept from an earlier run, and the walks that do not depend on each other run side by side. The whole export, shipped file to cleaned file, takes about half a minute for the oldest build, one minute for 1.30.0 and under two minutes for 1.69.0, the largest.
The evidence is of different kinds, and it is worth keeping them apart.
| what | compared with | result |
|---|---|---|
| bootstrap layer | memory left by the real routines, run to completion in the emulator | 25 bytes differ in 224,083,968, all of them the routines' own bookkeeping |
| bootstrap layer | memory dump of the running game | 99.05% of the game's code equal, up from 3.67% |
| writer layer | the same writers applied to the dump | 883,737 of 883,737 bytes equal |
| 615 start-up chains skipped | the chain, run from its first instruction to its exit | 615 equal |
| 730 routine replacements | the real routine, from its call to the continuation | 730 equal |
| 309 nests folded | the shipped nest with the real routines running | 309 equal |
| 183,544 branches rewritten | the shipped idiom, one of each of 1,605 shapes and a sample | 42,717 runs, all equal |
| 113,572 stack pairs | the shipped pair, over 22,202 shapes | 24,610 pairs, all equal |
| whole functions | the decrypted image with its protection running | 6,089 equal, 0 different, 82 out of time |
the start, entry point to main
|
the same, protection running | every stretch equal, on all ten versions |
| one cleaned build, as a process | the shipped file, as a process | the same window, four seconds sooner |
Conclusion
Arxan in this game is smaller than its footprint suggests. Under a hundred megabytes of scattered chunks there are four kinds of routine, three hash functions, six debugger probes and one response primitive. Under 209 MB of ciphertext there is one keystream, one list, and four ways of encoding a dword. What makes it hard is not any one of those. It is that each of them is arranged so that the obvious next step is slightly wrong.
The design choices I would remember:
-
One list format for everything. What a guard hashes, what the bootstrap decrypts, where a writer writes, and which import slots get copied are all the same LEB128
(gap, length)stream with the same terminator. Recognise it once and every table in the protection becomes readable. -
Encrypt around the loader, not against it. The file is a valid PE that Windows can map, relocate and bind unaided. The cipher is cut into 1.3 million pieces to fit between the relocations. The entry point is the compiler's, with one
callredirected. - Nothing is derived at run time. The key, the starting block, every range list, every stash and every stash key are bytes in the file. So is every address a routine sends its caller to, and every value a check expects. That is why the whole of it can be undone statically, and why the decryptor destroys its key after use: the file is the only place it ever needed to be.
- Copies, not ciphers. An on-demand function is not decrypted. It is overwritten from an encoded copy kept somewhere else, sometimes through two more copies, and overwritten with noise again when it is done. The noise at rest is a placeholder.
- Self-containment. A routine carries its own base calculation, tables and frame, so it can be spliced anywhere. The same property lets each one be run in isolation, which is what made all of this possible.
- Mutual coverage. A tenth of the protection's own section is hashed, against less than half a percent of the game's. The guards are there mainly to protect each other.
- Separation of check and penalty. A failed guard poisons its own return or leaves a wrong number behind. The damage appears later, in code that never compared anything.
And the things that taking it out taught me, mostly by being wrong about them first:
- The way on is inside the routine. A routine spliced into a function does not return to where its caller says. The construct around it pushes three believable addresses, and the routine replaces all three while it runs. Nothing that skips the routine can find where the function continues.
- Decoys are real code. Each of the three pushed addresses is a valid instruction in some other function. A patched-out routine does not crash at once. It carries on somewhere plausible with the wrong stack.
-
What the program needs is small. One function the entry point's
callused to name, one import table instead of two, and forty dwords of published state, each at the right time. Everything else the protection does at run time is for itself. - Most of the bulk is handwriting. 184,000 disguised branches and 114,000 stack instructions written as pairs carry no secret at all. They are a fixed set of spellings, and undoing them is a table lookup plus the care not to overwrite a byte something else jumps to.
- A static walk has an edge. Removal is exact for the code a walk can reach, and the honest thing to do with the rest is to leave it and everything it touches alone. Finding the rest is a search, not a walk: a computed jump still has to land on bytes the file spells out.
- A check can be there to fail. A check placed before its guard takes its failing branch in the shipped program every time, and the program is written to need that. Supplying the guard's answer early switches the branch off, and nothing crashes to say so.
- A dump is a moment, and so is a function entered cold. The running process has functions hidden again, stashes rewritten and holes punched in its code; a function run on its own has no history. Both are true pictures of something that is not quite the program.
Looking back over the order of it, the pattern is that the emulator kept being right about less than I thought. It was right about every routine it ran, and that was enough to model the protection. It was right about every function it compared, and that was not enough to start a process, because a process has a history and a function entered in the middle of one does not. Each time, the fix was the same: stop fitting to the sample I had and go to the next larger thing, a second build, a real start, the whole run from the entry point, ten versions. The protection's values have a time as well as a place, and a program can be built to need the moment before one of its own checks passes. The listing had been in front of me the whole time. It took a window that did not open to make me read it that way.
The weakness from the first part, publishing before judging, held up in a running process. A guard found five changed bytes, the handler gave it the digest it expected at the moment it published, and the game went on as if nothing had changed, where without the handler the protection answered within a second and the process died. What is still open is the same experiment against the guards that hash the game's own code, which did not run in the part of the game I could reach.
Top comments (0)