Disassemble Sunshine Code

From Sunshine Wiki
Jump to navigation Jump to search

Most of the code that controls Super Mario Sunshine is contained within the main.dol file inside the games ISO. With a combination of a disassembler and a symbol map, we're able to convert the .dol into a more readable format, allowing us to

Setup[edit | edit source]

Ghidra Setup[edit | edit source]

This is a framework created by the NSA for reverse engineering of software. It has a lot of complex features, so looking for tutorials on how to use it could be helpful in the long run

  • Download 9.1.2 of Ghidra and extract it from the zip
  • Run ghidraRun.bat to launch the program. If it opens up to a screen like the image on this section, then close the program and continue to next step
What Ghidra should look like when you run the .bat with a valid Java version

If the command prompt has an error about no versions of Java were on the PATH:

  • Download the x64 Windows JDK zip file and extract it
  • Set the path variable to the location of the bin folder of you JDK
    • For Windows 10: Click on the windows search bar and type "About your PC" and select it
    • Click "System Info" on the right, and then click "Advanced System Settings" on the right of the new window
    • Under System variables, highlight Path and click Edit
    • Click the new button on this window, put the path of your extracted JDK folder with \bin added at the end
    • Then hit Ok on the windows to close them all. Your JDK path should now be set

ghidra-gekko-broadway-lang[edit | edit source]

This is a language addon for Ghidra that allows it to read gamecube code

  • Download ghidra-gekko-broadway-lang and extract it from the zip
  • Copy all the files from the data/languages folder to <Ghidra install directory>/Ghidra/Processors/PowerPC/data/languages

Ghidra Gamecube Loader[edit | edit source]

This is an extension for Ghidra that allows it to import and load gamecube binary code

  • Download the Ghidra 9.1.2 Support release of Gamecube Loader. Do not extract it
  • Copy the zip file to <Ghidra install directory>/Extensions/Ghidra
  • Open Ghidra, and select File->Install Extensions
  • Click the checkbox next to the GameCubeLoader extension and hit Ok. If you were able to do this, continue to the next step

If the GameCubeLoader extension is red and you can't click the checkbox, make sure you have the correct version of Gamecube Loader and that it's the release version. If the zip file contains gradlew.bat, you have the non-production version and should click the releases button on the github project

.MAP File[edit | edit source]

The .map file, or the symbol map file, is the way we make the dissembled code have variable and function names instead of hex and default names

  • Find out which version of Sunshine you have (US, PAL, JP, JPA). You will have to download the map file that corresponds to the region that you are dissasembling
  • Find your matching .map file and click on it. Right click the download button on the new page and click "Save link as..." and save it somewhere

Make sure the file is around 7.53 MB. If you have text at the bottom of the window that says "symbol map might not be loaded properly" during the disassembly steps, the map is wrong or corrupt. Contact the Sunshine Hut Discord for a working file and so we can remove the ones linked

Disassembly[edit | edit source]

At this point, you should have Ghidra running with the GameCubeLoader extension installed and the ghidra-gekko-broadway-lang languages added. Make sure you have an extracted ISO of the region of Sunshine that you got the .map file for

  • In Ghidra, go to File->New Project. Continue with the project creation steps until it shows you have an empty folder in your project view
  • Go to File->Import File. Locate the main.dol file. It should be located in your /sys folder of your extracted ISO
  • A window should pop up looking like the one on the side of this section. Make sure change the to language to the option with PowerPC, Gekko/Broadway, 32, big, default
The prompt for adding the .dol file to Ghidra
  • When you click Ok, it should prompt you for a MAP file. Select yes and select the .map file you downloaded earlier. Keep you eye out for the "symbol map might not be loaded properly" error at the bottom of Ghidra in case the MAP file is invalid
  • You have now correctly added a .dol file to disassemble. To actually view the code, double click on the main.iso file in Ghidra. Hit yes when it prompts to analyze, and use all the default selections that it gives you.

If done correctly, you should have named classes that you can look through. If the function folder on the left side of the Code Browser window is full of FUN_<numbers> folders and objects, your MAP file didn't work. Double check that you have the right region and that the file is the right size. If both of those are correct, contact someone in the Sunshine Hut Discord for a different .map file, or if you just need other help in general

View of the code browser for main.dol with a working .map file