I'm using Ghidra to reverse engineer an EXE file and save its assembly line code only. Does Ghidra have any function or scripts which exports the assembly line code? I don't want to manually copy the code from the Listing window.

1 Answer 1


Not sure if you ask about one line or the whole program.

One assembly line can be obtain for example by such script:

addr = toAddr(<address>)

if we are talking about the whole program

for instr in currentProgram.getListing().getInstructions(True):

but I guess the last one can take a while. More information can be found in the docs about Listing object.

  • Thank you so much, this is exactly what I wanted. The program has to be analyzed for this to work, I wrote a script which analyzes the program and then extracts the assembly code, but the issue is that the first time i run the script, it can't detect the current Listing window and gets a NoneType error (even though the script was analyzed), but if I run the script again after it has been analyzed once, then the assembly code is displayed. Is there a way where the script extracts the assembly code the first time the script has been run? Commented Jun 11, 2020 at 12:34
  • share a link to this script. I'll have a look Commented Jun 11, 2020 at 13:16
  • I fixed it, thank you for your time! Commented Jun 11, 2020 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.