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 ++++++++++++------------ binaryninjacore.h | 15 +-- binaryview.cpp | 38 +++---- collaboration.cpp | 42 +++---- database.cpp | 8 +- debuginfo.cpp | 2 +- examples/background_task/src/backgroundtask.cpp | 2 +- examples/triage/baseaddress.cpp | 2 +- filemetadata.cpp | 14 +-- http.cpp | 26 ++--- http.h | 37 +++--- interaction.cpp | 6 +- project.cpp | 14 +-- rust/src/download_provider.rs | 8 +- typearchive.cpp | 2 +- typecontainer.cpp | 2 +- ui/historyview.h | 2 +- ui/progresstask.h | 8 +- ui/projectbrowser.h | 2 +- ui/viewframe.h | 12 +- update.cpp | 6 +- 21 files changed, 197 insertions(+), 196 deletions(-) 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 diff --git a/binaryninjacore.h b/binaryninjacore.h index 4c941309..4a75eeb1 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -308,6 +308,8 @@ extern "C" typedef struct BNRenderLayer BNRenderLayer; typedef struct BNStringRef BNStringRef; + typedef bool(*BNProgressFunction)(void*, size_t, size_t); + //! Console log levels typedef enum BNLogLevel { @@ -2713,7 +2715,7 @@ extern "C" void* readContext; uint64_t (*writeCallback)(uint8_t* data, uint64_t len, void* ctxt); void* writeContext; - bool (*progressCallback)(void* ctxt, uint64_t progress, uint64_t total); + BNProgressFunction progressCallback; void* progressContext; } BNDownloadInstanceInputOutputCallbacks; @@ -2721,7 +2723,7 @@ extern "C" { uint64_t (*writeCallback)(uint8_t* data, uint64_t len, void* ctxt); void* writeContext; - bool (*progressCallback)(void* ctxt, uint64_t progress, uint64_t total); + BNProgressFunction progressCallback; void* progressContext; } BNDownloadInstanceOutputCallbacks; @@ -3012,7 +3014,7 @@ extern "C" void* ctxt, const char* title, const char* text, BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon); bool (*openUrl)(void* ctxt, const char* url); bool (*runProgressDialog)(void* ctxt, const char* title, bool canCancel, - void (*task)(void* taskCtxt, bool(*progress)(void* progressCtxt, size_t cur, size_t max), void* progressCtxt), void* taskCtxt); + void (*task)(void* taskCtxt, BNProgressFunction progress, void* progressCtxt), void* taskCtxt); } BNInteractionHandlerCallbacks; typedef struct BNObjectDestructionCallbacks @@ -3495,7 +3497,6 @@ extern "C" uint32_t flags; } BNSegmentInfo; - typedef bool(*BNProgressFunction)(void*, size_t, size_t); typedef bool(*BNCollaborationAnalysisConflictHandler)(void*, const char** keys, BNAnalysisMergeConflict** conflicts, size_t conflictCount); typedef bool(*BNCollaborationNameChangesetFunction)(void*, BNCollaborationChangeset*); @@ -4230,7 +4231,7 @@ extern "C" BINARYNINJACOREAPI bool BNSearch(BNBinaryView* view, const char* query, void* context, BNProgressFunction progressCallback, void* matchContext, bool (*callback)(void*, uint64_t, BNDataBuffer*)); BINARYNINJACOREAPI char* BNDetectSearchMode(const char* query); - BINARYNINJACOREAPI bool BNPerformSearch(const char* query, const uint8_t* buffer, size_t size, bool(*callback)(void*, size_t, size_t), void* context); + BINARYNINJACOREAPI bool BNPerformSearch(const char* query, const uint8_t* buffer, size_t size, BNProgressFunction callback, void* context); BINARYNINJACOREAPI void BNBeginBulkAddSegments(BNBinaryView* view); BINARYNINJACOREAPI void BNEndBulkAddSegments(BNBinaryView* view); @@ -5274,7 +5275,7 @@ extern "C" BINARYNINJACOREAPI BNTypeContainerType BNTypeContainerGetType(BNTypeContainer* container); BINARYNINJACOREAPI bool BNTypeContainerIsMutable(BNTypeContainer* container); BINARYNINJACOREAPI BNPlatform* BNTypeContainerGetPlatform(BNTypeContainer* container); - BINARYNINJACOREAPI bool BNTypeContainerAddTypes(BNTypeContainer* container, const BNQualifiedName* typeNames, BNType** types, size_t typeCount, bool(*progress)(void*, size_t, size_t), void* progressContext, BNQualifiedName** resultNames, char*** resultIds, size_t* resultCount); + BINARYNINJACOREAPI bool BNTypeContainerAddTypes(BNTypeContainer* container, const BNQualifiedName* typeNames, BNType** types, size_t typeCount, BNProgressFunction progress, void* progressContext, BNQualifiedName** resultNames, char*** resultIds, size_t* resultCount); BINARYNINJACOREAPI bool BNTypeContainerRenameType(BNTypeContainer* container, const char* typeId, const BNQualifiedName* newName); BINARYNINJACOREAPI bool BNTypeContainerDeleteType(BNTypeContainer* container, const char* typeId); BINARYNINJACOREAPI bool BNTypeContainerGetTypeId(BNTypeContainer* container, const BNQualifiedName* typeName, char** result); @@ -7158,7 +7159,7 @@ extern "C" const char* title, const char* text, BNMessageBoxButtonSet buttons, BNMessageBoxIcon icon); BINARYNINJACOREAPI bool BNOpenUrl(const char* url); BINARYNINJACOREAPI bool BNRunProgressDialog(const char* title, bool canCancel, - void (*task)(void* taskCtxt, bool(*progress)(void* progressCtxt, size_t cur, size_t max), void* progressCtxt), void* taskCtxt); + void (*task)(void* taskCtxt, BNProgressFunction progress, void* progressCtxt), void* taskCtxt); BINARYNINJACOREAPI BNReportCollection* BNCreateReportCollection(void); BINARYNINJACOREAPI BNReportCollection* BNNewReportCollectionReference(BNReportCollection* reports); diff --git a/binaryview.cpp b/binaryview.cpp index 7a6f3df3..9a223932 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1634,7 +1634,7 @@ bool BinaryView::CreateDatabase(const string& path, Ref settings) bool BinaryView::CreateDatabase(const string& path, - const function& progressCallback, Ref settings) + const ProgressFunction& progressCallback, Ref settings) { auto parent = GetParentView(); if (parent) @@ -1650,7 +1650,7 @@ bool BinaryView::SaveAutoSnapshot(Ref settings) bool BinaryView::SaveAutoSnapshot( - const function& progressCallback, Ref settings) + const ProgressFunction& progressCallback, Ref settings) { return m_file->SaveAutoSnapshot(this, progressCallback, settings); } @@ -4217,7 +4217,7 @@ void BinaryView::DefineUserType(const QualifiedName& name, Ref type) } -std::unordered_map BinaryView::DefineTypes(const vector>& types, std::function progress) +std::unordered_map BinaryView::DefineTypes(const vector>& types, ProgressFunction progress) { BNQualifiedNameTypeAndId* apiTypes = new BNQualifiedNameTypeAndId[types.size()]; for (size_t i = 0; i < types.size(); i++) @@ -4255,7 +4255,7 @@ std::unordered_map BinaryView::DefineTypes(const vec } -void BinaryView::DefineUserTypes(const vector& types, std::function progress) +void BinaryView::DefineUserTypes(const vector& types, ProgressFunction progress) { BNQualifiedNameAndType* apiTypes = new BNQualifiedNameAndType[types.size()]; for (size_t i = 0; i < types.size(); i++) @@ -4276,7 +4276,7 @@ void BinaryView::DefineUserTypes(const vector& types, std: } -void BinaryView::DefineUserTypes(const vector& types, std::function progress) +void BinaryView::DefineUserTypes(const vector& types, ProgressFunction progress) { BNQualifiedNameAndType* apiTypes = new BNQualifiedNameAndType[types.size()]; for (size_t i = 0; i < types.size(); i++) @@ -4735,7 +4735,7 @@ static bool MatchCallbackForConstant(void* ctxt, uint64_t addr, BNLinearDisassem bool BinaryView::FindNextData(uint64_t start, uint64_t end, const DataBuffer& data, uint64_t& addr, BNFindFlag flags, - const std::function& progress) + const ProgressFunction& progress) { ProgressContext fp; fp.callback = progress; @@ -4746,7 +4746,7 @@ bool BinaryView::FindNextData(uint64_t start, uint64_t end, const DataBuffer& da bool BinaryView::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) { ProgressContext fp; fp.callback = progress; @@ -4757,7 +4757,7 @@ bool BinaryView::FindNextText(uint64_t start, uint64_t end, const std::string& d bool BinaryView::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) { ProgressContext fp; fp.callback = progress; @@ -4767,7 +4767,7 @@ bool BinaryView::FindNextConstant(uint64_t start, uint64_t end, uint64_t constan bool BinaryView::FindAllData(uint64_t start, uint64_t end, const DataBuffer& data, BNFindFlag flags, - const std::function& progress, + const ProgressFunction& progress, const std::function& matchCallback) { ProgressContext fp; @@ -4780,7 +4780,7 @@ bool BinaryView::FindAllData(uint64_t start, uint64_t end, const DataBuffer& dat bool BinaryView::FindAllText(uint64_t start, uint64_t end, const std::string& data, Ref settings, - BNFindFlag flags, const FunctionViewType& viewType, const std::function& progress, + BNFindFlag flags, const FunctionViewType& viewType, const ProgressFunction& progress, const std::function& matchCallback) { @@ -4794,7 +4794,7 @@ bool BinaryView::FindAllText(uint64_t start, uint64_t end, const std::string& da bool BinaryView::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) { ProgressContext fp; @@ -4815,7 +4815,7 @@ string BinaryView::DetectSearchMode(const string& query) } -bool BinaryView::Search(const string& query, const std::function& progressCallback, const std::function& matchCallback) +bool BinaryView::Search(const string& query, const ProgressFunction& progressCallback, const std::function& matchCallback) { ProgressContext fp; fp.callback = progressCallback; @@ -5598,14 +5598,14 @@ Ref BinaryData::CreateFromFile(FileMetadata* file, FileAccessor* acc Ref BinaryNinja::Load(const std::string& filename, bool updateAnalysis, - std::function progress, Ref options) + ProgressFunction progress, Ref options) { return Load(filename, updateAnalysis, options->GetJsonString(), progress); } Ref BinaryNinja::Load( - const DataBuffer& rawData, bool updateAnalysis, std::function progress, Ref options) + const DataBuffer& rawData, bool updateAnalysis, ProgressFunction progress, Ref options) { Ref file = new FileMetadata(); Ref view = new BinaryData(file, rawData); @@ -5614,13 +5614,13 @@ Ref BinaryNinja::Load( Ref BinaryNinja::Load(Ref view, bool updateAnalysis, - std::function progress, Ref options, bool isDatabase) + ProgressFunction progress, Ref options, bool isDatabase) { return Load(view, updateAnalysis, options->GetJsonString(), progress); } -Ref BinaryNinja::Load(const std::string& filename, bool updateAnalysis, const std::string& options, std::function progress) +Ref BinaryNinja::Load(const std::string& filename, bool updateAnalysis, const std::string& options, ProgressFunction progress) { ProgressContext cb; cb.callback = progress; @@ -5631,7 +5631,7 @@ Ref BinaryNinja::Load(const std::string& filename, bool updateAnalys } -Ref BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis, const std::string& options, std::function progress) +Ref BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis, const std::string& options, ProgressFunction progress) { Ref file = new FileMetadata(); Ref view = new BinaryData(file, rawData); @@ -5639,7 +5639,7 @@ Ref BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis } -Ref BinaryNinja::Load(Ref view, bool updateAnalysis, const std::string& options, std::function progress) +Ref BinaryNinja::Load(Ref view, bool updateAnalysis, const std::string& options, ProgressFunction progress) { ProgressContext cb; cb.callback = progress; @@ -5650,7 +5650,7 @@ Ref BinaryNinja::Load(Ref view, bool updateAnalysis, con } -Ref BinaryNinja::Load(Ref projectFile, bool updateAnalysis, const std::string& options, std::function progress) +Ref BinaryNinja::Load(Ref projectFile, bool updateAnalysis, const std::string& options, ProgressFunction progress) { ProgressContext cb; cb.callback = progress; diff --git a/collaboration.cpp b/collaboration.cpp index 28ad916a..b07cd845 100644 --- a/collaboration.cpp +++ b/collaboration.cpp @@ -454,7 +454,7 @@ bool BinaryNinja::Collaboration::NameChangesetCallback(void* ctxt, BNCollaborati }; -void BinaryNinja::Collaboration::SyncDatabase(Ref database, Ref file, std::function>& conflicts)> conflictHandler, std::function progress, NameChangesetFunction nameChangeset) +void BinaryNinja::Collaboration::SyncDatabase(Ref database, Ref file, std::function>& conflicts)> conflictHandler, ProgressFunction progress, NameChangesetFunction nameChangeset) { ProgressContext pctxt; pctxt.callback = progress; @@ -762,7 +762,7 @@ Ref Remote::GetProjectByName(const std::string& name) } -void Remote::PullProjects(std::function progress) +void Remote::PullProjects(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -779,7 +779,7 @@ Ref Remote::CreateProject(const std::string& name, const std::str } -Ref Remote::ImportLocalProject(Ref localProject, std::function progress) +Ref Remote::ImportLocalProject(Ref localProject, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -867,7 +867,7 @@ std::vector> Remote::SearchGroups(const std::st } -void Remote::PullGroups(std::function progress) +void Remote::PullGroups(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -977,7 +977,7 @@ std::vector> Remote::SearchUsers(const std:: } -void Remote::PullUsers(std::function progress) +void Remote::PullUsers(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1168,7 +1168,7 @@ bool RemoteProject::IsOpen() } -bool RemoteProject::Open(std::function progress) +bool RemoteProject::Open(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1336,7 +1336,7 @@ Ref RemoteProject::GetFileByName(const std::string& name) } -void RemoteProject::PullFiles(std::function progress) +void RemoteProject::PullFiles(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1344,7 +1344,7 @@ void RemoteProject::PullFiles(std::function progress) } -void RemoteProject::PullFolders(std::function progress) +void RemoteProject::PullFolders(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1353,7 +1353,7 @@ void RemoteProject::PullFolders(std::function progress) } -Ref RemoteProject::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) +Ref RemoteProject::CreateFile(const std::string& filename, std::vector& contents, const std::string& name, const std::string& description, Ref folder, BNRemoteFileType type, ProgressFunction progress, Ref coreFile) { ProgressContext pctxt; pctxt.callback = progress; @@ -1364,7 +1364,7 @@ Ref RemoteProject::CreateFile(const std::string& filename, std::vect } -Ref RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref parent, std::function progress, Ref coreFolder) +Ref RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref parent, ProgressFunction progress, Ref coreFolder) { ProgressContext pctxt; pctxt.callback = progress; @@ -1473,7 +1473,7 @@ Ref RemoteProject::GetPermissionById(const std::string& id) } -void RemoteProject::PullGroupPermissions(std::function progress) +void RemoteProject::PullGroupPermissions(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1481,7 +1481,7 @@ void RemoteProject::PullGroupPermissions(std::function pro } -void RemoteProject::PullUserPermissions(std::function progress) +void RemoteProject::PullUserPermissions(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1489,7 +1489,7 @@ void RemoteProject::PullUserPermissions(std::function prog } -Ref RemoteProject::CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, std::function progress) +Ref RemoteProject::CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1500,7 +1500,7 @@ Ref RemoteProject::CreateGroupPermission(int groupId, BNCollab } -Ref RemoteProject::CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, std::function progress) +Ref RemoteProject::CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1777,7 +1777,7 @@ Ref RemoteFile::GetSnapshotById(const std::string& id) } -void RemoteFile::PullSnapshots(std::function progress) +void RemoteFile::PullSnapshots(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1785,7 +1785,7 @@ void RemoteFile::PullSnapshots(std::function progress) } -Ref RemoteFile::CreateSnapshot(std::string name, std::vector contents, std::vector analysisCacheContents, std::optional> fileContents, std::vector parentIds, std::function progress) +Ref RemoteFile::CreateSnapshot(std::string name, std::vector contents, std::vector analysisCacheContents, std::optional> fileContents, std::vector parentIds, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1825,7 +1825,7 @@ void RemoteFile::DeleteSnapshot(const Ref snapshot) } -std::vector RemoteFile::Download(std::function progress) +std::vector RemoteFile::Download(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2600,7 +2600,7 @@ Ref CollabSnapshot::GetUndoEntryById(uint64_t id) } -void CollabSnapshot::PullUndoEntries(std::function progress) +void CollabSnapshot::PullUndoEntries(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2623,7 +2623,7 @@ void CollabSnapshot::Finalize() } -std::vector CollabSnapshot::DownloadSnapshotFile(std::function progress) +std::vector CollabSnapshot::DownloadSnapshotFile(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2640,7 +2640,7 @@ std::vector CollabSnapshot::DownloadSnapshotFile(std::function CollabSnapshot::Download(std::function progress) +std::vector CollabSnapshot::Download(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2657,7 +2657,7 @@ std::vector CollabSnapshot::Download(std::function CollabSnapshot::DownloadAnalysisCache(std::function progress) +std::vector CollabSnapshot::DownloadAnalysisCache(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; diff --git a/database.cpp b/database.cpp index d15ab1cd..0fdc50e1 100644 --- a/database.cpp +++ b/database.cpp @@ -310,7 +310,7 @@ vector> Snapshot::GetUndoEntries() } -vector> Snapshot::GetUndoEntries(const std::function& progress) +vector> Snapshot::GetUndoEntries(const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -339,7 +339,7 @@ Ref Snapshot::ReadData() } -Ref Snapshot::ReadData(const std::function& progress) +Ref Snapshot::ReadData(const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -352,7 +352,7 @@ Ref Snapshot::ReadData(const std::function& } -bool Snapshot::StoreData(const Ref& data, const std::function& progress) +bool Snapshot::StoreData(const Ref& data, const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -413,7 +413,7 @@ Ref Database::GetCurrentSnapshot() int64_t Database::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) { ProgressContext pctxt; pctxt.callback = progress; diff --git a/debuginfo.cpp b/debuginfo.cpp index 859c88f7..b3f14383 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -406,7 +406,7 @@ string DebugInfoParser::GetName() const Ref DebugInfoParser::Parse(Ref view, Ref debugFile, Ref existingDebugInfo, - std::function progress) const + ProgressFunction progress) const { ProgressContext ctxt; if (progress) diff --git a/examples/background_task/src/backgroundtask.cpp b/examples/background_task/src/backgroundtask.cpp index 8a307080..9b0a17be 100644 --- a/examples/background_task/src/backgroundtask.cpp +++ b/examples/background_task/src/backgroundtask.cpp @@ -41,7 +41,7 @@ uint64_t InspireWriteCallback(uint8_t *data, uint64_t len, void *ctxt) return len; } -bool InspireProgressCallback(void *ctxt, uint64_t progress, uint64_t total) +bool InspireProgressCallback(void *ctxt, size_t progress, size_t total) { // Close connection on cancellation return !inspireBackgroundTask->IsCancelled(); diff --git a/examples/triage/baseaddress.cpp b/examples/triage/baseaddress.cpp index 436066eb..f32169ad 100644 --- a/examples/triage/baseaddress.cpp +++ b/examples/triage/baseaddress.cpp @@ -305,7 +305,7 @@ void BaseAddressDetectionWidget::RebaseWithFullAnalysis() return; bool result = false; - ProgressTask* task = new ProgressTask(this, "Rebase", "Rebasing...", "Cancel", [&](std::function progress) { + ProgressTask* task = new ProgressTask(this, "Rebase", "Rebasing...", "Cancel", [&](BinaryNinja::ProgressFunction progress) { result = fileMetadata->Rebase(view, address, progress); }); task->wait(); diff --git a/filemetadata.cpp b/filemetadata.cpp index f2b4f57b..e45354c7 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -166,7 +166,7 @@ bool FileMetadata::CreateDatabase(const string& name, BinaryView* data, Ref& progressCallback, Ref settings) + const ProgressFunction& progressCallback, Ref settings) { ProgressContext cb; cb.callback = progressCallback; @@ -185,7 +185,7 @@ Ref FileMetadata::OpenExistingDatabase(const string& path) Ref FileMetadata::OpenExistingDatabase( - const string& path, const function& progressCallback) + const string& path, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -212,7 +212,7 @@ bool FileMetadata::SaveAutoSnapshot(BinaryView* data, Ref settings bool FileMetadata::SaveAutoSnapshot( - BinaryView* data, const function& progressCallback, Ref settings) + BinaryView* data, const ProgressFunction& progressCallback, Ref settings) { ProgressContext cb; cb.callback = progressCallback; @@ -222,7 +222,7 @@ bool FileMetadata::SaveAutoSnapshot( void FileMetadata::GetSnapshotData( - Ref data, Ref cache, const std::function& progress) + Ref data, Ref cache, const ProgressFunction& progress) { ProgressContext cb; cb.callback = progress; @@ -231,7 +231,7 @@ void FileMetadata::GetSnapshotData( void FileMetadata::ApplySnapshotData(BinaryView* file, Ref data, Ref cache, - const std::function& progress, bool openForConfiguration, bool restoreRawView) + const ProgressFunction& progress, bool openForConfiguration, bool restoreRawView) { ProgressContext cb; cb.callback = progress; @@ -256,7 +256,7 @@ bool FileMetadata::Rebase(BinaryView* data, uint64_t address) bool FileMetadata::Rebase( - BinaryView* data, uint64_t address, const function& progressCallback) + BinaryView* data, uint64_t address, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -271,7 +271,7 @@ bool FileMetadata::CreateSnapshotedView(BinaryView *data, const std::string &vie bool FileMetadata::CreateSnapshotedView(BinaryView* data, const std::string& viewName, - const function& progressCallback) + const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; diff --git a/http.cpp b/http.cpp index 2b600823..4ce4206c 100644 --- a/http.cpp +++ b/http.cpp @@ -230,8 +230,8 @@ namespace BinaryNinja::Http Request::Request(string method, string url, const unordered_map& headers, - vector> params, std::function downloadProgress, - std::function uploadProgress) : + vector> params, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) : m_method(method), m_url(url), m_headers(headers), m_downloadProgress(downloadProgress), m_uploadProgress(uploadProgress) { @@ -253,8 +253,8 @@ namespace BinaryNinja::Http Request::Request(string method, string url, const unordered_map& headers, - vector> params, vector body, std::function downloadProgress, - std::function uploadProgress) : + vector> params, vector body, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) : m_method(method), m_url(url), m_headers(headers), m_body(body), m_downloadProgress(downloadProgress), m_uploadProgress(uploadProgress) @@ -278,7 +278,7 @@ namespace BinaryNinja::Http Request::Request(string method, string url, const unordered_map& headers, vector> params, vector> formFields, - std::function downloadProgress, std::function uploadProgress) : + ProgressFunction downloadProgress, ProgressFunction uploadProgress) : m_method(method), m_url(url), m_headers(headers), m_downloadProgress(downloadProgress), m_uploadProgress(uploadProgress) { @@ -305,7 +305,7 @@ namespace BinaryNinja::Http Request::Request(string method, string url, const unordered_map& headers, vector> params, vector formFields, - std::function downloadProgress, std::function uploadProgress) : + ProgressFunction downloadProgress, ProgressFunction uploadProgress) : m_method(method), m_url(url), m_headers(headers), m_downloadProgress(downloadProgress), m_uploadProgress(uploadProgress) { @@ -332,31 +332,31 @@ namespace BinaryNinja::Http Request Request::Get(string url, const unordered_map& headers, const vector>& params, - std::function downloadProgress, std::function uploadProgress) + ProgressFunction downloadProgress, ProgressFunction uploadProgress) { return Request("GET", url, headers, params, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map& headers, const vector>& params, - const vector& body, std::function downloadProgress, - std::function uploadProgress) + const vector& body, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, body, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map& headers, const vector>& params, - const vector>& formFields, std::function downloadProgress, - std::function uploadProgress) + const vector>& formFields, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, formFields, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map& headers, const vector>& params, - const vector& formFields, std::function downloadProgress, - std::function uploadProgress) + const vector& formFields, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, formFields, downloadProgress, uploadProgress); } diff --git a/http.h b/http.h index 8cade41b..59567178 100644 --- a/http.h +++ b/http.h @@ -29,6 +29,7 @@ #include #ifdef BINARYNINJACORE_LIBRARY + #include "progress.h" #include "downloadprovider.h" #include "json/json.h" #else @@ -195,8 +196,8 @@ namespace BinaryNinja::Http _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING> m_headers; _STD_VECTOR m_body; - std::function m_downloadProgress; - std::function m_uploadProgress; + ProgressFunction m_downloadProgress; + ProgressFunction m_uploadProgress; /*! Construct an arbitrary HTTP request with an empty body @@ -209,8 +210,8 @@ namespace BinaryNinja::Http */ Request(_STD_STRING method, _STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers = {}, _STD_VECTOR> params = {}, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -225,8 +226,8 @@ namespace BinaryNinja::Http */ Request(_STD_STRING method, _STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers, _STD_VECTOR> params, _STD_VECTOR body, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -242,8 +243,8 @@ namespace BinaryNinja::Http Request(_STD_STRING method, _STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers, _STD_VECTOR> params, _STD_VECTOR> formFields, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -258,8 +259,8 @@ namespace BinaryNinja::Http */ Request(_STD_STRING method, _STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers, _STD_VECTOR> params, _STD_VECTOR formFields, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -273,8 +274,8 @@ namespace BinaryNinja::Http */ static Request Get(_STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers = {}, const _STD_VECTOR>& params = {}, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -289,8 +290,8 @@ namespace BinaryNinja::Http */ static Request Post(_STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers = {}, const _STD_VECTOR>& params = {}, const _STD_VECTOR& body = {}, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -306,8 +307,8 @@ namespace BinaryNinja::Http static Request Post(_STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers, const _STD_VECTOR>& params, const _STD_VECTOR>& formFields, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); /*! @@ -322,8 +323,8 @@ namespace BinaryNinja::Http */ static Request Post(_STD_STRING url, const _STD_UNORDERED_MAP<_STD_STRING, _STD_STRING>& headers, const _STD_VECTOR>& params, const _STD_VECTOR& formFields, - std::function downloadProgress = {}, - std::function uploadProgress = {}); + ProgressFunction downloadProgress = {}, + ProgressFunction uploadProgress = {}); }; diff --git a/interaction.cpp b/interaction.cpp index 973bde38..adc661c8 100644 --- a/interaction.cpp +++ b/interaction.cpp @@ -435,7 +435,7 @@ static bool RunProgressDialogCallback(void* ctxt, const char* title, bool canCan void (*task)(void*, bool (*)(void*, size_t, size_t), void*), void* taskCtxt) { InteractionHandler* handler = (InteractionHandler*)ctxt; - return handler->RunProgressDialog(title, canCancel, [=](std::function progress) { + return handler->RunProgressDialog(title, canCancel, [=](ProgressFunction progress) { ProgressContext context; context.callback = progress; task(taskCtxt, ProgressCallback, &context); @@ -715,7 +715,7 @@ bool BinaryNinja::OpenUrl(const std::string& url) struct TaskContext { - std::function progress)> callback; + std::function callback; }; @@ -728,7 +728,7 @@ static void TaskCallback(void* taskCtxt, BNProgressFunction progress, void* prog } -bool BinaryNinja::RunProgressDialog(const std::string& title, bool canCancel, std::function progress)> task) +bool BinaryNinja::RunProgressDialog(const std::string& title, bool canCancel, std::function task) { TaskContext context; context.callback = task; diff --git a/project.cpp b/project.cpp index b023635b..da4ee88d 100644 --- a/project.cpp +++ b/project.cpp @@ -338,7 +338,7 @@ void Project::RemoveMetadata(const std::string& key) Ref Project::CreateFolderFromPath(const std::string& path, Ref parent, const std::string& description, - const std::function& progressCallback) + const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -399,7 +399,7 @@ void Project::PushFolder(Ref folder) } -bool Project::DeleteFolder(Ref folder, const std::function& progressCallback) +bool Project::DeleteFolder(Ref folder, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -407,7 +407,7 @@ bool Project::DeleteFolder(Ref folder, const std::function Project::CreateFileFromPath(const std::string& path, Ref folder, const std::string& name, const std::string& description, const std::function& progressCallback) +Ref Project::CreateFileFromPath(const std::string& path, Ref folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -418,7 +418,7 @@ Ref Project::CreateFileFromPath(const std::string& path, Ref Project::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 Project::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) { ProgressContext cb; cb.callback = progressCallback; @@ -429,7 +429,7 @@ Ref Project::CreateFileFromPathUnsafe(const std::string& path, Ref< } -Ref Project::CreateFile_(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const std::function& progressCallback) +Ref Project::CreateFile_(const std::vector& contents, Ref folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -440,7 +440,7 @@ Ref Project::CreateFile_(const std::vector& contents, Ref< } -Ref Project::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 Project::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) { ProgressContext cb; cb.callback = progressCallback; @@ -691,7 +691,7 @@ void ProjectFolder::SetParent(Ref parent) } -bool ProjectFolder::Export(const std::string& destination, const std::function& progressCallback) const +bool ProjectFolder::Export(const std::string& destination, const ProgressFunction& progressCallback) const { ProgressContext cb; cb.callback = progressCallback; diff --git a/rust/src/download_provider.rs b/rust/src/download_provider.rs index 1e61c87d..6dd349e7 100644 --- a/rust/src/download_provider.rs +++ b/rust/src/download_provider.rs @@ -76,13 +76,13 @@ unsafe impl CoreArrayProviderInner for DownloadProvider { pub struct DownloadInstanceOutputCallbacks { pub write: Option usize>>, - pub progress: Option bool>>, + pub progress: Option bool>>, } pub struct DownloadInstanceInputOutputCallbacks { pub read: Option Option>>, pub write: Option usize>>, - pub progress: Option bool>>, + pub progress: Option bool>>, } pub struct DownloadResponse { @@ -121,7 +121,7 @@ impl DownloadInstance { } } - unsafe extern "C" fn o_progress_callback(ctxt: *mut c_void, progress: u64, total: u64) -> bool { + unsafe extern "C" fn o_progress_callback(ctxt: *mut c_void, progress: usize, total: usize) -> bool { let callbacks = ctxt as *mut DownloadInstanceOutputCallbacks; if let Some(func) = &mut (*callbacks).progress { (func)(progress, total) @@ -186,7 +186,7 @@ impl DownloadInstance { } } - unsafe extern "C" fn i_progress_callback(ctxt: *mut c_void, progress: u64, total: u64) -> bool { + unsafe extern "C" fn i_progress_callback(ctxt: *mut c_void, progress: usize, total: usize) -> bool { let callbacks = ctxt as *mut DownloadInstanceInputOutputCallbacks; if let Some(func) = &mut (*callbacks).progress { (func)(progress, total) diff --git a/typearchive.cpp b/typearchive.cpp index 77841472..acd4447b 100644 --- a/typearchive.cpp +++ b/typearchive.cpp @@ -576,7 +576,7 @@ std::optional TypeArchive::MergeSnapshots( const std::string& secondSnapshot, const std::unordered_map& mergeConflictsIn, std::unordered_set& mergeConflictsOut, - std::function progress + ProgressFunction progress ) { std::vector mergeConflictKeysIn; diff --git a/typecontainer.cpp b/typecontainer.cpp index 5d2982d1..5d706fbf 100644 --- a/typecontainer.cpp +++ b/typecontainer.cpp @@ -149,7 +149,7 @@ std::optional TypeContainer::AddType(QualifiedName name, Ref std::optional> TypeContainer::AddTypes( const std::vector>>& types, - std::function progress) + ProgressFunction progress) { BNQualifiedName* apiTypeNames = new BNQualifiedName[types.size()]; BNType** apiTypes = new BNType*[types.size()]; diff --git a/ui/historyview.h b/ui/historyview.h index 0db0318d..80e356f6 100644 --- a/ui/historyview.h +++ b/ui/historyview.h @@ -88,7 +88,7 @@ class BINARYNINJAUIAPI HistorySidebarWidget : public SidebarWidget void scrollBarValueChanged(int value); void scrollBarRangeChanged(int min, int max); - void resetToSelectedEntry(std::function progress); + void resetToSelectedEntry(BinaryNinja::ProgressFunction progress); public: virtual void copy(); diff --git a/ui/progresstask.h b/ui/progresstask.h index a1a375cb..6765ec2d 100644 --- a/ui/progresstask.h +++ b/ui/progresstask.h @@ -88,7 +88,7 @@ class BINARYNINJAUIAPI ProgressDialog : public QDialog \code{.cpp} // Starts task ProgressTask* task = new ProgressTask("Long Operation", "Long Operation", "Cancel", - [](std::function progress) { + [](ProgressFunction progress) { doLongOperationWithProgress(progress); // Report progress by calling the progress function @@ -107,7 +107,7 @@ class BINARYNINJAUIAPI ProgressTask : public QObject Q_OBJECT ProgressDialog* m_dialog; - std::function)> m_func; + std::function m_func; std::thread m_thread; std::mutex m_mutex; std::condition_variable m_cv; @@ -133,7 +133,7 @@ class BINARYNINJAUIAPI ProgressTask : public QObject cancellation. */ ProgressTask(QWidget* parent, const QString& name, const QString& text, const QString& cancel, - std::function)> func); + std::function func); virtual ~ProgressTask(); /*! @@ -279,7 +279,7 @@ class BINARYNINJAUIAPI BackgroundThread : public QObject Q_OBJECT public: - typedef std::function ProgressFunction; + typedef BinaryNinja::ProgressFunction ProgressFunction; typedef std::function ThenFunction; typedef std::function CatchFunction; diff --git a/ui/projectbrowser.h b/ui/projectbrowser.h index 5e69f332..b76aa3d8 100644 --- a/ui/projectbrowser.h +++ b/ui/projectbrowser.h @@ -87,7 +87,7 @@ public: QStandardItem* ItemForId(const std::string& id); - void reloadData(const std::function& progress = [](size_t, size_t){ return true; }); + void reloadData(const BinaryNinja::ProgressFunction& progress = [](size_t, size_t){ return true; }); virtual QMimeData* mimeData(const QModelIndexList& indexes) const override; virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; diff --git a/ui/viewframe.h b/ui/viewframe.h index 3d15cfee..e0235603 100644 --- a/ui/viewframe.h +++ b/ui/viewframe.h @@ -138,23 +138,23 @@ class BINARYNINJAUIAPI View virtual bool canCompile() { return false; } virtual bool findNextData(uint64_t start, uint64_t end, const BinaryNinja::DataBuffer& data, uint64_t& addr, - BNFindFlag flags, const std::function& cb); + BNFindFlag flags, const BinaryNinja::ProgressFunction& cb); virtual bool findNextText(uint64_t start, uint64_t end, const std::string& text, uint64_t& addr, DisassemblySettingsRef settings, BNFindFlag flags, const BinaryNinja::FunctionViewType& graph, - const std::function& cb); + const BinaryNinja::ProgressFunction& cb); virtual bool findNextConstant(uint64_t start, uint64_t end, uint64_t constant, uint64_t& addr, DisassemblySettingsRef settings, const BinaryNinja::FunctionViewType& graph, - const std::function& cb); + const BinaryNinja::ProgressFunction& cb); virtual bool findAllData(uint64_t start, uint64_t end, const BinaryNinja::DataBuffer& data, BNFindFlag flags, - const std::function& cb, + const BinaryNinja::ProgressFunction& cb, const std::function& matchCallback); virtual bool findAllText(uint64_t start, uint64_t end, const std::string& data, DisassemblySettingsRef settings, - BNFindFlag flags, const BinaryNinja::FunctionViewType& graph, const std::function& cb, + BNFindFlag flags, const BinaryNinja::FunctionViewType& graph, const BinaryNinja::ProgressFunction& cb, const std::function& matchCallback); virtual bool findAllConstant(uint64_t start, uint64_t end, uint64_t constant, DisassemblySettingsRef settings, - const BinaryNinja::FunctionViewType& graph, const std::function& cb, + const BinaryNinja::FunctionViewType& graph, const BinaryNinja::ProgressFunction& cb, const std::function& matchCallback); virtual BinaryViewRef getData() = 0; diff --git a/update.cpp b/update.cpp index a1ad18ad..7fe2eec7 100644 --- a/update.cpp +++ b/update.cpp @@ -27,7 +27,7 @@ using namespace std; namespace BinaryNinja { struct UpdateProgress { - function func; + ProgressFunction func; static bool UpdateCallback(void* ctxt, size_t progress, size_t total) { @@ -90,7 +90,7 @@ BNUpdateResult UpdateChannel::UpdateToVersion(const string& version) BNUpdateResult UpdateChannel::UpdateToVersion( - const string& version, const function& progress) + const string& version, const ProgressFunction& progress) { UpdateProgress up; up.func = progress; @@ -116,7 +116,7 @@ BNUpdateResult UpdateChannel::UpdateToLatestVersion() } -BNUpdateResult UpdateChannel::UpdateToLatestVersion(const function& progress) +BNUpdateResult UpdateChannel::UpdateToLatestVersion(const ProgressFunction& progress) { UpdateProgress up; up.func = progress; -- cgit v1.3.1