project module¶
Class | Description |
|---|---|
Class representing a project | |
Class representing a file in a project | |
Class representing a folder in a project |
Project¶
- classProject[source]¶
Bases:
objectClass representing a project
- 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 stateif an exception occurs while a bulk operation is happening.
- Example:
>>>frompathlibimportPath>>>withproject.bulk_operation():...foriinPath('/bin/').iterdir():...ifi.is_file()andnoti.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.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:
- 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:
- 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:
- staticcreate_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_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 projectNote that files in a project can share names and paths within the projectbut 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:
- 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:
- staticopen_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
- remove_metadata(key:str)→bool[source]¶
Removes the metadata associated with this key from the project
- 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
- propertyfiles:List[ProjectFile]¶
Get a list of files in the project
- Returns:
List of files in the project
- propertyfolders:List[ProjectFolder]¶
Get a list of folders in the project
- Returns:
List of folders in the project
ProjectFile¶
- classProjectFile[source]¶
Bases:
objectClass representing a file in a project
- 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:
- 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:
- 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:
- 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:
- propertyexists_on_disk:bool¶
Check if this file’s contents exist on disk
- Returns:
True if this file’s contents exist on disk, False otherwise
- propertyfolder:ProjectFolder|None¶
Get the folder that contains this file
- Returns:
Folder that contains this file, or None
ProjectFolder¶
- classProjectFolder[source]¶
Bases:
objectClass representing a folder in a project
- export(dest:~os.PathLike|str,progress_func:~typing.Callable[[int,int],bool]=<function_nop>)→bool[source]¶
Recursively export this folder to disk
- propertyparent:ProjectFolder|None¶
Get the parent folder of this folder
- Returns:
Folder that contains this folder, or None if it is a root folder