Inside Arxan in Modern Warfare (2019)

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.
原文:https://www.a8q9.cn/en/article/inside-arxan-in-modern-warfare-2019-0630d3.html