|
47 | 47 | from . import workflow |
48 | 48 | from . import languagerepresentation |
49 | 49 | from . import deprecation |
| 50 | +from . import metadata |
50 | 51 | from . import __version__ |
51 | 52 |
|
52 | 53 | # we define the following as such so the linter doesn't confuse 'highlight' the module with the |
@@ -3390,6 +3391,68 @@ def is_region_collapsed(self, hash) -> bool: |
3390 | 3391 | """ |
3391 | 3392 | return core.BNFunctionIsRegionCollapsed(self.handle, hash) |
3392 | 3393 |
|
| 3394 | + def store_metadata(self, key: str, md: metadata.MetadataValueType, isAuto: bool = False) -> None: |
| 3395 | + """ |
| 3396 | + `store_metadata` stores an object for the given key in the current Function. Objects stored using |
| 3397 | + `store_metadata` can be retrieved when the database is reopened unless isAuto is set to True. |
| 3398 | +
|
| 3399 | + :param str key: key value to associate the Metadata object with |
| 3400 | + :param Varies md: object to store |
| 3401 | + :param bool isAuto: whether the metadata is an auto metadata |
| 3402 | + :rtype: None |
| 3403 | + """ |
| 3404 | + _md = md |
| 3405 | + if not isinstance(_md, metadata.Metadata): |
| 3406 | + _md = metadata.Metadata(_md) |
| 3407 | + core.BNFunctionStoreMetadata(self.handle, key, _md.handle, isAuto) |
| 3408 | + |
| 3409 | + def query_metadata(self, key: str) -> 'metadata.MetadataValueType': |
| 3410 | + """ |
| 3411 | + `query_metadata` retrieves metadata associated with the given key stored in the current function. |
| 3412 | +
|
| 3413 | + :param str key: key to query |
| 3414 | + :rtype: metadata associated with the key |
| 3415 | + """ |
| 3416 | + md_handle = core.BNFunctionQueryMetadata(self.handle, key) |
| 3417 | + if md_handle is None: |
| 3418 | + raise KeyError(key) |
| 3419 | + return metadata.Metadata(handle=md_handle).value |
| 3420 | + |
| 3421 | + def remove_metadata(self, key: str) -> None: |
| 3422 | + """ |
| 3423 | + `remove_metadata` removes the metadata associated with key from the current function. |
| 3424 | +
|
| 3425 | + :param str key: key associated with metadata to remove from the function |
| 3426 | + :rtype: None |
| 3427 | + """ |
| 3428 | + core.BNFunctionRemoveMetadata(self.handle, key) |
| 3429 | + |
| 3430 | + @property |
| 3431 | + def metadata(self) -> Dict[str, 'metadata.MetadataValueType']: |
| 3432 | + """ |
| 3433 | + `metadata` retrieves the metadata associated with the current function. |
| 3434 | +
|
| 3435 | + :rtype: metadata associated with the function |
| 3436 | + """ |
| 3437 | + md_handle = core.BNFunctionGetMetadata(self.handle) |
| 3438 | + assert md_handle is not None, "core.BNFunctionGetMetadata returned None" |
| 3439 | + value = metadata.Metadata(handle=md_handle).value |
| 3440 | + assert isinstance(value, dict), "core.BNFunctionGetMetadata did not return a dict" |
| 3441 | + return value |
| 3442 | + |
| 3443 | + @property |
| 3444 | + def auto_metadata(self) -> Dict[str, 'metadata.MetadataValueType']: |
| 3445 | + """ |
| 3446 | + `metadata` retrieves the metadata associated with the current function. |
| 3447 | +
|
| 3448 | + :rtype: metadata associated with the function |
| 3449 | + """ |
| 3450 | + md_handle = core.BNFunctionGetAutoMetadata(self.handle) |
| 3451 | + assert md_handle is not None, "core.BNFunctionGetAutoMetadata returned None" |
| 3452 | + value = metadata.Metadata(handle=md_handle).value |
| 3453 | + assert isinstance(value, dict), "core.BNFunctionGetAutoMetadata did not return a dict" |
| 3454 | + return value |
| 3455 | + |
3393 | 3456 |
|
3394 | 3457 | class AdvancedFunctionAnalysisDataRequestor: |
3395 | 3458 | def __init__(self, func: Optional['Function'] = None): |
|
0 commit comments