demangle module

Class

Description

binaryninja.demangle.CoreDemangler

Pluggable name demangling interface. See register and demangle

binaryninja.demangle.Demangler

Pluggable name demangling interface. See register and demangle

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 demangle should 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 to demangle_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 demangle will determine the result of a call to demangle_generic. Returning True from this does not require the demangler to succeed the call to demangle, but simply implies that it may succeed.

Parameters:

name (str) – Raw mangled name string

Returns:

True if the demangler thinks it can handle the name

Return type:

bool

Demangler

class Demangler[source]

Bases: object

Pluggable name demangling interface. See register and demangle for details on the process of this interface.

The list of Demanglers can be queried:

>>> list(Demangler)
[<Demangler: MS>, <Demangler: GNU3>]
__init__(handle=None)[source]
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 demangle should 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 to demangle_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 demangle will determine the result of a call to demangle_generic. Returning True from this does not require the demangler to succeed the call to demangle, but simply implies that it may succeed.

Parameters:

name (str) – Raw mangled name string

Returns:

True if the demangler thinks it can handle the name

Return type:

bool

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