How to See What C# Turns Into
I’ve been writing a lot recently about the C++ and assembly that C# code turns into when it’s run through IL2CPP and a C++ compiler. Today’s article shows you the steps so that you can see what your own game’s C# code turns into.
iOS Build on macOS
Open the Unity editor and go to File > Build Settings
. Under Platform
, choose iOS
then click Switch Platform
.
Click Build
, enter a folder name (e.g. iOS
), then click Save
.
When the build is complete, double-click Unity-iPhone.xcodeproj
to open Xcode.
Click the magnifying glass in the top-left corner of the Xcode window and type in MyType::MyMethod
to search for a method in your game. Press return and click each of the results until you find the corresponding C++ code.
Select the method’s C++ name (e.g. TestScript_Start_m1023860210
) and copy it to the clipboard. Click the “four squares” icon in the top-left of the text editor area and click Assembly
.
Press Command + F
and paste in the method’s C++ name into the text field.
Android Build on macOS
Open the Unity editor and go to File > Build Settings
. Under Platform
, choose Android
then click Switch Platform
.
Click Build
, enter an APK name (e.g. UnityPlayground.apk
), then click Save
.
When the build is complete, use Finder to open the Temp/il2CppOutput/il2CppOutput
directory. Click in the Search
field in the top-right corner of the Finder window and type MyType::MyMethod
to search for a method in your game. Double-click on the files that were found to open them in Xcode.
Press Command + F
and enter MyType::MyMethod
into the text field. Select the method’s C++ name (e.g. TestScript_Start_m1023860210
) and copy it to the clipboard.
Open the Terminal application and enter objdump --disassemble /path/to/project/Temp/StagingArea/libs/armeabi-v7a/libil2cpp.so > /path/to/output.s
. Replace /path/to/project
with the path to your Unity project and /path/to/output.s
with the path to a file to put the assembly code in.
Open the assembly code file (e.g. output.s
) in a text editor. Xcode may take a long time to open such a large file. Press Command + F
and paste in the method’s C++ name into the text field.
iOS Build on Windows
Make an iOS build per the macOS instructions and then inspect the C++ source code in the Classes/Native
directory. Xcode is not available to generate iOS assembly code on Windows.
Android Build on Windows
Make an Android build and inspect the C++ source per the macOS instructions. Use \path\to\android-ndk\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-objdump.exe
instead of just objdump
to generate the assembly code from a Command Prompt.