← IL2CPP
IL2CPP·Guide
All tools

The IL2CPP tool

Unity games built with IL2CPP don't ship .NET assemblies: their C# is translated to C++ and compiled into libil2cpp.so (Android) or UnityFramework (iOS). What remains of the managed code is global-metadata.dat, which keeps every type, method, field, property, parameter name, token and string literal. The tool reads it, and with the matching binary resolves type references, field offsets and method addresses, and shows each method's disassembly and decompiled pseudocode. Everything runs in your browser; nothing is uploaded.

Contents

  1. The files
  2. What the tool shows
  3. Limits
  4. The libraries

1The files

2What the tool shows

3Limits

4The libraries

The tool is a page on top of four JavaScript modules with no user interface, which can be used elsewhere (another page, a Web Worker, or jsc). Each imports what it needs: lib/il2cpp-types.js builds on the ARM64 disassembler and decompiler shared with the native viewers (lib/arm64-disasm.js, lib/decompiler-core.js, lib/arm64-decompiler.js).

import { Il2CppMetadata } from "../lib/il2cpp-metadata.js";
import { Il2CppBinary } from "../lib/il2cpp-binary.js";
import { Il2CppDecompiler } from "../lib/il2cpp-types.js";
import { Il2CppDump } from "../lib/il2cpp-dump.js";

lib/il2cpp-metadata.js — Il2CppMetadata

An Il2CppMetadata is a parsed global-metadata.dat; its static methods describe types and methods.

MethodWhat it does
Il2CppMetadata.parse(arrayBuffer)
new Il2CppMetadata(arrayBuffer)
The metadata (throws on a missing magic or an unsupported version): version, header, types, methods, fields, params, properties, events, images, assemblies, literals, generic containers and parameters, stats and warnings, with helpers: str(index), typeFullName(type), typeNestedName, typeSimpleName, typeRefName(typeIndex) (null when it needs the binary), typeDefOfRef(typeIndex), outermost(type), genericNames(containerIndex), fieldDefault(index), paramDefault(index); and unityHint, names, regionDesc, headerSize, sizes, byteLength.
Il2CppMetadata.typeKind(type), typeModifiers(type)"class", "struct", "enum" or "interface"; the C# modifiers.
Il2CppMetadata.methodModifiers(method, inInterface), methodImplFlags(method)A method's C# modifiers; its implementation flags (internal call, noinline…).
Il2CppMetadata.SANITYThe magic, 0xFAB11BAF.

lib/il2cpp-binary.js — Il2CppBinary

MethodWhat it does
Il2CppBinary.parse(arrayBuffer, metadata)
new Il2CppBinary(arrayBuffer, metadata)
Applies the relocations (in place), finds Il2CppCodeRegistration and Il2CppMetadataRegistration (throws when they aren't found), and returns the binary: arch, machine, is64, ps (pointer size), segs, metaReg, codeGenModules, mapped, textRange, typeName(typeIndex), typeAttrs, typeShape, methodAddr[methodIndex], fieldOffsets(typeIndex), typeSizes, genericMethods, the code ranges with rangeAt(address) and rangeName(range), the runtime metadata slots (usages, literalSlot), describeAddr(address), buildXrefs() (string-literal uses and callers), dynSyms(), vaToOff(address), readU32(address), isCode(address), usageKindName(kind), buffer and dv (a DataView on the relocated file).

lib/il2cpp-types.js — Il2CppDecompiler

MethodWhat it does
Il2CppDecompiler.decompile(metadata, binary, range, method){ res, params }: the ARM64 decompiler's result for a code range (res.lines, res.text), with IL2CPP's calling convention and the metadata's types applied.
Il2CppDecompiler.disassemble(binary, range){ rows, text }: each instruction with a note (described data address, called method, metadata-slot initialisation) and whether it is a branch target.
Il2CppDecompiler.makePass(metadata, binary, shapes), isResolver(binary, address), finalTarget(binary, address)The decompiler pass itself, and helpers that follow the runtime's stubs.

lib/il2cpp-dump.js — Il2CppDump

MethodWhat it does
Il2CppDump.fileKind(arrayBuffer)"meta", "elf", "macho" or "?".
Il2CppDump.buildIndex(metadata), imageRank(name)Images with their types by namespace, app code first.
Il2CppDump.typeLines(metadata, binary, type), lineText(line)A type's C# skeleton as lines of tokens [className, text] (kw, ty, nm, str, num, cm, ur), or as text. binary may be null.
Il2CppDump.declarationLine, methodDisplayName, methodParams, methodSignature, methodFullName, typeReferenceName, fieldModifiersThe pieces of the skeleton.
Il2CppDump.filterTypes(metadata, name, member, cap)Types matching a name and a member name, with the matching members.
Il2CppDump.dumpCs(metadata, binary, index, fileName, binaryName)The text of dump.cs.
Il2CppDump.scriptJson(metadata, binary)An Il2CppDumper-style script.json object.
Il2CppDump.fridaHook(metadata, binary, method, range, instantiation)A Frida Interceptor snippet for a method's code.
Il2CppDump.literalTags(text), LITERAL_TAGSThe heuristic categories of a string literal.
Il2CppDump.headerRecordSizes(metadata)The record size of each header region.
import { Il2CppMetadata } from "../lib/il2cpp-metadata.js";
import { Il2CppBinary } from "../lib/il2cpp-binary.js";
import { Il2CppDecompiler } from "../lib/il2cpp-types.js";
import { Il2CppDump } from "../lib/il2cpp-dump.js";

const metadata = Il2CppMetadata.parse(metadataBuffer);
const binary = Il2CppBinary.parse(libil2cppBuffer, metadata);
const type = metadata.types.find(t => metadata.typeFullName(t) === "PlayerController");
console.log(Il2CppDump.typeLines(metadata, binary, type).map(line => Il2CppDump.lineText(line)).join("\n"));
const update = metadata.methods[type.methodStart];
const range = binary.rangeByStart.get(binary.methodAddr[update.i]);
console.log(Il2CppDecompiler.decompile(metadata, binary, range, update).res.text);