cesena / ghidra2dwarf

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

Handle Unicode in decompiler output #11

Closed nneonneo closed 2 years ago

nneonneo commented 2 years ago

The decompiler output can legitimately contain Unicode (e.g. Unicode strings). Currently, the script will crash with an error like this:

Traceback (most recent call last):
  File "ghidra2dwarf.py", line 512, in <module>
    write_source()
  File "ghidra2dwarf.py", line 343, in write_source
    src.write("\n".join(decomp_lines))
UnicodeEncodeError: 'ascii' codec can't encode character u'\uefbe' in position 14630: ordinal not in range(128)

This fix makes the output UTF-8, which solves this issue for all valid Unicode characters.

NextLight commented 2 years ago

Nice!
Thank you for your contributions.