typelibrary module

binaryninja.typelibrary.TypeLibrary(handle)

class TypeLibrary(handle: LP_BNTypeLibrary)[source]

Bases: object

Parameters:

handle (LP_BNTypeLibrary) –

add_alternate_name(name: str) None[source]

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

Parameters:

name (str) –

Return type:

None

add_named_object(name: QualifiedName, type: Type) None[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: types.QualifiedNameType, type: Type) None[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: Platform) None[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.

Parameters:

plat (Platform) –

Return type:

None

add_type_source(name: QualifiedName, source: str) None[source]

Manually flag NamedTypeReferences to the given QualifiedName as originating from another source TypeLibrary with the given dependency name.

Warning

Use this api with extreme caution.

Parameters:
Return type:

None

clear_platforms() None[source]

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

Return type:

None

static decompress_to_file(path: str, output: str) bool[source]

Decompresses a type library file to a file on disk.

Parameters:
  • path (str) –

  • output (str) –

Return type:

bool

finalize() bool[source]

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

Return type:

True if the type library was successfully finalized, False otherwise

static from_guid(arch: Architecture, guid: str)[source]

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

Parameters:
Return type:

TypeLibrary

static from_name(arch: Architecture, name: str)[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: QualifiedName | str) Type | None[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: str | QualifiedName) Type | None[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

static load_from_file(path: str) TypeLibrary | None[source]

Loads a finalized type library instance from file

Parameters:

path (str) –

Return type:

TypeLibrary

static new(arch: Architecture, name: str) TypeLibrary[source]

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

Parameters:
Return type:

TypeLibrary

query_metadata(key: str) metadata.MetadataValueType | None[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: str) None[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: str, md: Metadata) None[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: str) None[source]

Saves a finalized type library instance to file

Parameters:

path (str) –

Return type:

None

property alternate_names: List[str]

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

property arch: Architecture

The Architecture this type library is associated with

property dependency_name: str | None

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.

property guid: str | None

Returns the GUID associated with the type library

property metadata: Dict[str, metadata.MetadataValueType]

metadata retrieves the metadata associated with the current type library.

Return type:

Metadata object

Example:
>>> lib.store_metadata("integer", 1337)
>>> lib.metadata["integer"]
1337
property name: str | None

The primary name associated with this type library

property named_objects: Dict[QualifiedName, Type]

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

property named_types: Dict[QualifiedName, Type]

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

property platform_names: List[str]

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.

property type_container: TypeContainer

Type Container for all TYPES within the Type Library. Objects are not included. The Type Container’s Platform will be the first platform associated with the Type Library. :return: Type Library Type Container