summaryrefslogtreecommitdiff
path: root/python/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/project.py')
-rw-r--r--python/project.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/python/project.py b/python/project.py
index c3504dd4..ba7cf2d3 100644
--- a/python/project.py
+++ b/python/project.py
@@ -22,7 +22,7 @@ import ctypes
from contextlib import contextmanager
from os import PathLike
-from typing import Callable, List, Optional, Union
+from typing import Any, Callable, List, Optional, Union
import binaryninja
from . import _binaryninjacore as core
@@ -545,6 +545,33 @@ class Project:
raise KeyError(key)
return 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 Project.
+
+ 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:
+
+ >>> current_project.store_metadata("integer", 1337)
+ >>> current_project.get_metadata("integer")
+ 1337L
+ >>> current_project.get_metadata("missing")
+ None
+ >>> current_project.get_metadata("missing", 42)
+ 42
+ """
+ md_handle = core.BNProjectQueryMetadata(self._handle, key)
+ if md_handle is None:
+ return default
+ return Metadata(handle=md_handle).value
+
def store_metadata(self, key: str, value: MetadataValueType) -> bool:
"""
Stores metadata within the project