diff options
| author | Glenn Smith <glenn@vector35.com> | 2023-02-19 17:05:33 -0500 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2023-02-19 17:21:20 -0500 |
| commit | 9993345001464331697167349803235498218652 (patch) | |
| tree | 68c0f3796472880913edd1163f287caf457d3ff6 /binaryview.cpp | |
| parent | 18ffd57986569523887621d6b1937046849849a8 (diff) | |
Account for BinaryData::Ctor potentially failing
Diffstat (limited to 'binaryview.cpp')
| -rw-r--r-- | binaryview.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/binaryview.cpp b/binaryview.cpp index c818bed6..52fd3dd3 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4412,6 +4412,9 @@ Ref<Symbol> 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> 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> 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<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAnalysis, std::function<bool(size_t, size_t)> progress, Json::Value options) { if (!progress) @@ -4475,7 +4498,7 @@ Ref<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAn { // Open file, read raw contents Ref<FileMetadata> file = new FileMetadata(filename); - view = new BinaryData(file, filename); + view = BinaryData::CreateFromFilename(file, filename); } if (!view) |
