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.

Internal-use constructor. API users will want to use TypeArchive.open or TypeArchive.create instead to get an instance of a TypeArchive.

Parameters:

handle (LP_BNTypeArchive) – Handle pointer (Internal use only.)

add_type(name: _types.QualifiedNameType, type: _types.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.

Parameters:
  • name (_types.QualifiedNameType) – Name of new type

  • type (_types.Type) – Definition of new type

Return type:

None

add_types(new_types: List[Tuple[_types.QualifiedNameType, _types.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.

Parameters:

new_types (List[Tuple[_types.QualifiedNameType, _types.Type]]) – Names and definitions of new types

Return type:

None

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

Create a Type Archive at the given path.

Parameters:
  • path (str) – Path to Type Archive file

  • platform (Platform) – Relevant platform for types in the archive

Returns:

Type Archive, or None if it could not be created.

Return type:

TypeArchive | None

delete_type(name: _types.QualifiedNameType) None[source]

Delete an existing type in the type archive.

Parameters:

name (_types.QualifiedNameType) – Type name

Return type:

None

delete_type_by_id(id: str) None[source]

Delete an existing type in the type archive.

Parameters:

id (str) – Type id

Return type:

None

deserialize_snapshot(data: databuffer.DataBufferInputType) str[source]

Take a serialized snapshot data stream and create a new snapshot from it

Parameters:

data (databuffer.DataBufferInputType) – Snapshot data

Returns:

String of created snapshot id

Return type:

str

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

Get all types that reference a given type

Parameters:
  • id (str) – Target type id

  • snapshot (str | None) – Snapshot id to search for types, or empty string to search the latest snapshot

Returns:

Source type ids

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

Parameters:
  • id (str) – Target type id

  • snapshot (str | None) – Snapshot id to search for types, or empty string to search the latest snapshot

Returns:

Source type ids

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

Parameters:
  • id (str) – Source type id

  • snapshot (str | None) – Snapshot id to search for types, or empty string to search the latest snapshot

Returns:

Target type ids

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

Parameters:
  • id (str) – Source type id

  • snapshot (str | None) – Snapshot id to search for types, or empty string to search the latest snapshot

Returns:

Target type ids

Return type:

List[str]

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

Get the ids of the children to the given snapshot

Parameters:

snapshot (str) – Parent snapshot id

Returns:

Child snapshot ids, or empty list if the snapshot is a leaf

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

Parameters:

snapshot (str) – Child snapshot id

Returns:

Parent snapshot ids, or empty list if the snapshot is a root

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

Parameters:
  • id (str) – Type id

  • snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Type, if it exists. Otherwise None

Return type:

Type | None

get_type_by_name(name: _types.QualifiedNameType, snapshot: str | None = None) Type | None[source]

Retrieve a stored type in the archive

Parameters:
  • name (_types.QualifiedNameType) – Type name

  • snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Type, if it exists. Otherwise None

Return type:

Type | None

get_type_id(name: _types.QualifiedNameType, snapshot: str | None = None) str | None[source]

Retrieve a type’s id by its name

Parameters:
  • name (_types.QualifiedNameType) – Type name

  • snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Type id, if it exists. Otherwise None

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

Parameters:

snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

All type ids

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

Parameters:
  • id (str) – Type id

  • snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Type name, if it exists. Otherwise 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

Parameters:

snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

All type names

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

Parameters:

snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Mapping of all type ids to names

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

Parameters:

snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Map of all types, by name

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

Parameters:

snapshot (str | None) – Snapshot id to search for types, or None to search the latest snapshot

Returns:

Map of type id to type name and definition

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.

Parameters:

id (str) – Type Archive id

Returns:

Type archive, or None if it could not be found.

Return type:

TypeArchive | None

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

Open the Type Archive at the given path, if it exists.

Parameters:

path (str) – Path to Type Archive file

Returns:

Type Archive, or None if it could not be loaded.

Return type:

TypeArchive | None

query_metadata(key: str) metadata.MetadataValueType | None[source]

Look up a metadata entry in the archive

Parameters:

key (string) – key to query

Return type:

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"
register_notification(notify: TypeArchiveNotification) None[source]

Register a notification listener

Parameters:

notify (TypeArchiveNotification) – Object to receive notifications

Return type:

None

remove_metadata(key: str) None[source]

Delete a given metadata entry in the archive

Parameters:

key (string) – key associated with metadata

Example:
>>> ta: TypeArchive
>>> ta.store_metadata("integer", 1337)
>>> ta.remove_metadata("integer")
Return type:

None

rename_type(old_name: _types.QualifiedNameType, new_name: _types.QualifiedNameType) None[source]

Change the name of an existing type in the type archive.

Parameters:
  • old_name (_types.QualifiedNameType) – Old type name in archive

  • new_name (_types.QualifiedNameType) – New type name

Return type:

None

rename_type_by_id(id: str, new_name: _types.QualifiedNameType) None[source]

Change the name of an existing type in the type archive.

Parameters:
  • id (str) – Old id of type in archive

  • new_name (_types.QualifiedNameType) – New type name

Return type:

None

serialize_snapshot(snapshot: str) DataBuffer[source]

Turn a given snapshot into a data stream

Parameters:

snapshot (str) – Snapshot id

Returns:

Buffer containing serialized snapshot data

Return type:

DataBuffer

store_metadata(key: str, md: metadata.MetadataValueType) None[source]

Store a key/value pair in the archive’s metadata storage

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

  • md (Varies) – object to store.

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

None

unregister_notification(notify: TypeArchiveNotification) None[source]

Unregister a notification listener

Parameters:

notify (TypeArchiveNotification) – Object to no longer receive notifications

Return type:

None

property all_snapshot_ids: List[str]

Get a list of every snapshot’s id

Returns:

All ids (including the empty first snapshot)

property current_snapshot_id: str

Get the id of the current snapshot in the type archive

Returns:

Snapshot id

property id: str | None

Get the guid for a Type Archive

Returns:

Guid string

property path: str | None

Get the path to the Type Archive’s file

Returns:

File path

property platform: Platform

Get the associated Platform for a Type Archive

Returns:

Platform object

property type_ids: List[str]

Get a list of all types’ ids in the archive at the current snapshot

Returns:

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

Returns:

Mapping of all type ids to names

property types: Dict[QualifiedName, Type]

Retrieve all stored types in the archive at the current snapshot

Returns:

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

Returns:

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

Parameters:
  • archive (TypeArchive) – Source Type archive

  • id (str) – Id of type added

  • definition (Type) – Definition of type

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

Parameters:
  • archive (TypeArchive) – Source Type archive

  • id (str) – Id of type deleted

  • definition (Type) – Definition of type deleted

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

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

Parameters:
  • archive (TypeArchive) – Source Type archive

  • id (str) – Id of type

  • old_definition (Type) – Previous definition

  • new_definition (Type) – Current definition

Return type:

None

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

Bases: object

Parameters:
property archive: TypeArchive
property notify: TypeArchiveNotification