NationalSecurityAgency / ghidra

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

feature/bug: 6502 operands have several display issues when referencing memory #3316

Open sarchar opened 3 years ago

sarchar commented 3 years ago

I'd like to start a small discussion about how to improve the display of operand references in 6502 disassembly.

I've been looking at 6502 disassembly for the better part of a year, so I'm fairly accustomed to the quirks in Ghidra's 6502 disassembly. I understand that 6502 isn't a priority, but I think these display changes probably aren't major in terms of code changes .. and maybe someone would be inspired to fix them. I'd also be willing to tackle them myself, if there's some guidance on where to start.

Basically, there are several places where memory references should be changed to be more consistent with 6502 assembly code.

  1. Any memory reference to zero-page address $0 gets a memory reference with "=>" on the right of the operands, when it really should just be like any other memory reference and replace the operand with the reference.

  2. Offset references should be displayed in code. The most glaring one is when you do something like "sta buffer+5". Ghidra would create a dynamic label to buffer[5] (which isn't really ever seen in 6502 assembly), but when you apply an Offset to the reference of -5, it changes the display to "offset buffer" and loses all sense of what the offset is. It would be best to show "buffer+5" where +5 isn't part of the label.

  3. Jump tables are quite frustrating to work with when they're offset by a value, which is quite common in 6502 where the RTS instruction adds 1 to the return address. So jump tables often have the label with an offset of 1, but Ghidra doesn't show that in the disassembly.

Does anyone have suggestions for how to work with these quirks, or is this an issue that we could see a fix for? You can look at the assembly in my github repository (at https://github.com/sarchar/GhidraBugFeature), and here below is my demonstration of what I see in Ghidra when I start analyzing the file:

zeropage

main1

main2

Cheers, and I much appreciate everyone's time and work they've put into this project.

agatti commented 2 years ago

@sarchar I believe your first point is already covered by #982.

sarchar commented 2 years ago

@sarchar I believe your first point is already covered by #982.

Ah, yes. Indeed it looks like the same issue.