3

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:

example Ghidra screenshot

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:

  1. Extract data blocks
  2. Convert db, dw, ddw to dc.b, dc.w, dc.l
  3. Convert hex from 0xNN to $NN notation
  4. Extract plate comments
  5. Extract labels
  6. Extract disassembled code lines
  7. Extract EOL comments

Is there a readily available script for this or can someone show a working example?

2
  • Have you looked at the "Export Program" menu dialog? None of the options in that dialog do exactly what you are looking for, but the C/C++ export and the ASCII export could be combined by some other script to produce what you are looking for. Nov 15 at 16:22
  • @dingo_kinznerhook Yes, this could be a starting point. I may have to run a script outside of Ghidra to do what I want. Nov 18 at 8:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.