summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-02-09 23:40:54 -0500
committerGlenn Smith <glenn@vector35.com>2022-03-23 15:11:08 -0400
commitaf05063f05b0b126a15b996d1954b90d0d17c05a (patch)
tree4c41366339383e4e558919b8faad9cd7fe491d34
parent04622e5b43406f44dd7dc020040a11387791148d (diff)
OpenView for 2 more argument types: data and bv
-rw-r--r--binaryninjaapi.h36
-rw-r--r--binaryview.cpp24
2 files changed, 55 insertions, 5 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 37b7bb71..04cdfd12 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -667,6 +667,42 @@ namespace BinaryNinja {
*/
Ref<BinaryView> OpenView(const std::string& filename, bool updateAnalysis = true, std::function<bool(size_t, size_t)> progress = {}, Json::Value options = Json::Value(Json::objectValue));
+ /*!
+ Open a BinaryView from a raw data buffer, initializing data views and loading settings.
+
+ See BinaryNinja::OpenView(const std::string&, bool, std::function<bool(size_t, size_t)>, Json::Value)
+ for discussion of this function.
+
+ \param rawData Buffer with raw binary data to load (cannot load from bndb)
+ \param updateAnalysis If true, UpdateAnalysisAndWait() will be called after opening
+ a BinaryView.
+ \param progress Optional function to be called with progress updates as the view is
+ being loaded. If the function returns false, it will cancel OpenView.
+ \param options A Json object whose keys are setting identifiers and whose values are
+ the desired settings.
+ \return Constructed view, or a nullptr Ref<BinaryView>
+ */
+ Ref<BinaryView> OpenView(const DataBuffer& rawData, bool updateAnalysis = true, std::function<bool(size_t, size_t)> progress = {}, Json::Value options = Json::Value(Json::objectValue));
+
+
+ /*!
+ Open a BinaryView from a raw BinaryView, initializing data views and loading settings.
+
+ See BinaryNinja::OpenView(const std::string&, bool, std::function<bool(size_t, size_t)>, 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 progress Optional function to be called with progress updates as the view is
+ being loaded. If the function returns false, it will cancel OpenView.
+ \param options A Json object whose keys are setting identifiers and whose values are
+ the desired settings.
+ \param isDatabase True if the view being loaded is the raw view of an already opened database.
+ \return Constructed view, or a nullptr Ref<BinaryView>
+ */
+ Ref<BinaryView> OpenView(Ref<BinaryView> rawData, bool updateAnalysis = true, std::function<bool(size_t, size_t)> progress = {}, Json::Value options = Json::Value(Json::objectValue), bool isDatabase = false);
+
bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
const bool simplify = false);
bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
diff --git a/binaryview.cpp b/binaryview.cpp
index 13e9f439..d5390ddc 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -3842,6 +3842,10 @@ Ref<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAn
if (!progress)
progress = [](size_t, size_t) { return true; };
+ // Loading will surely fail if the file does not exist, so exit early
+ if (!BNPathExists(filename.c_str()))
+ return nullptr;
+
// Detect bndb
bool isDatabase = false;
Ref<BinaryView> view = nullptr;
@@ -3864,18 +3868,28 @@ Ref<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAn
Ref<FileMetadata> file = new FileMetadata(filename);
view = file->OpenDatabaseForConfiguration(filename);
- isDatabase = true;
+ return OpenView(view, updateAnalysis, progress, options, true);
}
else
{
// Open file, read raw contents
Ref<FileMetadata> file = new FileMetadata(filename);
view = new BinaryData(file, filename);
+ return OpenView(view, updateAnalysis, progress, options, false);
}
+}
- if (!view)
- return nullptr;
+Ref<BinaryView> BinaryNinja::OpenView(const DataBuffer& rawData, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Json::Value options)
+{
+ Ref<FileMetadata> file = new FileMetadata();
+ Ref<BinaryView> view = new BinaryData(file, rawData);
+ return OpenView(view, updateAnalysis, progress, options, false);
+}
+
+
+Ref<BinaryView> BinaryNinja::OpenView(Ref<BinaryView> view, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Json::Value options, bool isDatabase)
+{
Ref<BinaryViewType> bvt;
Ref<BinaryViewType> universalBvt;
for (auto available : BinaryViewType::GetViewTypesForData(view))
@@ -4017,10 +4031,10 @@ Ref<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAn
Ref<BinaryView> bv;
if (isDatabase)
{
- view = view->GetFile()->OpenExistingDatabase(filename, progress);
+ view = view->GetFile()->OpenExistingDatabase(view->GetFile()->GetFilename(), progress);
if (!view)
{
- LogError("Unable to open existing database with filename %s", filename.c_str());
+ LogError("Unable to open existing database with filename %s", view->GetFile()->GetFilename().c_str());
return nullptr;
}
bv = view->GetFile()->GetViewOfType(bvt->GetName());