From 129e2468285be11a0156ef52833daeb31d274c7d Mon Sep 17 00:00:00 2001 From: Aetias Date: Sun, 25 Feb 2024 09:51:53 +0100 Subject: [PATCH] Add `decompiling.md` --- CONTRIBUTING.md | 6 +++--- docs/decompiling.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 docs/decompiling.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4cc55a0d..9e5e071a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contribution guide - [Project structure](#project-structure) -- [Decompiling a function](#decompiling-a-function) +- [Decompiling](#decompiling) - [Code style](#code-style) - [Creating new `.c`/`.cpp` files](#creating-new-ccpp-files) - [Non-matching functions](#non-matching-functions) @@ -39,8 +39,8 @@ - `assets.txt`: The order of asset directories to put in the ROM - `*.sha1`: SHA-1 digests of different versions of the game -## Decompiling a function -WIP +## Decompiling +See [/docs/decompiling.md](/docs/decompiling.md). ## Creating new `.c`/`.cpp` files New source files must be added to the LCF (Linker Command File). This is done via `lcf.py`, which generates the LCF when diff --git a/docs/decompiling.md b/docs/decompiling.md new file mode 100644 index 00000000..74c3125e --- /dev/null +++ b/docs/decompiling.md @@ -0,0 +1,41 @@ +# Decompiling +This document describes how you can start decompiling code and contribute to the project. Feel free to ask for help if you get +stuck or need assistance. +- [Decompiling a function](#decompiling-a-function) +- [The Ghidra project](#the-ghidra-project) + +## Decompiling a function +Say you've found a function you want to decompile. Here are the steps we recommend for decompiling it: +1. Visit [decomp.me](https://decomp.me/) and start decomping. +1. Under the platforms, select "Nintendo DS". +1. Select compiler version `2.0sp1p5`. +1. Copy and paste the target assembly for your function, including the `func_start` and `func_end` macros, and the pool constants. +For example: +```arm + .global func_ov09_0211bf48 + thumb_func_start func_ov09_0211bf48 +func_ov09_0211bf48: ; 0x0211bf48 + ldr r0, _0211bf50 ; =data_ov09_0211f59c + ldrb r0, [r0] + bx lr + nop + thumb_func_end func_ov09_0211bf48 +_0211bf50: .word data_ov09_0211f59c +``` +6. Run `m2ctx.py include/MyHeader.hpp -c` to generate a context and put it in your clipboard. + - If no suitable header file exists, make a new one and put any structs and types you need in there. +1. Paste the context into decomp.me, and create the scratch. +1. Copy the `CC_FLAGS` from `Makefile` into the arguments field in decomp.me. + - Replace the `-d $(REGION)` flag with whichever region you intend to decompile for. You can also delete the flag entirely + if the function contains no region differences. +1. Decompile the function and try to get a 100% match. + - There's no ARM decompiler in decomp.me yet, but Ghidra does the job quite well. See [the Ghidra section](#the-ghidra-project) + for more info. + - If you're unable to get a 100% match, share your decomp.me scratch with other contributors and they may assist you. + - In the worst case, you can also contribute [non-matching functions](/CONTRIBUTING.md#non-matching-functions) to this + project. + +## The Ghidra project +We use a shared Ghidra project to analyze the game and decompile functions. We can't give access to the Ghidra server just yet, +so come back here later for instructions on how to access it. +