database module

binaryninja.database.Database(handle)

class Database provides lower level access to raw snapshot data used to construct analysis data

binaryninja.database.KeyValueStore([buffer, ...])

class KeyValueStore maintains access to the raw data stored in Snapshots and various other Database-related structures.

binaryninja.database.Snapshot(handle)

class Snapshot is a model of an individual database snapshot, created on save.

class Database(handle)[source]

Bases: object

class Database provides lower level access to raw snapshot data used to construct analysis data

get_snapshot(id: int) Optional[Snapshot][source]

Get a snapshot by its id, or None if no snapshot with that id exists

Parameters

id (int) –

Return type

Optional[Snapshot]

read_global(key: str) str[source]

Get a specific global by key

Parameters

key (str) –

Return type

str

read_global_data(key: str) DataBuffer[source]

Get a specific global by key, as a binary buffer

Parameters

key (str) –

Return type

DataBuffer

remove_snapshot(id: int)[source]

Remove a snapshot in the database by id, deleting its contents and references. Attempting to remove a snapshot with children will raise an exception.

Parameters

id (int) –

trim_snapshot(id: int)[source]

Trim a snapshot’s contents in the database by id, but leave the parent/child hierarchy intact. Future references to this snapshot will return False for has_contents

Parameters

id (int) –

write_global(key: str, value: str)[source]

Write a global into the database

Parameters
  • key (str) –

  • value (str) –

write_global_data(key: str, value: DataBuffer)[source]

Write a binary buffer into a global in the database

Parameters
property analysis_cache: KeyValueStore

Get the backing analysis cache kvs (read-only)

property current_snapshot: Optional[Snapshot]

Get the current snapshot

property file: FileMetadata

Get the owning FileMetadata (read-only)

property global_keys: List[str]

Get a list of keys for all globals in the database (read-only)

property globals: Dict[str, str]

Get a dictionary of all globals (read-only)

property snapshots: List[Snapshot]

Get a list of all snapshots in the database (read-only)

class KeyValueStore(buffer: Optional[DataBuffer] = None, handle=None)[source]

Bases: object

class KeyValueStore maintains access to the raw data stored in Snapshots and various other Database-related structures.

Parameters

buffer (Optional[DataBuffer]) –

begin_namespace(name: str)[source]

Begin storing new keys into a namespace

Parameters

name (str) –

end_namespace()[source]

End storing new keys into a namespace

get_value(key: str) DataBuffer[source]

Get the value for a single key

Parameters

key (str) –

Return type

DataBuffer

set_value(key: str, value: DataBuffer)[source]

Set the value for a single key

Parameters
property data_size: bool

Length of serialized data (read-only)

property empty: bool

If the kvs is empty (read-only)

property keys

Get a list of all keys stored in the kvs (read-only)

property namespace_size: bool

Number of namespaces pushed with begin_namespace (read-only)

property serialized_data: DataBuffer

Get the stored representation of the kvs (read-only)

property value_size: bool

Number of values in the kvs (read-only)

property value_storage_size: bool

Size of all data in storage (read-only)

class Snapshot(handle)[source]

Bases: object

class Snapshot is a model of an individual database snapshot, created on save.

has_ancestor(other: Snapshot) bool[source]

Determine if this snapshot has another as an ancestor

Parameters

other (Snapshot) –

Return type

bool

property children: List[Snapshot]

Get a list of all child snapshots of the snapshot (read-only)

property data: KeyValueStore

Get the backing kvs data with snapshot fields (read-only)

property database: Database

Get the owning database (read-only)

property file_contents: DataBuffer

Get a buffer of the raw data at the time of the snapshot (read-only)

property file_contents_hash: DataBuffer

Get a hash of the data at the time of the snapshot (read-only)

property first_parent: Optional[Snapshot]

Get the first parent of the snapshot, or None if it has no parents (read-only)

property has_contents: bool

If the snapshot has contents, and has not been trimmed (read-only)

property has_undo: bool

If the snapshot has undo data (read-only)

property id: int

Get the numerical id (read-only)

property is_auto_save: bool

If the snapshot was the result of an auto-save (read-only)

property name: str

Get the displayed snapshot name (read-only)

property parents: List[Snapshot]

Get a list of all parent snapshots of the snapshot (read-only)

property undo_entries

Get a list of undo entries at the time of the snapshot (read-only)