-
-
Save winterqt/f90059c0c52ae46c0bd20099d7c50d0b to your computer and use it in GitHub Desktop.
Ghidra script to demangle Rust symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Demangle swift function names | |
# A script can be easily created in the Script Manager window | |
# Make sure https://github.com/luser/rustfilt is installed on your system | |
#@author Daniel Lim | |
#@category Demangler.Rust | |
#@keybinding | |
#@menupath | |
#@toolbar | |
from subprocess import Popen, PIPE | |
from ghidra.program.model.symbol import SourceType | |
from ghidra.program.model.listing import CodeUnit | |
functionManager = currentProgram.getFunctionManager() | |
# Get functions in ascending order | |
monitor.initialize(functionManager.getFunctionCount()) | |
fns = functionManager.getFunctions(True) | |
for f in fns: | |
monitor.incrementProgress(1) | |
f_name = f.getName() | |
# Is it a mangled name? | |
if not (f_name.startswith("_ZN") or f_name.startswith("_R")): | |
continue | |
previous_comment = f.getComment() | |
if not previous_comment: | |
previous_comment = "" | |
rustfilt = Popen(['rustfilt'], stdin=PIPE, stdout=PIPE) | |
signature = rustfilt.communicate(input=f_name)[0] | |
# Replace characters we can't have in our name | |
signature = signature.split("(")[0] | |
signature = signature.replace(" ", "_") | |
f.setName(signature, SourceType.ANALYSIS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment