diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-04-24 14:46:37 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-04-25 13:43:01 -0400 |
| commit | 9262278979709181414664053523657355762707 (patch) | |
| tree | c472e0620b1fdfe3b3c9fd26c7cbf41425b27740 | |
| parent | 4aac12b0e429fedb02a645e5eb82ca2d88902e25 (diff) | |
std::function<bool(size_t,size_t)> ==> ProgressFunction
| -rw-r--r-- | binaryninjaapi.h | 145 | ||||
| -rw-r--r-- | binaryninjacore.h | 15 | ||||
| -rw-r--r-- | binaryview.cpp | 38 | ||||
| -rw-r--r-- | collaboration.cpp | 42 | ||||
| -rw-r--r-- | database.cpp | 8 | ||||
| -rw-r--r-- | debuginfo.cpp | 2 | ||||
| -rw-r--r-- | examples/background_task/src/backgroundtask.cpp | 2 | ||||
| -rw-r--r-- | examples/triage/baseaddress.cpp | 2 | ||||
| -rw-r--r-- | filemetadata.cpp | 14 | ||||
| -rw-r--r-- | http.cpp | 26 | ||||
| -rw-r--r-- | http.h | 37 | ||||
| -rw-r--r-- | interaction.cpp | 6 | ||||
| -rw-r--r-- | project.cpp | 14 | ||||
| -rw-r--r-- | rust/src/download_provider.rs | 8 | ||||
| -rw-r--r-- | typearchive.cpp | 2 | ||||
| -rw-r--r-- | typecontainer.cpp | 2 | ||||
| -rw-r--r-- | ui/historyview.h | 2 | ||||
| -rw-r--r-- | ui/progresstask.h | 8 | ||||
| -rw-r--r-- | ui/projectbrowser.h | 2 | ||||
| -rw-r--r-- | ui/viewframe.h | 12 | ||||
| -rw-r--r-- | 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<bool(size_t, size_t)> 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<BinaryView> */ - Ref<BinaryView> Load(const std::string& filename, bool updateAnalysis = true, const std::string& options = "{}", std::function<bool(size_t, size_t)> progress = {}); + Ref<BinaryView> 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<bool(size_t, size_t)>, 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<BinaryView> */ - Ref<BinaryView> Load(const DataBuffer& rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function<bool(size_t, size_t)> progress = {}); + Ref<BinaryView> 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<bool(size_t, size_t)>, 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<BinaryView> */ - Ref<BinaryView> Load(Ref<BinaryView> rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function<bool(size_t, size_t)> progress = {}); + Ref<BinaryView> Load(Ref<BinaryView> 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<bool(size_t, size_t)>, 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<BinaryView> */ - Ref<BinaryView> Load(Ref<ProjectFile> rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function<bool(size_t, size_t)> progress = {}); + Ref<BinaryView> Load(Ref<ProjectFile> rawData, bool updateAnalysis = true, const std::string& options = "{}", ProgressFunction progress = {}); Ref<BinaryView> ParseTextFormat(const std::string& filename); /*! Deprecated. Use non-metadata version. */ - Ref<BinaryView> Load(const std::string& filename, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType)); + Ref<BinaryView> Load(const std::string& filename, bool updateAnalysis, ProgressFunction progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType)); /*! Deprecated. Use non-metadata version. */ - Ref<BinaryView> Load(const DataBuffer& rawData, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType)); + Ref<BinaryView> Load(const DataBuffer& rawData, bool updateAnalysis, ProgressFunction progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType)); /*! Deprecated. Use non-metadata version. */ - Ref<BinaryView> Load(Ref<BinaryView> rawData, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType), bool isDatabase = false); + Ref<BinaryView> Load(Ref<BinaryView> rawData, bool updateAnalysis, ProgressFunction progress, Ref<Metadata> 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<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<Ref<UndoEntry>> GetUndoEntries(); - std::vector<Ref<UndoEntry>> GetUndoEntries(const std::function<bool(size_t, size_t)>& progress); + std::vector<Ref<UndoEntry>> GetUndoEntries(const ProgressFunction& progress); Ref<KeyValueStore> ReadData(); - Ref<KeyValueStore> ReadData(const std::function<bool(size_t, size_t)>& progress); - bool StoreData(const Ref<KeyValueStore>& data, const std::function<bool(size_t, size_t)>& progress); + Ref<KeyValueStore> ReadData(const ProgressFunction& progress); + bool StoreData(const Ref<KeyValueStore>& data, const ProgressFunction& progress); bool HasAncestor(Ref<Snapshot> other); }; @@ -2541,7 +2541,7 @@ namespace BinaryNinja { void SetCurrentSnapshot(int64_t id); Ref<Snapshot> GetCurrentSnapshot(); int64_t WriteSnapshotData(std::vector<int64_t> parents, Ref<BinaryView> file, const std::string& name, - const Ref<KeyValueStore>& data, bool autoSave, const std::function<bool(size_t, size_t)>& progress); + const Ref<KeyValueStore>& 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<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; + bool Export(const std::string& destination, const ProgressFunction& progressCallback = {}) const; }; /*! @@ -2840,18 +2840,18 @@ namespace BinaryNinja { 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 = {}); + const ProgressFunction& 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); - bool DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback = {}); + bool DeleteFolder(Ref<ProjectFolder> folder, const ProgressFunction& 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, int64_t creationTimestamp, 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, int64_t creationTimestamp, 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 ProgressFunction& progressCallback = {}); + Ref<ProjectFile> CreateFileFromPathUnsafe(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const ProgressFunction& progressCallback = {}); + Ref<ProjectFile> CreateFile_(const std::vector<uint8_t>& contents, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const ProgressFunction& 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, int64_t creationTimestamp, const ProgressFunction& progressCallback = {}); std::vector<Ref<ProjectFile>> GetFiles() const; Ref<ProjectFile> GetFileById(const std::string& id) const; Ref<ProjectFile> 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<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings); + const ProgressFunction& progressCallback, Ref<SaveSettings> 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<BinaryView> OpenExistingDatabase( - const std::string& path, const std::function<bool(size_t progress, size_t total)>& progressCallback); + const std::string& path, const ProgressFunction& progressCallback); Ref<BinaryView> 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<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings); + const ProgressFunction& progressCallback, Ref<SaveSettings> settings); void GetSnapshotData( - Ref<KeyValueStore> data, Ref<KeyValueStore> cache, const std::function<bool(size_t, size_t)>& progress); + Ref<KeyValueStore> data, Ref<KeyValueStore> cache, const ProgressFunction& progress); void ApplySnapshotData(BinaryView* file, Ref<KeyValueStore> data, Ref<KeyValueStore> cache, - const std::function<bool(size_t, size_t)>& progress, bool openForConfiguration = false, + const ProgressFunction& progress, bool openForConfiguration = false, bool restoreRawView = true); Ref<Database> GetDatabase(); @@ -3061,10 +3061,10 @@ namespace BinaryNinja { \return Whether the rebase was successful */ bool Rebase(BinaryView* data, uint64_t address, - const std::function<bool(size_t progress, size_t total)>& progressCallback); + const ProgressFunction& progressCallback); bool CreateSnapshotedView(BinaryView* data, const std::string& viewName); bool CreateSnapshotedView(BinaryView* data, const std::string& viewName, - const std::function<bool(size_t progress, size_t total)>& 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<bool(size_t progress, size_t total)>& progressCallback, + const ProgressFunction& progressCallback, Ref<SaveSettings> settings = new SaveSettings()); bool SaveAutoSnapshot(Ref<SaveSettings> settings = new SaveSettings()); - bool SaveAutoSnapshot(const std::function<bool(size_t progress, size_t total)>& progressCallback, + bool SaveAutoSnapshot(const ProgressFunction& progressCallback, Ref<SaveSettings> 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> type); - std::unordered_map<std::string, QualifiedName> DefineTypes(const std::vector<std::pair<std::string, QualifiedNameAndType>>& types, std::function<bool(size_t, size_t)> progress = {}); + std::unordered_map<std::string, QualifiedName> DefineTypes(const std::vector<std::pair<std::string, QualifiedNameAndType>>& types, ProgressFunction progress = {}); void DefineUserType(const QualifiedName& name, Ref<Type> type); - void DefineUserTypes(const std::vector<QualifiedNameAndType>& types, std::function<bool(size_t, size_t)> progress = {}); - void DefineUserTypes(const std::vector<ParsedType>& types, std::function<bool(size_t, size_t)> progress = {}); + void DefineUserTypes(const std::vector<QualifiedNameAndType>& types, ProgressFunction progress = {}); + void DefineUserTypes(const std::vector<ParsedType>& 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<bool(size_t current, size_t total)>& progress); + const ProgressFunction& progress); bool FindNextText(uint64_t start, uint64_t end, const std::string& data, uint64_t& addr, Ref<DisassemblySettings> settings, BNFindFlag flags, const FunctionViewType& viewType, - const std::function<bool(size_t current, size_t total)>& progress); + const ProgressFunction& progress); bool FindNextConstant(uint64_t start, uint64_t end, uint64_t constant, uint64_t& addr, Ref<DisassemblySettings> settings, const FunctionViewType& viewType, - const std::function<bool(size_t current, size_t total)>& progress); + const ProgressFunction& progress); bool FindAllData(uint64_t start, uint64_t end, const DataBuffer& data, BNFindFlag flags, - const std::function<bool(size_t current, size_t total)>& progress, + const ProgressFunction& progress, const std::function<bool(uint64_t addr, const DataBuffer& match)>& matchCallback); bool FindAllText(uint64_t start, uint64_t end, const std::string& data, Ref<DisassemblySettings> settings, BNFindFlag flags, const FunctionViewType& viewType, - const std::function<bool(size_t current, size_t total)>& progress, + const ProgressFunction& progress, const std::function<bool(uint64_t addr, const std::string& match, const LinearDisassemblyLine& line)>& matchCallback); bool FindAllConstant(uint64_t start, uint64_t end, uint64_t constant, Ref<DisassemblySettings> settings, - const FunctionViewType& viewType, const std::function<bool(size_t current, size_t total)>& progress, + const FunctionViewType& viewType, const ProgressFunction& progress, const std::function<bool(uint64_t addr, const LinearDisassemblyLine& line)>& matchCallback); std::string DetectSearchMode(const std::string& query); bool Search(const std::string& query, - const std::function<bool(size_t current, size_t total)>& progressCallback, + const ProgressFunction& progressCallback, const std::function<bool(uint64_t addr, const DataBuffer& buffer)>& matchCallback); void Reanalyze(); @@ -14409,9 +14409,9 @@ namespace BinaryNinja { BNUpdateResult UpdateToVersion(const std::string& version); BNUpdateResult UpdateToVersion( - const std::string& version, const std::function<bool(size_t progress, size_t total)>& progress); + const std::string& version, const ProgressFunction& progress); BNUpdateResult UpdateToLatestVersion(); - BNUpdateResult UpdateToLatestVersion(const std::function<bool(size_t progress, size_t total)>& 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<void(std::function<bool(size_t, size_t)> progress)> task) = 0; + virtual bool RunProgressDialog(const std::string& title, bool canCancel, std::function<void(ProgressFunction progress)> task) = 0; }; typedef BNPluginOrigin PluginOrigin; @@ -17557,7 +17557,7 @@ namespace BinaryNinja { static std::vector<Ref<DebugInfoParser>> GetListForView(const Ref<BinaryView> data); std::string GetName() const; - Ref<DebugInfo> Parse(Ref<BinaryView> view, Ref<BinaryView> debugView, Ref<DebugInfo> existingDebugInfo = nullptr, std::function<bool(size_t, size_t)> progress = {}) const; + Ref<DebugInfo> Parse(Ref<BinaryView> view, Ref<BinaryView> debugView, Ref<DebugInfo> existingDebugInfo = nullptr, ProgressFunction progress = {}) const; bool IsValidForView(const Ref<BinaryView> view) const; }; @@ -17577,7 +17577,7 @@ namespace BinaryNinja { virtual bool IsValid(Ref<BinaryView>) = 0; virtual bool ParseInfo( - Ref<DebugInfo>, Ref<BinaryView>, Ref<BinaryView>, std::function<bool(size_t, size_t)>) = 0; + Ref<DebugInfo>, Ref<BinaryView>, Ref<BinaryView>, 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<std::string, std::string>& mergeConflictsIn, std::unordered_set<std::string>& mergeConflictsOut, - std::function<bool(size_t, size_t)> progress + ProgressFunction progress ); }; @@ -18569,7 +18569,7 @@ namespace BinaryNinja { */ std::optional<std::unordered_map<QualifiedName, std::string>> AddTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, - std::function<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<RemoteProject> ImportLocalProject(Ref<Project> localProject, std::function<bool(size_t, size_t)> progress = {}); + Ref<RemoteProject> ImportLocalProject(Ref<Project> 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<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<uint8_t> DownloadSnapshotFile(std::function<bool(size_t, size_t)> progress = {}); + std::vector<uint8_t> 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<uint8_t> Download(std::function<bool(size_t, size_t)> progress = {}); + std::vector<uint8_t> 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<uint8_t> DownloadAnalysisCache(std::function<bool(size_t, size_t)> progress = {}); + std::vector<uint8_t> 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<bool(size_t, size_t)> progress = {}); + void PullSnapshots(ProgressFunction progress = {}); /*! Create a new snapshot on the remote (and pull it) @@ -20378,7 +20378,7 @@ namespace BinaryNinja::Collaboration std::vector<uint8_t> analysisCacheContents, std::optional<std::vector<uint8_t>> fileContents, std::vector<std::string> parentIds, - std::function<bool(size_t, size_t)> 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<uint8_t> Download(std::function<bool(size_t, size_t)> progress = {}); + std::vector<uint8_t> Download(ProgressFunction progress = {}); /*! Get the current user positions for this file @@ -20444,7 +20444,7 @@ namespace BinaryNinja::Collaboration Ref<Project> GetCoreProject(); bool IsOpen(); - bool Open(std::function<bool(size_t, size_t)> progress = {}); + bool Open(ProgressFunction progress = {}); void Close(); Ref<Remote> GetRemote(); @@ -20467,10 +20467,10 @@ namespace BinaryNinja::Collaboration std::vector<Ref<RemoteFolder>> GetFolders(); Ref<RemoteFile> GetFileById(const std::string& id); Ref<RemoteFile> GetFileByName(const std::string& name); - void PullFiles(std::function<bool(size_t, size_t)> progress = {}); - void PullFolders(std::function<bool(size_t, size_t)> progress = {}); - Ref<RemoteFile> CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress = {}, Ref<ProjectFile> coreFile = nullptr); - Ref<RemoteFolder> CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress = {}, Ref<ProjectFolder> coreFolder = nullptr); + void PullFiles(ProgressFunction progress = {}); + void PullFolders(ProgressFunction progress = {}); + Ref<RemoteFile> CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, ProgressFunction progress = {}, Ref<ProjectFile> coreFile = nullptr); + Ref<RemoteFolder> CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, ProgressFunction progress = {}, Ref<ProjectFolder> coreFolder = nullptr); void PushFile(Ref<RemoteFile> file, const std::vector<std::pair<std::string, std::string>>& extraFields = {}); void PushFolder(Ref<RemoteFolder> folder, const std::vector<std::pair<std::string, std::string>>& extraFields = {}); void DeleteFolder(const Ref<RemoteFolder> folder); @@ -20479,10 +20479,10 @@ namespace BinaryNinja::Collaboration std::vector<Ref<CollabPermission>> GetGroupPermissions(); std::vector<Ref<CollabPermission>> GetUserPermissions(); Ref<CollabPermission> GetPermissionById(const std::string& id); - void PullGroupPermissions(std::function<bool(size_t, size_t)> progress = {}); - void PullUserPermissions(std::function<bool(size_t, size_t)> progress = {}); - Ref<CollabPermission> CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, std::function<bool(size_t, size_t)> progress = {}); - Ref<CollabPermission> CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, std::function<bool(size_t, size_t)> progress = {}); + void PullGroupPermissions(ProgressFunction progress = {}); + void PullUserPermissions(ProgressFunction progress = {}); + Ref<CollabPermission> CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, ProgressFunction progress = {}); + Ref<CollabPermission> CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, ProgressFunction progress = {}); void PushPermission(Ref<CollabPermission> permission, const std::vector<std::pair<std::string, std::string>>& extraFields = {}); void DeletePermission(Ref<CollabPermission> permission); bool CanUserView(const std::string& username); @@ -20549,7 +20549,6 @@ namespace BinaryNinja::Collaboration }; typedef std::function<bool(Ref<CollabChangeset>)> NameChangesetFunction; - typedef std::function<bool(size_t, size_t)> ProgressFunction; typedef std::function<bool(const std::unordered_map<std::string, Ref<AnalysisMergeConflict>>& conflicts)> AnalysisConflictHandler; typedef std::function<bool(const std::vector<Ref<TypeArchiveMergeConflict>>& 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> database, Ref<RemoteFile> file, AnalysisConflictHandler conflictHandler, std::function<bool(size_t, size_t)> progress = {}, NameChangesetFunction nameChangeset = [](Ref<CollabChangeset>){ return true; }); + void SyncDatabase(Ref<Database> database, Ref<RemoteFile> file, AnalysisConflictHandler conflictHandler, ProgressFunction progress = {}, NameChangesetFunction nameChangeset = [](Ref<CollabChangeset>){ 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<SaveSettings> settings) bool BinaryView::CreateDatabase(const string& path, - const function<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings) + const ProgressFunction& progressCallback, Ref<SaveSettings> settings) { auto parent = GetParentView(); if (parent) @@ -1650,7 +1650,7 @@ bool BinaryView::SaveAutoSnapshot(Ref<SaveSettings> settings) bool BinaryView::SaveAutoSnapshot( - const function<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings) + const ProgressFunction& progressCallback, Ref<SaveSettings> settings) { return m_file->SaveAutoSnapshot(this, progressCallback, settings); } @@ -4217,7 +4217,7 @@ void BinaryView::DefineUserType(const QualifiedName& name, Ref<Type> type) } -std::unordered_map<std::string, QualifiedName> BinaryView::DefineTypes(const vector<pair<string, QualifiedNameAndType>>& types, std::function<bool(size_t, size_t)> progress) +std::unordered_map<std::string, QualifiedName> BinaryView::DefineTypes(const vector<pair<string, QualifiedNameAndType>>& 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<std::string, QualifiedName> BinaryView::DefineTypes(const vec } -void BinaryView::DefineUserTypes(const vector<QualifiedNameAndType>& types, std::function<bool(size_t, size_t)> progress) +void BinaryView::DefineUserTypes(const vector<QualifiedNameAndType>& 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<QualifiedNameAndType>& types, std: } -void BinaryView::DefineUserTypes(const vector<ParsedType>& types, std::function<bool(size_t, size_t)> progress) +void BinaryView::DefineUserTypes(const vector<ParsedType>& 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<bool(size_t current, size_t total)>& 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<DisassemblySettings> settings, BNFindFlag flags, const FunctionViewType& viewType, - const std::function<bool(size_t current, size_t total)>& 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<DisassemblySettings> settings, const FunctionViewType& viewType, - const std::function<bool(size_t current, size_t total)>& 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<bool(size_t current, size_t total)>& progress, + const ProgressFunction& progress, const std::function<bool(uint64_t addr, const DataBuffer& match)>& 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<DisassemblySettings> settings, - BNFindFlag flags, const FunctionViewType& viewType, const std::function<bool(size_t current, size_t total)>& progress, + BNFindFlag flags, const FunctionViewType& viewType, const ProgressFunction& progress, const std::function<bool(uint64_t addr, const std::string& match, const LinearDisassemblyLine& line)>& 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<DisassemblySettings> settings, - const FunctionViewType& viewType, const std::function<bool(size_t current, size_t total)>& progress, + const FunctionViewType& viewType, const ProgressFunction& progress, const std::function<bool(uint64_t addr, const LinearDisassemblyLine& line)>& matchCallback) { ProgressContext fp; @@ -4815,7 +4815,7 @@ string BinaryView::DetectSearchMode(const string& query) } -bool BinaryView::Search(const string& query, const std::function<bool(size_t current, size_t total)>& progressCallback, const std::function<bool(uint64_t offset, const DataBuffer& buffer)>& matchCallback) +bool BinaryView::Search(const string& query, const ProgressFunction& progressCallback, const std::function<bool(uint64_t offset, const DataBuffer& buffer)>& matchCallback) { ProgressContext fp; fp.callback = progressCallback; @@ -5598,14 +5598,14 @@ Ref<BinaryData> BinaryData::CreateFromFile(FileMetadata* file, FileAccessor* acc Ref<BinaryView> BinaryNinja::Load(const std::string& filename, bool updateAnalysis, - std::function<bool(size_t, size_t)> progress, Ref<Metadata> options) + ProgressFunction progress, Ref<Metadata> options) { return Load(filename, updateAnalysis, options->GetJsonString(), progress); } Ref<BinaryView> BinaryNinja::Load( - const DataBuffer& rawData, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Ref<Metadata> options) + const DataBuffer& rawData, bool updateAnalysis, ProgressFunction progress, Ref<Metadata> options) { Ref<FileMetadata> file = new FileMetadata(); Ref<BinaryView> view = new BinaryData(file, rawData); @@ -5614,13 +5614,13 @@ Ref<BinaryView> BinaryNinja::Load( Ref<BinaryView> BinaryNinja::Load(Ref<BinaryView> view, bool updateAnalysis, - std::function<bool(size_t, size_t)> progress, Ref<Metadata> options, bool isDatabase) + ProgressFunction progress, Ref<Metadata> options, bool isDatabase) { return Load(view, updateAnalysis, options->GetJsonString(), progress); } -Ref<BinaryView> BinaryNinja::Load(const std::string& filename, bool updateAnalysis, const std::string& options, std::function<bool(size_t, size_t)> progress) +Ref<BinaryView> BinaryNinja::Load(const std::string& filename, bool updateAnalysis, const std::string& options, ProgressFunction progress) { ProgressContext cb; cb.callback = progress; @@ -5631,7 +5631,7 @@ Ref<BinaryView> BinaryNinja::Load(const std::string& filename, bool updateAnalys } -Ref<BinaryView> BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis, const std::string& options, std::function<bool(size_t, size_t)> progress) +Ref<BinaryView> BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis, const std::string& options, ProgressFunction progress) { Ref<FileMetadata> file = new FileMetadata(); Ref<BinaryView> view = new BinaryData(file, rawData); @@ -5639,7 +5639,7 @@ Ref<BinaryView> BinaryNinja::Load(const DataBuffer& rawData, bool updateAnalysis } -Ref<BinaryView> BinaryNinja::Load(Ref<BinaryView> view, bool updateAnalysis, const std::string& options, std::function<bool(size_t, size_t)> progress) +Ref<BinaryView> BinaryNinja::Load(Ref<BinaryView> view, bool updateAnalysis, const std::string& options, ProgressFunction progress) { ProgressContext cb; cb.callback = progress; @@ -5650,7 +5650,7 @@ Ref<BinaryView> BinaryNinja::Load(Ref<BinaryView> view, bool updateAnalysis, con } -Ref<BinaryView> BinaryNinja::Load(Ref<ProjectFile> projectFile, bool updateAnalysis, const std::string& options, std::function<bool(size_t, size_t)> progress) +Ref<BinaryView> BinaryNinja::Load(Ref<ProjectFile> 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> database, Ref<RemoteFile> file, std::function<bool(const std::unordered_map<std::string, Ref<AnalysisMergeConflict>>& conflicts)> conflictHandler, std::function<bool(size_t, size_t)> progress, NameChangesetFunction nameChangeset) +void BinaryNinja::Collaboration::SyncDatabase(Ref<Database> database, Ref<RemoteFile> file, std::function<bool(const std::unordered_map<std::string, Ref<AnalysisMergeConflict>>& conflicts)> conflictHandler, ProgressFunction progress, NameChangesetFunction nameChangeset) { ProgressContext pctxt; pctxt.callback = progress; @@ -762,7 +762,7 @@ Ref<RemoteProject> Remote::GetProjectByName(const std::string& name) } -void Remote::PullProjects(std::function<bool(size_t, size_t)> progress) +void Remote::PullProjects(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -779,7 +779,7 @@ Ref<RemoteProject> Remote::CreateProject(const std::string& name, const std::str } -Ref<RemoteProject> Remote::ImportLocalProject(Ref<Project> localProject, std::function<bool(size_t, size_t)> progress) +Ref<RemoteProject> Remote::ImportLocalProject(Ref<Project> localProject, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -867,7 +867,7 @@ std::vector<std::pair<uint64_t, std::string>> Remote::SearchGroups(const std::st } -void Remote::PullGroups(std::function<bool(size_t, size_t)> progress) +void Remote::PullGroups(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -977,7 +977,7 @@ std::vector<std::pair<std::string, std::string>> Remote::SearchUsers(const std:: } -void Remote::PullUsers(std::function<bool(size_t, size_t)> progress) +void Remote::PullUsers(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1168,7 +1168,7 @@ bool RemoteProject::IsOpen() } -bool RemoteProject::Open(std::function<bool(size_t, size_t)> progress) +bool RemoteProject::Open(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1336,7 +1336,7 @@ Ref<RemoteFile> RemoteProject::GetFileByName(const std::string& name) } -void RemoteProject::PullFiles(std::function<bool(size_t, size_t)> progress) +void RemoteProject::PullFiles(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1344,7 +1344,7 @@ void RemoteProject::PullFiles(std::function<bool(size_t, size_t)> progress) } -void RemoteProject::PullFolders(std::function<bool(size_t, size_t)> progress) +void RemoteProject::PullFolders(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1353,7 +1353,7 @@ void RemoteProject::PullFolders(std::function<bool(size_t, size_t)> progress) } -Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, std::function<bool(size_t, size_t)> progress, Ref<ProjectFile> coreFile) +Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vector<uint8_t>& contents, const std::string& name, const std::string& description, Ref<RemoteFolder> folder, BNRemoteFileType type, ProgressFunction progress, Ref<ProjectFile> coreFile) { ProgressContext pctxt; pctxt.callback = progress; @@ -1364,7 +1364,7 @@ Ref<RemoteFile> RemoteProject::CreateFile(const std::string& filename, std::vect } -Ref<RemoteFolder> RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, std::function<bool(size_t, size_t)> progress, Ref<ProjectFolder> coreFolder) +Ref<RemoteFolder> RemoteProject::CreateFolder(const std::string& name, const std::string& description, Ref<RemoteFolder> parent, ProgressFunction progress, Ref<ProjectFolder> coreFolder) { ProgressContext pctxt; pctxt.callback = progress; @@ -1473,7 +1473,7 @@ Ref<CollabPermission> RemoteProject::GetPermissionById(const std::string& id) } -void RemoteProject::PullGroupPermissions(std::function<bool(size_t, size_t)> progress) +void RemoteProject::PullGroupPermissions(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1481,7 +1481,7 @@ void RemoteProject::PullGroupPermissions(std::function<bool(size_t, size_t)> pro } -void RemoteProject::PullUserPermissions(std::function<bool(size_t, size_t)> progress) +void RemoteProject::PullUserPermissions(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1489,7 +1489,7 @@ void RemoteProject::PullUserPermissions(std::function<bool(size_t, size_t)> prog } -Ref<CollabPermission> RemoteProject::CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, std::function<bool(size_t, size_t)> progress) +Ref<CollabPermission> RemoteProject::CreateGroupPermission(int groupId, BNCollaborationPermissionLevel level, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1500,7 +1500,7 @@ Ref<CollabPermission> RemoteProject::CreateGroupPermission(int groupId, BNCollab } -Ref<CollabPermission> RemoteProject::CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, std::function<bool(size_t, size_t)> progress) +Ref<CollabPermission> RemoteProject::CreateUserPermission(const std::string& userId, BNCollaborationPermissionLevel level, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1777,7 +1777,7 @@ Ref<CollabSnapshot> RemoteFile::GetSnapshotById(const std::string& id) } -void RemoteFile::PullSnapshots(std::function<bool(size_t, size_t)> progress) +void RemoteFile::PullSnapshots(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1785,7 +1785,7 @@ void RemoteFile::PullSnapshots(std::function<bool(size_t, size_t)> progress) } -Ref<CollabSnapshot> RemoteFile::CreateSnapshot(std::string name, std::vector<uint8_t> contents, std::vector<uint8_t> analysisCacheContents, std::optional<std::vector<uint8_t>> fileContents, std::vector<std::string> parentIds, std::function<bool(size_t, size_t)> progress) +Ref<CollabSnapshot> RemoteFile::CreateSnapshot(std::string name, std::vector<uint8_t> contents, std::vector<uint8_t> analysisCacheContents, std::optional<std::vector<uint8_t>> fileContents, std::vector<std::string> parentIds, ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -1825,7 +1825,7 @@ void RemoteFile::DeleteSnapshot(const Ref<CollabSnapshot> snapshot) } -std::vector<uint8_t> RemoteFile::Download(std::function<bool(size_t, size_t)> progress) +std::vector<uint8_t> RemoteFile::Download(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2600,7 +2600,7 @@ Ref<CollabUndoEntry> CollabSnapshot::GetUndoEntryById(uint64_t id) } -void CollabSnapshot::PullUndoEntries(std::function<bool(size_t, size_t)> progress) +void CollabSnapshot::PullUndoEntries(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2623,7 +2623,7 @@ void CollabSnapshot::Finalize() } -std::vector<uint8_t> CollabSnapshot::DownloadSnapshotFile(std::function<bool(size_t, size_t)> progress) +std::vector<uint8_t> CollabSnapshot::DownloadSnapshotFile(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2640,7 +2640,7 @@ std::vector<uint8_t> CollabSnapshot::DownloadSnapshotFile(std::function<bool(siz } -std::vector<uint8_t> CollabSnapshot::Download(std::function<bool(size_t, size_t)> progress) +std::vector<uint8_t> CollabSnapshot::Download(ProgressFunction progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -2657,7 +2657,7 @@ std::vector<uint8_t> CollabSnapshot::Download(std::function<bool(size_t, size_t) } -std::vector<uint8_t> CollabSnapshot::DownloadAnalysisCache(std::function<bool(size_t, size_t)> progress) +std::vector<uint8_t> 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<Ref<UndoEntry>> Snapshot::GetUndoEntries() } -vector<Ref<UndoEntry>> Snapshot::GetUndoEntries(const std::function<bool(size_t, size_t)>& progress) +vector<Ref<UndoEntry>> Snapshot::GetUndoEntries(const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -339,7 +339,7 @@ Ref<KeyValueStore> Snapshot::ReadData() } -Ref<KeyValueStore> Snapshot::ReadData(const std::function<bool(size_t, size_t)>& progress) +Ref<KeyValueStore> Snapshot::ReadData(const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -352,7 +352,7 @@ Ref<KeyValueStore> Snapshot::ReadData(const std::function<bool(size_t, size_t)>& } -bool Snapshot::StoreData(const Ref<KeyValueStore>& data, const std::function<bool(size_t, size_t)>& progress) +bool Snapshot::StoreData(const Ref<KeyValueStore>& data, const ProgressFunction& progress) { ProgressContext pctxt; pctxt.callback = progress; @@ -413,7 +413,7 @@ Ref<Snapshot> Database::GetCurrentSnapshot() int64_t Database::WriteSnapshotData(std::vector<int64_t> parents, Ref<BinaryView> file, const std::string& name, - const Ref<KeyValueStore>& data, bool autoSave, const std::function<bool(size_t, size_t)>& progress) + const Ref<KeyValueStore>& 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<DebugInfo> DebugInfoParser::Parse(Ref<BinaryView> view, Ref<BinaryView> debugFile, Ref<DebugInfo> existingDebugInfo, - std::function<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<Save bool FileMetadata::CreateDatabase(const string& name, BinaryView* data, - const function<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings) + const ProgressFunction& progressCallback, Ref<SaveSettings> settings) { ProgressContext cb; cb.callback = progressCallback; @@ -185,7 +185,7 @@ Ref<BinaryView> FileMetadata::OpenExistingDatabase(const string& path) Ref<BinaryView> FileMetadata::OpenExistingDatabase( - const string& path, const function<bool(size_t progress, size_t total)>& progressCallback) + const string& path, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -212,7 +212,7 @@ bool FileMetadata::SaveAutoSnapshot(BinaryView* data, Ref<SaveSettings> settings bool FileMetadata::SaveAutoSnapshot( - BinaryView* data, const function<bool(size_t progress, size_t total)>& progressCallback, Ref<SaveSettings> settings) + BinaryView* data, const ProgressFunction& progressCallback, Ref<SaveSettings> settings) { ProgressContext cb; cb.callback = progressCallback; @@ -222,7 +222,7 @@ bool FileMetadata::SaveAutoSnapshot( void FileMetadata::GetSnapshotData( - Ref<KeyValueStore> data, Ref<KeyValueStore> cache, const std::function<bool(size_t, size_t)>& progress) + Ref<KeyValueStore> data, Ref<KeyValueStore> cache, const ProgressFunction& progress) { ProgressContext cb; cb.callback = progress; @@ -231,7 +231,7 @@ void FileMetadata::GetSnapshotData( void FileMetadata::ApplySnapshotData(BinaryView* file, Ref<KeyValueStore> data, Ref<KeyValueStore> cache, - const std::function<bool(size_t, size_t)>& 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<bool(size_t progress, size_t total)>& 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<bool(size_t progress, size_t total)>& progressCallback) + const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -230,8 +230,8 @@ namespace BinaryNinja::Http Request::Request(string method, string url, const unordered_map<string, string>& headers, - vector<pair<string, string>> params, std::function<bool(size_t, size_t)> downloadProgress, - std::function<bool(size_t, size_t)> uploadProgress) : + vector<pair<string, string>> 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<string, string>& headers, - vector<pair<string, string>> params, vector<uint8_t> body, std::function<bool(size_t, size_t)> downloadProgress, - std::function<bool(size_t, size_t)> uploadProgress) : + vector<pair<string, string>> params, vector<uint8_t> 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<string, string>& headers, vector<pair<string, string>> params, vector<pair<string, string>> formFields, - std::function<bool(size_t, size_t)> downloadProgress, std::function<bool(size_t, size_t)> 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<string, string>& headers, vector<pair<string, string>> params, vector<MultipartField> formFields, - std::function<bool(size_t, size_t)> downloadProgress, std::function<bool(size_t, size_t)> 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<string, string>& headers, const vector<pair<string, string>>& params, - std::function<bool(size_t, size_t)> downloadProgress, std::function<bool(size_t, size_t)> uploadProgress) + ProgressFunction downloadProgress, ProgressFunction uploadProgress) { return Request("GET", url, headers, params, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map<string, string>& headers, const vector<pair<string, string>>& params, - const vector<uint8_t>& body, std::function<bool(size_t, size_t)> downloadProgress, - std::function<bool(size_t, size_t)> uploadProgress) + const vector<uint8_t>& body, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, body, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map<string, string>& headers, const vector<pair<string, string>>& params, - const vector<pair<string, string>>& formFields, std::function<bool(size_t, size_t)> downloadProgress, - std::function<bool(size_t, size_t)> uploadProgress) + const vector<pair<string, string>>& formFields, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, formFields, downloadProgress, uploadProgress); } Request Request::Post(string url, const unordered_map<string, string>& headers, const vector<pair<string, string>>& params, - const vector<MultipartField>& formFields, std::function<bool(size_t, size_t)> downloadProgress, - std::function<bool(size_t, size_t)> uploadProgress) + const vector<MultipartField>& formFields, ProgressFunction downloadProgress, + ProgressFunction uploadProgress) { return Request("POST", url, headers, params, formFields, downloadProgress, uploadProgress); } @@ -29,6 +29,7 @@ #include <cstdint> #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<uint8_t> m_body; - std::function<bool(size_t, size_t)> m_downloadProgress; - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>> params = {}, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>> params, _STD_VECTOR<uint8_t> body, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>> params, _STD_VECTOR<std::pair<_STD_STRING, _STD_STRING>> formFields, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>> params, _STD_VECTOR<MultipartField> formFields, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>>& params = {}, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>>& params = {}, const _STD_VECTOR<uint8_t>& body = {}, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>>& params, const _STD_VECTOR<std::pair<_STD_STRING, _STD_STRING>>& formFields, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<std::pair<_STD_STRING, _STD_STRING>>& params, const _STD_VECTOR<MultipartField>& formFields, - std::function<bool(size_t, size_t)> downloadProgress = {}, - std::function<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<void(std::function<bool(size_t, size_t)> progress)> callback; + std::function<void(ProgressFunction progress)> 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<void(std::function<bool(size_t, size_t)> progress)> task) +bool BinaryNinja::RunProgressDialog(const std::string& title, bool canCancel, std::function<void(ProgressFunction progress)> 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<ProjectFolder> Project::CreateFolderFromPath(const std::string& path, Ref<ProjectFolder> parent, const std::string& description, - const std::function<bool(size_t progress, size_t total)>& progressCallback) + const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -399,7 +399,7 @@ void Project::PushFolder(Ref<ProjectFolder> folder) } -bool Project::DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback) +bool Project::DeleteFolder(Ref<ProjectFolder> folder, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -407,7 +407,7 @@ bool Project::DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(s } -Ref<ProjectFile> Project::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> Project::CreateFileFromPath(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -418,7 +418,7 @@ Ref<ProjectFile> Project::CreateFileFromPath(const std::string& path, Ref<Projec } -Ref<ProjectFile> Project::CreateFileFromPathUnsafe(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const std::function<bool(size_t progress, size_t total)>& progressCallback) +Ref<ProjectFile> Project::CreateFileFromPathUnsafe(const std::string& path, Ref<ProjectFolder> 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<ProjectFile> Project::CreateFileFromPathUnsafe(const std::string& path, Ref< } -Ref<ProjectFile> Project::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> Project::CreateFile_(const std::vector<uint8_t>& contents, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback) { ProgressContext cb; cb.callback = progressCallback; @@ -440,7 +440,7 @@ Ref<ProjectFile> Project::CreateFile_(const std::vector<uint8_t>& contents, Ref< } -Ref<ProjectFile> Project::CreateFileUnsafe(const std::vector<uint8_t>& contents, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const std::function<bool(size_t progress, size_t total)>& progressCallback) +Ref<ProjectFile> Project::CreateFileUnsafe(const std::vector<uint8_t>& contents, Ref<ProjectFolder> 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<ProjectFolder> parent) } -bool ProjectFolder::Export(const std::string& destination, const std::function<bool(size_t progress, size_t total)>& 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<Box<dyn FnMut(&[u8]) -> usize>>, - pub progress: Option<Box<dyn FnMut(u64, u64) -> bool>>, + pub progress: Option<Box<dyn FnMut(usize, usize) -> bool>>, } pub struct DownloadInstanceInputOutputCallbacks { pub read: Option<Box<dyn FnMut(&mut [u8]) -> Option<isize>>>, pub write: Option<Box<dyn FnMut(&[u8]) -> usize>>, - pub progress: Option<Box<dyn FnMut(u64, u64) -> bool>>, + pub progress: Option<Box<dyn FnMut(usize, usize) -> 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<std::string> TypeArchive::MergeSnapshots( const std::string& secondSnapshot, const std::unordered_map<std::string, std::string>& mergeConflictsIn, std::unordered_set<std::string>& mergeConflictsOut, - std::function<bool(size_t, size_t)> progress + ProgressFunction progress ) { std::vector<const char*> 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<std::string> TypeContainer::AddType(QualifiedName name, Ref<Type> std::optional<std::unordered_map<QualifiedName, std::string>> TypeContainer::AddTypes( const std::vector<std::pair<QualifiedName, Ref<Type>>>& types, - std::function<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<bool(size_t, size_t)> 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<void(std::function<bool(size_t, size_t)>)> m_func; + std::function<void(BinaryNinja::ProgressFunction)> 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<void(std::function<bool(size_t, size_t)>)> func); + std::function<void(BinaryNinja::ProgressFunction)> func); virtual ~ProgressTask(); /*! @@ -279,7 +279,7 @@ class BINARYNINJAUIAPI BackgroundThread : public QObject Q_OBJECT public: - typedef std::function<bool(size_t, size_t)> ProgressFunction; + typedef BinaryNinja::ProgressFunction ProgressFunction; typedef std::function<QVariant(QVariant value)> ThenFunction; typedef std::function<void(std::exception_ptr exc)> 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<bool(size_t, size_t)>& 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<bool(size_t current, size_t total)>& 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<bool(size_t current, size_t total)>& 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<bool(size_t current, size_t total)>& cb); + const BinaryNinja::ProgressFunction& cb); virtual bool findAllData(uint64_t start, uint64_t end, const BinaryNinja::DataBuffer& data, BNFindFlag flags, - const std::function<bool(size_t current, size_t total)>& cb, + const BinaryNinja::ProgressFunction& cb, const std::function<bool(uint64_t addr, const BinaryNinja::DataBuffer& match)>& 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<bool(size_t current, size_t total)>& cb, + BNFindFlag flags, const BinaryNinja::FunctionViewType& graph, const BinaryNinja::ProgressFunction& cb, const std::function<bool( uint64_t addr, const std::string& match, const BinaryNinja::LinearDisassemblyLine& line)>& matchCallback); virtual bool findAllConstant(uint64_t start, uint64_t end, uint64_t constant, DisassemblySettingsRef settings, - const BinaryNinja::FunctionViewType& graph, const std::function<bool(size_t current, size_t total)>& cb, + const BinaryNinja::FunctionViewType& graph, const BinaryNinja::ProgressFunction& cb, const std::function<bool(uint64_t addr, const BinaryNinja::LinearDisassemblyLine& line)>& matchCallback); virtual BinaryViewRef getData() = 0; @@ -27,7 +27,7 @@ using namespace std; namespace BinaryNinja { struct UpdateProgress { - function<bool(size_t progress, size_t total)> 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<bool(size_t progress, size_t total)>& progress) + const string& version, const ProgressFunction& progress) { UpdateProgress up; up.func = progress; @@ -116,7 +116,7 @@ BNUpdateResult UpdateChannel::UpdateToLatestVersion() } -BNUpdateResult UpdateChannel::UpdateToLatestVersion(const function<bool(size_t progress, size_t total)>& progress) +BNUpdateResult UpdateChannel::UpdateToLatestVersion(const ProgressFunction& progress) { UpdateProgress up; up.func = progress; |
