GeezerVison is showing api.binary.ninja — project module — Binary Ninja API Documentation v6.0.10905
project module¶
Project¶
-
class Project[source]¶
Bases: object
Class representing a project
-
__init__(handle: LP_BNProject)[source]¶
- 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:
bool
-
create_file(contents: bytes, folder: ~binaryninja.project.ProjectFolder | 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 (ProjectFolder | 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:
ProjectFile
-
create_file_from_path(path: ~os.PathLike | str, folder: ~binaryninja.project.ProjectFolder | 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:
path (PathLike | str) – Path on disk
folder (ProjectFolder | 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:
ProjectFile
-
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:
ProjectFolder
-
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:
path (PathLike | str) – Path to folder on disk
parent (ProjectFolder | None) – Parent folder in the project that will contain the new contents
description (str) – Description for created root folder
progress_func (Callable[[int, int], bool]) – Progress function that will be called
- Returns:
Created root folder
- Return type:
ProjectFolder
-
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:
Project
-
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:
bool
-
delete_folder(folder: ~binaryninja.project.ProjectFolder, progress_func: ~typing.Callable[[int, int], bool] = <function _nop>) → bool[source]¶
Recursively delete a folder from the project
- Parameters:
folder (ProjectFolder) – Folder to delete recursively
progress_func (Callable[[int, int], bool]) – Progress function that will be called as objects get deleted
- Returns:
True if the folder was deleted, False otherwise
- Return type:
bool
-
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_file_by_path_on_disk(path: str) → ProjectFile | None[source]¶
Retrieve a file in the project by its path on disk
- Parameters:
path (str) – Path of the file on the disk
- Returns:
File with the requested path or None
- Return type:
ProjectFile | None
-
get_files_by_path_in_project(path: str) → List[ProjectFile][source]¶
Retrieve a file(s) by path in the project
Note that files in a project can share names and paths within the project
but are uniquely identified by a disk path or id.
- Parameters:
path (str) – Path of the file(s) in the project, separate from their path on disk.
- Returns:
List of files with the requested path
- Return type:
List[ProjectFile]
-
get_files_in_folder(folder: ProjectFolder | None) → List[ProjectFile][source]¶
Get the list of files in a folder
- Returns:
List of files contained in the folder
- Parameters:
folder (ProjectFolder | None)
- Return type:
List[ProjectFile]
-
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
-
get_metadata(key: str, default: Any = None) → metadata.MetadataValueType | Any[source]¶
get_metadata retrieves a metadata value associated with the given key stored in the current Project.
This method behaves like dict.get():
If the key exists, its metadata value is returned.
If the key does not exist and default is not provided, None is returned.
If the key does not exist and default is provided, default is returned.
- Parameters:
-
- Return type:
metadata associated with the key or the default value
- Example:
>>> current_project.store_metadata("integer", 1337)
>>> current_project.get_metadata("integer")
1337L
>>> current_project.get_metadata("missing")
None
>>> current_project.get_metadata("missing", 42)
42
-
open() → bool[source]¶
Open a closed project
- Returns:
True if the project is now open, False otherwise
- Return type:
bool
-
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:
Project
-
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) → bool[source]¶
Removes the metadata associated with this key from the project
- Parameters:
key (str) – Key associated with the metadata object to remove
- Return type:
bool
-
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) → bool[source]¶
Stores metadata within the project
- Parameters:
-
- Return type:
bool
-
property description: str¶
Get the description of the project
- Returns:
Description of the project
-
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
-
property id: str¶
Get the unique id of this project
- Returns:
Unique identifier of project
-
property is_open: bool¶
Check if the project is currently open
- Returns:
True if the project is currently open, False otherwise
-
property name: str¶
Get the name of the project
- Returns:
Name of the project
-
property path: str¶
Get the path of the project
- Returns:
Path of the project’s .bnpr directory
ProjectFile¶
-
class ProjectFile[source]¶
Bases: object
Class representing a file in a project
-
__init__(handle: LP_BNProjectFile)[source]¶
- Parameters:
handle (LP_BNProjectFile)
-
add_dependency(file: ProjectFile) → bool[source]¶
Add a ProjectFile as a dependency of this file
- Returns:
True on success, False otherwise
- Parameters:
file (ProjectFile)
- Return type:
bool
-
export(dest: PathLike | str) → bool[source]¶
Export this file to disk
- Parameters:
dest (PathLike | str) – Destination path for the exported contents
- Returns:
True if the export succeeded, False otherwise
- Return type:
bool
-
get_dependencies() → List[ProjectFile][source]¶
Get the list of files that this file depends on
- Returns:
List of ProjectFiles that this file depends on
- Return type:
List[ProjectFile]
-
get_path_in_project() → str | None[source]¶
Get this file’s path in its parent project
- Returns:
The path in the project or None
- Return type:
str | None
-
get_path_on_disk() → str | None[source]¶
Get this file’s path on disk
- Returns:
The path on disk of the file or None
- Return type:
str | None
-
get_required_by() → List[ProjectFile][source]¶
Get the list of files that depend on this file
- Returns:
List of ProjectFiles that depend on this file
- Return type:
List[ProjectFile]
-
remove_dependency(file: ProjectFile) → bool[source]¶
Remove a ProjectFile as a dependency of this file
- Returns:
True on success, False otherwise
- Parameters:
file (ProjectFile)
- Return type:
bool
-
property description: str¶
Get the description of this file
- Returns:
Description of this file
-
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
-
property id: str¶
Get the unique id of this file
- Returns:
Unique identifier of this file
-
property name: str¶
Get the name of this file
- Returns:
Name of this file
-
property path_on_disk: str¶
Get the path on disk to this file’s contents
- Returns:
Path on disk as a string
-
property project: Project¶
Get the project that owns this file
- Returns:
Project that owns this file
ProjectFolder¶
-
class ProjectFolder[source]¶
Bases: object
Class representing a folder in a project
-
__init__(handle: LP_BNProjectFolder)[source]¶
- 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
- Parameters:
dest (PathLike | str) – Destination path for the exported contents
progress_func (Callable[[int, int], bool]) – Progress function that will be called as contents are exporting
- Returns:
True if the export succeeded, False otherwise
- Return type:
bool
-
property description: str¶
Get the description of this folder
- Returns:
Description of this folder
-
property files: List[ProjectFile]¶
Get the list of files in this folder
- Returns:
List of files contained in the folder
-
property id: str¶
Get the unique id of this folder
- Returns:
Unique identifier of this folder
-
property name: str¶
Get the name of this folder
- Returns:
Name of this folder
-
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
-
property project: Project¶
Get the project that owns this folder
- Returns:
Project that owns this folder
|