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.

iOS Build on macOS - Build Settings

Click Build, enter a folder name (e.g. iOS), then click Save.

iOS Build on macOS - Save As

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.

iOS Build on macOS - Xcode Search

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.

iOS Build on macOS - Assembly Menu

Press Command + F and paste in the method’s C++ name into the text field.

iOS Build on macOS - Assembly Code

Android Build on macOS

Open the Unity editor and go to File > Build Settings. Under Platform, choose Android then click Switch Platform.

Android Build on macOS - Build Settings

Click Build, enter an APK name (e.g. UnityPlayground.apk), then click Save.

Android Build on macOS - Save As

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.

Android Build on macOS - Search in Finder

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.

Android Build on macOS - Found C++

Open the Terminal application and enter objdump --disassembly /path/to/project/Temp/StagingArea/libs/armeabi-v7a/ilbil2cpp.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.

Android Build on macOS - Disassemble Command

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.

Android Build on macOS - Disassembly

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.