How can I extract a code listing from a Ghidra project such that I can reassemble with something like vasm? I have gone through a memory snapshot and disassembled the code and marked data sections etc. to a point where I would like to check my work.
Further to the question and answer in Extracting Assembly line code from an executable in Ghidra I would like to extract line labels, plate comments and EOL comments.
Here is an example:
Here's what I'd like the extracted code to look like:
; Extracted data blocks
STATUS_STRING_BUFFER:
dc.b 0
dc.b 0
dc.b 0
dc.b 0
; etc
CURRENT_STATUS_MESSAGE_CODE:
dc.b 0
; Extracted subroutine
**************************************************************
* Display a message in the status bar *
**************************************************************
DisplayStatusMessage:
movem.l {a2, a1, d5},-(sp)
lea STATUS_STRING_BUFFER, a1
clr.w d0
move.b (a0)+,d0
move.b d0,CURRENT_STATUS_MESSAGE_CODE ; Store Message byte
andi.b #$7f ; Mask out msb
; ... etc
As you can see there are a number of things to do including:
- Extract data blocks
- Convert
db
,dw
,ddw
todc.b
,dc.w
,dc.l
- Convert hex from
0xNN
to$NN
notation - Extract plate comments
- Extract labels
- Extract disassembled code lines
- Extract EOL comments
Is there a readily available script for this or can someone show a working example?