From 9993345001464331697167349803235498218652 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Sun, 19 Feb 2023 17:05:33 -0500 Subject: Account for BinaryData::Ctor potentially failing --- binaryview.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index c818bed6..52fd3dd3 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4412,6 +4412,9 @@ Ref Relocation::GetSymbol() const } +BinaryData::BinaryData(BNBinaryView* view) : BinaryView(view) {} + + BinaryData::BinaryData(FileMetadata* file) : BinaryView(BNCreateBinaryDataView(file->GetObject())) {} @@ -4435,6 +4438,26 @@ BinaryData::BinaryData(FileMetadata* file, FileAccessor* accessor) : {} +Ref BinaryData::CreateFromFilename(FileMetadata* file, const std::string& path) +{ + // This can fail, and throwing an exception in a c++ ctor is Ugly, so now there's a helper method here + BNBinaryView* handle = BNCreateBinaryDataViewFromFilename(file->GetObject(), path.c_str()); + if (!handle) + return nullptr; + return new BinaryData(handle); +} + + +Ref BinaryData::CreateFromFile(FileMetadata* file, FileAccessor* accessor) +{ + // This can fail, and throwing an exception in a c++ ctor is Ugly, so now there's a helper method here + BNBinaryView* handle = BNCreateBinaryDataViewFromFile(file->GetObject(), accessor->GetCallbacks()); + if (!handle) + return nullptr; + return new BinaryData(handle); +} + + Ref BinaryNinja::OpenView(const std::string& filename, bool updateAnalysis, std::function progress, Json::Value options) { if (!progress) @@ -4475,7 +4498,7 @@ Ref BinaryNinja::OpenView(const std::string& filename, bool updateAn { // Open file, read raw contents Ref file = new FileMetadata(filename); - view = new BinaryData(file, filename); + view = BinaryData::CreateFromFilename(file, filename); } if (!view) -- cgit v1.3.1