diff options
| author | Mason Reed <mason@vector35.com> | 2025-11-03 20:12:58 -0500 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-11-04 13:34:46 -0500 |
| commit | dcfe8c5416e3245c986b5dd4326e77ba53145159 (patch) | |
| tree | 367d9400f76900c45969754dd338da7fd95c51e0 /plugins/warp | |
| parent | 427745da6d4bed73394995a3c768efcd10a78062 (diff) | |
[WARP] Update python example to fix adding a source to a "read-only" container
Diffstat (limited to 'plugins/warp')
| -rw-r--r-- | plugins/warp/api/python/warp.py | 7 | ||||
| -rwxr-xr-x | plugins/warp/examples/create_signatures.py | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/plugins/warp/api/python/warp.py b/plugins/warp/api/python/warp.py index 866d179b..fc487a4d 100644 --- a/plugins/warp/api/python/warp.py +++ b/plugins/warp/api/python/warp.py @@ -350,6 +350,13 @@ class WarpContainer(metaclass=_WarpContainerMetaclass): warpcore.BNWARPFreeContainerList(containers, count.value) return result + @staticmethod + def by_name(name: str) -> Optional['WarpContainer']: + for container in WarpContainer: + if container.name == name: + return container + return None + @property def name(self) -> str: return warpcore.BNWARPContainerGetName(self.handle) diff --git a/plugins/warp/examples/create_signatures.py b/plugins/warp/examples/create_signatures.py index 6fbcae54..82ed724c 100755 --- a/plugins/warp/examples/create_signatures.py +++ b/plugins/warp/examples/create_signatures.py @@ -14,12 +14,15 @@ def process_binary(input_file: str, output_dir: str) -> None: if not bv: return - # Sources exist only in containers, so we will just pull off the first available container. - # In the future we might make container construction available to the API. - container = WarpContainer.all()[0] + # For the sake of this example we are going to assume the container "User" + # is available, in the future we might want to make containers constructable + container = WarpContainer.by_name("User") output_file = output_dir / f"{input_path.stem}_analysis.warp" # Add the source so we can add functions to it and then commit it (write to disk) source = container.add_source(str(output_file)) + if source is None: + print(f"Failed to create source {str(output_file)}") + return # NOTE: You probably want to pull the platform from the function, but for this example it's fine. target = WarpTarget(bv.platform) @@ -30,6 +33,7 @@ def process_binary(input_file: str, output_dir: str) -> None: # Actually write the warp file to disk. container.commit_source(source) bv.file.close() + print(f"committed {len(functions_to_warp)} functions to {output_file}") if __name__ == "__main__": if len(sys.argv) != 3: |
