diff options
| author | Peter LaFosse <peter@vector35.com> | 2017-06-24 01:33:04 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2017-07-01 10:02:27 -0400 |
| commit | 0de62768c8afc5ca27576b59d4591ca8dbbd7cee (patch) | |
| tree | bbd69585e0705905fddef54d32e2ab50aa91f6a6 /binaryview.cpp | |
| parent | b0778fc4d0271a9ba16e7c81c2c4c67a8273cda6 (diff) | |
Adding settings system apis, and binaryview metadata apis
Diffstat (limited to 'binaryview.cpp')
| -rw-r--r-- | binaryview.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/binaryview.cpp b/binaryview.cpp index b18b065b..6eb299a3 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1826,6 +1826,57 @@ vector<BNAddressRange> 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<uint8_t> 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())) { } |
