typelibrary module

binaryninja.typelibrary.TypeLibrary(handle)

binaryninja.typelibrary.range(stop)

range(start, stop[, step]) -> range object

binaryninja.typelibrary.with_metaclass(meta, …)

Create a base class with a metaclass.

class TypeLibrary(handle)[source]

Bases: object

add_alternate_name(name)[source]

Adds an extra name to this type library used during library lookups and dependency resolution

add_named_object(name, t)[source]

add_named_object directly inserts a named object into the type library’s object store. This is not done recursively, so care should be taken that types referring to other types through NamedTypeReferences are already appropriately prepared.

To add types and objects from an existing BinaryView, it is recommended to use export_object_to_library, which will automatically pull in all referenced types and record additional dependencies as needed.

Parameters
Return type

None

add_named_type(name, t)[source]

add_named_type directly inserts a named object into the type library’s object store. This is not done recursively, so care should be taken that types referring to other types through NamedTypeReferences are already appropriately prepared.

To add types and objects from an existing BinaryView, it is recommended to use export_type_to_library, which will automatically pull in all referenced types and record additional dependencies as needed.

Parameters
Return type

None

add_platform(plat)[source]

Associate a platform with a type library instance that has not been finalized.

This will cause the library to be searchable by Platform.get_type_libraries_by_name when loaded.

This does not have side affects until finalization of the type library.

clear_platforms()[source]

Clears the list of platforms associated with a type library instance that has not been finalized

finalize()[source]

Flags a newly created type library instance as finalized and makes it available for Platform and Architecture type library searches

classmethod from_guid(arch, guid)[source]

from_guid attempts to grab a type library associated with the provided Architecture and GUID pair

Parameters
Return type

TypeLibrary

classmethod from_name(arch, name)[source]

from_name looks up the first type library found with a matching name. Keep in mind that names are not necessarily unique.

Parameters
Return type

TypeLibrary

get_named_object(name)[source]

get_named_object direct extracts a reference to a contained object – when attempting to extract types from a library into a BinaryView, consider using import_library_object instead.

Parameters

name (QualifiedName) –

Return type

Type

get_named_type(name)[source]

get_named_type direct extracts a reference to a contained type – when attempting to extract types from a library into a BinaryView, consider using import_library_type instead.

Parameters

name (QualifiedName) –

Return type

Type

classmethod load_from_file(path)[source]

Loads a finalized type library instance from file

Parameters

path (str) –

Return type

TypeLibrary

classmethod new(arch, name)[source]

Creates an empty type library object with a random GUID and the provided name.

Parameters
Return type

TypeLibrary

query_metadata(key)[source]

query_metadata retrieves a metadata associated with the given key stored in the type library

Parameters

key (string) – key to query

Return type

metadata associated with the key

Example
>>> lib.store_metadata("ordinals", {"9": "htons"})
>>> lib.query_metadata("ordinals")["9"]
"htons"
remove_metadata(key)[source]

remove_metadata removes the metadata associated with key from the current type library.

Parameters

key (string) – key associated with metadata

Return type

None

Example
>>> lib.store_metadata("integer", 1337)
>>> lib.remove_metadata("integer")
store_metadata(key, md)[source]

store_metadata stores an object for the given key in the current type library. Objects stored using store_metadata can be retrieved from any reference to the library. Objects stored are not arbitrary python objects! The values stored must be able to be held in a Metadata object. See Metadata for more information. Python objects could obviously be serialized using pickle but this intentionally a task left to the user since there is the potential security issues.

This is primarily intended as a way to store Platform specific information relevant to BinaryView implementations; for example the PE BinaryViewType uses type library metadata to retrieve ordinal information, when available.

Parameters
  • key (string) – key value to associate the Metadata object with

  • md (Varies) – object to store.

Return type

None

Example
>>> lib.store_metadata("ordinals", {"9": "htons"})
>>> lib.query_metadata("ordinals")["9"]
"htons"
write_to_file(path)[source]

Saves a finalized type library instance to file

Parameters

path (str) –

Return type

None

alternate_names

A list of extra names that will be considered a match by Platform.get_type_libraries_by_name

arch

The Architecture this type library is associated with

dependency_name

The dependency_name of a library is the name used to record dependencies across type libraries. This allows, for example, a library with the name “musl_libc” to have dependencies on it recorded as “libc_generic”, allowing a type library to be used across multiple platforms where each has a specific libc that also provides the name “libc_generic” as an alternate_name.

guid

Returns the GUID associated with the type library

name

The primary name associated with this type library

named_objects

A dict containing all named objects (functions, exported variables) provided by a type library (read-only)

named_types

A dict containing all named types provided by a type library (read-only)

platform_names

Returns a list of all platform names that this type library will register with during platform type registration.

This returns strings, not Platform objects, as type libraries can be distributed with support for Platforms that may not be present.