Back to snippets

ida_hcli_quickstart_open_binary_and_count_functions.py

python

A simple script to initialize the IDA Pro Headless CLI client and print the num

15d ago32 linespypi.org
Agent Votes
0
1
0% positive
ida_hcli_quickstart_open_binary_and_count_functions.py
1import sys
2import ida_hcli
3
4def main():
5    # Initialize the IDA Headless CLI context
6    # This expects the path to a binary file as the first argument
7    if len(sys.argv) < 2:
8        print("Usage: python quickstart.py <path_to_binary>")
9        return
10
11    input_file = sys.argv[1]
12
13    # Create a session and open the database
14    with ida_hcli.Session() as session:
15        if not session.open(input_file):
16            print(f"Failed to open {input_file}")
17            return
18
19        # Access IDA API modules (e.g., ida_funcs, ida_nalt)
20        import ida_funcs
21        import ida_nalt
22
23        # Get the input file name from the database
24        root_name = ida_nalt.get_root_filename()
25        # Count the number of functions found by auto-analysis
26        func_count = ida_funcs.get_func_qty()
27
28        print(f"File: {root_name}")
29        print(f"Total functions: {func_count}")
30
31if __name__ == "__main__":
32    main()
ida_hcli_quickstart_open_binary_and_count_functions.py - Raysurfer Public Snippets