typearchive module¶
Type Archives are a collection of types which can be shared between different analysis sessions and are backed by a database file on disk. |
|
Class providing an interface to receive event notifications for updates that happen to a Type Archive. |
|
|
- 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
orTypeArchive.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 dependent 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 dependent named types added prior to the parent types being added (or included in the list) or this function will fail. Types already existing with any added names will be overwritten.
- static create(path: str, platform: Platform) TypeArchive | None [source]¶
Create a Type Archive at the given path.
- Parameters:
- 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:
- get_incoming_direct_references(id: str, snapshot: str | None = None) List[str] [source]¶
Get all types that reference a given type
- 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
- get_outgoing_direct_references(id: str, snapshot: str | None = None) List[str] [source]¶
Get all types a given type references directly
- 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
- get_snapshot_child_ids(snapshot: str) List[str] | None [source]¶
Get the ids of the children to the given snapshot
- get_snapshot_parent_ids(snapshot: str) List[str] | None [source]¶
Get the ids of the parents to the given snapshot
- get_type_by_id(id: str, snapshot: str | None = None) Type | None [source]¶
Retrieve a stored type in the archive by id
- get_type_by_name(name: _types.QualifiedNameType, snapshot: str | None = None) Type | None [source]¶
Retrieve a stored type in the archive
- get_type_id(name: _types.QualifiedNameType, snapshot: str | None = None) str | None [source]¶
Retrieve a type’s id by its name
- get_type_ids(snapshot: str | None = None) List[str] [source]¶
Get a list of all types’ ids in the archive at a snapshot
- get_type_name_by_id(id: str, snapshot: str | None = None) QualifiedName | None [source]¶
Retrieve a type’s name by its id
- Parameters:
- 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:
- 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:
- 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:
- get_types_and_ids(snapshot: str | None = None) Dict[str, Tuple[QualifiedName, Type]] [source]¶
Retrieve all stored types in the archive at a snapshot
- 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:
- 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 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
- 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:
archive (TypeArchive) – Source Type archive
id (str) – Type id
old_name (QualifiedName) – Previous name
new_name (QualifiedName) – Current name
- 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:
archive (TypeArchive) –
notify (TypeArchiveNotification) –
- property archive: TypeArchive¶
- property notify: TypeArchiveNotification¶