NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.23k stars 5.84k forks source link

PPC: e_li D, SIMM20 incorrectly calculates the immediate value #2990

Closed bobataylor closed 3 years ago

bobataylor commented 3 years ago

Describe the bug SIMM20 only exports the lowest 16 bits of a 20-bit immediate value. This causes any immediate greater than 0xFFFF or less than 0x0000 to be incorrect. https://github.com/NationalSecurityAgency/ghidra/blob/5234839b24c418219e35d0902161ca47ce98ce91/Ghidra/Processors/PowerPC/data/languages/ppc_vle.sinc#L48

To Reproduce Find any e_li instruction that uses an immediate larger than 16 bits. Ghidra's assembler works for testing negative values, just remember to set the VLE register to 1.

Expected behavior SIMM20 should export all 20 bits of the immediate. Values like -0x1 and 0x12345 should work.

Actual:        70 7f 07 ff     e_li       r3, 0xffff
Expected:      70 7f 07 ff     e_li       r3, -0x1
Actual:        70 82 52 34     e_li       r4, 0x1234
Expected:      70 82 52 34     e_li       r4, 0x12345

Environment (please complete the following information):

Additional context Changing the size of the export to 3 bytes instead of 2 seems to fix the problem, but I'm not sure this is the best solution.

GhidorahRex commented 3 years ago

We have a fix in for this that should be ready in the next couple of days. I'll make a note of this issue when it gets merged.

mumbel commented 3 years ago

@GhidorahRex if you're looking into PPC fixes, any chance for some attention on 1672?

GhidorahRex commented 3 years ago

Fixed by b7499e1bc1c4f097de2312fad3acae990fb2ac43