database module

Class

Description

binaryninja.database.Database

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

binaryninja.database.KeyValueStore

class KeyValueStore maintains access to the raw data stored in Snapshots and various

binaryninja.database.Snapshot

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

class Database[source]

Bases: object

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

__init__(handle)[source]
get_snapshot(id: int) Snapshot | None[source]

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

Parameters:

id (int) –

Return type:

Snapshot | None

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: Snapshot | None

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[source]

Bases: object

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

__init__(buffer: DataBuffer | None = None, handle=None)[source]
Parameters:

buffer (DataBuffer | None) –

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: int

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: int

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: int

Number of values in the kvs (read-only)

property value_storage_size: int

Size of all data in storage (read-only)

class Snapshot[source]

Bases: object

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

__init__(handle)[source]
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: Snapshot | None

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

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)

Database

class Database[source]

Bases: object

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

__init__(handle)[source]
get_snapshot(id: int) Snapshot | None[source]

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

Parameters:

id (int) –

Return type:

Snapshot | None

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: Snapshot | None

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)

KeyValueStore

class KeyValueStore[source]

Bases: object

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

__init__(buffer: DataBuffer | None = None, handle=None)[source]
Parameters:

buffer (DataBuffer | None) –

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: int

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: int

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: int

Number of values in the kvs (read-only)

property value_storage_size: int

Size of all data in storage (read-only)

Snapshot

class Snapshot[source]

Bases: object

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

__init__(handle)[source]
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: Snapshot | None

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

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)