Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age

Carl Svensson (Security Engineer)

RE//verse 2026 · Day 1 · Coral Ballroom A

Overview

Carl Svensson's talk, "Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age," delves into the intricate process of reverse engineering a modern iteration of a classic real-time strategy game, Age of Empires II: Definitive Edition. The presentation highlights the significant challenges posed by contemporary game binaries, which often employ sophisticated encryption and obfuscation techniques to protect intellectual property and deter tampering. Svensson, a seasoned CTF veteran, showcases how he systematically dismantled these protections, moving beyond manual analysis to develop robust, automated tooling that can adapt to the game's frequent updates.

Watch on YouTube

Visual summary for Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age by Carl Svensson
Visual summary for Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age by Carl Svensson

Key moments

  1. 0:00 Introduction and pattern matching tool teaser
  2. 2:20 Initial binary exploration and encryption discovery
  3. 6:00 Deep dive into AES decryption mechanism details
  4. 10:00 Automating decryption across 100+ game versions
  5. 13:00 Introducing BNIL pattern matching for deobfuscation
  6. 17:00 Visual demonstration of deobfuscation in action
  7. 21:00 Future work: headless engine, bot development, vuln research
  8. 22:30 Q&A: Tool used for entropy analysis graph

Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age

Speakers: Carl Svensson, Security Engineer

Conference: RE//verse

YouTube: https://www.youtube.com/watch?v=Dp-IvqfCoL0

Overview

Carl Svensson's talk, "Reversing Age of Empires 2: Upgrading tools from Dark Age to Castle Age," delves into the intricate process of reverse engineering a modern iteration of a classic real-time strategy game, Age of Empires II: Definitive Edition. The presentation highlights the significant challenges posed by contemporary game binaries, which often employ sophisticated encryption and obfuscation techniques to protect intellectual property and deter tampering. Svensson, a seasoned CTF veteran, showcases how he systematically dismantled these protections, moving beyond manual analysis to develop robust, automated tooling that can adapt to the game's frequent updates.

The core of Svensson's work involves creating a pipeline for automated decryption and a novel Intermediate Language (IL) pattern-matching system for deobfuscation. This endeavor is not merely academic but driven by a practical need to analyze a game that receives continuous patches—over 100 versions of the Definitive Edition have been released. By sharing his methodology and the tools developed, Svensson provides valuable insights for security researchers and reverse engineers tackling similar challenges in software analysis, whether for game hacking, malware analysis, or vulnerability research.

The talk serves as a compelling case study on applying advanced reverse engineering techniques to a complex, actively developed commercial product. It demonstrates how a passion project can yield powerful, generalizable tools, transforming the "Dark Age" of manual, single-version analysis into the "Castle Age" of automated, adaptable reverse engineering workflows. The insights shared are particularly relevant for those dealing with binaries that utilize custom, multi-layered protective mechanisms.

Background

▶ Watch: Introduction and pattern matching tool teaser (0:00)

Age of Empires II (AoE2), originally released in 1999 by Ensemble Studios, is a beloved real-time strategy game that has seen continuous development, culminating in the Definitive Edition released in 2019. This version, the focus of Svensson's research, remains under active development, with new expansions and over 100 different patch versions released to date. Svensson chose this game not only for his personal enjoyment as a competitive player but also as an ideal "playground" for developing reverse engineering tools. It presented a challenge that was substantial enough to be interesting but not overwhelmingly complex like a modern AAA game with cutting-edge anti-cheat and DRM.

The initial hurdle in analyzing the AoE2: Definitive Edition binary was its heavily protected nature. An entropy analysis revealed that a significant portion of the 80 MB Windows executable was either compressed or encrypted, indicating a deliberate effort to obscure its contents. Furthermore, the presence of a non-standard .text2 section hinted at additional complexities. This scenario is common in commercial software, where developers seek to protect their code from reverse engineering, intellectual property theft, or unauthorized modifications. The problem for reverse engineers is that these protections render traditional static analysis tools ineffective, necessitating dynamic analysis and the development of custom decryption and deobfuscation routines.

Svensson's motivation extended beyond merely understanding a single version of the game. Given the frequent patches, he aimed to build a reusable toolkit that could automatically adapt to new versions, extracting necessary parameters and decrypting/deobfuscating the binary without manual intervention for each update. This ambition required moving beyond one-off scripts to a more robust, automated pipeline, addressing the inherent volatility of actively developed software.

Key Findings

▶ Watch: Deep dive into AES decryption mechanism details (6:00)

Svensson's reverse engineering journey uncovered several critical findings regarding Age of Empires II: Definitive Edition's protection mechanisms and led to the development of innovative tools to overcome them.

Firstly, the game binary employs a multi-layered encryption scheme. The primary protection involves AES in ECB mode (AES-ECB) to encrypt large portions of the code. This encryption uses a hardcoded key and is preceded by an integrity check using SHA-384, a surprisingly specific choice for a hash function. A crucial discovery was the existence of a massive table of variable-length encoded integers within the binary. This table precisely delineates which regions of the binary are encrypted ciphertext and which are unencrypted data (e.g., relocation tables), allowing the decryption routine to selectively process only the encrypted segments. This selective decryption mechanism is essential for handling relocations without corrupting the ciphertext.

Secondly, beyond the primary AES layer, Svensson identified a second layer of encryption utilizing the TEA (Tiny Encryption Algorithm). While still a work in progress at the time of the talk, this discovery highlights the depth of the obfuscation efforts and the need for a multi-stage approach to fully unpack the binary.

Thirdly, Svensson developed an automated parameter extraction pipeline to deal with the game's frequent updates. By analyzing the decryption routine in Binary Ninja's Intermediate Language (IL), he devised a "sieve approach" using pattern matching to automatically locate and extract the hardcoded AES key, the SHA-384 target hash, and other critical parameters across different game versions. This pipeline proved highly effective, successfully extracting parameters from 80 out of 96 available binaries from the Steam CDN.

Finally, to address local code obfuscations, Svensson created a novel Binary Ninja IL (BNIL) query system for pattern matching and deobfuscation. Inspired by tools like Veggli and Ryan's instruction graph plugin, this system exports BNIL into a Lisp-like syntax, which is then parsed by the Tree-sitter library. This allows for sophisticated pattern matching, including the use of wildcards for temporary registers and defining relationships between values, enabling the automatic identification and replacement of obfuscated instruction sequences with their simpler, equivalent forms. This deobfuscation plugin significantly enhances code readability, transforming complex, unintuitive IL into more comprehensible structures.

Technical Deep Dive

▶ Watch: Introducing BNIL pattern matching for deobfuscation (13:00)

Svensson's technical journey began in the "Dark Age" with manual exploration of the 80-megabyte Age of Empires II: Definitive Edition binary. Initial entropy analysis immediately revealed high entropy regions, indicating heavy compression or encryption. Static analysis was further hampered by the entry point of the executable, which contained a single jump instruction to a routine followed by "garbage," typical of packed or encrypted binaries.

Decryption Mechanism

The first step was to perform dynamic analysis by running the game and dumping its memory. This confirmed that the game unpacks and decrypts itself at startup, providing an in-memory "plaintext" copy of the binary as a crucial reference. Analyzing the entry point's jump target revealed a specific routine structure:

  1. Stash registers: A large number of registers are saved.
  2. Stack alignment: The stack is aligned to 16 bytes.
  3. Function call 1: A function is called.
  4. Restore registers: All stashed registers are restored.
  5. Repeat: The same process (stash, align, call, restore) occurs for a second function call.

It was discovered that the first function call makes the relevant memory pages writable, while the second performs the actual decryption. This decryption routine uses AES in ECB mode with a hardcoded key. Before decryption, an integrity check is performed using SHA-384, a robust but somewhat unusual choice for this context.

A critical aspect of the decryption process is handling relocations. Encrypting a binary with relocations applied would corrupt the ciphertext. The developers circumvent this by not encrypting the relocation tables themselves. Instead, they employ a massive table of variable-length encoded integers that describes precisely which byte ranges are ciphertext and which are plaintext. This table allows the routine to "grab 20 bytes of ciphertext, skip 8 bytes, grab 16 bytes," and so on, throughout the binary. All collected ciphertext snippets are then decrypted with AES-ECB. Due to the block-oriented nature of ECB, the ciphertext length must be a multiple of the AES block size (16 bytes). The developers handle this by storing the trailing part of the last block elsewhere in the binary and appending it before decryption to ensure proper alignment.

An interesting side observation was related to the game's sound engine. Many sound-related functions, statically linked and exported, contained the same decryption detour. Svensson hypothesized that a binary-to-binary translation tool, used post-compilation, inserted this routine into every exported function, unable to distinguish between internal and external call sites.

After the AES decryption, Svensson noted that an entropy graph of the resulting binary still showed high-entropy regions, indicating a second layer of encryption using TEA (Tiny Encryption Algorithm). This layer is still under active investigation.

Automation for Decryption

To address the game's frequent patching, Svensson moved into the "Feudal Age" by automating the parameter extraction process. He developed a "sieve approach" using Binary Ninja's Medium Level IL (MLIL). For instance, to find the AES key, he identified that the AES initialization function takes the key as its second argument. His script iterates through MLIL instructions, filtering for call instructions with three arguments, then specifically targets the second argument as a potential pointer to the AES key. This method allowed for the automatic extraction of the AES key, target SHA-384 hash, and other necessary parameters across different versions.

This led to a two-stage toolchain:

  1. A Binary Ninja script to extract decryption parameters from a given binary.
  2. A second script that takes these parameters and performs the actual decryption, producing a clean binary.

To validate this approach, Svensson leveraged the Steam CDN, which retains all published versions of the game. He downloaded 96 distinct binaries. Fortuitously, an unencrypted version was accidentally uploaded to the CDN at one point, providing an excellent reference point. His "CI-like pipeline" successfully extracted parameters from 80 of these 96 binaries, with 4 others failing during the decryption process, demonstrating a high success rate for automated analysis.

Code Obfuscation & Deobfuscation

Beyond encryption, the game also employs local code obfuscations, where single instructions are replaced by several functionally equivalent, but more complex, instruction sequences. For example, a simple push instruction might be expanded into multiple mov, sub, and store operations, often using a temporary register.

Svensson's solution, developed in the "Castle Age," is a Binary Ninja IL (BNIL) query system. Inspired by Veggli (a C code pattern matcher) and Ryan's instruction graph plugin for Binary Ninja, he aimed to build a similar system for BNIL. The core idea is to export Binary Ninja's IL into a Lisp-like syntax, which is then parsed by the Tree-sitter library. This Lisp-like representation is ideal for querying due to its structured nature.

The query system allows defining patterns that include:

  • Sequences of instructions.
  • Wildcards for registers or values (e.g., reg A1 could match any register used as a temporary).
  • Relationships between values (e.g., reg A1 == reg A2 ensures two wildcards refer to the same register).

The deobfuscation workflow within Binary Ninja involves:

  1. Iteratively searching for known obfuscation patterns using the BNIL query system.
  2. Upon a match, "NOPing out" the obfuscated instructions.
  3. Inserting the equivalent, simpler instruction (e.g., replacing the complex push sequence with a single push).
  4. Repeating until no more patterns are matched.

Svensson chose to NOP out instructions rather than deleting them to simplify control flow management, as Binary Ninja's IL lifting process later cleans up these NOPs. This results in significantly more readable IL, transforming convoluted sequences into clear, deobfuscated code, making subsequent analysis much easier.

Future Work

Looking ahead to the "Imperial Age," Svensson plans to use SOGON, a Windows user-space emulator by Moritz Heimann, for instrumentation. This will help analyze crashes in binaries that didn't decrypt cleanly or failed to run after decryption, further refining the decryption and deobfuscation pipeline. Longer-term goals include building a headless version of the game engine for replay analysis or bot development, and exploring vulnerability research opportunities in areas like the network protocol or custom map scripting language.

Demo / Proof of Concept

▶ Watch: Visual demonstration of deobfuscation in action (17:00)

While the talk did not feature a live, interactive demo, Carl Svensson presented clear, compelling "before and after" examples of his deobfuscation tool in action. He demonstrated how complex, highly obfuscated assembly and corresponding low-level IL, difficult to interpret even for experienced reverse engineers, could be transformed into significantly more readable code.

One notable example illustrated the obfuscation of a simple push instruction. Initially, this single operation was replaced by a series of instructions involving temporary registers (RCX in one instance) and stack manipulation, making its original intent obscure. After processing with Svensson's BNIL query system, the tool effectively identified this pattern, NOP'd out the obfuscated sequence, and inserted the simpler, equivalent push instruction. The resulting medium-level IL was dramatically clearer, directly showing registers being pushed to the stack.

Another example showcased a more intricate piece of obfuscated code, presenting its raw disassembly, its corresponding low-level IL, and the Lisp-like serialized version fed into Tree-sitter. The output post-deobfuscation was a much more streamlined and comprehensible block of IL. Svensson emphasized that while the deobfuscated code might not be "crystal clear" in all cases, the improvement in readability is substantial, making subsequent static analysis (e.g., understanding function arguments, control flow) far more manageable.

Svensson also announced the immediate release of his deobfuscation toolkit, available as both a library and a Binary Ninja plugin. This makes the proof of concept directly usable by other researchers. He highlighted its potential applications beyond game hacking, specifically mentioning deobfuscation workflows for malware analysis, which often employs similar techniques to evade detection and frustrate analysis.

Defensive Implications

▶ Watch: Q&A: Tool used for entropy analysis graph (22:30)

While Carl Svensson's talk focuses on breaking protection mechanisms, the insights gained offer valuable lessons for software defenders and developers. Understanding the techniques used to circumvent encryption and obfuscation is crucial for building more resilient defenses.

For game developers and software vendors, the talk underscores the reality that custom encryption and obfuscation, while delaying analysis, are not insurmountable security measures. Relying solely on security by obscurity is insufficient. The multi-layered encryption (AES, TEA) and local code transformations in Age of Empires II were eventually reverse engineered. This highlights the need for a layered security approach that includes robust anti-tampering measures, integrity checks, and potentially server-side validation for critical game logic or sensitive data, rather than just client-side obfuscation. Developers should also be aware that common choices like AES-ECB with a hardcoded key are particularly vulnerable once the key is extracted.

For general security practitioners and malware analysts, Svensson's methodologies provide directly applicable tools and techniques. The automated parameter extraction pipeline is highly relevant for analyzing malware that frequently updates its command-and-control (C2) protocols or encryption keys. Malware often uses similar custom packing or encryption schemes to evade signature-based detection. A "sieve approach" using IL patterns to locate decryption routines and extract keys can significantly accelerate malware analysis across numerous samples.

Furthermore, the Binary Ninja IL query system for deobfuscation is a powerful asset. Malware frequently employs various code obfuscation techniques (e.g., junk code insertion, control flow flattening, instruction substitution) to complicate static analysis. A customizable pattern-matching system that operates on a high-level IL like BNIL can effectively undo these transformations, making the underlying malicious logic transparent. This capability can drastically reduce the manual effort required to analyze complex, obfuscated malware strains, enabling faster threat intelligence and defensive countermeasure development. The ability to generalize these tools from game reversing to malware analysis, as Svensson explicitly suggests, demonstrates their broad utility in the defensive landscape.

Key Takeaways

  • Multi-layered Protections Require Multi-layered Analysis: Modern software, even older games like AoE2:DE, can employ sophisticated, multi-layered protections (e.g., AES-ECB, TEA encryption, custom relocation handling, local code obfuscation) that necessitate a systematic, multi-stage reverse engineering approach.
  • Automation is Essential for Evolving Targets: For actively developed software with frequent patches, manual reverse engineering is unsustainable. Developing automated pipelines for parameter extraction (e.g., AES keys, hashes) and decryption, adaptable across versions, is critical for efficient and continuous analysis.
  • Intermediate Language (IL) is a Powerful Abstraction: Performing analysis and developing deobfuscation tools at the IL level (e.g., Binary Ninja's MLIL/BNIL) provides a higher-level, architecture-agnostic view of code, simplifying pattern matching and transformation compared to raw assembly.
  • Pattern Matching for Deobfuscation: Custom code obfuscations can be effectively undone using flexible pattern-matching systems that operate on IL. Tools built with libraries like Tree-sitter, allowing for wildcarding and relational constraints in queries, enable automated identification and replacement of complex, obfuscated instruction sequences with simpler equivalents.
  • Game Reversing as a Training Ground: Reverse engineering games, particularly those with moderate protection levels, serves as an excellent practical "playground" for developing and refining advanced reverse engineering tools and techniques that are directly transferable to other domains like malware analysis or vulnerability research.

About the Speaker(s)

Carl Svensson is a Security Engineer based in London, originally from Sweden. He is a prominent figure in the CTF (Capture The Flag) community, where he has actively participated in and organized numerous competitions. Svensson has also contributed to various publications throughout his career, including articles in Paged Out, a well-regarded security zine. His work on Age of Empires II: Definitive Edition began as a personal project, driven by his passion for competitive gaming and reverse engineering, showcasing his expertise in tackling complex software challenges and developing practical tooling.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

Svensson took a game hacking side project and squeezed a genuinely useful Binary Ninja deobfuscation pipeline out of it. Exporting BNIL to Lisp syntax to use Tree-sitter for pattern matching is exactly the kind of clever, transferable engineering I want to see at a reversing con.

Heather Calloway (CISO) — SOLID

A deeply technical walkthrough on building automated reverse-engineering pipelines to bypass commercial software protections. While the target is a video game, the research cleanly demonstrates that client-side obfuscation has a finite half-life against automated tooling.

→ Top-rated talks at RE//verse 2026

All talks from RE//verse 2026