Inspired by
- @djkaty's IL2CPP Reverse Engineering Part 1: Hello World and the IL2CPP Toolchain article
- @jacksondunstan's How to See What C# Turns Into article
For whom
For Unity programmers and Unity performance engineers.
Aim
This tool aimed to see literally "What C# Turns Into" but without Unity compilation time overhead for fast proving or disproving your performance assumptions.
How to use
Based on il2cpp.ps1 but rewritten for my purposes and wishes. Read script yourself for more understanding. Or read the articles above.
- Clone repo or just download the il2cpp.ps1 file to directory you want
- Create
unity_search_path.txt
and paste Unity installation directory path (usuallyC:\Program Files\Unity\Hub\Editor
) to it (Optional, but recommended) - Create
android_ndk_search_path.txt
and paste Android NDK directory path to it (Optional, but recommended) - Create directory
TestSources
and place your.cs
files into it - Call script with required parameters in PowerShell
il2cpp.ps1 [sourceFileWithoutExtension,...] [unityVersionOrFullPath] [ndkVersionOrFullPath] [target,...]
- It should create next dirs:
TestAssemblies
- contains compiled dll'sTestBinaries
- contains compiled binary for specified targets (x86, x64, armv7 or arm64)TestCpp
- contains compiled.cpp
files
Usage example
- Suppose in file
unity_search_path.txt
we specifiedC:\Program Files\Unity\Hub\Editor
path and that path contains2019.4.33f
directory (with installed Unity, ofc) - Suppose in file
android_ndk_search_path.txt
we specifiedC:\Users\Brown2Fox\DevTools\Android\Ndk
path and that path containsandroid-ndk-r19c
directory (with installed NDK, ofc) - Suppose directory
TestSources
contains fileMyTest.cs
- Then we call in PowerShell command
il2cpp.ps1 MyTest 2019.4.33* *r19c armv7
and get the result
Some other notes
- You can specify no target (x86, x64, armv7 or arm64) if you interested only in cpp part
- Remove
UnityEngine.CoreModule.dll
from$csrefs
var in script if you want test simple C# without Unity's stuff (and for speeding up binary compilation time) - Resulting cpp files can varies depending on
csc
andil2cpp
compilation options- By default for
csc
specified-optimize+
option and foril2cpp
specified--configuration=ReleasePlus
option - Tweak script to change this behavior
- By default for