Access and manipulate binary files, segments, sections, and data
The BinaryView class is the primary interface for working with binary files in Binary Ninja. It provides access to file data, segments, sections, functions, symbols, types, and more.
# Get all functionsfor func in bv.functions: print(f"{func.name} @ {func.start:#x}")# Get function at addressfunc = bv.get_function_at(0x401000)# Get functions by namefuncs = bv.get_functions_by_name("main")# Create a new functionbv.add_function(0x402000)# Remove a functionbv.remove_function(func)
# Get symbol by namesym = bv.symbols['main']print(f"Symbol: {sym.name} at {sym.address:#x}")# Get symbol at addresssym = bv.get_symbol_at(0x401000)# Define a new symbolfrom binaryninja.types import Symbol, SymbolTypesym = Symbol(SymbolType.FunctionSymbol, 0x402000, "my_function")bv.define_user_symbol(sym)# Get all symbolsfor sym in bv.get_symbols(): print(f"{sym.type.name}: {sym.name} @ {sym.address:#x}")
# Get all stringsfor string_ref in bv.strings: print(f"{string_ref.start:#x}: {string_ref.value}")# Search for specific stringfor string_ref in bv.strings: if "password" in string_ref.value.lower(): print(f"Found at {string_ref.start:#x}: {string_ref.value}")
Data variables represent typed data in the binary (3.0 API enhancements).
# Get data variable at addressdata_var = bv.get_data_var_at(0x404000)# Set name (new in 3.0)data_var.name = "global_config"# Set typedata_var.type = Type.int(4)# Read value (new in 3.0)value = data_var.valueprint(f"Value: {value}")# For structures, access fieldsif data_var.type.type_class == TypeClass.StructureTypeClass: field_value = data_var['field_name'].value