chaoticgd / ghidra-emotionengine-reloaded

An extension for Ghidra that adds support for the PlayStation 2.
Apache License 2.0
118 stars 11 forks source link

Add Ghidra's unaligned MIPS load/store analyzer from upstream #62

Closed abelbriggs1 closed 2 months ago

abelbriggs1 commented 2 months ago

The standard implementations of memcpy/strcpy were often optimized to chains of paired unaligned ldr/sdr instructions. The resulting pcode is extremely ugly and impossible to read, so upstream Ghidra implemented a MipsPreAnalyzer which would detect paired instructions and combine them into a single 4-byte/8-byte memory operation.

This PR adds Ghidra's MipsPreAnalyzer to the repository which will work if the analyzed CPU is MIPS-R5900.

Inlined memcpy

Before: memcpy_before_fix

After: memcpy_after_fix

Inlined strcpy

Before: strcpy_before_fix

After: strcpy_after_fix

The resulting code is still a bit annoying in the case of strcpy, but it's still much more usable.

chaoticgd commented 2 months ago

I've tested it and it looks good. Thanks for finding this, I had no idea upstream had fixed this even before the first public release.

Maybe change the name that shows up in the GUI to something like "MIPS-R5900 Unaligned Load/Store Fixer" so people know it's the version from the extension.