project module

binaryninja.project.Project(handle)

Class representing a project

binaryninja.project.ProjectFile(handle)

Class representing a file in a project

binaryninja.project.ProjectFolder(handle)

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:

bool

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:

ProjectFile

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:
  • path (PathLike | str) – Path on disk

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

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:
  • path (PathLike | str) – Path to the project directory (.bnpr)

  • name (str) – Name of the new project

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

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)[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 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

class ProjectFile(handle: LP_BNProjectFile)[source]

Bases: object

Class representing a file in a project

Parameters:

handle (LP_BNProjectFile) –

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

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

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

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