From c407679358f035aa9e16e3bb740f8e6d9a73d138 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 1 Jul 2017 10:02:12 -0400 Subject: Refactor of metadata api names. modify how QueryMetadata works --- binaryview.cpp | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index 6eb299a3..b330508d 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "binaryninjaapi.h" using namespace BinaryNinja; @@ -1833,48 +1834,37 @@ void BinaryView::StoreMetadata(const std::string& key, Metadata* inValue) BNBinaryViewStoreMetadata(m_object, key.c_str(), inValue->GetObject()); } - -bool BinaryView::QueryMetadata(const std::string& key, Metadata** outValue) +unique_ptr BinaryView::QueryMetadata(const std::string& key) { - BNMetadata* value = nullptr; - bool status = BNBinaryViewQueryMetadata(m_object, key.c_str(), &value); - if (!status) - { - *outValue = nullptr; - return false; - } - *outValue = new Metadata(value); - return true; + BNMetadata* value = BNBinaryViewQueryMetadata(m_object, key.c_str()); + if (!value) + return nullptr; + auto a = new Metadata(value); + return unique_ptr(a); } string BinaryView::GetStringMetadata(const string& key) { - Metadata* data; - if (!QueryMetadata(key, &data) || !data || data->IsString()) + auto data = QueryMetadata(key); + if (!data || !data->IsString()) throw QueryMetadataException("Failed to find key: " + key); - auto result = data->GetString(); - delete data; - return result; + return data->GetString(); } vector BinaryView::GetRawMetadata(const string& key) { - Metadata* data; - if (!QueryMetadata(key, &data) || !data || data->IsRaw()) + auto data = QueryMetadata(key); + if (!data || !data->IsRaw()) throw QueryMetadataException("Failed to find key: " + key); - auto result = data->GetRaw(); - delete data; - return result; + return data->GetRaw(); } uint64_t BinaryView::GetUIntMetadata(const string& key) { - Metadata* data; - if (!QueryMetadata(key, &data) || !data || data->IsUnsignedInteger()) + auto data = QueryMetadata(key); + if (!data || !data->IsUnsignedInteger()) throw QueryMetadataException("Failed to find key: " + key); - auto result = data->GetUnsignedInteger(); - delete data; - return result; + return data->GetUnsignedInteger(); } BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetObject())) -- cgit v1.3.1