summaryrefslogtreecommitdiff
path: root/python/binaryview.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2024-01-12 16:55:19 -0500
committerPeter LaFosse <peter@vector35.com>2024-01-15 08:50:51 -0500
commitecfc518d025359e7d2cf7e5da30f856916bf48b4 (patch)
tree1142480ecbd1ddabe3c2e1893441226619749e50 /python/binaryview.py
parent0747711195517010294963997446673189669493 (diff)
Add APIs for getting the the base Metadata object for BinaryViews and TypeLibraries
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 2446f04f..0c475445 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -7458,6 +7458,30 @@ class BinaryView:
return None
return _types.Type.create(handle, platform=self.platform)
+ def import_com_type_for_guid(self, guid: Union[str, uuid.UUID]) -> Optional['_types.Type']:
+ """
+ ``import_com_type_for_guid`` recursively imports a com interface given its GUID.
+
+ .. note:: This method is only available on Windows.
+
+ :param str guid: GUID of the COM interface to import
+ :return: the object type, with any interior `NamedTypeReferences` renamed as necessary to be appropriate for the current view
+ :rtype: Type
+ """
+ if not isinstance(guid, str):
+ guid = str(guid)
+
+ tl = self.get_type_library("win32common")
+ if tl is None:
+ return None
+
+ type_name = tl.metadata.get("com_interface_guids", {})
+ assert isinstance(type_name, dict)
+ type_name = type_name.get(guid, None)
+ if type_name is None:
+ return None
+ return self.import_library_type(type_name, tl)
+
def import_library_object(self, name: str, lib: Optional[typelibrary.TypeLibrary] = None) -> Optional['_types.Type']:
"""
``import_library_object`` recursively imports an object from the specified type library, or, if \
@@ -8463,6 +8487,40 @@ class BinaryView:
"""
core.BNBinaryViewRemoveMetadata(self.handle, key)
+ @property
+ def metadata(self) -> Dict[str, 'metadata.MetadataValueType']:
+ """
+ `metadata` retrieves the metadata associated with the current BinaryView.
+
+ :rtype: metadata associated with the BinaryView
+ :Example:
+
+ >>> bv.metadata
+ <metadata: {}>
+ """
+ md_handle = core.BNBinaryViewGetMetadata(self.handle)
+ assert md_handle is not None, "core.BNBinaryViewGetMetadata returned None"
+ value = metadata.Metadata(handle=md_handle).value
+ assert isinstance(value, dict), "core.BNBinaryViewGetMetadata did not return a dict"
+ return value
+
+ @property
+ def auto_metadata(self) -> Dict[str, 'metadata.MetadataValueType']:
+ """
+ `metadata` retrieves the metadata associated with the current BinaryView.
+
+ :rtype: metadata associated with the BinaryView
+ :Example:
+
+ >>> bv.metadata
+ <metadata: {}>
+ """
+ md_handle = core.BNBinaryViewGetAutoMetadata(self.handle)
+ assert md_handle is not None, "core.BNBinaryViewGetAutoMetadata returned None"
+ value = metadata.Metadata(handle=md_handle).value
+ assert isinstance(value, dict), "core.BNBinaryViewGetAutoMetadata did not return a dict"
+ return value
+
def get_load_settings_type_names(self) -> List[str]:
"""
``get_load_settings_type_names`` retrieve a list :py:class:`BinaryViewType` names for which load settings exist in \