cesena / ghidra2dwarf

🐉 Export ghidra decompiled code to dwarf sections inside ELF binary
MIT License
179 stars 17 forks source link

Ghidra2Dwarf not working with these binaries #5

Closed meowmeowxw closed 3 years ago

meowmeowxw commented 3 years ago

Saas

saas from MhackeCTF:

section_count 6
Traceback (most recent call last):
  File "ghidra2dwarf/src/ghidra2dwarf.py", line 443, in <module>
    write_detached_dwarf_file(exe_path)
  File "/ghidra2dwarf/src/ghidra2dwarf.py", line 386, in write_detached_dwarf_file
    section_name = debug_sections[section_index]
IndexError: index out of range: 0L
ghidra2dwarf.py> Finished!

Server

server from Reply CTF:

section_count 4
Traceback (most recent call last):
  File "/ghidra2dwarf/src/ghidra2dwarf.py", line 474, in <module>
    write_detached_dwarf_file(exe_path)
  File "/ghidra2dwarf/src/ghidra2dwarf.py", line 413, in write_detached_dwarf_file
    section_name = debug_sections[section_index]
IndexError: index out of range: 0L

I tried re-running the scripts > 10 times but it doesn't work.

RSA

rsa from TokyoWesterns CTF:

I have added these lines:

diff --git a/src/ghidra2dwarf.py b/src/ghidra2dwarf.py
index 55780a6..84afd28 100755
--- a/src/ghidra2dwarf.py
+++ b/src/ghidra2dwarf.py
@@ -211,6 +228,8 @@ def add_variable(cu, func_die, name, datatype, addr, storage):

     # TODO: there could be more than one varnode, what does it even mean?
     varnode = storage.firstVarnode
+    if varnode is None:
+        return None

to bypass the issue of https://github.com/cesena/ghidra2dwarf/issues/1, however the export is incorrect. It happened something similar when I enabled: https://github.com/cesena/ghidra2dwarf/blob/4f61106ab6120a30b40a4b7464e5f4c60f278bc2/src/ghidra2dwarf.py#L191

Dwarf Error: wrong version in compilation unit header (is 24428, should be 2, 3, 4 or 5) [in module ./rsa_dbg]
(No debugging symbols found in rsa_dbg)

Don't think that the it exports uncorrect information because of the varnode None (sketchy patch), but I could be wrong.

elf.zip