summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2024-01-22 16:11:19 -0500
committerJosh Ferrell <josh@vector35.com>2024-01-22 16:11:19 -0500
commit3dd22f40996fc128ffce6026e8e747ca66bcc21d (patch)
treea5e7fc57dc620fc4d4a408ffdbf114bb66dcf91d /binaryninjaapi.h
parent96053ffc711aa27fcaeeb6cbfa89df0c253361f8 (diff)
Project support
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h381
1 files changed, 371 insertions, 10 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 872b862b..4dc1ac07 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2384,11 +2384,314 @@ namespace BinaryNinja {
void WriteGlobalData(const std::string& key, const DataBuffer& val);
Ref<FileMetadata> GetFile();
+ void ReloadConnection();
Ref<KeyValueStore> ReadAnalysisCache() const;
void WriteAnalysisCache(Ref<KeyValueStore> val);
};
+
+ /*!
+
+ \ingroup project
+ */
+ struct ProjectException : std::runtime_error
+ {
+ ProjectException(const std::string& desc) : std::runtime_error(desc.c_str()) {}
+ };
+
+ class ExternalLibrary;
+ class Symbol;
+ class Project;
+ class ProjectFile;
+ class ProjectFolder;
+
+ /*!
+
+ \ingroup project
+ */
+
+ class ExternalLocation : public CoreRefCountObject<BNExternalLocation, BNNewExternalLocationReference, BNFreeExternalLocation>
+ {
+ public:
+ ExternalLocation(BNExternalLocation* loc);
+
+ Ref<Symbol> GetInternalSymbol();
+ std::optional<uint64_t> GetAddress();
+ std::optional<std::string> GetSymbol();
+ Ref<ExternalLibrary> GetExternalLibrary();
+
+ bool HasAddress();
+ bool HasSymbol();
+
+ void SetAddress(std::optional<uint64_t> address);
+ void SetSymbol(std::optional<std::string> symbol);
+ void SetExternalLibrary(Ref<ExternalLibrary> library);
+ };
+
+ /*!
+
+ \ingroup project
+ */
+
+ class ExternalLibrary : public CoreRefCountObject<BNExternalLibrary, BNNewExternalLibraryReference, BNFreeExternalLibrary>
+ {
+ public:
+ ExternalLibrary(BNExternalLibrary* lib);
+
+ std::string GetName() const;
+ Ref<ProjectFile> GetBackingFile() const;
+
+ void SetBackingFile(Ref<ProjectFile> file);
+ };
+
+
+ /*!
+ \ingroup project
+ */
+ class ProjectNotification
+ {
+ private:
+ BNProjectNotification m_callbacks;
+
+ static bool BeforeOpenProjectCallback(void* ctxt, BNProject* project);
+ static void AfterOpenProjectCallback(void* ctxt, BNProject* project);
+ static bool BeforeCloseProjectCallback(void* ctxt, BNProject* project);
+ static void AfterCloseProjectCallback(void* ctxt, BNProject* project);
+ static bool BeforeProjectMetadataWrittenCallback(void* ctxt, BNProject* project, char* key, BNMetadata* value);
+ static void AfterProjectMetadataWrittenCallback(void* ctxt, BNProject* project, char* key, BNMetadata* value);
+ static bool BeforeProjectFileCreatedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static void AfterProjectFileCreatedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static bool BeforeProjectFileUpdatedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static void AfterProjectFileUpdatedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static bool BeforeProjectFileDeletedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static void AfterProjectFileDeletedCallback(void* ctxt, BNProject* project, BNProjectFile* projectFile);
+ static bool BeforeProjectFolderCreatedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+ static void AfterProjectFolderCreatedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+ static bool BeforeProjectFolderUpdatedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+ static void AfterProjectFolderUpdatedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+ static bool BeforeProjectFolderDeletedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+ static void AfterProjectFolderDeletedCallback(void* ctxt, BNProject* project, BNProjectFolder* projectFolder);
+
+ public:
+ ProjectNotification();
+ virtual ~ProjectNotification() {}
+
+ BNProjectNotification* GetCallbacks() { return &m_callbacks; }
+
+ virtual bool OnBeforeOpenProject(Project* project)
+ {
+ (void)project;
+ return true;
+ }
+
+ virtual void OnAfterOpenProject(Project* project)
+ {
+ (void)project;
+ }
+
+ virtual bool OnBeforeCloseProject(Project* project)
+ {
+ (void)project;
+ return true;
+ }
+
+ virtual void OnAfterCloseProject(Project* project)
+ {
+ (void)project;
+ }
+
+ virtual bool OnBeforeProjectMetadataWritten(Project* project, std::string& key, Metadata* value)
+ {
+ (void)project;
+ (void)key;
+ (void)value;
+ return true;
+ }
+
+ virtual void OnAfterProjectMetadataWritten(Project* project, std::string& key, Metadata* value)
+ {
+ (void)project;
+ (void)key;
+ (void)value;
+ }
+
+ virtual bool OnBeforeProjectFileCreated(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ return true;
+ }
+
+ virtual void OnAfterProjectFileCreated(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ }
+
+ virtual bool OnBeforeProjectFileUpdated(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ return true;
+ }
+
+ virtual void OnAfterProjectFileUpdated(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ }
+
+ virtual bool OnBeforeProjectFileDeleted(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ return true;
+ }
+
+ virtual void OnAfterProjectFileDeleted(Project* project, ProjectFile* projectFile)
+ {
+ (void)project;
+ (void)projectFile;
+ }
+
+ virtual bool OnBeforeProjectFolderCreated(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ return true;
+ }
+
+ virtual void OnAfterProjectFolderCreated(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ }
+
+ virtual bool OnBeforeProjectFolderUpdated(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ return true;
+ }
+
+ virtual void OnAfterProjectFolderUpdated(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ }
+
+ virtual bool OnBeforeProjectFolderDeleted(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ return true;
+ }
+
+ virtual void OnAfterProjectFolderDeleted(Project* project, ProjectFolder* projectFolder)
+ {
+ (void)project;
+ (void)projectFolder;
+ }
+ };
+
+ /*!
+
+ \ingroup project
+ */
+ class ProjectFolder : public CoreRefCountObject<BNProjectFolder, BNNewProjectFolderReference, BNFreeProjectFolder>
+ {
+ public:
+ ProjectFolder(BNProjectFolder* folder);
+
+ Ref<Project> GetProject() const;
+ std::string GetId() const;
+ std::string GetName() const;
+ std::string GetDescription() const;
+ void SetName(const std::string& name);
+ void SetDescription(const std::string& description);
+ Ref<ProjectFolder> GetParent() const;
+ void SetParent(Ref<ProjectFolder> parent);
+ bool Export(const std::string& destination, const std::function<bool(size_t progress, size_t total)>& progressCallback = {}) const;
+ };
+
+ /*!
+
+ \ingroup project
+ */
+ class ProjectFile : public CoreRefCountObject<BNProjectFile, BNNewProjectFileReference, BNFreeProjectFile>
+ {
+ public:
+ ProjectFile(BNProjectFile* file);
+
+ Ref<Project> GetProject() const;
+ std::string GetPathOnDisk() const;
+ bool ExistsOnDisk() const;
+ std::string GetName() const;
+ std::string GetDescription() const;
+ void SetName(const std::string& name);
+ void SetDescription(const std::string& description);
+ std::string GetId() const;
+ Ref<ProjectFolder> GetFolder() const;
+ void SetFolder(Ref<ProjectFolder> folder);
+ bool Export(const std::string& destination) const;
+ };
+
+
+ /*!
+
+ \ingroup project
+ */
+ class Project : public CoreRefCountObject<BNProject, BNNewProjectReference, BNFreeProject>
+ {
+ public:
+ Project(BNProject* project);
+
+ static Ref<Project> CreateProject(const std::string& path, const std::string& name);
+ static Ref<Project> OpenProject(const std::string& path);
+ static std::vector<Ref<Project>> GetOpenProjects();
+
+ bool Open();
+ bool Close();
+ std::string GetId() const;
+ bool IsOpen() const;
+ std::string GetPath() const;
+ std::string GetName() const;
+ void SetName(const std::string& name);
+ std::string GetDescription() const;
+ void SetDescription(const std::string& description);
+
+ Ref<Metadata> QueryMetadata(const std::string& key);
+ bool StoreMetadata(const std::string& key, Ref<Metadata> value);
+ void RemoveMetadata(const std::string& key);
+
+ Ref<ProjectFolder> CreateFolderFromPath(const std::string& path, Ref<ProjectFolder> parent, const std::string& description,
+ const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+ Ref<ProjectFolder> CreateFolder(Ref<ProjectFolder> parent, const std::string& name, const std::string& description);
+ Ref<ProjectFolder> CreateFolderUnsafe(Ref<ProjectFolder> parent, const std::string& name, const std::string& description, const std::string& id);
+ std::vector<Ref<ProjectFolder>> GetFolders() const;
+ Ref<ProjectFolder> GetFolderById(const std::string& id) const;
+ void PushFolder(Ref<ProjectFolder> folder);
+ void DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+
+ Ref<ProjectFile> CreateFileFromPath(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+ Ref<ProjectFile> CreateFileFromPathUnsafe(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+ Ref<ProjectFile> CreateFile(const std::vector<uint8_t>& contents, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+ Ref<ProjectFile> CreateFileUnsafe(const std::vector<uint8_t>& contents, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
+ std::vector<Ref<ProjectFile>> GetFiles() const;
+ Ref<ProjectFile> GetFileById(const std::string& id) const;
+ Ref<ProjectFile> GetFileByPathOnDisk(const std::string& path);
+ void PushFile(Ref<ProjectFile> file);
+ void DeleteFile_(Ref<ProjectFile> file);
+
+ void RegisterNotification(ProjectNotification* notify);
+ void UnregisterNotification(ProjectNotification* notify);
+
+ void BeginBulkOperation();
+ void EndBulkOperation();
+ };
+
+
/*!
\ingroup undo
@@ -2439,6 +2742,7 @@ namespace BinaryNinja {
public:
FileMetadata();
FileMetadata(const std::string& filename);
+ FileMetadata(Ref<ProjectFile> projectFile);
FileMetadata(BNFileMetadata* file);
/*! Close the underlying file handle
@@ -2646,10 +2950,6 @@ namespace BinaryNinja {
std::optional<std::string> GetLastRedoEntryTitle();
void ClearUndoEntries();
- bool OpenProject();
- void CloseProject();
- bool IsProjectOpen();
-
/*! Get the current View name, e.g. ``Linear:ELF``, ``Graph:PE``
\return The current view name
@@ -2706,11 +3006,13 @@ namespace BinaryNinja {
\param data the binary view to unregister
*/
void UnregisterViewOfType(const std::string& type, BinaryNinja::Ref<BinaryNinja::BinaryView> data);
+
+ Ref<ProjectFile> GetProjectFile() const;
+ void SetProjectFile(Ref<ProjectFile> projectFile);
};
class Function;
struct DataVariable;
- class Symbol;
class Tag;
class TagType;
struct TagReference;
@@ -2770,6 +3072,12 @@ namespace BinaryNinja {
static void ComponentFunctionRemovedCallback(void* ctxt, BNBinaryView* data, BNComponent* component, BNFunction* function);
static void ComponentDataVariableAddedCallback(void* ctxt, BNBinaryView* data, BNComponent* component, BNDataVariable* var);
static void ComponentDataVariableRemovedCallback(void* ctxt, BNBinaryView* data, BNComponent* component, BNDataVariable* var);
+ static void ExternalLibraryAddedCallback(void* ctxt, BNBinaryView* data, BNExternalLibrary* library);
+ static void ExternalLibraryUpdatedCallback(void* ctxt, BNBinaryView* data, BNExternalLibrary* library);
+ static void ExternalLibraryRemovedCallback(void* ctxt, BNBinaryView* data, BNExternalLibrary* library);
+ static void ExternalLocationAddedCallback(void* ctxt, BNBinaryView* data, BNExternalLocation* location);
+ static void ExternalLocationUpdatedCallback(void* ctxt, BNBinaryView* data, BNExternalLocation* location);
+ static void ExternalLocationRemovedCallback(void* ctxt, BNBinaryView* data, BNExternalLocation* location);
public:
@@ -2814,6 +3122,12 @@ namespace BinaryNinja {
ComponentFunctionRemoved = 1ULL << 36,
ComponentDataVariableAdded = 1ULL << 37,
ComponentDataVariableRemoved = 1ULL << 38,
+ ExternalLibraryAdded = 1ULL << 39,
+ ExternalLibraryUpdated = 1ULL << 40,
+ ExternalLibraryRemoved = 1ULL << 41,
+ ExternalLocationAdded = 1ULL << 42,
+ ExternalLocationUpdated = 1ULL << 43,
+ ExternalLocationRemoved = 1ULL << 44,
BinaryDataUpdates = DataWritten | DataInserted | DataRemoved,
FunctionLifetime = FunctionAdded | FunctionRemoved,
@@ -3120,6 +3434,42 @@ namespace BinaryNinja {
(void)component;
(void)var;
}
+
+ virtual void OnExternalLibraryAdded(BinaryView* data, ExternalLibrary* library)
+ {
+ (void)data;
+ (void)library;
+ }
+
+ virtual void OnExternalLibraryUpdated(BinaryView* data, ExternalLibrary* library)
+ {
+ (void)data;
+ (void)library;
+ }
+
+ virtual void OnExternalLibraryRemoved(BinaryView* data, ExternalLibrary* library)
+ {
+ (void)data;
+ (void)library;
+ }
+
+ virtual void OnExternalLocationAdded(BinaryView* data, ExternalLocation* location)
+ {
+ (void)data;
+ (void)location;
+ }
+
+ virtual void OnExternalLocationUpdated(BinaryView* data, ExternalLocation* location)
+ {
+ (void)data;
+ (void)location;
+ }
+
+ virtual void OnExternalLocationRemoved(BinaryView* data, ExternalLocation* location)
+ {
+ (void)data;
+ (void)location;
+ }
};
/*!
@@ -3233,9 +3583,9 @@ namespace BinaryNinja {
*/
class QualifiedName : public NameList
{
- public:
- using NameList::operator=;
using NameList::operator+;
+ using NameList::operator=;
+ public:
QualifiedName();
QualifiedName(const BNQualifiedName* name);
@@ -3260,9 +3610,9 @@ namespace BinaryNinja {
*/
class NameSpace : public NameList
{
- public:
- using NameList::operator=;
using NameList::operator+;
+ using NameList::operator=;
+ public:
NameSpace();
NameSpace(const std::string& name);
@@ -6008,6 +6358,16 @@ namespace BinaryNinja {
\return Whether the magic value exists
*/
bool GetExpressionParserMagicValue(const std::string& name, uint64_t* value);
+
+ Ref<ExternalLibrary> AddExternalLibrary(const std::string& name, Ref<ProjectFile> backingFile, bool isAuto = false);
+ void RemoveExternalLibrary(const std::string& name);
+ Ref<ExternalLibrary> GetExternalLibrary(const std::string& name);
+ std::vector<Ref<ExternalLibrary>> GetExternalLibraries();
+
+ Ref<ExternalLocation> AddExternalLocation(Ref<Symbol> internalSymbol, Ref<ExternalLibrary> library, std::optional<std::string> externalSymbol, std::optional<uint64_t> externalAddress, bool isAuto = false);
+ void RemoveExternalLocation(Ref<Symbol> internalSymbol);
+ Ref<ExternalLocation> GetExternalLocation(Ref<Symbol> internalSymbol);
+ std::vector<Ref<ExternalLocation>> GetExternalLocations();
};
@@ -14815,6 +15175,7 @@ namespace BinaryNinja {
bool IsCancelled() const;
bool IsFinished() const;
std::string GetProgressText() const;
+ uint64_t GetRuntimeSeconds() const;
void Cancel();
void Finish();
@@ -15037,7 +15398,7 @@ namespace BinaryNinja {
================= ========================== ============== ==============================================
Default SettingsDefaultScope Lowest Settings Schema
User SettingsUserScope - <User Directory>/settings.json
- Project SettingsProjectScope - <Project Directory>/.binaryninja/settings.json
+ Project SettingsProjectScope - <Project Directory>/settings.json
Resource SettingsResourceScope Highest Raw BinaryView (Storage in BNDB)
================= ========================== ============== ==============================================