From c5500f2063ebae5ed32b2cf54e1be51fb56b6bdc Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 26 Mar 2026 13:23:31 -0700 Subject: [WARP] More documentation updates and python examples --- plugins/warp/examples/create_signatures.py | 36 ++++++------------- .../warp/examples/create_signatures_advanced.py | 40 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 25 deletions(-) mode change 100755 => 100644 plugins/warp/examples/create_signatures.py create mode 100755 plugins/warp/examples/create_signatures_advanced.py (limited to 'plugins') diff --git a/plugins/warp/examples/create_signatures.py b/plugins/warp/examples/create_signatures.py old mode 100755 new mode 100644 index 82ed724c..efae8b36 --- a/plugins/warp/examples/create_signatures.py +++ b/plugins/warp/examples/create_signatures.py @@ -2,41 +2,27 @@ import sys from pathlib import Path -from binaryninja import load -from binaryninja.warp import WarpContainer, WarpFunction, WarpTarget +from binaryninja.warp import * def process_binary(input_file: str, output_dir: str) -> None: input_path = Path(input_file) output_dir = Path(output_dir) output_dir.mkdir(parents=True, exist_ok=True) - bv = load(input_path) - bv.update_analysis_and_wait() - if not bv: + output_file = output_dir / f"{input_path.stem}.warp" + processor = WarpProcessor() + processor.add_path(input_file) + file = processor.start() + if not file: return + buffer = file.to_data_buffer() + with open(output_file, 'wb') as f: + f.write(bytes(buffer)) + print(f"Wrote {len(buffer)} bytes to {output_file}") - # 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) - # NOTE: You probably want to filter for functions with actual annotations, no point to signature a function with no symbol. - functions_to_warp = [WarpFunction(func) for func in bv.functions] - container.add_functions(target, source, functions_to_warp) - - # 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: print(f"Usage: {sys.argv[0]} ") sys.exit(1) + binaryninja._init_plugins() process_binary(sys.argv[1], sys.argv[2]) \ No newline at end of file diff --git a/plugins/warp/examples/create_signatures_advanced.py b/plugins/warp/examples/create_signatures_advanced.py new file mode 100755 index 00000000..8f2af5a6 --- /dev/null +++ b/plugins/warp/examples/create_signatures_advanced.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import sys +from pathlib import Path +from binaryninja import load +from binaryninja.warp import WarpContainer, WarpFunction, WarpTarget + +def process_binary(input_file: str, output_dir: str) -> None: + input_path = Path(input_file) + output_dir = Path(output_dir) + output_dir.mkdir(parents=True, exist_ok=True) + bv = load(input_path) + bv.update_analysis_and_wait() + if not bv: + return + + container = WarpContainer.add("Python") + 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) + # NOTE: You probably want to filter for functions with actual annotations, no point to signature a function with no symbol. + functions_to_warp = [WarpFunction(func) for func in bv.functions] + container.add_functions(target, source, functions_to_warp) + + # 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: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + process_binary(sys.argv[1], sys.argv[2]) \ No newline at end of file -- cgit v1.3.1