collaboration.file module¶
Class representing a remote analysis database. |
- class File(handle)[source]¶
Bases:
object
Class representing a remote analysis database. It controls the various snapshots and raw file contents associated with the analysis.
- create_snapshot(name: str, contents: bytes, analysis_cache_contents: bytes, file: bytes, parent_ids: ~typing.List[str], progress: ~typing.Callable[[int, int], bool] = <function nop>) Snapshot [source]¶
Create a new snapshot on the remote (and pull it)
- Parameters:
name (str) – Snapshot name
contents (bytes) – Snapshot contents
analysis_cache_contents (bytes) – Contents of analysis cache of snapshot
file (bytes) – New file contents (if contents changed)
parent_ids (List[str]) – List of ids of parent snapshots (or empty if this is a root snapshot)
progress (Callable[[int, int], bool]) – Function to call on progress updates
- Returns:
Reference to the created snapshot
- Raises:
RuntimeError if there was an error
- Return type:
- delete_snapshot(snapshot: Snapshot)[source]¶
Delete a snapshot from the remote
- Parameters:
snapshot (Snapshot) – Snapshot to delete
- Raises:
RuntimeError if there was an error
- download(progress: ~typing.Callable[[int, int], bool] = <function nop>) bytes [source]¶
Download the contents of a remote file
- download_to_bndb(path: ~typing.Optional[str] = None, progress: ~typing.Callable[[int, int], bool] = <function nop>) FileMetadata [source]¶
Download a remote file and save it to a bndb at the given path. This calls databasesync.download_file and self.sync to fully prepare the bndb.
- static get_for_bv(bv: BinaryView) Optional[File] [source]¶
Look up the remote File for a local BinaryView, or None if there is no matching remote File found.
- Parameters:
bv (BinaryView) – Local BinaryView
- Returns:
Remote File object
- Return type:
File or None
- static get_for_local_database(database: Database) Optional[File] [source]¶
Look up the remote File for a local database, or None if there is no matching remote File found. See
get_for_bv
to load from a BinaryView.
- get_snapshot_by_id(id: str) Optional[Snapshot] [source]¶
Get a specific Snapshot in the File by its id
Note
If snapshots have not been pulled, they will be pulled upon calling this.
- pull(bv_or_db: ~typing.Union[binaryninja.BinaryView, binaryninja.Database], conflict_handler: util.ConflictHandlerType, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>)[source]¶
Pull updated snapshots from the remote. Merge local changes with remote changes and potentially create a new snapshot for unsaved changes, named via name_changeset.
- Parameters:
bv_or_db (Union[binaryninja.BinaryView, binaryninja.Database]) – Binary view or database to sync with
conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts
name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary
progress (util.ProgressFuncType) – Function to call for progress updates
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- pull_snapshots(progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]¶
Pull the list of Snapshots from the Remote.
- push(bv_or_db: ~typing.Union[~binaryninja.binaryview.BinaryView, ~binaryninja.database.Database], progress: ~typing.Callable[[int, int], bool] = <function nop>)[source]¶
Push locally added snapshots to the remote
- Parameters:
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- sync(bv_or_db: ~typing.Union[binaryninja.BinaryView, binaryninja.Database], conflict_handler: util.ConflictHandlerType, progress: util.ProgressFuncType = <function nop>, name_changeset: util.NameChangesetFuncType = <function nop>)[source]¶
Completely sync a file, pushing/pulling/merging/applying changes
- Parameters:
bv_or_db (Union[binaryninja.BinaryView, binaryninja.Database]) – Binary view or database to sync with
conflict_handler (util.ConflictHandlerType) – Function to call to resolve snapshot conflicts
name_changeset (util.NameChangesetFuncType) – Function to call for naming a pushed changeset, if necessary
progress (util.ProgressFuncType) – Function to call for progress updates
- Raises:
RuntimeError – If there was an error (or the operation was cancelled)
- property default_bndb_path: str¶
Get the default filepath for a remote File. This is based off the Setting for collaboration.directory, the file’s id, the file’s project’s id, and the file’s remote’s id.
- Returns:
Default file path
- Return type:
- property folder: Optional[Folder]¶
Parent folder, if one exists. None if this is in the root of the project.
- Returns:
Folder object or None
- property has_pulled_snapshots: bool¶
If the file has pulled the snapshots yet
- Returns:
True if they have been pulled
- property last_snapshot_by: str¶
Username of user who pushed the last snapshot in the file
- Returns:
Username string