def add_call_comment(self, from_addr, to_addr): to_func = self.bv.get_function_at(to_addr) _, name = demangle.demangle_gnu3(self.bv.arch, to_func.name) old_comment = self.caller.get_comment_at(from_addr) self.caller.set_comment_at( from_addr, demangle.get_qualified_name(name) + "\n" + old_comment)
def demangle(bv, name): """ Try and demangle given name using all available demanglers """ for demangler in DEMANGLERS: type, new_name = demangler(bv.arch, name) if type is None or name == new_name: continue return get_qualified_name(new_name) return name
def fix_mangled_symbols(thread, view): for sym in view.symbols.values(): if thread.cancelled: break if not isinstance(sym, Symbol): continue if sym.short_name.startswith('?') and not sym.raw_name.startswith('?'): demangled_type, demangled_name = demangle_ms( view.arch, sym.short_name) if demangled_type is not None: new_symbol = Symbol( sym.type, sym.address, short_name=get_qualified_name(demangled_name), full_name=get_qualified_name(demangled_name), raw_name=sym.short_name, binding=sym.binding, namespace=sym.namespace, ordinal=sym.ordinal) view.undefine_user_symbol(sym) view.define_user_symbol(new_symbol) view.define_user_data_var(new_symbol.address, demangled_type) sym = new_symbol # Create vtables if 'vftable\'' in sym.full_name: create_vtable(view, None, sym.address) # Create strings if sym.raw_name.startswith('??_C@_'): view.undefine_user_symbol(sym) ascii_string = view.get_ascii_string_at(sym.address) if (ascii_string is not None) and (ascii_string.start == sym.address): view.define_user_data_var( sym.address, Type.array(Type.char(), ascii_string.length)) for func in view.functions: if thread.cancelled: break process_msvc_func(func)
def get_type_string(self, t, n): out = "" if t is not None: out = str(t.get_string_before_name()) if len(out) > 1 and out[-1] != ' ': out += " " out += get_qualified_name(n) out += str(t.get_string_after_name()) return out
def get_vtable_name(view, name): if name[:3] in [ '?AU', '?AV' ]: # demangle_ms doesn't support flags (UNDNAME_32_BIT_DECODE | UNDNAME_NAME_ONLY | UNDNAME_NO_ARGUMENTS | UNDNAME_NO_MS_KEYWORDS) demangle_type, demangle_name = demangle.demangle_ms(view.arch, '??_7{0}6B@'.format(name[3:])) if demangle_type is not None: return demangle.get_qualified_name(demangle_name) return 'vtable_{0}'.format(name)
def try_unmangle(self, value): if value[:2] != b'_Z': return (None, value) decoded_name = value.decode('ascii') demangled_type, demangled_name = demangle_gnu3(Architecture[self.ARCH], decoded_name) decoded_name = get_qualified_name(demangled_name) return (demangled_type, decoded_name)
def demangle_name(bv, name, max_size=64): res = name if bv.platform.name.startswith("linux-") or bv.platform.name.startswith( "mac-"): _, demangled = demangle.demangle_gnu3(bv.arch, name) if not isinstance(demangled, list): res = demangled else: res = demangle.simplify_name_to_string( demangle.get_qualified_name(demangled)) elif bv.platform.name.startswith("windows-"): _, demangled = demangle.demangle_ms(bv.arch, name) if not isinstance(demangled, list): res = demangled else: res = demangle.simplify_name_to_string( demangle.get_qualified_name(demangled)) if len(res) > max_size: res = res[:max_size // 2 - 3] + "..." + res[-max_size // 2:] return res