database module

Class

Description

binaryninja.database.Database

classDatabase provides lower level access to raw snapshot data used to construct analysis data

binaryninja.database.KeyValueStore

classKeyValueStore maintains access to the raw data stored in Snapshots and various other…

binaryninja.database.Snapshot

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

Database

classDatabase[source]

Bases:object

classDatabase 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/childhierarchy 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:
write_global_data(key:str,value:DataBuffer)[source]

Write a binary buffer into a global in the database

Parameters:
propertyanalysis_cache:KeyValueStore

Get the backing analysis cache kvs (read-only)

propertycurrent_snapshot:Snapshot|None

Get the current snapshot

propertyfile:FileMetadata

Get the owning FileMetadata (read-only)

propertyglobal_keys:List[str]

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

propertyglobals:Dict[str,str]

Get a dictionary of all globals (read-only)

propertysnapshots:List[Snapshot]

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

KeyValueStore

classKeyValueStore[source]

Bases:object

classKeyValueStore maintains access to the raw data stored in Snapshots and variousother 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:
propertydata_size:int

Length of serialized data (read-only)

propertyempty:bool

If the kvs is empty (read-only)

propertykeys

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

propertynamespace_size:int

Number of namespaces pushed with begin_namespace (read-only)

propertyserialized_data:DataBuffer

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

propertyvalue_size:int

Number of values in the kvs (read-only)

propertyvalue_storage_size:int

Size of all data in storage (read-only)

Snapshot

classSnapshot[source]

Bases:object

classSnapshot 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

propertychildren:List[Snapshot]

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

propertydata:KeyValueStore

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

propertydatabase:Database

Get the owning database (read-only)

propertyfile_contents:DataBuffer

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

propertyfile_contents_hash:DataBuffer

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

propertyfirst_parent:Snapshot|None

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

propertyhas_contents:bool

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

propertyhas_undo:bool

If the snapshot has undo data (read-only)

propertyid:int

Get the numerical id (read-only)

propertyis_auto_save:bool

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

propertyname:str

Get the displayed snapshot name

propertyparents:List[Snapshot]

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

propertyundo_entries

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