-
Notifications
You must be signed in to change notification settings - Fork 4
/
__init__.py
36 lines (33 loc) · 1.26 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from binaryninja import BinaryView
from binaryninja import PluginCommand
from binaryninja import Symbol, SymbolType
from rust_demangler import demangle
from rust_demangler.rust import TypeNotFoundError
from rust_demangler.rust_legacy import UnableToLegacyDemangle
from rust_demangler.rust_v0 import UnableTov0Demangle
def demangle_functions(bv: BinaryView):
bv.begin_undo_actions()
for f in bv.functions:
try:
f.name = demangle(f.symbol.raw_name)
# Not a valid mangled name
except TypeNotFoundError:
pass
except UnableToLegacyDemangle:
pass
except UnableTov0Demangle:
pass
for sym in bv.symbols.values():
for symbol in sym:
if symbol.type == SymbolType.ExternalSymbol:
try:
user_sym = Symbol(symbol.type, symbol.address, demangle(symbol.raw_name))
except TypeNotFoundError:
continue
except UnableToLegacyDemangle:
continue
except UnableTov0Demangle:
continue
bv.define_user_symbol(user_sym)
bv.commit_undo_actions()
PluginCommand.register("Rust Demangle", "Demangles Rust symbols.", demangle_functions)