1+ #!/usr/bin/env python3
2+
3+ import sys
4+ from pathlib import Path
5+ from binaryninja import load
6+ from binaryninja .warp import WarpContainer , WarpFunction , WarpTarget
7+
8+ def process_binary (input_file : str , output_dir : str ) -> None :
9+ input_path = Path (input_file )
10+ output_dir = Path (output_dir )
11+ output_dir .mkdir (parents = True , exist_ok = True )
12+ bv = load (input_path )
13+ bv .update_analysis_and_wait ()
14+ if not bv :
15+ return
16+
17+ # Sources exist only in containers, so we will just pull off the first available container.
18+ # In the future we might make container construction available to the API.
19+ container = WarpContainer .all ()[0 ]
20+ output_file = output_dir / f"{ input_path .stem } _analysis.warp"
21+ # Add the source so we can add functions to it and then commit it (write to disk)
22+ source = container .add_source (str (output_file ))
23+
24+ # NOTE: You probably want to pull the platform from the function, but for this example it's fine.
25+ target = WarpTarget (bv .platform )
26+ # NOTE: You probably want to filter for functions with actual annotations, no point to signature a function with no symbol.
27+ functions_to_warp = [WarpFunction (func ) for func in bv .functions ]
28+ container .add_functions (target , source , functions_to_warp )
29+
30+ # Actually write the warp file to disk.
31+ container .commit_source (source )
32+ bv .file .close ()
33+
34+ if __name__ == "__main__" :
35+ if len (sys .argv ) != 3 :
36+ print (f"Usage: { sys .argv [0 ]} <input_binary> <output_directory>" )
37+ sys .exit (1 )
38+ process_binary (sys .argv [1 ], sys .argv [2 ])
0 commit comments