Adubbz / Ghidra-Switch-Loader

Nintendo Switch loader for Ghidra
ISC License
283 stars 43 forks source link

[Feature Request] Allow decompiling A32 instructions #57

Open M1CR0H4CK3R opened 2 months ago

M1CR0H4CK3R commented 2 months ago

Monster Hunter Rise: Sunbreak contains exactly 3 trap instructions, and ghidra currently cannot decompile them, because SwitchLoader does not support A32 instructions. Can this be rectified? In the v16.0.2 update, they're at 0x71025562CC, 0x7106CE3E4C, and 0x7107221990. Thanks.

masagrator commented 2 months ago

Rise is using AARCH64 instruction set which doesn't use THUMB instructions.

From the ARMv8 Reference Manual, §A1.3.2 (p. A1-35):

AArch64 state supports only a single instruction set, called A64. This is a fixed-length instruction set that uses 32-bit instruction encodings.

M1CR0H4CK3R commented 2 months ago

Okay, apparently it is actually an A32 instruction, not a T32 instruction. image It's simply a trap instruction. There's 3 of them, but 1 of them is neutered. The 2 unneutered ones are for pausing the game during both village quests and hub quests. The neutered one is for pausing the game while playng online (which isn't possible normally, as the option is grayed out). MHR does a pseudo-breakpoint in order to pause the game, only resuming code and gameplay upon a specific button press. Because A64 code cannot resume the game when these happen, it needs to switch to A32. Apparently, SwitchLoader does not support A32, despite what I thought.

M1CR0H4CK3R commented 2 months ago

I edited my issue description as well above.

M1CR0H4CK3R commented 2 months ago

The issue is that the instruction refuses to decompile. And the instruction sets available online for ARMv8-A specifically omit this instruction.

M1CR0H4CK3R commented 2 months ago

image

image

masagrator commented 2 months ago

It supports A32 instructions. You are wrongly assuming that Switch games can use mixed instructions sets - they can't.

So what's going on? That's hardcoded ptrace breakpoint that Ghidra struggles what to do with since it's not a part of standard instruction set. Issue is completely unrelated to this loader.

https://github.com/NationalSecurityAgency/ghidra/issues/3723