Changes

Create page describing how to use Ghidra for reverse-engineering relevant stuff.
{{Infobox homebrew
| title = Ghidra
| image = [[File:Ghidra Logo.png|200px]]
| type = pc utility
| author = National Security Agency
| licence = Apache + Public Domain
| download = https://ghidra-sre.org/
| website = https://ghidra-sre.org/
| source = https://github.com/NationalSecurityAgency/ghidra
}}

[https://en.wikipedia.org/wiki/Ghidra Ghidra] is a FOSS reverse-engineering tool by the US National Security Agency. It includes a disassembler and a decompiler.

== Use with GameCube/Wii games ==

Ghidra does not include a GameCube loader by default, nor does it understand [[Hardware/Broadway|Broadway]]'s slightly extended instruction set featuring [[paired single]]s. However, this can be fixed by installing [https://github.com/aldelaro5/ghidra-gekko-broadway-lang ghidra-gekko-broadway-lang] and [https://github.com/Cuyler36/Ghidra-GameCube-Loader Ghidra-GameCube-Loader]. After these are installed, [[DOL]] and [[REL]] files can be imported using the normal import system. <!-- TODO: Explain how to overlay REL files in a way that makes sense, if that's been implemented --> To extract those files from a [[Wii Disc|disc image]], one option is to open the properties for the disc in [[Dolphin]], go to the filesystem tab, right-click, and select "Extract System Data" (or "Extract Entire Disc"/"Extract Entire Partition"). If a game [https://wiki.dolphin-emu.org/index.php?title=Ships_with_Debugging_Symbols includes debug symbols], then those can also be imported. When importing an [[ELF]] file, make sure to select the Gekko/Broadway PowerPC variant (which is selected by default for DOL and REL files).

== Use with [[IOS]] ==

Ghidra can naturally import some IOS [[ARM Binaries]], specifically those that are just regular [[ELF]] files. However, it will produce bad results due to the use of undefined instructions for [[IOS/Syscalls|syscalls]]. A [https://gist.github.com/Pokechu22/caa73242a5969ff5dc413177fcb7f516 language definition] exists to fix this (though it will not produce the cleanest results since it doesn't know what various registers are used/changed by each syscall). <!-- TODO: I should create a more meaningful GitHub repo for this --> For ELFLOADER files (used for monolithic IOS versions, and the kernel in non-monolithic IOS versions), the file must be converted to a normal ELF file first (by removing everything before the ELF header, or using [[ARM_Binaries#Extract_ELF_file|the program on the ARM Binaries page]]). <!-- TODO: Write a loader -->

== Use with [[Hardware/Disc Drive|Disc Drive]] firmware ==

A [https://github.com/Pokechu22/ghidra-mn102-lang/ MN102 processor spec] exists.
303

edits