From a10ba14f3528577432f51a940fcadc69a535af4b Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 14 Oct 2024 16:00:22 -0400 Subject: Add BinaryNinja::Load(Ref) to c++ api --- binaryninjaapi.h | 18 ++++++++++++++++++ binaryview.cpp | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 4acb7b7e..bc13d67c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1456,6 +1456,7 @@ namespace BinaryNinja { }; class BinaryView; + class ProjectFile; /*! OpenView opens a file on disk and returns a BinaryView, attempting to use the most relevant BinaryViewType and generating default load options (which are overridable). @@ -1527,6 +1528,23 @@ namespace BinaryNinja { */ Ref Load(Ref rawData, bool updateAnalysis = true, const std::string& options = "{}", std::function 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) + for discussion of this function. + + \param rawData BinaryView with raw binary data to load + \param updateAnalysis If true, UpdateAnalysisAndWait() will be called after opening + a BinaryView. + \param options A Json string whose keys are setting identifiers and whose values are the desired settings. + \param progress Optional function to be called with progress updates as the view is + 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 = {}); + /*! Deprecated. Use non-metadata version. */ diff --git a/binaryview.cpp b/binaryview.cpp index 0570e635..510d74a5 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -5455,6 +5455,17 @@ Ref BinaryNinja::Load(Ref view, bool updateAnalysis, con } +Ref BinaryNinja::Load(Ref projectFile, bool updateAnalysis, const std::string& options, std::function progress) +{ + ProgressContext cb; + cb.callback = progress; + BNBinaryView* handle = BNLoadProjectFile(projectFile->GetObject(), updateAnalysis, options.c_str(), ProgressCallback, &cb); + if (!handle) + return nullptr; + return new BinaryView(handle); +} + + SymbolQueue::SymbolQueue() { m_object = BNCreateSymbolQueue(); -- cgit v1.3.1