diff options
Diffstat (limited to 'python/binaryview.py')
| -rw-r--r-- | python/binaryview.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 491b023c..df534abd 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -10330,6 +10330,33 @@ to a the type "tagRECT" found in the typelibrary "winX64common" raise KeyError(key) return metadata.Metadata(handle=md_handle).value + def get_metadata(self, key: str, default: Any = None) -> 'metadata.MetadataValueType | Any': + """ + `get_metadata` retrieves a metadata value associated with the given key stored in the current BinaryView. + + This method behaves like `dict.get()`: + - If the key exists, its metadata value is returned. + - If the key does not exist and `default` is not provided, `None` is returned. + - If the key does not exist and `default` is provided, `default` is returned. + + :param str key: key to query + :param default: value to return if the key does not exist (defaults to None) + :rtype: metadata associated with the key or the default value + :Example: + + >>> bv.store_metadata("integer", 1337) + >>> bv.get_metadata("integer") + 1337L + >>> bv.get_metadata("missing") + None + >>> bv.get_metadata("missing", 42) + 42 + """ + md_handle = core.BNBinaryViewQueryMetadata(self.handle, key) + if md_handle is None: + return default + return metadata.Metadata(handle=md_handle).value + def store_metadata(self, key: str, md: metadata.MetadataValueType, isAuto: bool = False) -> None: """ `store_metadata` stores an object for the given key in the current BinaryView. Objects stored using |
