Skip to content

how to import with NTRGhidra #2

@DaisukeDaisuke

Description

@DaisukeDaisuke

WARNING: This analysis environment may contain viruses. Please take all possible measures, such as using a virtual environment.

what you need


Installing dependencies

vc_redist.x64.exe

Skipping is fine, but install vc_redist.x64.exe (Microsoft Visual C++ Redistributable Package) if necessary

jdk-23_windows-x64_bin.exe

jdk should also be installed at the default location if possible

ghidra 11.0.3

Please use 7zip or similar to unzip ghidra
In Explorer, right-click on the file (advanced in win11) > 7-zip > ghidra_11.0.3_PUBLIC_* to extract
In the extracted folder, double-click ghidraRun.bat to start ghidra


See this site for assembly analysis tutorial
https://www.starcubelabs.com/reverse-engineering-ds/

ghidra

Caution

Do not allow Ghidra in Windows Defender, as it may take over your computer

Next, unzip Ghidra.
Second, place ghidra_11.0.3_PUBLIC_20240411_NTRGhidra.zip as is in the GHIDRA_INSTALL_DIR/Extensions/Ghidra folder.
image
Third, click ghidraRun.bat to start ghidra
Then, in the Ghidra window (not in the code browser), open the File menu, select Install Extensions, check on NTRGhidra, and click OK  
image

image

Then quit Ghidra and start it again by running ghidraRun.bat
After startup is complete, open the File > New Project window, select Non-Shared Project, and click next.
Create a project with a project name of your choice.
Next, insert the NDS file directly
image

In this window, click arm9

image

In this window, click Yes

image

In this window, click OK

image

Once you have selected your language, click ok. ghidra will then start the import and display the technical details. Click ok on that too
Then double click on the file to open the disassembler

image

In this window, click Yes

image

To be sure, uncheck Non-Returning Functions - Discovered. This will disable the analysis that automatically discovers functions that do not return to the parent
"Non-Returning Functions - Discovered", in my experience, is a hindrance when analyzing code that directly manipulates the PC (PC is the current execution position of the CPU)

image

Press Analysis and wait about 20 minutes

Edit Tool options.
Select Edit > tool Option. Then select Listing Fields > Operands Field and uncheck Markup Register Variable References.
This prevents the register from being marked up as an argument, making it easier to see

image

image

Once the analysis is finished, press the play mark to open the script manager
image

Then click on the paper mark, select Python and press ok
image

image

image

image

Copy and paste import_symbols_json.py with GPL-3.0 license into the editor that appears
https://github.com/UsernameFodder/pmdsky-debug/blob/master/tools/ghidra_scripts/import_symbols_json.py

https://raw.githubusercontent.com/UsernameFodder/pmdsky-debug/master/tools/ghidra_scripts/import_symbols_json.py

image

Press play button to run

image

Select symbol_jpn/output/ram/arm9_ram_jpn.json from the unzipped symbol_jpn.zip

image

Similarly, import output/battle/arm9_battle_jp.json and output/field/arm9_field_jp.json as needed.
Once done, close the script manager

You have now imported the function names and descriptions posted in this repository.

example

Press the G key, type jp: 0209cd4c eu:0x209AFE4 in the window that appears, and press Enter.
image
This is a function that uses BT to generate the number of bodies in the first group and the types of the second and third groups.

Have fun exploring the assembly!

Q&A

Q: My Ghidra is broken, how do I fix it?

A: Please delete the %USERPROFILE%\.ghidra\ and start all over from scratch

Q: Can I allow Windows Defender?

A: NOOOOO, uncheck everything and never allow Windows Defender. Your computer may be hijacked
All reverse engineering can be done offline!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions