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.

5

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.

| improve this answer | |
  • 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? – Sajjad Zulphekari Jun 11 at 12:34
  • share a link to this script. I'll have a look – Paweł Łukasik Jun 11 at 13:16
  • I fixed it, thank you for your time! – Sajjad Zulphekari Jun 11 at 16:55

Your Answer

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

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