From 9262278979709181414664053523657355762707 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Thu, 24 Apr 2025 14:46:37 -0400 Subject: std::function ==> ProgressFunction --- binaryninjaapi.h | 145 +++++++++++++++++++++++++++---------------------------- 1 file changed, 72 insertions(+), 73 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 30cc6ad0..a749ac79 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1492,6 +1492,9 @@ namespace BinaryNinja { bool IsKeyValueStore() const; }; + typedef std::function ProgressFunction; + bool DefaultProgressFunction(size_t, size_t); + class BinaryView; class ProjectFile; @@ -1529,12 +1532,12 @@ namespace BinaryNinja { being loaded. If the function returns false, it will cancel Load. \return Constructed view, or a nullptr Ref */ - Ref Load(const std::string& filename, bool updateAnalysis = true, const std::string& options = "{}", std::function progress = {}); + Ref Load(const std::string& filename, bool updateAnalysis = true, const std::string& options = "{}", ProgressFunction progress = {}); /*! Open a BinaryView from a raw data buffer, initializing data views and loading settings. @threadmainonly - \see BinaryNinja::Load(const std::string&, bool, std::function, Json::Value) + \see BinaryNinja::Load(const std::string&, bool, ProgressFunction, Json::Value) for discussion of this function. \param rawData Buffer with raw binary data to load (cannot load from bndb) @@ -1545,14 +1548,14 @@ namespace BinaryNinja { being loaded. If the function returns false, it will cancel Load. \return Constructed view, or a nullptr Ref */ - Ref Load(const DataBuffer& rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function progress = {}); + Ref Load(const DataBuffer& rawData, bool updateAnalysis = true, const std::string& options = "{}", ProgressFunction progress = {}); /*! Open a BinaryView from a raw BinaryView, initializing data views and loading settings. @threadmainonly - \see BinaryNinja::Load(const std::string&, bool, std::function, Json::Value) + \see BinaryNinja::Load(const std::string&, bool, ProgressFunction, Json::Value) for discussion of this function. \param rawData BinaryView with raw binary data to load @@ -1563,13 +1566,13 @@ namespace BinaryNinja { being loaded. If the function returns false, it will cancel Load. \return Constructed view, or a nullptr Ref */ - Ref Load(Ref rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function progress = {}); + Ref Load(Ref rawData, bool updateAnalysis = true, const std::string& options = "{}", ProgressFunction progress = {}); /*! Open a BinaryView from a ProjectFile, initializing data views and loading settings. @threadmainonly - \see BinaryNinja::Load(const std::string&, bool, std::function, Json::Value) + \see BinaryNinja::Load(const std::string&, bool, ProgressFunction, Json::Value) for discussion of this function. \param rawData BinaryView with raw binary data to load @@ -1580,24 +1583,24 @@ namespace BinaryNinja { being loaded. If the function returns false, it will cancel Load. \return Constructed view, or a nullptr Ref */ - Ref Load(Ref rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function progress = {}); + Ref Load(Ref rawData, bool updateAnalysis = true, const std::string& options = "{}", ProgressFunction progress = {}); Ref ParseTextFormat(const std::string& filename); /*! Deprecated. Use non-metadata version. */ - Ref Load(const std::string& filename, bool updateAnalysis, std::function progress, Ref options = new Metadata(MetadataType::KeyValueDataType)); + Ref Load(const std::string& filename, bool updateAnalysis, ProgressFunction progress, Ref options = new Metadata(MetadataType::KeyValueDataType)); /*! Deprecated. Use non-metadata version. */ - Ref Load(const DataBuffer& rawData, bool updateAnalysis, std::function progress, Ref options = new Metadata(MetadataType::KeyValueDataType)); + Ref Load(const DataBuffer& rawData, bool updateAnalysis, ProgressFunction progress, Ref options = new Metadata(MetadataType::KeyValueDataType)); /*! Deprecated. Use non-metadata version. */ - Ref Load(Ref rawData, bool updateAnalysis, std::function progress, Ref options = new Metadata(MetadataType::KeyValueDataType), bool isDatabase = false); + Ref Load(Ref rawData, bool updateAnalysis, ProgressFunction progress, Ref options = new Metadata(MetadataType::KeyValueDataType), bool isDatabase = false); /*! Attempt to demangle a mangled name, trying all relevant demanglers and using whichever one accepts it @@ -2032,9 +2035,6 @@ namespace BinaryNinja { */ bool OpenUrl(const std::string& url); - typedef std::function ProgressFunction; - bool DefaultProgressFunction(size_t, size_t); - /*! Run a given task in a background thread, and show an updating progress bar which the user can cancel @threadsafe @@ -2092,7 +2092,7 @@ namespace BinaryNinja { struct ProgressContext { - std::function callback; + ProgressFunction callback; }; bool ProgressCallback(void* ctxt, size_t current, size_t total); @@ -2517,10 +2517,10 @@ namespace BinaryNinja { DataBuffer GetFileContentsHash(); DataBuffer GetUndoData(); std::vector> GetUndoEntries(); - std::vector> GetUndoEntries(const std::function& progress); + std::vector> GetUndoEntries(const ProgressFunction& progress); Ref ReadData(); - Ref ReadData(const std::function& progress); - bool StoreData(const Ref& data, const std::function& progress); + Ref ReadData(const ProgressFunction& progress); + bool StoreData(const Ref& data, const ProgressFunction& progress); bool HasAncestor(Ref other); }; @@ -2541,7 +2541,7 @@ namespace BinaryNinja { void SetCurrentSnapshot(int64_t id); Ref GetCurrentSnapshot(); int64_t WriteSnapshotData(std::vector parents, Ref file, const std::string& name, - const Ref& data, bool autoSave, const std::function& progress); + const Ref& data, bool autoSave, const ProgressFunction& progress); void TrimSnapshot(int64_t id); void RemoveSnapshot(int64_t id); @@ -2781,7 +2781,7 @@ namespace BinaryNinja { void SetDescription(const std::string& description); Ref GetParent() const; void SetParent(Ref parent); - bool Export(const std::string& destination, const std::function& progressCallback = {}) const; + bool Export(const std::string& destination, const ProgressFunction& progressCallback = {}) const; }; /*! @@ -2840,18 +2840,18 @@ namespace BinaryNinja { void RemoveMetadata(const std::string& key); Ref CreateFolderFromPath(const std::string& path, Ref parent, const std::string& description, - const std::function& progressCallback = {}); + const ProgressFunction& progressCallback = {}); Ref CreateFolder(Ref parent, const std::string& name, const std::string& description); Ref CreateFolderUnsafe(Ref parent, const std::string& name, const std::string& description, const std::string& id); std::vector> GetFolders() const; Ref GetFolderById(const std::string& id) const; void PushFolder(Ref folder); - bool DeleteFolder(Ref folder, const std::function& progressCallback = {}); + bool DeleteFolder(Ref folder, const ProgressFunction& progressCallback = {}); - Ref CreateFileFromPath(const std::string& path, Ref folder, const std::string& name, const std::string& description, const std::function& progressCallback = {}); - Ref CreateFileFromPathUnsafe(const std::string& path, Ref folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const std::function& progressCallback = {}); - Ref CreateFile_(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const std::function& progressCallback = {}); - Ref CreateFileUnsafe(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const std::function& progressCallback = {}); + Ref CreateFileFromPath(const std::string& path, Ref folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback = {}); + Ref CreateFileFromPathUnsafe(const std::string& path, Ref folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const ProgressFunction& progressCallback = {}); + Ref CreateFile_(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback = {}); + Ref CreateFileUnsafe(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const ProgressFunction& progressCallback = {}); std::vector> GetFiles() const; Ref GetFileById(const std::string& id) const; Ref GetFileByPathOnDisk(const std::string& path); @@ -2998,7 +2998,7 @@ namespace BinaryNinja { \return Whether the save was successful */ bool CreateDatabase(const std::string& name, BinaryView* data, - const std::function& progressCallback, Ref settings); + const ProgressFunction& progressCallback, Ref settings); /*! Open an existing database from a given path @@ -3014,7 +3014,7 @@ namespace BinaryNinja { \return The resulting BinaryView, if the load was successful */ Ref OpenExistingDatabase( - const std::string& path, const std::function& progressCallback); + const std::string& path, const ProgressFunction& progressCallback); Ref OpenDatabaseForConfiguration(const std::string& path); /*! Save the current database to the already created file. @@ -3037,11 +3037,11 @@ namespace BinaryNinja { \return Whether the save was successful */ bool SaveAutoSnapshot(BinaryView* data, - const std::function& progressCallback, Ref settings); + const ProgressFunction& progressCallback, Ref settings); void GetSnapshotData( - Ref data, Ref cache, const std::function& progress); + Ref data, Ref cache, const ProgressFunction& progress); void ApplySnapshotData(BinaryView* file, Ref data, Ref cache, - const std::function& progress, bool openForConfiguration = false, + const ProgressFunction& progress, bool openForConfiguration = false, bool restoreRawView = true); Ref GetDatabase(); @@ -3061,10 +3061,10 @@ namespace BinaryNinja { \return Whether the rebase was successful */ bool Rebase(BinaryView* data, uint64_t address, - const std::function& progressCallback); + const ProgressFunction& progressCallback); bool CreateSnapshotedView(BinaryView* data, const std::string& viewName); bool CreateSnapshotedView(BinaryView* data, const std::string& viewName, - const std::function& progressCallback); + const ProgressFunction& progressCallback); /*! Run a function in a context in which any changes made to analysis will be added to an undo state. If the function returns false or throws an exception, any changes made within will be reverted. @@ -4837,10 +4837,10 @@ namespace BinaryNinja { \return Whether the save was successful */ bool CreateDatabase(const std::string& path, - const std::function& progressCallback, + const ProgressFunction& progressCallback, Ref settings = new SaveSettings()); bool SaveAutoSnapshot(Ref settings = new SaveSettings()); - bool SaveAutoSnapshot(const std::function& progressCallback, + bool SaveAutoSnapshot(const ProgressFunction& progressCallback, Ref settings = new SaveSettings()); /*! Run a function in a context in which any changes made to analysis will be added to an undo state. @@ -6289,10 +6289,10 @@ namespace BinaryNinja { QualifiedName GetTypeNameById(const std::string& id); bool IsTypeAutoDefined(const QualifiedName& name); QualifiedName DefineType(const std::string& id, const QualifiedName& defaultName, Ref type); - std::unordered_map DefineTypes(const std::vector>& types, std::function progress = {}); + std::unordered_map DefineTypes(const std::vector>& types, ProgressFunction progress = {}); void DefineUserType(const QualifiedName& name, Ref type); - void DefineUserTypes(const std::vector& types, std::function progress = {}); - void DefineUserTypes(const std::vector& types, std::function progress = {}); + void DefineUserTypes(const std::vector& types, ProgressFunction progress = {}); + void DefineUserTypes(const std::vector& types, ProgressFunction progress = {}); void UndefineType(const std::string& id); void UndefineUserType(const QualifiedName& name); void RenameType(const QualifiedName& oldName, const QualifiedName& newName); @@ -6516,30 +6516,30 @@ namespace BinaryNinja { const FunctionViewType& viewType = NormalFunctionGraph); bool FindNextData(uint64_t start, uint64_t end, const DataBuffer& data, uint64_t& addr, BNFindFlag flags, - const std::function& progress); + const ProgressFunction& progress); bool FindNextText(uint64_t start, uint64_t end, const std::string& data, uint64_t& addr, Ref settings, BNFindFlag flags, const FunctionViewType& viewType, - const std::function& progress); + const ProgressFunction& progress); bool FindNextConstant(uint64_t start, uint64_t end, uint64_t constant, uint64_t& addr, Ref settings, const FunctionViewType& viewType, - const std::function& progress); + const ProgressFunction& progress); bool FindAllData(uint64_t start, uint64_t end, const DataBuffer& data, BNFindFlag flags, - const std::function& progress, + const ProgressFunction& progress, const std::function& matchCallback); bool FindAllText(uint64_t start, uint64_t end, const std::string& data, Ref settings, BNFindFlag flags, const FunctionViewType& viewType, - const std::function& progress, + const ProgressFunction& progress, const std::function& matchCallback); bool FindAllConstant(uint64_t start, uint64_t end, uint64_t constant, Ref settings, - const FunctionViewType& viewType, const std::function& progress, + const FunctionViewType& viewType, const ProgressFunction& progress, const std::function& matchCallback); std::string DetectSearchMode(const std::string& query); bool Search(const std::string& query, - const std::function& progressCallback, + const ProgressFunction& progressCallback, const std::function& matchCallback); void Reanalyze(); @@ -14409,9 +14409,9 @@ namespace BinaryNinja { BNUpdateResult UpdateToVersion(const std::string& version); BNUpdateResult UpdateToVersion( - const std::string& version, const std::function& progress); + const std::string& version, const ProgressFunction& progress); BNUpdateResult UpdateToLatestVersion(); - BNUpdateResult UpdateToLatestVersion(const std::function& progress); + BNUpdateResult UpdateToLatestVersion(const ProgressFunction& progress); }; /*! UpdateVersion documentation @@ -16780,7 +16780,7 @@ namespace BinaryNinja { virtual BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text, BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon) = 0; virtual bool OpenUrl(const std::string& url) = 0; - virtual bool RunProgressDialog(const std::string& title, bool canCancel, std::function progress)> task) = 0; + virtual bool RunProgressDialog(const std::string& title, bool canCancel, std::function task) = 0; }; typedef BNPluginOrigin PluginOrigin; @@ -17557,7 +17557,7 @@ namespace BinaryNinja { static std::vector> GetListForView(const Ref data); std::string GetName() const; - Ref Parse(Ref view, Ref debugView, Ref existingDebugInfo = nullptr, std::function progress = {}) const; + Ref Parse(Ref view, Ref debugView, Ref existingDebugInfo = nullptr, ProgressFunction progress = {}) const; bool IsValidForView(const Ref view) const; }; @@ -17577,7 +17577,7 @@ namespace BinaryNinja { virtual bool IsValid(Ref) = 0; virtual bool ParseInfo( - Ref, Ref, Ref, std::function) = 0; + Ref, Ref, Ref, ProgressFunction) = 0; }; /*! Class for storing secrets (e.g. tokens) in a system-specific manner @@ -18458,7 +18458,7 @@ namespace BinaryNinja { const std::string& secondSnapshot, const std::unordered_map& mergeConflictsIn, std::unordered_set& mergeConflictsOut, - std::function progress + ProgressFunction progress ); }; @@ -18569,7 +18569,7 @@ namespace BinaryNinja { */ std::optional> AddTypes( const std::vector>>& types, - std::function progress = {}); + ProgressFunction progress = {}); /*! Rename a type in the Type Container. All references to this type will be updated (by id) to use the new name. @@ -19968,7 +19968,7 @@ namespace BinaryNinja::Collaboration \param progress Function to call on progress updates \throws RemoteException If there is an error in any request or if the remote is not connected */ - void PullProjects(std::function progress = {}); + void PullProjects(ProgressFunction progress = {}); /*! @@ -19988,7 +19988,7 @@ namespace BinaryNinja::Collaboration \return Reference to the created project \throws RemoteException If there is an error in any request or if the remote is not connected */ - Ref ImportLocalProject(Ref localProject, std::function progress = {}); + Ref ImportLocalProject(Ref localProject, ProgressFunction progress = {}); /*! @@ -20046,7 +20046,7 @@ namespace BinaryNinja::Collaboration \param progress Function to call on progress updates \throws RemoteException If there is an error in any request or if the remote is not connected */ - void PullGroups(std::function progress = {}); + void PullGroups(ProgressFunction progress = {}); /*! @@ -20122,7 +20122,7 @@ namespace BinaryNinja::Collaboration \param progress Function to call on progress updates \throws RemoteException If there is an error in any request or if the remote is not connected */ - void PullUsers(std::function progress = {}); + void PullUsers(ProgressFunction progress = {}); /*! @@ -20259,7 +20259,7 @@ namespace BinaryNinja::Collaboration \param progress Function to call on progress updates \throws RemoteException If there is an error in any request or if the remote is not connected */ - void PullUndoEntries(std::function progress = {}); + void PullUndoEntries(ProgressFunction progress = {}); /*! Create a new undo entry on the remote (and pull it) @@ -20285,7 +20285,7 @@ namespace BinaryNinja::Collaboration \return Contents of the file at the point of the snapshot \throws RemoteException If there is an error in any request or if the remote is not connected */ - std::vector DownloadSnapshotFile(std::function progress = {}); + std::vector DownloadSnapshotFile(ProgressFunction progress = {}); /*! Download the contents of the snapshot @@ -20293,7 +20293,7 @@ namespace BinaryNinja::Collaboration \return Contents of the snapshot \throws RemoteException If there is an error in any request or if the remote is not connected */ - std::vector Download(std::function progress = {}); + std::vector Download(ProgressFunction progress = {}); /*! Download the contents of the analysis cache for this snapshot, returns an empty vector if there is no cache (eg: old snapshots) @@ -20301,7 +20301,7 @@ namespace BinaryNinja::Collaboration \return Contents of the analysis cache \throws RemoteException If there is an error in any request or if the remote is not connected */ - std::vector DownloadAnalysisCache(std::function progress = {}); + std::vector DownloadAnalysisCache(ProgressFunction progress = {}); }; /*! @@ -20359,7 +20359,7 @@ namespace BinaryNinja::Collaboration \param progress Function to call on progress updates \throws RemoteException If there is an error in any request or if the remote is not connected */ - void PullSnapshots(std::function progress = {}); + void PullSnapshots(ProgressFunction progress = {}); /*! Create a new snapshot on the remote (and pull it) @@ -20378,7 +20378,7 @@ namespace BinaryNinja::Collaboration std::vector analysisCacheContents, std::optional> fileContents, std::vector parentIds, - std::function progress = {} + ProgressFunction progress = {} ); /*! @@ -20394,7 +20394,7 @@ namespace BinaryNinja::Collaboration \return Contents of the file \throws RemoteException If there is an error in any request or if the remote is not connected */ - std::vector Download(std::function progress = {}); + std::vector Download(ProgressFunction progress = {}); /*! Get the current user positions for this file @@ -20444,7 +20444,7 @@ namespace BinaryNinja::Collaboration Ref GetCoreProject(); bool IsOpen(); - bool Open(std::function progress = {}); + bool Open(ProgressFunction progress = {}); void Close(); Ref GetRemote(); @@ -20467,10 +20467,10 @@ namespace BinaryNinja::Collaboration std::vector> GetFolders(); Ref GetFileById(const std::string& id); Ref GetFileByName(const std::string& name); - void PullFiles(std::function progress = {}); - void PullFolders(std::function progress = {}); - Ref CreateFile(const std::string& filename, std::vector& contents, const std::string& name, const std::string& description, Ref folder, BNRemoteFileType type, std::function progress = {}, Ref coreFile = nullptr); - Ref CreateFolder(const std::string& name, const std::string& description, Ref parent, std::function progress = {}, Ref coreFolder = nullptr); + void PullFiles(ProgressFunction progress = {}); + void PullFolders(ProgressFunction progress = {}); + Ref CreateFile(const std::string& filename, std::vector& contents, const std::string& name, const std::string& description, Ref folder, BNRemoteFileType type, ProgressFunction progress = {}, Ref coreFile = nullptr); + Ref CreateFolder(const std::string& name, const std::string& description, Ref parent, ProgressFunction progress = {}, Ref coreFolder = nullptr); void PushFile(Ref file, const std::vector>& extraFields = {}); void PushFolder(Ref folder, const std::vector>& extraFields = {}); void DeleteFolder(const Ref folder); @@ -20479,10 +20479,10 @@ namespace BinaryNinja::Collaboration std::vector> GetGroupPermissions(); std::vector> GetUserPermissions(); Ref GetPermissionById(const std::string& id); - void PullGroupPermissions(std::function progress = {}); - void PullUserPermissions(std::function progress = {}); - Ref CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, std::function progress = {}); - Ref CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, std::function progress = {}); + void PullGroupPermissions(ProgressFunction progress = {}); + void PullUserPermissions(ProgressFunction progress = {}); + Ref CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, ProgressFunction progress = {}); + Ref CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, ProgressFunction progress = {}); void PushPermission(Ref permission, const std::vector>& extraFields = {}); void DeletePermission(Ref permission); bool CanUserView(const std::string& username); @@ -20549,7 +20549,6 @@ namespace BinaryNinja::Collaboration }; typedef std::function)> NameChangesetFunction; - typedef std::function ProgressFunction; typedef std::function>& conflicts)> AnalysisConflictHandler; typedef std::function>& conflicts)> TypeArchiveConflictHandler; @@ -20577,7 +20576,7 @@ namespace BinaryNinja::Collaboration \param nameChangeset Function to call for naming a pushed changeset, if necessary \throws SyncException If there is an error syncing */ - void SyncDatabase(Ref database, Ref file, AnalysisConflictHandler conflictHandler, std::function progress = {}, NameChangesetFunction nameChangeset = [](Ref){ return true; }); + void SyncDatabase(Ref database, Ref file, AnalysisConflictHandler conflictHandler, ProgressFunction progress = {}, NameChangesetFunction nameChangeset = [](Ref){ return true; }); /*! Completely sync a type archive, pushing/pulling/merging/applying changes -- cgit v1.3.1