From 0de62768c8afc5ca27576b59d4591ca8dbbd7cee Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 24 Jun 2017 01:33:04 -0400 Subject: Adding settings system apis, and binaryview metadata apis --- binaryview.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index b18b065b..6eb299a3 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1826,6 +1826,57 @@ vector BinaryView::GetAllocatedRanges() } +void BinaryView::StoreMetadata(const std::string& key, Metadata* inValue) +{ + if (!inValue) + return; + BNBinaryViewStoreMetadata(m_object, key.c_str(), inValue->GetObject()); +} + + +bool BinaryView::QueryMetadata(const std::string& key, Metadata** outValue) +{ + BNMetadata* value = nullptr; + bool status = BNBinaryViewQueryMetadata(m_object, key.c_str(), &value); + if (!status) + { + *outValue = nullptr; + return false; + } + *outValue = new Metadata(value); + return true; +} + +string BinaryView::GetStringMetadata(const string& key) +{ + Metadata* data; + if (!QueryMetadata(key, &data) || !data || data->IsString()) + throw QueryMetadataException("Failed to find key: " + key); + auto result = data->GetString(); + delete data; + return result; +} + +vector BinaryView::GetRawMetadata(const string& key) +{ + Metadata* data; + if (!QueryMetadata(key, &data) || !data || data->IsRaw()) + throw QueryMetadataException("Failed to find key: " + key); + auto result = data->GetRaw(); + delete data; + return result; +} + +uint64_t BinaryView::GetUIntMetadata(const string& key) +{ + Metadata* data; + if (!QueryMetadata(key, &data) || !data || data->IsUnsignedInteger()) + throw QueryMetadataException("Failed to find key: " + key); + auto result = data->GetUnsignedInteger(); + delete data; + return result; +} + BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetObject())) { } -- cgit v1.3.1