typearchive module

binaryninja.typearchive.TypeArchive(handle)

Type Archives are a collection of types which can be shared between different analysis sessions and are backed by a database file on disk.

binaryninja.typearchive.TypeArchiveNotification()

Class providing an interface to receive event notifications for updates that happen to a Type Archive.

binaryninja.typearchive.TypeArchiveNotificationCallbacks(...)

class TypeArchive(handle: LP_BNTypeArchive)[source]

Bases: object

Type Archives are a collection of types which can be shared between different analysis sessions and are backed by a database file on disk. Their types can be modified, and a history of previous versions of types is stored in snapshots in the archive.

Parameters:

handle (LP_BNTypeArchive) –

add_type(name: Iterable[str | bytes] | str | QualifiedName, type: Type) None[source]

Add named types to the type archive. Type must have all dependant named types added prior to being added, or this function will fail. If the type already exists, it will be overwritten. :param name: Name of new type :param type: Definition of new type

Parameters:
Return type:

None

add_types(new_types: List[Tuple[Iterable[str | bytes] | str | QualifiedName, Type]]) None[source]

Add named types to the type archive. Types must have all dependant named types prior to being added, or included in the list, or this function will fail. Types already existing with any added names will be overwritten. :param new_types: Names and definitions of new types

Parameters:

new_types (List[Tuple[Iterable[str | bytes] | str | QualifiedName, Type]]) –

Return type:

None

static create(path: str, platform: Platform) TypeArchive | None[source]

Create a Type Archive at the given path. :param path: Path to Type Archive file :param platform: Relevant platform for types in the archive :return: Type Archive, or None if it could not be created.

Parameters:
Return type:

TypeArchive | None

delete_type(name: Iterable[str | bytes] | str | QualifiedName) None[source]

Delete an existing type in the type archive. :param name: Type name

Parameters:

name (Iterable[str | bytes] | str | QualifiedName) –

Return type:

None

delete_type_by_id(id: str) None[source]

Delete an existing type in the type archive. :param id: Type id

Parameters:

id (str) –

Return type:

None

deserialize_snapshot(data: str | bytes | DataBuffer | int) str[source]

Take a serialized snapshot data stream and create a new snapshot from it :param data: Snapshot data :return: String of created snapshot id

Parameters:

data (str | bytes | DataBuffer | int) –

Return type:

str

get_incoming_direct_references(id: str, snapshot: str | None = None) List[str][source]

Get all types that reference a given type :param id: Target type id :param snapshot: Snapshot id to search for types, or empty string to search the latest snapshot :return: Source type ids

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

List[str]

get_incoming_recursive_references(id: str, snapshot: str | None = None) List[str][source]

Get all types that reference a given type, and all types that reference them, recursively :param id: Target type id :param snapshot: Snapshot id to search for types, or empty string to search the latest snapshot :return: Source type ids

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

List[str]

get_outgoing_direct_references(id: str, snapshot: str | None = None) List[str][source]

Get all types a given type references directly :param id: Source type id :param snapshot: Snapshot id to search for types, or empty string to search the latest snapshot :return: Target type ids

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

List[str]

get_outgoing_recursive_references(id: str, snapshot: str | None = None) List[str][source]

Get all types a given type references, and any types that the referenced types reference :param id: Source type id :param snapshot: Snapshot id to search for types, or empty string to search the latest snapshot :return: Target type ids

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

List[str]

get_snapshot_child_ids(snapshot: str) List[str] | None[source]

Get the ids of the children to the given snapshot :param snapshot: Parent snapshot id :return: Child snapshot ids, or empty list if the snapshot is a leaf

Parameters:

snapshot (str) –

Return type:

List[str] | None

get_snapshot_parent_ids(snapshot: str) List[str] | None[source]

Get the ids of the parents to the given snapshot :param snapshot: Child snapshot id :return: Parent snapshot ids, or empty list if the snapshot is a root

Parameters:

snapshot (str) –

Return type:

List[str] | None

get_type_by_id(id: str, snapshot: str | None = None) Type | None[source]

Retrieve a stored type in the archive by id :param id: Type id :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Type, if it exists. Otherwise None

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

Type | None

get_type_by_name(name: Iterable[str | bytes] | str | QualifiedName, snapshot: str | None = None) Type | None[source]

Retrieve a stored type in the archive :param name: Type name :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Type, if it exists. Otherwise None

Parameters:
Return type:

Type | None

get_type_id(name: Iterable[str | bytes] | str | QualifiedName, snapshot: str | None = None) str | None[source]

Retrieve a type’s id by its name :param name: Type name :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Type id, if it exists. Otherwise None

Parameters:
Return type:

str | None

get_type_ids(snapshot: str | None = None) List[str][source]

Get a list of all types’ ids in the archive at a snapshot :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: All type ids

Parameters:

snapshot (str | None) –

Return type:

List[str]

get_type_name_by_id(id: str, snapshot: str | None = None) QualifiedName | None[source]

Retrieve a type’s name by its id :param id: Type id :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Type name, if it exists. Otherwise None

Parameters:
  • id (str) –

  • snapshot (str | None) –

Return type:

QualifiedName | None

get_type_names(snapshot: str | None = None) List[QualifiedName][source]

Get a list of all types’ names in the archive at a snapshot :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: All type names

Parameters:

snapshot (str | None) –

Return type:

List[QualifiedName]

get_type_names_and_ids(snapshot: str | None = None) Dict[str, QualifiedName][source]

Get a list of all types’ names and ids in the archive at a current snapshot :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Mapping of all type ids to names

Parameters:

snapshot (str | None) –

Return type:

Dict[str, QualifiedName]

get_types(snapshot: str | None = None) Dict[QualifiedName, Type][source]

Retrieve all stored types in the archive at a snapshot :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Map of all types, by name

Parameters:

snapshot (str | None) –

Return type:

Dict[QualifiedName, Type]

get_types_and_ids(snapshot: str | None = None) Dict[str, Tuple[QualifiedName, Type]][source]

Retrieve all stored types in the archive at a snapshot :param snapshot: Snapshot id to search for types, or None to search the latest snapshot :return: Map of type id to type name and definition

Parameters:

snapshot (str | None) –

Return type:

Dict[str, Tuple[QualifiedName, Type]]

static lookup_by_id(id: str) TypeArchive | None[source]

Get a reference to the Type Archive with the known id, if one exists. :param id: Type Archive id :return: Type archive, or None if it could not be found.

Parameters:

id (str) –

Return type:

TypeArchive | None

static open(path: str) TypeArchive | None[source]

Open the Type Archive at the given path, if it exists. :param path: Path to Type Archive file :return: Type Archive, or None if it could not be loaded.

Parameters:

path (str) –

Return type:

TypeArchive | None

query_metadata(key: str) Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict | None[source]

Look up a metadata entry in the archive :param string key: key to query :rtype: Metadata associated with the key, if it exists. Otherwise, None :Example:

>>> ta: TypeArchive
>>> ta.store_metadata("ordinals", {"9": "htons"})
>>> ta.query_metadata("ordinals")["9"]
"htons"
Parameters:

key (str) –

Return type:

Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict | None

register_notification(notify: TypeArchiveNotification) None[source]

Register a notification listener :param notify: Object to receive notifications

Parameters:

notify (TypeArchiveNotification) –

Return type:

None

remove_metadata(key: str) None[source]

Delete a given metadata entry in the archive :param string key: key associated with metadata :Example:

>>> ta: TypeArchive
>>> ta.store_metadata("integer", 1337)
>>> ta.remove_metadata("integer")
Parameters:

key (str) –

Return type:

None

rename_type(old_name: Iterable[str | bytes] | str | QualifiedName, new_name: Iterable[str | bytes] | str | QualifiedName) None[source]

Change the name of an existing type in the type archive. :param old_name: Old type name in archive :param new_name: New type name

Parameters:
Return type:

None

rename_type_by_id(id: str, new_name: Iterable[str | bytes] | str | QualifiedName) None[source]

Change the name of an existing type in the type archive. :param id: Old id of type in archive :param new_name: New type name

Parameters:
Return type:

None

serialize_snapshot(snapshot: str) DataBuffer[source]

Turn a given snapshot into a data stream :param snapshot: Snapshot id :return: Buffer containing serialized snapshot data

Parameters:

snapshot (str) –

Return type:

DataBuffer

store_metadata(key: str, md: Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict) None[source]

Store a key/value pair in the archive’s metadata storage :param string key: key value to associate the Metadata object with :param Varies md: object to store. :Example:

>>> ta: TypeArchive
>>> ta.store_metadata("ordinals", {"9": "htons"})
>>> ta.query_metadata("ordinals")["9"]
"htons"
Parameters:
Return type:

None

unregister_notification(notify: TypeArchiveNotification) None[source]

Unregister a notification listener :param notify: Object to no longer receive notifications

Parameters:

notify (TypeArchiveNotification) –

Return type:

None

property all_snapshot_ids: List[str]

Get a list of every snapshot’s id :return: All ids (including the empty first snapshot)

property current_snapshot_id: str

Get the id of the current snapshot in the type archive :return: Snapshot id

property id: str | None

Get the guid for a Type Archive :return: Guid string

property path: str | None

Get the path to the Type Archive’s file :return: File path

property platform: Platform

Get the associated Platform for a Type Archive :return: Platform object

property type_ids: List[str]

Get a list of all types’ ids in the archive at the current snapshot :return: All type ids

property type_names: List[QualifiedName]

Get a list of all types’ names in the archive at the current snapshot :return: All type names

property type_names_and_ids: Dict[str, QualifiedName]

Get a list of all types’ names and ids in the archive at the current snapshot :return: Mapping of all type ids to names

property types: Dict[QualifiedName, Type]

Retrieve all stored types in the archive at the current snapshot :return: Map of all types, by name

property types_and_ids: Dict[str, Tuple[QualifiedName, Type]]

Retrieve all stored types in the archive at the current snapshot :return: Map of type id to type name and definition

class TypeArchiveNotification[source]

Bases: object

Class providing an interface to receive event notifications for updates that happen to a Type Archive.

type_added(archive: TypeArchive, id: str, definition: Type) None[source]

Called when a type is added to the archive :param archive: Source Type archive :param id: Id of type added :param definition: Definition of type

Parameters:
Return type:

None

type_deleted(archive: TypeArchive, id: str, definition: Type) None[source]

Called when a type in the archive is deleted from the archive :param archive: Source Type archive :param id: Id of type deleted :param definition: Definition of type deleted

Parameters:
Return type:

None

type_renamed(archive: TypeArchive, id: str, old_name: QualifiedName, new_name: QualifiedName) None[source]

Called when a type in the archive is renamed :param archive: Source Type archive :param id: Type id :param old_name: Previous name :param new_name: Current name

Parameters:
Return type:

None

type_updated(archive: TypeArchive, id: str, old_definition: Type, new_definition: Type) None[source]

Called when a type in the archive is updated to a new definition :param archive: Source Type archive :param id: Id of type :param old_definition: Previous definition :param new_definition: Current definition

Parameters:
Return type:

None

class TypeArchiveNotificationCallbacks(archive: TypeArchive, notify: TypeArchiveNotification)[source]

Bases: object

Parameters:
property archive: TypeArchive
property notify: TypeArchiveNotification