xur_

> module

std::re::dotnet::il2cpp

read Unity Il2Cpp games

use std::re::dotnet::il2cpp; feature re-dotnet-il2cpp native only

std::re::dotnet::il2cpp reads the type metadata of a Unity game built with Il2Cpp: its global-metadata.dat and its GameAssembly binary. Game is the entry point; it gives every type, field and method by name, and can generate .NET declaration assemblies to compile mods against.

TypeView is a handle on one type of the game. FieldView and MethodView are snapshots of a field or method; printing one shows a C#-like declaration such as static string Concat(string str0, string str1). Type names are C#-like too, such as List<int>.

Backed by hao-il2cpp.

> functions

# from_bytes(metadata: bytes, binary: bytes) -> Result<Game, str>

Read a game from the contents of those two files.

# from_files(metadata: str, binary: str) -> Result<Game, str>

Open a game from the paths of its global-metadata.dat and GameAssembly binary.

# open(path: str) -> Result<Game, str>

Open a game folder: the one holding GameAssembly.so or GameAssembly.dll and a *_Data folder with il2cpp_data/Metadata/global-metadata.dat.

> types

┌ type FieldView
# field_view.constant() -> Option<ConstantValue>

The field's compile-time constant (enum members and const fields), if it has one.

# field_view.is_static() -> bool

Whether the field is static.

# field_view.name() -> str

The field's name.

# field_view.type_name() -> str

The field's type, such as "List<int>".

┌ type Game
# game.bytes_at(vaddr: u64, len: usize) -> Option<bytes>

len bytes of the GameAssembly binary at virtual address vaddr, such as a method's code_address(); None if they aren't mapped.

# game.find_type(name: str) -> Option<TypeView>

The type with full name name, such as "UnityEngine.GameObject", "Outer/Nested" or "List`1".

# game.image_names() -> list<str>

The assembly names, such as "Assembly-CSharp.dll".

# game.types() -> list<TypeView>

Every type definition in the game.

# game.write_assemblies(dir: str) -> Result<list<str>, str>

Generate a declaration assembly for every image and write them to dir, returning their paths.

┌ type MethodView
# method_view.code_address() -> Option<i64>

The virtual address of the method's native code in the GameAssembly binary, if known. Read it with Game.bytes_at().

# method_view.is_static() -> bool

Whether the method is static.

# method_view.name() -> str

The method's name.

# method_view.parameter_names() -> list<str>

The parameter names, in order.

# method_view.parameter_type_names() -> list<str>

The parameter type names, in order, such as ["string",\"int"].

# method_view.return_type() -> str

The return type's name.

┌ type TypeView
# type_view.base_type_name() -> Option<str>

The base type's name, such as "UnityEngine.MonoBehaviour", if it has one.

# type_view.declaring_type() -> Option<TypeView>

The type this one is nested in, if any.

# type_view.enum_values() -> list<(str, i64)>

For an enum, each member's name and value; empty for other types.

# type_view.fields() -> list<FieldView>

The type's fields.

# type_view.find_field(name: str) -> Option<FieldView>

The field named name.

# type_view.find_method(name: str) -> Option<MethodView>

The first method named name; use methods() to see every overload.

# type_view.flags() -> i64

The type's TypeAttributes as an integer; see dotnet::type_attributes_names().

# type_view.full_name() -> str

"Namespace.Name", with / before a nested type's name.

# type_view.image_name() -> str

The assembly the type is in, such as "Assembly-CSharp.dll".

# type_view.methods() -> list<MethodView>

The type's methods, overloads included.

# type_view.name() -> str

The type's name.

# type_view.namespace() -> str

The type's namespace.

# type_view.nested_types() -> list<TypeView>

The types nested directly in this one.

> examples

use std::io;
use std::re::dotnet::il2cpp;

fn main() -> Result<(), str> {
    let game = il2cpp::open("path/to/game")?;
    for ty in game.types() {
        io::println("{}", ty.full_name());
        for method in ty.methods() {
            io::println("  {}", method);
        }
    }
    game.write_assemblies("out")?;
    Ok(())
}