NationalSecurityAgency / ghidra

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

HCS12 Decompiler Jargon #4495

Open Zephurah opened 1 year ago

Zephurah commented 1 year ago

Describe the bug Decompiler for HCS12 processors adds unnecessary local variables to the decompiler window when analyzing functions. Not sure where the - 34 info is coming from, nowhere in the instructions is there a subtraction that's relevant to those registers / variables.

To Reproduce Steps to reproduce the behavior: 1.Load given binary 2.Apply either HCS12 or HC12 processor languages 3.Go to memory location 0xd6fc 4.See error

Expected behavior Decompiler window should show a simple line of code that should be as following:

if(NEO_Interrupt_Counter < 35) {
   break;
} else {
   NEO_Interrupt_Counter = 0;

Screenshots image image image image

Attachments Example issue.zip

Environment (please complete the following information):

astrelsky commented 1 year ago

The subtraction is from CMPB. I don't know anything about HCS12 but cmp instructions in most processors is an unstored subtraction. I'm not saying I'd implement it in sleigh that way, I'd actually avoid it for exactly this reason, but it looks like it has been implemented with subtraction.