summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2017-07-12 22:47:12 -0400
committerPeter LaFosse <peter@vector35.com>2017-07-12 22:47:12 -0400
commit0e6019edc8c5949de4989ef9577c07913946135b (patch)
treecb3a8dbcbd1f2473f32a6797bced0b4a4b59256f /python
parentc05fbe9e3cffc727536a6df6893116af1570327c (diff)
Adding remove_metadata API to BinaryView. Add remove APIs to Metadata
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py15
-rw-r--r--python/metadata.py12
2 files changed, 24 insertions, 3 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index d04dca86..ee019dcb 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -27,7 +27,7 @@ import threading
# Binary Ninja components
import _binaryninjacore as core
from enums import (AnalysisState, SymbolType, InstructionTextTokenType,
- Endianness, ModificationStatus, StringType, SegmentFlag, MetadataType)
+ Endianness, ModificationStatus, StringType, SegmentFlag)
import function
import startup
import architecture
@@ -3312,6 +3312,19 @@ class BinaryView(object):
raise ValueError("metadata argument must be of type Metadata")
core.BNBinaryViewStoreMetadata(self.handle, key, md.handle)
+ def remove_metadata(self, key):
+ """
+ `remove_metadata` removes the Metadata object associated with key from the current BinaryView
+
+ :param string key: key to remove from the BinaryView
+ :rtype: None
+ :Example:
+
+ >>> bv.store_metadata("integer", Metadata(1337))
+ >>> bv.remove_metadata("integer")
+ """
+ core.BNBinaryViewRemoveMetadata(self.handle, key)
+
def __setattr__(self, name, value):
try:
object.__setattr__(self, name, value)
diff --git a/python/metadata.py b/python/metadata.py
index f0e7764d..2817d777 100644
--- a/python/metadata.py
+++ b/python/metadata.py
@@ -114,6 +114,14 @@ class Metadata(object):
def is_dict(self):
return core.BNMetadataIsKeyValueStore(self.handle)
+ def remove(self, key_or_index):
+ if isinstance(key_or_index, str) and self.is_dict:
+ core.BNMetadataRemoveKey(self.handle, key_or_index)
+ elif isinstance(key_or_index, int) and self.is_array:
+ core.BNMetadataRemoveIndex(self.handle, key_or_index)
+ else:
+ raise TypeError("remove only valid for dict and array objects")
+
def __len__(self):
if self.is_array or self.is_dict or self.is_string or self.is_raw:
return core.BNMetadataSize(self.handle)
@@ -122,7 +130,7 @@ class Metadata(object):
def __iter__(self):
if self.is_array:
for i in xrange(core.BNMetadataSize(self.handle)):
- yield Metadata(handle=core.BNMetadataGetForIdx(self.handle, i))
+ yield Metadata(handle=core.BNMetadataGetForIndex(self.handle, i))
elif self.is_dict:
result = core.BNMetadataGetValueStore(self.handle)
try:
@@ -139,7 +147,7 @@ class Metadata(object):
raise ValueError("Metadata object only supports integers for indexing")
if value >= len(self):
raise IndexError("Index value out of range")
- return Metadata(handle=core.BNMetadataGetForIdx(self.handle, value))
+ return Metadata(handle=core.BNMetadataGetForIndex(self.handle, value))
if self.is_dict:
if not isinstance(value, str):
raise ValueError("Metadata object only supports strings for indexing")