lab313ru / ghidra_psx_ldr

Sony Playstation PSX executables loader for GHIDRA
231 stars 31 forks source link

PsxLoader: fix calculation of $gp with signed addition #60

Closed xyzz closed 2 years ago

xyzz commented 2 years ago

The code failed to account for addui being used with a signed operand. Fixes #57

For example in the following assembly:

CODE:80017644   07801c3c        lui         gp,0x8007
CODE:80017648   34c69c27        addiu       gp,gp,-0x39cc
CODE:8001764c   21f0a003        move        s8,sp

it would previously combine (0x80 << 24) | (0x07 << 16) | (0xc6 << 8) | (0x34 << 0) resulting in 0x8007c634. However, the correct value is 0x8006c634.

Added a lot of casts to (long) because otherwise java kept sign-extending everything.