Skip to main content
This example demonstrates how to perform basic binary analysis to extract metadata, functions, and strings from a binary file with minimal analysis overhead.

Overview

The bin_info.py example shows how to:
  • Load a binary with minimal analysis modes
  • Extract basic metadata (architecture, entry point, start address)
  • List functions and strings
  • Generate formatted reports
  • Properly manage BinaryView file handles

Complete Source Code

#!/usr/bin/env python3
import os
import sys
from glob import glob

from binaryninja import LogLevel, PluginCommand, interaction, load, log, log_to_stdout, log_warn


def get_bininfo(bv, filename=None):
    if bv is None:
        if not (os.path.isfile(filename) and os.access(filename, os.R_OK)):
            return("Cannot read {}\n".format(filename))
        bv = load(filename, options={'analysis.mode': 'basic', 'analysis.linearSweep.autorun' : False})
    else:
        filename = ""
        if len(sys.argv) > 1:
            filename = sys.argv[1]
        else:
            filename = interaction.get_open_filename_input("Filename:")
            if filename is None:
                log_warn("No file specified")
                sys.exit(1)

        bv = load(filename)
        log_to_stdout(LogLevel.InfoLog)

    contents = "## %s ##\n" % os.path.basename(bv.file.filename)
    contents += "- START: 0x%x\n\n" % bv.start
    contents += "- ENTRY: 0x%x\n\n" % bv.entry_point
    contents += "- ARCH: %s\n\n" % bv.arch.name
    contents += "### First 10 Functions ###\n"

    contents += "| Start | Name   |\n"
    contents += "|------:|:-------|\n"
    functions = list(bv.functions)
    for i in range(min(10, len(functions))):
        contents += "| 0x%x | %s |\n" % (functions[i].start, functions[i].symbol.full_name)

    contents += "### First 10 Strings ###\n"
    contents += "| Start | Length | String |\n"
    contents += "|------:|-------:|:-------|\n"
    for i in range(min(10, len(bv.strings))):
        start = bv.strings[i].start
        length = bv.strings[i].length
        string = bv.strings[i].value
        contents += "| 0x%x |%d | %s |\n" % (start, length, string)

    # Note that we need to close BV file handles that we opened to prevent a
    # memory leak due to a circular reference between BinaryViews and the
    # FileMetadata that backs them

    if filename != "":
        bv.file.close()
    return contents


def display_bininfo(bv):
    interaction.show_markdown_report("Binary Info Report", get_bininfo(bv))


if __name__ == "__main__":
    if len(sys.argv) == 1:
        filename = interaction.get_open_filename_input("Filename:")
        if filename is None:
            log.log_warn("No file specified")
        else:
            print(get_bininfo(None, filename=filename))
    else:
        for pattern in sys.argv[1:]:
            for filename in glob(pattern):
                print(get_bininfo(None, filename=filename))
else:
    PluginCommand.register("Binary Info", "Display basic info about the binary using minimal analysis modes", display_bininfo)

Key Concepts Explained

1
Load Binary with Custom Options
2
bv = load(filename, options={'analysis.mode': 'basic', 'analysis.linearSweep.autorun' : False})
3
This loads the binary with minimal analysis for faster processing. Use 'basic' mode when you only need function boundaries and basic disassembly.
4
Extract Basic Metadata
5
contents = "## %s ##\n" % os.path.basename(bv.file.filename)
contents += "- START: 0x%x\n\n" % bv.start
contents += "- ENTRY: 0x%x\n\n" % bv.entry_point
contents += "- ARCH: %s\n\n" % bv.arch.name
6
Access binary properties through the BinaryView object:
7
  • bv.start - Base address where binary is loaded
  • bv.entry_point - Entry point address
  • bv.arch.name - Architecture name
  • 8
    Iterate Functions
    9
    functions = list(bv.functions)
    for i in range(min(10, len(functions))):
        contents += "| 0x%x | %s |\n" % (functions[i].start, functions[i].symbol.full_name)
    
    10
    The bv.functions property returns all discovered functions. Each function has:
    11
  • start - Function start address
  • symbol.full_name - Function name from symbols
  • 12
    Access Strings
    13
    for i in range(min(10, len(bv.strings))):
        start = bv.strings[i].start
        length = bv.strings[i].length
        string = bv.strings[i].value
    
    14
    Binary Ninja automatically identifies strings. Each string object provides:
    15
  • start - Address where string is located
  • length - String length in bytes
  • value - Actual string content
  • 16
    Clean Up Resources
    17
    if filename != "":
        bv.file.close()
    
    18
    Important: Always close file handles you opened to prevent memory leaks from circular references between BinaryViews and FileMetadata.

    Running the Example

    Command Line Mode

    python bin_info.py /path/to/binary
    
    Process multiple files with glob patterns:
    python bin_info.py /bin/*
    

    Plugin Mode

    When loaded as a plugin, it registers a command:
    1. Open a binary in Binary Ninja
    2. Run Tools > Binary Info
    3. View the generated markdown report

    Expected Output

    ## binary_name ##
    - START: 0x100000000
    
    - ENTRY: 0x100001a40
    
    - ARCH: aarch64
    
    ### First 10 Functions ###
    | Start | Name   |
    |------:|:-------|
    | 0x100001a40 | _start |
    | 0x100001a60 | _main |
    | 0x100001b20 | _process_data |
    ...
    
    ### First 10 Strings ###
    | Start | Length | String |
    |------:|-------:|:-------|
    | 0x100003f80 |15 | Hello, World! |
    | 0x100003f90 |23 | Error: Invalid input |
    ...
    

    Use Cases

    • Quick Binary Triage - Rapidly assess binaries without full analysis
    • Batch Processing - Process multiple binaries and extract metadata
    • Report Generation - Create formatted reports for documentation
    • Malware Analysis - Quick overview of suspicious files

    Build docs developers (and LLMs) love