0

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

6

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>)
print(currentProgram.getListing().getInstructionAt(addr))

if we are talking about the whole program

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

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

3
  • 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? Jun 11, 2020 at 12:34
  • share a link to this script. I'll have a look Jun 11, 2020 at 13:16
  • I fixed it, thank you for your time! Jun 11, 2020 at 16:55

Your Answer

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

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