Unity IL2CPP Save File Encryption: A Reverse Engineering Walkthrough

    This article walks through a practical workflow for locating and analyzing save file encryption in Unity projects built with IL2CPP. It covers restoring symbols and string constants from native libraries and metadata, mapping RVA, VA, and file offsets, identifying encryption configuration functions, extracting and validating candidate keys, and parsing the decrypted save structure. It also outlines the security implications of hardcoded keys and the compliance boundaries for working only on local copies.

    1. Background and Problem Definition

    In Unity projects, save persistence is usually handled by a serialization framework. When a project is compiled with IL2CPP, C# managed code is translated into C++ and compiled into a native dynamic library, while symbol information is stripped during the release stage. As a result, conventional managed decompilation no longer works. Locating save encryption logic therefore has to move down to the native binary level, using a three-step approach: metadata restoration, offset calculation, and constant search.

    The technical path discussed here falls within the analysis of local data structures. Its engineering value lies in understanding how encryption configuration is written into saves, what form the key takes in the program’s constant area, and how save fields are organized. All operations should be performed on copies you own, with local backups in place.

    2. Toolchain and Role Separation (Vendor Neutral)

    The workflow can be abstracted into four capabilities, none of which need to be tied to a specific product:

    1. Symbol restoration: Read the native library and the global metadata file, reconstruct class names, method names, and the string constant table, and output proxy assemblies that can be imported along with a constant inventory.
    2. Managed structure inspection: Load the proxy assemblies, search by class name and method name, read the address attributes on method bodies, and obtain the relative virtual address and file offset.
    3. Hex viewing and navigation: Jump to machine code by file offset and verify instruction meaning byte by byte.
    4. Text search and structured editing: Run regex searches over the constant inventory, and perform field level editing and format validation on the exported structured save text.

    Any equivalent general purpose combination of tools can replace these four capabilities. This article only describes their input and output contracts, not any specific implementation.

    3. Stage One: Symbol and Constant Restoration

    Feed the native library file and the metadata file into the restoration flow as two inputs. Once processing completes, the output typically has two parts: a directory of proxy assemblies and a string constant inventory file.

    Key engineering points:

    • Input files must be paired from exactly the same build version. When the native library and the metadata come from different versions, method addresses shift as a whole and every subsequent offset calculation becomes invalid.
    • The constant inventory is the highest value entry point. Most encryption schemes compile the passphrase into the constant area as a plaintext string, so searching for the save class name and encryption related keywords can hit candidate passphrases directly.
    • Keep hashes of the original artifacts. Record digest values for both the input files and the output inventory to make later reproduction and version comparison easier.

    Illustrative validation flow:

    1. Input: native_lib + global_metadata
    2. Process: symbol reconstruction
    3. Output: proxy_assemblies/ , string_constants.json
    4. Validation: record input/output digests, confirm version match

    4. Stage Two: Locating the Save and Determining Encryption State

    On desktop platforms, Unity local saves generally live under the LocalLow level of the user directory. The path consists of three segments: company identifier / product identifier / save directory, and save files are usually named after slot numbers.

    Operating rules:

    1. Back up before analyzing. Copy the entire save directory to form a read only baseline, and run all experiments against that copy.
    2. Determine whether encryption is enabled. Open the save in a text editor. If it starts with readable structured markers such as key value pairs, encryption is not enabled. If it is a stream of high entropy bytes with no discernible pattern, block encryption is highly likely.
    3. Sample and compare. Compare the first several bytes of two different slot files. If the prefixes are identical and the content diverges afterward, there is a fixed header or a fixed initialization vector, a characteristic that is critical for later parsing.

    5. Stage Three: Locating the Encryption Configuration Function and Converting Offsets

    After loading the proxy assemblies into the managed inspection tool, search globally by the save manager class name. This usually locates the factory method responsible for constructing the encryption settings. IL2CPP output retains address attributes above the method body, in a form like:

    1. [Address(RVA = "0x73E650", Offset = "0x73D450", VA = "0x18073E650")]
    2. private ES3Settings CreateEncryptedSettings(string filePath)

    The relationship among the three values needs to be clear: VA is the absolute virtual address inside the process, RVA is the offset relative to the module base, and Offset is the physical offset in the file. The difference between them is the shift introduced by section alignment, and the conversion formula is:

    1. Offset = RVA - (VA - ImageBase)

    After jumping to that file offset in a hex viewer, focus on two kinds of instruction patterns:

    • Switch write: For example C7 43 20 01 00 00 00, which writes 1 to the field at offset 0x20 of a structure, meaning encryption is enabled.
    • Passphrase load: The push or mov immediate that follows is often the index or address of a string constant in the constant area. Following it leads back to the constant inventory to pin down the plaintext passphrase.

    Engineering tip: organize the address, bytes, and semantic explanation of each key instruction into a table to form a reviewable analysis record, rather than relying on memory alone.

    6. Stage Four: Key Extraction and Validation

    With a candidate passphrase in hand, use a general purpose encryption editor or a custom script to decrypt a copy of the save. There are three validation criteria:

    1. The decrypted result should begin with readable structured text.
    2. The field hierarchy and naming should match a conventional save model (slot, timestamp, progress integers, and so on).
    3. Re-encrypting the result should be byte for byte identical to the original file, which shows the passphrase and mode, including initialization vector and padding, match completely.

    If validation fails, check three things first: whether the passphrase is another one of the candidates, whether a fixed salt is concatenated, and whether the block mode is a chained mode with an initialization vector.

    7. Stage Five: Parsing the Save Structure and Security Takeaways

    The decrypted structured text usually contains slot metadata and business fields. During analysis, pay attention to field types and value ranges, and build a field dictionary to support later compatibility migration or corruption repair.

    From a defensive perspective, the lesson here is clear: a passphrase hardcoded in the constant area reduces encryption to obfuscation. A more sound engineering approach is to use device bound key derivation, implement integrity checks such as a message authentication code separately from encryption, and mark saves with both a version number and a checksum, so that changes to the field structure do not fail silently.

    8. Risk and Compliance Boundaries

    • Work only on copies you own and in a local environment, and keep the original backups and operation logs.
    • Use analysis conclusions for technical learning and security hardening, not for damaging other people’s data.
    • When cloud capabilities are involved, generic categories can be used, such as object storage for backup retention, a logging service for operation auditing, and monitoring alerts for suspicious access notices, without binding to any specific vendor interface.