Setting Up Ghidra
Introduction
Ghidra is a really useful tool for reverse engineering the code already written for the game. With it we are able to see the instructions called by the game to run and the offsets of those instructions. We use these offsets to tell ExLaunch where to inject our custom code.
IL2CPPDumper Allows us to automatically assign names to various points in the program such as functions and static data.
dnSpy is also a very useful tool here as its much more user friendly and allows us to easily find offsets. Just load the dummy DLLs produced by IL2CPPDumper.
Requirements
- Ghidra
- Ghidra Switch Loader or nx2elf
- The Ghidra Switch Loader loads the program with a base address of
0x7100000000
but we can change this pretty easily and its simpler.
- The Ghidra Switch Loader loads the program with a base address of
- IL2CPPDumper
- A Game Dump with exefs and romfs. We need specifically two files.
main
fromexefs/main
global-metadata.dat
fromromfs/Data/Managed/Metadata/global-metadata.dat
Importing to Ghidra
Run IL2CPPDumper on
main
andglobal-metadata.dat
from the game dump. This will output a bunch of interesting files toil2cpp_dump
folder. (mainlyil2cpp.h
,script.json
and a bunch of Dummy DLLs)il2cppdumper.exe main global-metadata.dat il2cpp_dump
Run the
il2cpp_header_to_ghidra.py
script onil2cpp.h
outputted from the previous step.Make sure
il2cpp_header_to_ghidra.py
andil2cpp.h
are in the same folder.python il2cpp_header_to_ghidra.py
Open Ghidra and create a new project.
Install the Ghidra Switch Loader Plugin.
- File > Install Extension > Click the Plus Icon > Select the Ghidra Switch Loader .zip
Import the
main
file.- File > Import File > Select
main
from game dump
- File > Import File > Select
double click the imported file to open it in code browser
Parse C Source
il2cpp_ghidra.h
- File > Parse C Source
- Click the pencil eraser icon to clear the current config
- Click the plus icon to add the
il2cpp_ghidra.h
file - Click Parse to Program
Run script
ghidra_with_struct.py
withscript.json
- Window > Script Manager
- Click the three lines icon to modify script directories
- Click the green plus icon to add a new directory
- Choose the IL2CPPDumper folder that contains all the .py scripts
- Close the script directories window
- Click the refresh button at the top right
- Find the
ghidra_with_struct.py
script from the list and click the green play button to run it - When prompted for the
script.json
file, choose thescript.json
file outputted by IL2CPPDumper
Run Auto Analysis
- Analysis > Auto Analyse main. This will take a long time.