project module¶
|
Class representing a project |
|
Class representing a file in a project |
Class representing a folder in a project |
- class Project(handle: LP_BNProject)[source]¶
Bases:
object
Class representing a project
- Parameters:
handle (LP_BNProject) –
- bulk_operation()[source]¶
A context manager to speed up bulk project operations. Project modifications are synced to disk in chunks, and the project on disk vs in memory may not agree on state if an exception occurs while a bulk operation is happening.
- Example:
>>> from pathlib import Path >>> with project.bulk_operation(): ... for i in Path('/bin/').iterdir(): ... if i.is_file() and not i.is_symlink(): ... project.create_file_from_path(i, None, i.name)
- close() bool [source]¶
Close an opened project
- Returns:
True if the project is now closed, False otherwise
- Return type:
- create_file(contents: bytes, folder: ~binaryninja.project.ProjectFile | None, name: str, description: str = '', progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) ProjectFile [source]¶
Create a file in the project
- Parameters:
contents (bytes) – Bytes of the file that will be created
folder (ProjectFile | None) – Folder to place the created file in
name (str) – Name to assign to the created file
description (str) – Description to assign to the created file
progress_func (Callable[[int, int], bool]) – Progress function that will be called as the file is being added
- Return type:
- create_file_from_path(path: ~os.PathLike | str, folder: ~binaryninja.project.ProjectFile | None, name: str, description: str = '', progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) ProjectFile [source]¶
Create a file in the project from a path on disk
- Parameters:
- Return type:
- create_folder(parent: ProjectFolder | None, name: str, description: str = '') ProjectFolder [source]¶
Recursively create files and folders in the project from a path on disk
- Parameters:
parent (ProjectFolder | None) – Parent folder in the project that will contain the new folder
name (str) – Name for the created folder
description (str) – Description for created folder
- Returns:
Created folder
- Return type:
- create_folder_from_path(path: ~os.PathLike | str, parent: ~binaryninja.project.ProjectFolder | None = None, description: str = '', progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) ProjectFolder [source]¶
Recursively create files and folders in the project from a path on disk
- Parameters:
- Returns:
Created root folder
- Return type:
- static create_project(path: PathLike | str, name: str) Project [source]¶
Create a new project
- Parameters:
- Returns:
Opened project
- Raises:
ProjectException – If there was an error creating the project
- Return type:
- delete_file(file: ProjectFile) bool [source]¶
Delete a file from the project
- Parameters:
file (ProjectFile) – File to delete
- Returns:
True if the file was deleted, False otherwise
- Return type:
- delete_folder(folder: ~binaryninja.project.ProjectFolder, progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) bool [source]¶
Recursively delete a folder from the project
- get_file_by_id(id: str) ProjectFile | None [source]¶
Retrieve a file in the project by unique id
- Parameters:
id (str) – Unique identifier for a file
- Returns:
File with the requested id or None
- Return type:
ProjectFile | None
- get_folder_by_id(id: str) ProjectFolder | None [source]¶
Retrieve a folder in the project by unique id
- Parameters:
id (str) – Unique identifier for a folder
- Returns:
Folder with the requested id or None
- Return type:
ProjectFolder | None
- open() bool [source]¶
Open a closed project
- Returns:
True if the project is now open, False otherwise
- Return type:
- static open_project(path: PathLike | str) Project [source]¶
Open an existing project
- Parameters:
path (PathLike | str) – Path to the project directory (.bnpr) or project metadata file (.bnpm)
- Returns:
Opened project
- Raises:
ProjectException – If there was an error opening the project
- Return type:
- query_metadata(key: str) Metadata | int | bool | str | bytes | float | List[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | Tuple[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | dict [source]¶
Retrieves metadata stored under a key from the project
- Parameters:
key (str) – Key to query
- Return type:
Metadata | int | bool | str | bytes | float | List[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | Tuple[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | dict
- remove_metadata(key: str)[source]¶
Removes the metadata associated with this key from the project
- Parameters:
key (str) – Key associated with the metadata object to remove
- store_metadata(key: str, value: Metadata | int | bool | str | bytes | float | List[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | Tuple[Metadata | int | bool | str | bytes | float | List[MetadataValueType] | Tuple[MetadataValueType] | dict] | dict)[source]¶
Stores metadata within the project
- Parameters:
key (str) – Key under which to store the Metadata object
value (Varies) – Object to store
- property files: List[ProjectFile]¶
Get a list of files in the project
- Returns:
List of files in the project
- property folders: List[ProjectFolder]¶
Get a list of folders in the project
- Returns:
List of folders in the project
- class ProjectFile(handle: LP_BNProjectFile)[source]¶
Bases:
object
Class representing a file in a project
- Parameters:
handle (LP_BNProjectFile) –
- property exists_on_disk: bool¶
Check if this file’s contents exist on disk
- Returns:
True if this file’s contents exist on disk, False otherwise
- property folder: ProjectFolder | None¶
Get the folder that contains this file
- Returns:
Folder that contains this file, or None
- class ProjectFolder(handle: LP_BNProjectFolder)[source]¶
Bases:
object
Class representing a folder in a project
- Parameters:
handle (LP_BNProjectFolder) –
- export(dest: ~os.PathLike | str, progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) bool [source]¶
Recursively export this folder to disk
- property parent: ProjectFolder | None¶
Get the parent folder of this folder
- Returns:
Folder that contains this folder, or None if it is a root folder