demangle module¶
Class |
Description |
|---|---|
Pluggable name demangling interface. See |
|
Pluggable name demangling interface. See |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CoreDemangler¶
- class CoreDemangler[source]¶
Bases:
Demangler- demangle(arch: Architecture, name: str, view: BinaryView | None = None) Tuple[Type | None, QualifiedName] | None[source]¶
Demangle a raw name into a Type and QualifiedName.
The result of this function is a (Type, QualifiedName) tuple for the demangled name’s details.
Any unresolved named types referenced by the resulting Type will be created as empty structures or void typedefs in the view, if the result is used on a data structure in the view. Given this, the call to
demangleshould NOT cause any side-effects creating types in the view trying to resolve this and instead just return a type with unresolved named type references.The most recently registered demangler that claims a name is a mangled string (returns true from
is_mangled_string), and then returns a value from this function will determine the result of a call todemangle_generic. If this call returns None, the next most recently used demangler(s) will be tried instead.If the mangled name has no type information, but a name is still possible to extract, this function may return a successful (None, <name>) result, which will be accepted.
- Parameters:
arch (Architecture) – Architecture for context in which the name exists, eg for pointer sizes
name (str) – Raw mangled name
view (BinaryView | None) – (Optional) BinaryView context in which the name exists, eg for type lookup
- Returns:
Tuple of (Type, Name) if successful, None if not. Type may be None if only a demangled name can be recovered from the raw name.
- Return type:
Tuple[Type | None, QualifiedName] | None
- is_mangled_string(name: str) bool[source]¶
Determine if a given name is mangled and this demangler can process it
The most recently registered demangler that claims a name is a mangled string (returns true from this function), and then returns a value from
demanglewill determine the result of a call todemangle_generic. Returning True from this does not require the demangler to succeed the call todemangle, but simply implies that it may succeed.
Demangler¶
- class Demangler[source]¶
Bases:
objectPluggable name demangling interface. See
registeranddemanglefor details on the process of this interface.The list of Demanglers can be queried:
>>> list(Demangler) [<Demangler: MS>, <Demangler: GNU3>]
- demangle(arch: Architecture, name: str, view: BinaryView | None = None) Tuple[Type, QualifiedName] | None[source]¶
Demangle a raw name into a Type and QualifiedName.
The result of this function is a (Type, QualifiedName) tuple for the demangled name’s details.
Any unresolved named types referenced by the resulting Type will be created as empty structures or void typedefs in the view, if the result is used on a data structure in the view. Given this, the call to
demangleshould NOT cause any side-effects creating types in the view trying to resolve this and instead just return a type with unresolved named type references.The most recently registered demangler that claims a name is a mangled string (returns true from
is_mangled_string), and then returns a value from this function will determine the result of a call todemangle_generic. If this call returns None, the next most recently used demangler(s) will be tried instead.If the mangled name has no type information, but a name is still possible to extract, this function may return a successful (None, <name>) result, which will be accepted.
- Parameters:
arch (Architecture) – Architecture for context in which the name exists, eg for pointer sizes
name (str) – Raw mangled name
view (BinaryView | None) – (Optional) BinaryView context in which the name exists, eg for type lookup
- Returns:
Tuple of (Type, Name) if successful, None if not. Type may be None if only a demangled name can be recovered from the raw name.
- Return type:
Tuple[Type, QualifiedName] | None
- is_mangled_string(name: str) bool[source]¶
Determine if a given name is mangled and this demangler can process it
The most recently registered demangler that claims a name is a mangled string (returns true from this function), and then returns a value from
demanglewill determine the result of a call todemangle_generic. Returning True from this does not require the demangler to succeed the call todemangle, but simply implies that it may succeed.
- classmethod promote(demangler)[source]¶
Promote a demangler to the highest-priority position.
>>> list(Demangler) [<Demangler: MS>, <Demangler: GNU3>] >>> Demangler.promote(list(Demangler)[0]) >>> list(Demangler) [<Demangler: GNU3>, <Demangler: MS>]
- Parameters:
demangler – Demangler to promote
- classmethod register()[source]¶
Register a custom Demangler. Newly registered demanglers will get priority over previously registered demanglers and built-in demanglers.
- name = None¶
demangle_generic¶
- class demangle_generic[source]¶
Bases:
demangle_genericdemangles a mangled symbol name to a Type object.- Parameters:
archOrPlatform (Union[Architecture, Platform]) – Architecture or Platform for the symbol. Required for pointer/integer sizes and calling conventions.
mangled_name (str) – a mangled symbol name
view – (optional) view of the binary containing the mangled name
simplify – (optional) Whether to simplify demangled names
- Returns:
returns tuple of (Optional[Type], demangled_name) or None on error
- Return type:
Tuple
- Example:
>>> demangle_generic(Architecture["x86_64"], "?testf@Foobar@@SA?AW4foo@1@W421@@Z") (<type: public: static enum Foobar::foo __cdecl (enum Foobar::foo)>, ['Foobar', 'testf']) >>> demangle_generic(Architecture["x86_64"], "__ZN20ArmCallingConvention27GetIntegerArgumentRegistersEv") (<type: immutable:FunctionTypeClass 'int64_t()'>, ['ArmCallingConvention', 'GetIntegerArgumentRegisters']) >>>
demangle_gnu3¶
- class demangle_gnu3[source]¶
Bases:
demangle_gnu3demangles a mangled name to a Type object.- Parameters:
arch (Architecture) – Architecture for the symbol. Required for pointer and integer sizes.
mangled_name (str) – a mangled GNU3 name
options (Optional[Union[bool, BinaryView]]) – (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView’s settings, or a boolean to set it directly
- Returns:
returns tuple of (Type, demangled_name) or (None, mangled_name) on error
- Return type:
demangle_llvm¶
- class demangle_llvm[source]¶
Bases:
demangle_llvmdemangles a mangled name using the LLVM demangler.- Parameters:
mangled_name (str) – a mangled (msvc/itanium/rust/dlang) name
options (Optional[Union[bool, BinaryView]]) – (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView’s settings, or a boolean to set it directly
- Returns:
returns demangled name or None on error
- Return type:
Optional[List[str]]
- Example:
>>> demangle_llvm("?testf@Foobar@@SA?AW4foo@1@W421@@Z") ['public: static enum Foobar::foo __cdecl Foobar::testf(enum Foobar::foo)'] >>>
demangle_ms¶
- class demangle_ms[source]¶
Bases:
demangle_msdemangles a mangled Microsoft Visual Studio C++ name to a Type object.- Parameters:
archOrPlatform (Union[Architecture, Platform]) – Architecture or Platform for the symbol. Required for pointer/integer sizes and calling conventions.
mangled_name (str) – a mangled Microsoft Visual Studio C++ name
options (Optional[Union[bool, BinaryView]]) – (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView’s settings, or a boolean to set it directly
- Returns:
returns tuple of (Type, demangled_name) or (None, mangled_name) on error
- Return type:
- Example:
>>> demangle_ms(Platform["x86_64"], "?testf@Foobar@@SA?AW4foo@1@W421@@Z") (<type: public: static enum Foobar::foo __cdecl (enum Foobar::foo)>, ['Foobar', 'testf']) >>>
get_qualified_name¶
simplify_name_to_qualified_name¶
- class simplify_name_to_qualified_name[source]¶
Bases:
simplify_name_to_qualified_namesimplifies a templated C++ name with default arguments and returns a qualified name. This can also tokenize a string to a qualified name with/without simplifying it- Parameters:
input_name (Union[str, QualifiedName]) – String or qualified name to be simplified
simplify (bool) – (optional) Whether to simplify input string (no effect if given a qualified name; will always simplify)
- Returns:
simplified name (or one-element array containing the input if simplifier fails/cannot simplify)
- Return type:
- Example:
>>> demangle.simplify_name_to_qualified_name(QualifiedName(["std", "__cxx11", "basic_string<wchar, std::char_traits<wchar>, std::allocator<wchar> >"]), True) 'std::wstring' >>>
simplify_name_to_string¶
- class simplify_name_to_string[source]¶
Bases:
simplify_name_to_stringsimplifies a templated C++ name with default arguments and returns a string- Parameters:
input_name (Union[str, QualifiedName]) – String or qualified name to be simplified
- Returns:
simplified name (or original name if simplifier fails/cannot simplify)
- Return type:
- Example:
>>> demangle.simplify_name_to_string("std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >") 'std::string' >>>