binaryview module¶
-
class
binaryninja.binaryview.ActiveAnalysisInfo(func, analysis_time, update_count, submit_count)[source]¶ Bases:
object
-
class
binaryninja.binaryview.AnalysisCompletionEvent(view, callback)[source]¶ Bases:
objectThe
AnalysisCompletionEventobject provides an asynchronous mechanism for receiving callbacks when analysis is complete. The callback runs once. A completion event must be added for each new analysis in order to be notified of each analysis completion. The AnalysisCompletionEvent class takes responcibility for keeping track of the object’s lifetime.Example: >>> def on_complete(self): ... print("Analysis Complete", self.view) ... >>> evt = AnalysisCompletionEvent(bv, on_complete) >>>
-
class
binaryninja.binaryview.BinaryReader(view, endian=None)[source]¶ Bases:
objectclass BinaryReaderis a convenience class for reading binary data.BinaryReader can be instantiated as follows and the rest of the document will start from this context
>>> from binaryninja import * >>> bv = BinaryViewType['Mach-O'].open("/bin/ls") >>> br = BinaryReader(bv) >>> hex(br.read32()) '0xfeedfacfL' >>>
Or using the optional endian parameter
>>> from binaryninja import * >>> br = BinaryReader(bv, Endianness.BigEndian) >>> hex(br.read32()) '0xcffaedfeL' >>>
-
endianness¶ The Endianness to read data. (read/write)
Getter: returns the endianness of the reader Setter: sets the endianness of the reader (BigEndian or LittleEndian) Type: Endianness
-
eof¶ Is end of file (read-only)
Getter: returns boolean, true if end of file, false otherwise Type: bool
-
offset¶ The current read offset (read/write).
Getter: returns the current internal offset Setter: sets the internal offset Type: int
-
read(length)[source]¶ readreturnslengthbytes read from the current offset, addinglengthto offset.Parameters: length (int) – number of bytes to read.
Returns: lengthbytes from current offsetReturn type: str, or None on failure
Example: >>> br.read(8) '\xcf\xfa\xed\xfe\x07\x00\x00\x01' >>>
-
read16()[source]¶ read16returns a two byte integer from offet incrementing the offset by two, using specified endianness.Returns: a two byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read16()) '0xfacf' >>>
-
read16be()[source]¶ read16bereturns a two byte big endian integer from offet incrementing the offset by two.Returns: a two byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read16be()) '0xcffa' >>>
-
read16le()[source]¶ read16lereturns a two byte little endian integer from offet incrementing the offset by two.Returns: a two byte integer at offset.
Return type: int, or None on failure
Exmaple: >>> br.seek(0x100000000) >>> hex(br.read16le()) '0xfacf' >>>
-
read32()[source]¶ read32returns a four byte integer from offet incrementing the offset by four, using specified endianness.Returns: a four byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read32()) '0xfeedfacfL' >>>
-
read32be()[source]¶ read32bereturns a four byte big endian integer from offet incrementing the offset by four.Returns: a four byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read32be()) '0xcffaedfe' >>>
-
read32le()[source]¶ read32lereturns a four byte little endian integer from offet incrementing the offset by four.Returns: a four byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read32le()) '0xfeedfacf' >>>
-
read64()[source]¶ read64returns an eight byte integer from offet incrementing the offset by eight, using specified endianness.Returns: an eight byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read64()) '0x1000007feedfacfL' >>>
-
read64be()[source]¶ read64bereturns an eight byte big endian integer from offet incrementing the offset by eight.Returns: a eight byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read64be()) '0xcffaedfe07000001L'
-
read64le()[source]¶ read64lereturns an eight byte little endian integer from offet incrementing the offset by eight.Returns: a eight byte integer at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> hex(br.read64le()) '0x1000007feedfacf' >>>
-
read8()[source]¶ read8returns a one byte integer from offet incrementing the offset.Returns: byte at offset.
Return type: int, or None on failure
Example: >>> br.seek(0x100000000) >>> br.read8() 207 >>>
-
-
class
binaryninja.binaryview.BinaryView(file_metadata=None, parent_view=None, handle=None)[source]¶ Bases:
objectclass BinaryViewimplements a view on binary data, and presents a queryable interface of a binary file. One key job of BinaryView is file format parsing which allows Binary Ninja to read, write, insert, remove portions of the file given a virtual address. For the purposes of this documentation we define a virtual address as the memory address that the various pieces of the physical file will be loaded at.A binary file does not have to have just one BinaryView, thus much of the interface to manipulate disassembly exists within or is accessed through a BinaryView. All files are guaranteed to have at least the
RawBinaryView. TheRawBinaryView is simply a hex editor, but is helpful for manipulating binary files via their absolute addresses.BinaryViews are plugins and thus registered with Binary Ninja at startup, and thus should never be instantiated directly as this is already done. The list of available BinaryViews can be seen in the BinaryViewType class which provides an iterator and map of the various installed BinaryViews:
>>> list(BinaryViewType) [<view type: 'Raw'>, <view type: 'ELF'>, <view type: 'Mach-O'>, <view type: 'PE'>] >>> BinaryViewType['ELF'] <view type: 'ELF'>
To open a file with a given BinaryView the following code can be used:
>>> bv = BinaryViewType['Mach-O'].open("/bin/ls") >>> bv <BinaryView: '/bin/ls', start 0x100000000, len 0xa000>
By convention in the rest of this document we will use bv to mean an open BinaryView of an executable file. When a BinaryView is open on an executable view, analysis does not automatically run, this can be done by running the
update_analysis_and_wait()method which disassembles the executable and returns when all disassembly is finished:>>> bv.update_analysis_and_wait() >>>
Since BinaryNinja’s analysis is multi-threaded (depending on version) this can also be done in the background by using the
update_analysis()method instead.By standard python convention methods which start with ‘_’ should be considered private and should not be called externally. Additionanlly, methods which begin with
perform_should not be called either and are used explicitly for subclassing the BinaryView.Note
An important note on the
*_user_*()methods. Binary Ninja makes a distinction between edits performed by the user and actions performed by auto analysis. Auto analysis actions that can quickly be recalculated are not saved to the database. Auto analysis actions that take a long time and all user edits are stored in the database (e.g.remove_user_function()rather thanremove_function()). Thus use_user_methods if saving to the database is desired.-
abort_analysis()[source]¶ abort_analysiswill abort the currently running analysis.Return type: None
-
add_analysis_completion_event(callback)[source]¶ add_analysis_completion_eventsets up a call back function to be called when analysis has been completed. This is helpful when usingupdate_analysiswhich does not wait for analysis completion before returning.The callee of this function is not resposible for maintaining the lifetime of the returned AnalysisCompletionEvent object.
Parameters: callback (callable()) – A function to be called with no parameters when analysis has completed.
Returns: An initialized AnalysisCompletionEvent object.
Return type: Example: >>> def completionEvent(): ... print("done") ... >>> bv.add_analysis_completion_event(completionEvent) <binaryninja.AnalysisCompletionEvent object at 0x10a2c9f10> >>> bv.update_analysis() done >>>
-
add_analysis_option(name)[source]¶ add_analysis_optionadds an analysis option. Analysis options elaborate the analysis phase. The user must start analysis by calling eitherupdate_analysis()orupdate_analysis_and_wait().Parameters: name (str) – name of the analysis option. Available options: “linearsweep” : apply linearsweep analysis during the next analysis update (run-once semantics)
Return type: Example: >>> bv.add_analysis_option("linearsweep") >>> bv.update_analysis_and_wait()
-
add_auto_section(name, start, length, semantics=<SectionSemantics.DefaultSectionSemantics: 0>, type='', align=1, entry_size=1, linked_section='', info_section='', info_data=0)[source]¶
-
add_entry_point(addr, plat=None)[source]¶ add_entry_pointadds an virtual address to start analysis from for a given plat.Parameters: Return type: Example: >>> bv.add_entry_point(0xdeadbeef) >>>
-
add_function(addr, plat=None)[source]¶ add_functionadd a new function of the givenplatat the virtual addressaddrParameters: Return type: Example: >>> bv.add_function(1) >>> bv.functions [<func: x86_64@0x1>]
-
add_user_section(name, start, length, semantics=<SectionSemantics.DefaultSectionSemantics: 0>, type='', align=1, entry_size=1, linked_section='', info_section='', info_data=0)[source]¶
-
address_size¶ Address size of the binary (read-only)
-
allocated_ranges¶ List of valid address ranges for this view (read-only)
-
always_branch(addr, arch=None)[source]¶ always_branchconvert the instruction of architecturearchat the virtual addressaddrto an unconditional branch.Note
This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary file must be saved in order to preserve the changes made.
Parameters: - addr (int) – virtual address of the instruction to be modified
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True on success, False on falure.
Return type: Example: >>> bv.get_disassembly(0x100012ef) 'jg 0x100012f5' >>> bv.always_branch(0x100012ef) True >>> bv.get_disassembly(0x100012ef) 'jmp 0x100012f5' >>>
-
analysis_changed¶ boolean analysis state changed of the currently running analysis (read-only)
-
analysis_info¶ Relevant analysis information with list of functions under active analysis (read-only)
-
analysis_progress¶ Status of current analysis (read-only)
-
arch¶ The architecture associated with the current BinaryView (read/write)
-
available_view_types¶ Available view types (read-only)
-
basic_blocks¶ A generator of all BasicBlock objects in the BinaryView
-
begin_undo_actions()[source]¶ begin_undo_actionsstart recording actions taken so the can be undone at some point.Return type: Example: >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.begin_undo_actions() >>> bv.convert_to_nop(0x100012f1) True >>> bv.commit_undo_actions() >>> bv.get_disassembly(0x100012f1) 'nop' >>> bv.undo() >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>>
-
commit_undo_actions()[source]¶ commit_undo_actionscommit the actions taken since the last commit to the undo database.Return type: Example: >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.begin_undo_actions() >>> bv.convert_to_nop(0x100012f1) True >>> bv.commit_undo_actions() >>> bv.get_disassembly(0x100012f1) 'nop' >>> bv.undo() >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>>
-
convert_to_nop(addr, arch=None)[source]¶ convert_to_nopconverts the instruction at virtual addressaddrto a nop of the provided architecture.Note
This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary file must be saved in order to preserve the changes made.
Parameters: - addr (int) – virtual address of the instruction to conver to nops
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True on success, False on falure.
Return type: Example: >>> bv.get_disassembly(0x100012fb) 'call 0x10001629' >>> bv.convert_to_nop(0x100012fb) True >>> #The above 'call' instruction is 5 bytes, a nop in x86 is 1 byte, >>> # thus 5 nops are used: >>> bv.get_disassembly(0x100012fb) 'nop' >>> bv.get_next_disassembly() 'nop' >>> bv.get_next_disassembly() 'nop' >>> bv.get_next_disassembly() 'nop' >>> bv.get_next_disassembly() 'nop' >>> bv.get_next_disassembly() 'mov byte [ebp-0x1c], al'
-
create_database(filename, progress_func=None)[source]¶ create_databasewrites the current database (.bndb) file out to the specified file.Parameters: - filename (str) – path and filename to write the bndb to, this string should have ”.bndb” appended to it.
- progress_func (callable()) – optional function to be called with the current progress and total count.
Returns: true on success, false on failure
Return type:
-
create_user_function(addr, plat=None)[source]¶ create_user_functionadd a new user function of the givenplatat the virtual addressaddrParameters: Return type: Example: >>> bv.create_user_function(1) >>> bv.functions [<func: x86_64@0x1>]
-
data_vars¶ List of data variables (read-only)
-
define_auto_symbol(sym)[source]¶ define_auto_symboladds a symbol to the internal list of automatically discovered Symbol objects.Warning
If multiple symbols for the same address are defined, only the most recent symbol will ever be used.
Parameters: sym (Symbol) – the symbol to define Return type: None
-
define_auto_symbol_and_var_or_function(sym, sym_type, plat=None)[source]¶ define_auto_symbol_and_var_or_functionWarning
If multiple symbols for the same address are defined, only the most recent symbol will ever be used.
Parameters: - sym (Symbol) – the symbol to define
- sym_type (SymbolType) – Type of symbol being defined
- plat (Platform) – (optional) platform
Return type:
-
define_data_var(addr, var_type)[source]¶ define_data_vardefines a non-user data variablevar_typeat the virtual addressaddr.Parameters: Return type: Example: >>> t = bv.parse_type_string("int foo") >>> t (<type: int32_t>, 'foo') >>> bv.define_data_var(bv.entry_point, t[0]) >>>
-
define_imported_function(import_addr_sym, func)[source]¶ define_imported_functiondefines an imported Functionfuncwith a ImportedFunctionSymbol type.Parameters: Return type:
-
define_type(type_id, default_name, type_obj)[source]¶ define_typeregisters aTypetype_objof the givennamein the global list of types for the currentBinaryView. This method should only be used for automatically generated types.Parameters: - type_id (str) – Unique identifier for the automatically generated type
- default_name (QualifiedName) – Name of the type to be registered
- type_obj (Type) – Type object to be registered
Returns: Registered name of the type. May not be the same as the requested name if the user has renamed types.
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> registered_name = bv.define_type(Type.generate_auto_type_id("source", name), name, type) >>> bv.get_type_by_name(registered_name) <type: int32_t>
-
define_user_data_var(addr, var_type)[source]¶ define_user_data_vardefines a user data variablevar_typeat the virtual addressaddr.Parameters: - addr (int) – virtual address to define the given data variable
- var_type (binaryninja.Type) – type to be defined at the given virtual address
Return type: Example: >>> t = bv.parse_type_string("int foo") >>> t (<type: int32_t>, 'foo') >>> bv.define_user_data_var(bv.entry_point, t[0]) >>>
-
define_user_symbol(sym)[source]¶ define_user_symboladds a symbol to the internal list of user added Symbol objects.Warning
If multiple symbols for the same address are defined, only the most recent symbol will ever be used.
Parameters: sym (Symbol) – the symbol to define Return type: None
-
define_user_type(name, type_obj)[source]¶ define_user_typeregisters aTypetype_objof the givennamein the global list of user types for the currentBinaryView.Parameters: - name (QualifiedName) – Name of the user type to be registered
- type_obj (Type) – Type object to be registered
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> bv.define_user_type(name, type) >>> bv.get_type_by_name(name) <type: int32_t>
-
end¶ End offset of the binary (read-only)
-
endianness¶ Endianness of the binary (read-only)
-
entry_function¶ Entry function (read-only)
-
entry_point¶ Entry point of the binary (read-only)
-
executable¶ Whether the binary is an executable (read-only)
-
find_next_data(start, data, flags=0)[source]¶ find_next_datasearchs for the bytes in data starting at the virtual addressstarteither, case-sensitive, or case-insensitive.Parameters:
-
functions¶ List of functions (read-only)
-
get_basic_blocks_at(addr)[source]¶ get_basic_blocks_atget a list ofBasicBlockobjects which exist at the provided virtual address.Parameters: addr (int) – virtual address of BasicBlock desired Returns: a list of BasicBlockobjectsReturn type: list(BasicBlock)
-
get_basic_blocks_starting_at(addr)[source]¶ get_basic_blocks_starting_atget a list ofBasicBlockobjects which start at the provided virtual address.Parameters: addr (int) – virtual address of BasicBlock desired Returns: a list of BasicBlockobjectsReturn type: list(BasicBlock)
-
get_code_refs(addr, length=None)[source]¶ get_code_refsreturns a list of ReferenceSource objects (xrefs or cross-references) that point to the provided virtual address.Parameters: addr (int) – virtual address to query for references
Returns: List of References for the given virtual address
Return type: list(ReferenceSource)
Example: >>> bv.get_code_refs(here) [<ref: x86@0x4165ff>] >>>
-
get_data_var_at(addr)[source]¶ get_data_var_atreturns the data type at a given virtual address.Parameters: addr (int) – virtual address to get the data type from
Returns: returns the DataVariable at the given virtual address, None on error.
Return type: Example: >>> t = bv.parse_type_string("int foo") >>> bv.define_data_var(bv.entry_point, t[0]) >>> bv.get_data_var_at(bv.entry_point) <var 0x100001174: int32_t>
-
get_disassembly(addr, arch=None)[source]¶ get_disassemblysimple helper function for printing disassembly of a given addressParameters: - addr (int) – virtual address of instruction
- arch (Architecture) – optional Architecture,
self.archis used if this parameter is None
Returns: a str representation of the instruction at virtual address
addror NoneReturn type: str or None
Example: >>> bv.get_disassembly(bv.entry_point) 'push ebp' >>>
-
get_function_at(addr, plat=None)[source]¶ get_function_atgets a Function object for the function that starts at virtual addressaddr:Parameters: Returns: returns a Function object or None for the function at the virtual address provided
Return type: Example: >>> bv.get_function_at(bv.entry_point) <func: x86_64@0x100001174> >>>
-
get_functions_at(addr)[source]¶ get_functions_atget a list of binaryninja.Function objects (one for each valid plat) at the given virtual address. Binary Ninja does not limit the number of platforms in a given file thus there may be multiple functions defined from different architectures at the same location. This API allows you to query all of valid platforms.Parameters: addr (int) – virtual address of the desired Function object list. Returns: a list of binaryninja.Function objects defined at the provided virtual address Return type: list(Function)
-
get_functions_containing(addr)[source]¶ get_functions_containingreturns a list of functions which contain the given address or None on failure.Parameters: addr (int) – virtual address to query. Return type: list of Function objects or None
-
get_instruction_length(addr, arch=None)[source]¶ get_instruction_lengthreturns the number of bytes in the instruction of Architecturearchat the virtual addressaddrParameters: - addr (int) – virtual address of the instruction query
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: Number of bytes in instruction
Return type: Example: >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.get_instruction_length(0x100012f1) 2L >>>
-
get_linear_disassembly(settings)[source]¶ get_linear_disassemblygets an iterator for all lines in the linear disassembly of the view for the given disassembly settings.Note
linear_disassembly doesn’t just return disassembly it will return a single line from the linear view, and thus will contain both data views, and disassembly.
Parameters: settings (DisassemblySettings) – instance specifying the desired output formatting.
Returns: An iterator containing formatted dissassembly lines.
Return type: LinearDisassemblyIterator
Example: >>> settings = DisassemblySettings() >>> lines = bv.get_linear_disassembly(settings) >>> for line in lines: ... print(line) ... break ... cf fa ed fe 07 00 00 01 ........
-
get_linear_disassembly_position_at(addr, settings)[source]¶ get_linear_disassembly_position_atinstantiates aLinearDisassemblyPositionobject for use inget_previous_linear_disassembly_lines()orget_next_linear_disassembly_lines().Parameters: - addr (int) – virtual address of linear disassembly position
- settings (DisassemblySettings) – an instantiated
DisassemblySettingsobject
Returns: An instantied
LinearDisassemblyPositionobject for the provided virtual addressReturn type: Example: >>> settings = DisassemblySettings() >>> pos = bv.get_linear_disassembly_position_at(0x1000149f, settings) >>> lines = bv.get_previous_linear_disassembly_lines(pos, settings) >>> lines [<0x1000149a: pop esi>, <0x1000149b: pop ebp>, <0x1000149c: retn 0xc>, <0x1000149f: >]
-
get_modification(addr, length=None)[source]¶ get_modificationreturns the modified bytes of up tolengthbytes from virtual addressaddr, or iflengthis None returns the ModificationStatus.Parameters: Returns: Either ModificationStatus of the byte at
addr, or string of modified bytes ataddrReturn type: ModificationStatus or str
-
get_next_basic_block_start_after(addr)[source]¶ get_next_basic_block_start_afterreturns the virtual address of the BasicBlock that occurs after the virtual- address
addr
Parameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the next BasicBlock
Return type: Example: >>> hex(bv.get_next_basic_block_start_after(bv.entry_point)) '0x100014a8L' >>> hex(bv.get_next_basic_block_start_after(0x100014a8)) '0x100014adL' >>>
-
get_next_data_after(addr)[source]¶ get_next_data_afterretrieves the virtual address of the next non-code byte.Parameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the next data byte which is data, not code
Return type: Example: >>> hex(bv.get_next_data_after(0x10000000)) '0x10000001L'
-
get_next_data_var_after(addr)[source]¶ get_next_data_var_afterretrieves the next virtual address of the nextDataVariableParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the next
DataVariableReturn type: Example: >>> hex(bv.get_next_data_var_after(0x10000000)) '0x1000003cL' >>> bv.get_data_var_at(0x1000003c) <var 0x1000003c: int32_t> >>>
-
get_next_disassembly(arch=None)[source]¶ get_next_disassemblysimple helper function for printing disassembly of the next instruction. The internal state of the instruction to be printed is stored in thenext_addressattributeParameters: arch (Architecture) – optional Architecture,
self.archis used if this parameter is NoneReturns: a str representation of the instruction at virtual address
self.next_addressReturn type: str or None
Example: >>> bv.get_next_disassembly() 'push ebp' >>> bv.get_next_disassembly() 'mov ebp, esp' >>> #Now reset the starting point back to the entry point >>> bv.next_address = bv.entry_point >>> bv.get_next_disassembly() 'push ebp' >>>
-
get_next_function_start_after(addr)[source]¶ get_next_function_start_afterreturns the virtual address of the Function that occurs after the virtual addressaddrParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the next Function
Return type: Example: >>> bv.get_next_function_start_after(bv.entry_point) 268441061L >>> hex(bv.get_next_function_start_after(bv.entry_point)) '0x100015e5L' >>> hex(bv.get_next_function_start_after(0x100015e5)) '0x10001629L' >>> hex(bv.get_next_function_start_after(0x10001629)) '0x1000165eL' >>>
-
get_next_linear_disassembly_lines(pos, settings)[source]¶ get_next_linear_disassembly_linesretrieves a list ofLinearDisassemblyLineobjects for the next disassembly lines, and updates the LinearDisassemblyPosition passed in. This function can be called repeatedly to get more lines of linear disassembly.Parameters: - pos (LinearDisassemblyPosition) – Position to start retrieving linear disassembly lines from
- settings (DisassemblySettings) – DisassemblySettings display settings for the linear disassembly
Returns: a list of
LinearDisassemblyLineobjects for the next lines.Example: >>> settings = DisassemblySettings() >>> pos = bv.get_linear_disassembly_position_at(0x10001483, settings) >>> bv.get_next_linear_disassembly_lines(pos, settings) [<0x10001483: xor eax, eax {0x0}>, <0x10001485: inc eax {0x1}>, ... , <0x10001488: >] >>> bv.get_next_linear_disassembly_lines(pos, settings) [<0x10001488: push dword [ebp+0x10 {arg_c}]>, ... , <0x1000149a: >] >>>
-
get_previous_basic_block_end_before(addr)[source]¶ get_previous_basic_block_end_beforeParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the previous BasicBlock end
Return type: Example: >>> hex(bv.entry_point) '0x1000149fL' >>> hex(bv.get_next_basic_block_start_after(bv.entry_point)) '0x100014a8L' >>> hex(bv.get_previous_basic_block_end_before(0x100014a8)) '0x100014a8L'
-
get_previous_basic_block_start_before(addr)[source]¶ get_previous_basic_block_start_beforereturns the virtual address of the BasicBlock that occurs prior to the provided virtual addressParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the previous BasicBlock
Return type: Example: >>> hex(bv.entry_point) '0x1000149fL' >>> hex(bv.get_next_basic_block_start_after(bv.entry_point)) '0x100014a8L' >>> hex(bv.get_previous_basic_block_start_before(0x100014a8)) '0x1000149fL' >>>
-
get_previous_data_before(addr)[source]¶ get_previous_data_beforeParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the previous data (non-code) byte
Return type: Example: >>> hex(bv.get_previous_data_before(0x1000001)) '0x1000000L' >>>
-
get_previous_data_var_before(addr)[source]¶ get_previous_data_var_beforeParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the previous
DataVariableReturn type: Example: >>> hex(bv.get_previous_data_var_before(0x1000003c)) '0x10000000L' >>> bv.get_data_var_at(0x10000000) <var 0x10000000: int16_t> >>>
-
get_previous_function_start_before(addr)[source]¶ get_previous_function_start_beforereturns the virtual address of the Function that occurs prior to the virtual address providedParameters: addr (int) – the virtual address to start looking from.
Returns: the virtual address of the previous Function
Return type: Example: >>> hex(bv.entry_point) '0x1000149fL' >>> hex(bv.get_next_function_start_after(bv.entry_point)) '0x100015e5L' >>> hex(bv.get_previous_function_start_before(0x100015e5)) '0x1000149fL' >>>
-
get_previous_linear_disassembly_lines(pos, settings)[source]¶ get_previous_linear_disassembly_linesretrieves a list ofLinearDisassemblyLineobjects for the previous disassembly lines, and updates the LinearDisassemblyPosition passed in. This function can be called repeatedly to get more lines of linear disassembly.Parameters: - pos (LinearDisassemblyPosition) – Position to start retrieving linear disassembly lines from
- settings (DisassemblySettings) – DisassemblySettings display settings for the linear disassembly
Returns: a list of
LinearDisassemblyLineobjects for the previous lines.Example: >>> settings = DisassemblySettings() >>> pos = bv.get_linear_disassembly_position_at(0x1000149a, settings) >>> bv.get_previous_linear_disassembly_lines(pos, settings) [<0x10001488: push dword [ebp+0x10 {arg_c}]>, ... , <0x1000149a: >] >>> bv.get_previous_linear_disassembly_lines(pos, settings) [<0x10001483: xor eax, eax {0x0}>, ... , <0x10001488: >]
-
get_strings(start=None, length=None)[source]¶ get_stringsreturns a list of strings defined in the binary in the optional virtual address range:start-(start+length)Parameters: Returns: a list of all strings or a list of strings defined between
startandstart+lengthReturn type: list(str())
Example: >>> bv.get_strings(0x1000004d, 1) [<AsciiString: 0x1000004d, len 0x2c>] >>>
-
get_symbol_at(addr)[source]¶ get_symbol_atreturns the Symbol at the provided virtual address.Parameters: addr (int) – virtual address to query for symbol
Returns: Symbol for the given virtual address
Return type: Example: >>> bv.get_symbol_at(bv.entry_point) <FunctionSymbol: "_start" @ 0x100001174> >>>
-
get_symbol_by_raw_name(name)[source]¶ get_symbol_by_raw_nameretrieves a Symbol object for the given a raw (mangled) name.Parameters: name (str) – raw (mangled) name of Symbol to be retrieved
Returns: Symbol object corresponding to the provided raw name
Return type: Example: >>> bv.get_symbol_by_raw_name('?testf@Foobar@@SA?AW4foo@1@W421@@Z') <FunctionSymbol: "public: static enum Foobar::foo __cdecl Foobar::testf(enum Foobar::foo)" @ 0x10001100> >>>
-
get_symbols(start=None, length=None)[source]¶ get_symbolsretrieves the list of all Symbol objects in the optionally provided range.Parameters: Returns: list of all Symbol objects, or those Symbol objects in the range of
start-start+lengthReturn type: list(Symbol)
Example: >>> bv.get_symbols(0x1000200c, 1) [<ImportAddressSymbol: "KERNEL32!IsProcessorFeaturePresent@IAT" @ 0x1000200c>] >>>
-
get_symbols_by_name(name)[source]¶ get_symbols_by_nameretrieves a list of Symbol objects for the given symbol name.Parameters: name (str) – name of Symbol object to be retrieved
Returns: Symbol object corresponding to the provided name
Return type: Example: >>> bv.get_symbols_by_name('?testf@Foobar@@SA?AW4foo@1@W421@@Z') [<FunctionSymbol: "public: static enum Foobar::foo __cdecl Foobar::testf(enum Foobar::foo)" @ 0x10001100>] >>>
-
get_symbols_of_type(sym_type, start=None, length=None)[source]¶ get_symbols_of_typeretrieves a list of all Symbol objects of the provided symbol type in the optionally- provided range.
Parameters: - sym_type (SymbolType) – A Symbol type:
Symbol. - start (int) – optional start virtual address
- length (int) – optional length
Returns: list of all Symbol objects of type sym_type, or those Symbol objects in the range of
start-start+lengthReturn type: list(Symbol)
Example: >>> bv.get_symbols_of_type(SymbolType.ImportAddressSymbol, 0x10002028, 1) [<ImportAddressSymbol: "KERNEL32!GetCurrentThreadId@IAT" @ 0x10002028>] >>>
-
get_type_by_id(id)[source]¶ get_type_by_idreturns the defined type whose unique identifier corresponds with the providedidParameters: id (str) – Unique identifier to lookup
Returns: A
Typeor None if the type does not existReturn type: Type or None
Example: >>> type, name = bv.parse_type_string("int foo") >>> type_id = Type.generate_auto_type_id("source", name) >>> bv.define_type(type_id, name, type) >>> bv.get_type_by_id(type_id) <type: int32_t> >>>
-
get_type_by_name(name)[source]¶ get_type_by_namereturns the defined type whose name corresponds with the providednameParameters: name (QualifiedName) – Type name to lookup
Returns: A
Typeor None if the type does not existReturn type: Type or None
Example: >>> type, name = bv.parse_type_string("int foo") >>> bv.define_user_type(name, type) >>> bv.get_type_by_name(name) <type: int32_t> >>>
-
get_type_id(name)[source]¶ get_type_idreturns the unique indentifier of the defined type whose name corresponds with the providednameParameters: name (QualifiedName) – Type name to lookup
Returns: The unique identifier of the type
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> type_id = Type.generate_auto_type_id("source", name) >>> registered_name = bv.define_type(type_id, name, type) >>> bv.get_type_id(registered_name) == type_id True >>>
-
get_type_name_by_id(id)[source]¶ get_type_name_by_idreturns the defined type name whose unique identifier corresponds with the providedidParameters: id (str) – Unique identifier to lookup
Returns: A QualifiedName or None if the type does not exist
Return type: QualifiedName or None
Example: >>> type, name = bv.parse_type_string("int foo") >>> type_id = Type.generate_auto_type_id("source", name) >>> bv.define_type(type_id, name, type) 'foo' >>> bv.get_type_name_by_id(type_id) 'foo' >>>
-
get_view_of_type(name)[source]¶ get_view_of_typereturns the BinaryView associated with the provided name if it exists.Parameters: name (str) – Name of the view to be retrieved Returns: BinaryView object assocated with the provided name or None on failure Return type: BinaryView or None
-
global_pointer_value¶ Discovered value of the global pointer register, if the binary uses one (read-only)
-
has_database¶ boolean has a database been written to disk (read-only)
-
has_functions¶ Boolean whether the binary has functions (read-only)
-
insert(addr, data)[source]¶ insertinserts the bytes indatato the virtual addressaddr.Parameters: Returns: number of bytes inserted to virtual address
addrReturn type: Example: >>> bv.insert(0,"BBBB") 4L >>> bv.read(0,8) 'BBBBAAAA'
-
instructions¶ A generator of instruction tokens and their start addresses
-
invert_branch(addr, arch=None)[source]¶ invert_branchconvert the branch instruction of architecturearchat the virtual addressaddrto the inverse branch.Note
This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary
file must be saved in order to preserve the changes made.
Parameters: - addr (int) – virtual address of the instruction to be modified
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True on success, False on falure.
Return type: Example: >>> bv.get_disassembly(0x1000130e) 'je 0x10001317' >>> bv.invert_branch(0x1000130e) True >>> >>> bv.get_disassembly(0x1000130e) 'jne 0x10001317' >>>
-
is_always_branch_patch_available(addr, arch=None)[source]¶ is_always_branch_patch_availablequeries the architecture plugin to determine if the instruction ataddrcan be made to always branch. The actual logic of which is implemented in theperform_is_always_branch_patch_availablein the corresponding architecture.Parameters: - addr (int) – the virtual address of the instruction to be patched
- arch (Architecture) – (optional) the architecture for the current view
Returns: True if the instruction can be patched, False otherwise
Return type: Example: >>> bv.get_disassembly(0x100012ed) 'test eax, eax' >>> bv.is_always_branch_patch_available(0x100012ed) False >>> bv.get_disassembly(0x100012ef) 'jg 0x100012f5' >>> bv.is_always_branch_patch_available(0x100012ef) True >>>
-
is_invert_branch_patch_available(addr, arch=None)[source]¶ is_invert_branch_patch_availablequeries the architecture plugin to determine if the instruction ataddris a branch that can be inverted. The actual logic of which is implemented in theperform_is_invert_branch_patch_availablein the corresponding architecture.Parameters: - addr (int) – the virtual address of the instruction to be patched
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True if the instruction can be patched, False otherwise
Return type: Example: >>> bv.get_disassembly(0x100012ed) 'test eax, eax' >>> bv.is_invert_branch_patch_available(0x100012ed) False >>> bv.get_disassembly(0x100012ef) 'jg 0x100012f5' >>> bv.is_invert_branch_patch_available(0x100012ef) True >>>
-
is_never_branch_patch_available(addr, arch=None)[source]¶ is_never_branch_patch_availablequeries the architecture plugin to determine if the instruction at the instruction ataddrcan be made to never branch. The actual logic of which is implemented in theperform_is_never_branch_patch_availablein the corresponding architecture.Parameters: - addr (int) – the virtual address of the instruction to be patched
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True if the instruction can be patched, False otherwise
Return type: Example: >>> bv.get_disassembly(0x100012ed) 'test eax, eax' >>> bv.is_never_branch_patch_available(0x100012ed) False >>> bv.get_disassembly(0x100012ef) 'jg 0x100012f5' >>> bv.is_never_branch_patch_available(0x100012ef) True >>>
-
is_offset_code_semantics(addr)[source]¶ is_offset_code_semanticschecks if an virtual addressaddris semantically valid for code.Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid for writing, false if the virtual address is invalid or error Return type: bool
-
is_offset_executable(addr)[source]¶ is_offset_executablechecks if an virtual addressaddris valid for executing.Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid for executing, false if the virtual address is invalid or error Return type: bool
-
is_offset_readable(addr)[source]¶ is_offset_readablechecks if an virtual addressaddris valid for reading.Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid for reading, false if the virtual address is invalid or error Return type: bool
-
is_offset_writable(addr)[source]¶ is_offset_writablechecks if an virtual addressaddris valid for writing.Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid for writing, false if the virtual address is invalid or error Return type: bool
-
is_offset_writable_semantics(addr)[source]¶ is_offset_writable_semanticschecks if an virtual addressaddris semantically writable. Some sections may have writable permissions for linking purposes but can be treated as read-only for the purposes of analysis.Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid for writing, false if the virtual address is invalid or error Return type: bool
-
is_skip_and_return_value_patch_available(addr, arch=None)[source]¶ is_skip_and_return_value_patch_availablequeries the architecture plugin to determine if the instruction ataddris similar to an x86 “call” instruction which can be made to return a value. The actual logic of which is implemented in theperform_is_skip_and_return_value_patch_availablein the corresponding architecture.Parameters: - addr (int) – the virtual address of the instruction to be patched
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True if the instruction can be patched, False otherwise
Return type: Example: >>> bv.get_disassembly(0x100012f6) 'mov dword [0x10003020], eax' >>> bv.is_skip_and_return_value_patch_available(0x100012f6) False >>> bv.get_disassembly(0x100012fb) 'call 0x10001629' >>> bv.is_skip_and_return_value_patch_available(0x100012fb) True >>>
-
is_skip_and_return_zero_patch_available(addr, arch=None)[source]¶ is_skip_and_return_zero_patch_availablequeries the architecture plugin to determine if the instruction ataddris similar to an x86 “call” instruction which can be made to return zero. The actual logic of which is implemented in theperform_is_skip_and_return_zero_patch_availablein the corresponding architecture.Parameters: - addr (int) – the virtual address of the instruction to be patched
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True if the instruction can be patched, False otherwise
Return type: Example: >>> bv.get_disassembly(0x100012f6) 'mov dword [0x10003020], eax' >>> bv.is_skip_and_return_zero_patch_available(0x100012f6) False >>> bv.get_disassembly(0x100012fb) 'call 0x10001629' >>> bv.is_skip_and_return_zero_patch_available(0x100012fb) True >>>
-
is_type_auto_defined(name)[source]¶ is_type_auto_definedqueries the user type list of name. If name is not in the user type list then the name is considered an auto type.Parameters: name (QualifiedName) – Name of type to query
Returns: True if the type is not a user type. False if the type is a user type.
Example: >>> bv.is_type_auto_defined("foo") True >>> bv.define_user_type("foo", bv.parse_type_string("struct {int x,y;}")[0]) >>> bv.is_type_auto_defined("foo") False >>>
-
is_valid_offset(addr)[source]¶ is_valid_offsetchecks if an virtual addressaddris valid .Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid, false if the virtual address is invalid or error Return type: bool
-
linear_disassembly¶ Iterator for all lines in the linear disassembly of the view
-
llil_basic_blocks¶ A generator of all LowLevelILBasicBlock objects in the BinaryView
-
llil_instructions¶ A generator of llil instructions
-
long_name= None¶
-
max_function_size_for_analysis¶ Maximum size of function (sum of basic block sizes in bytes) for auto analysis
-
mlil_basic_blocks¶ A generator of all MediumLevelILBasicBlock objects in the BinaryView
-
mlil_instructions¶ A generator of mlil instructions
-
modified¶ boolean modification state of the BinaryView (read/write)
-
name= None¶
-
never_branch(addr, arch=None)[source]¶ never_branchconvert the branch instruction of architecturearchat the virtual addressaddrto a fall through.Note
This API performs a binary patch, analysis may need to be updated afterward. Additionally the binary file must be saved in order to preserve the changes made.
Parameters: - addr (int) – virtual address of the instruction to be modified
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True on success, False on falure.
Return type: Example: >>> bv.get_disassembly(0x1000130e) 'jne 0x10001317' >>> bv.never_branch(0x1000130e) True >>> bv.get_disassembly(0x1000130e) 'nop' >>>
-
next_address= 0¶
-
offset¶
-
parameters_for_analysis¶
-
parent_view¶ View that contains the raw data used by this view (read-only)
-
parse_type_string(text)[source]¶ parse_type_stringconverts C-style string into aType.Parameters: text (str) – C-style string of type to create
Returns: A tuple of a
Typeand type nameReturn type: tuple(Type, QualifiedName)
Example: >>> bv.parse_type_string("int foo") (<type: int32_t>, 'foo') >>>
-
perform_get_default_endianness()[source]¶ perform_get_default_endiannessimplements a check which returns true if the BinaryView is executable.Note
This method may be implemented for custom BinaryViews that are not LittleEndian.
Warning
This method must not be called directly.
Returns: either Endianness.LittleEndianorEndianness.BigEndianReturn type: Endianness
-
perform_get_entry_point()[source]¶ perform_get_entry_pointimplements a query for the initial entry point for code execution.Note
This method should be implmented for custom BinaryViews that are executable.
Warning
This method must not be called directly.
Returns: the virtual address of the entry point Return type: int
-
perform_get_length()[source]¶ perform_get_lengthimplements a query for the size of the virtual address range used by the BinaryView.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Returns: returns the size of the virtual address range used by the BinaryView. Return type: int
-
perform_get_modification(addr)[source]¶ perform_get_modificationimplements query to the whether the virtual addressaddris modified.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: addr (int) – a virtual address to be checked Returns: One of the following: Original = 0, Changed = 1, Inserted = 2 Return type: ModificationStatus
-
perform_get_next_valid_offset(addr)[source]¶ perform_get_next_valid_offsetimplements a query for the next valid readable, writable, or executable virtual memory address.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: addr (int) – a virtual address to start checking from. Returns: the next readable, writable, or executable virtual memory address Return type: int
-
perform_get_start()[source]¶ perform_get_startimplements a query for the first readable, writable, or executable virtual address in the BinaryView.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Returns: returns the first virtual address in the BinaryView. Return type: int
-
perform_insert(addr, data)[source]¶ perform_insertimplements a mapping between a virtual address and an absolute file offset, inserting the bytesdatato rebased addressaddr.Note
This method may be overridden by custom BinaryViews. If not overridden, inserting is disallowed
Warning
This method must not be called directly.
Parameters: Returns: length of data inserted, should return 0 on error
Return type:
-
perform_is_executable()[source]¶ perform_is_executableimplements a check which returns true if the BinaryView is executable.Note
This method must be implemented for custom BinaryViews that are executable.
Warning
This method must not be called directly.
Returns: true if the current BinaryView is executable, false if it is not executable or on error Return type: bool
-
perform_is_offset_executable(addr)[source]¶ perform_is_offset_executableimplements a check if a virtual addressaddris executable.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is executable, false if the virtual address is not executable or error Return type: int
-
perform_is_offset_readable(offset)[source]¶ perform_is_offset_readableimplements a check if an virtual address is readable.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: offset (int) – a virtual address to be checked Returns: true if the virtual address is readable, false if the virtual address is not readable or error Return type: bool
-
perform_is_offset_writable(addr)[source]¶ perform_is_offset_writableimplements a check if a virtual addressaddris writable.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is writable, false if the virtual address is not writable or error Return type: bool
-
perform_is_relocatable()[source]¶ perform_is_relocatableimplements a check which returns true if the BinaryView is relocatable. Defaults to True.Note
This method may be implemented for custom BinaryViews that are relocatable.
Warning
This method must not be called directly.
Returns: True if the BinaryView is relocatable, False otherwise Return type: boolean
-
perform_is_valid_offset(addr)[source]¶ perform_is_valid_offsetimplements a check if an virtual addressaddris valid.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: addr (int) – a virtual address to be checked Returns: true if the virtual address is valid, false if the virtual address is invalid or error Return type: bool
-
perform_read(addr, length)[source]¶ perform_readimplements a mapping between a virtual address and an absolute file offset, readinglengthbytes from the rebased addressaddr.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: Returns: length bytes read from addr, should return empty string on error
Return type:
-
perform_remove(addr, length)[source]¶ perform_removeimplements a mapping between a virtual address and an absolute file offset, removinglengthbytes from the rebased addressaddr.Note
This method may be overridden by custom BinaryViews. If not overridden, removing data is disallowed
Warning
This method must not be called directly.
Parameters: Returns: length of data removed, should return 0 on error
Return type:
-
perform_write(addr, data)[source]¶ perform_writeimplements a mapping between a virtual address and an absolute file offset, writing the bytesdatato rebased addressaddr.Note
This method may be overridden by custom BinaryViews. Use
add_auto_segmentto providedata without overriding this method. .. warning:: This method must not be called directly.
Parameters: Returns: length of data written, should return 0 on error
Return type:
-
platform¶ The platform associated with the current BinaryView (read/write)
-
query_metadata(key)[source]¶ query_metadata retrieves a metadata associated with the given key stored in the current BinaryView.
Parameters: key (string) – key to query
Return type: metadata associated with the key
Example: >>> bv.store_metadata("integer", 1337) >>> bv.query_metadata("integer") 1337L >>> bv.store_metadata("list", [1,2,3]) >>> bv.query_metadata("list") [1L, 2L, 3L] >>> bv.store_metadata("string", "my_data") >>> bv.query_metadata("string") 'my_data'
-
read(addr, length)[source]¶ readreturns the data reads at mostlengthbytes from virtual addressaddr.Note: Python2 returns a str, but Python3 returns a bytes object. str(DataBufferObject) will still get you a str in either case.
Parameters: Returns: at most
lengthbytes from the virtual addressaddr, empty string on error or no data.Return type: python2 - str; python3 - bytes
Example: >>> #Opening a x86_64 Mach-O binary >>> bv = BinaryViewType['Raw'].open("/bin/ls") >>> bv.read(0,4) '\xcf\xfa\xed\xfe'
-
reanalyze()[source]¶ reanalyzecauses all functions to be reanalyzed. This function does not wait for the analysis to finish.Return type: None
-
redo()[source]¶ redoredo the last commited action in the undo database.Return type: Example: >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.begin_undo_actions() >>> bv.convert_to_nop(0x100012f1) True >>> bv.commit_undo_actions() >>> bv.get_disassembly(0x100012f1) 'nop' >>> bv.undo() >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.redo() >>> bv.get_disassembly(0x100012f1) 'nop' >>>
-
register_notification(notify)[source]¶ register_notification provides a mechanism for receiving callbacks for various analysis events. A full list of callbacks can be seen in
BinaryDataNotification.Parameters: notify (BinaryDataNotification) – notify is a subclassed instance of BinaryDataNotification.Return type: None
-
register_platform_types(platform)[source]¶ register_platform_typesensures that the platform-specific types for aPlatformare available for the currentBinaryView. This is automatically performed when adding a new function or setting the default platform.Parameters: platform (Platform) – Platform containing types to be registered
Return type: Example: >>> platform = Platform["linux-x86"] >>> bv.register_platform_types(platform) >>>
-
registered_view_type= None¶
-
relocatable¶ Boolean - is the binary relocatable (read-only)
-
remove(addr, length)[source]¶ removeremoves at mostlengthbytes from virtual addressaddr.Parameters: Returns: number of bytes removed from virtual address
addrReturn type: Example: >>> bv.read(0,8) 'BBBBAAAA' >>> bv.remove(0,4) 4L >>> bv.read(0,4) 'AAAA'
-
remove_function(func)[source]¶ remove_functionremoves the functionfuncfrom the list of functionsParameters: func (Function) – a Function object.
Return type: Example: >>> bv.functions [<func: x86_64@0x1>] >>> bv.remove_function(bv.functions[0]) >>> bv.functions []
-
remove_metadata(key)[source]¶ remove_metadata removes the metadata associated with key from the current BinaryView.
Parameters: key (string) – key associated with metadata to remove from the BinaryView
Return type: Example: >>> bv.store_metadata("integer", 1337) >>> bv.remove_metadata("integer")
-
remove_user_function(func)[source]¶ remove_user_functionremoves the user functionfuncfrom the list of functionsParameters: func (Function) – a Function object.
Return type: Example: >>> bv.functions [<func: x86_64@0x1>] >>> bv.remove_user_function(bv.functions[0]) >>> bv.functions []
-
rename_type(old_name, new_name)[source]¶ rename_typerenames a type in the global list of types for the currentBinaryViewParameters: - old_name (QualifiedName) – Existing name of type to be renamed
- new_name (QualifiedName) – New name of type to be renamed
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> bv.define_user_type(name, type) >>> bv.get_type_by_name("foo") <type: int32_t> >>> bv.rename_type("foo", "bar") >>> bv.get_type_by_name("bar") <type: int32_t> >>>
-
save(dest)[source]¶ savesaves the original binary file to the provided destinationdestalong with any modifications.Parameters: dest (str) – destination path and filename of file to be written Returns: boolean True on success, False on failure Return type: bool
-
save_auto_snapshot(progress_func=None)[source]¶ save_auto_snapshotsaves the current database to the already created file.Note
create_database()should have been called prior to executing this methodParameters: progress_func (callable()) – optional function to be called with the current progress and total count. Returns: True if it successfully saved the snapshot, False otherwise Return type: bool
-
saved¶ boolean state of whether or not the file has been saved (read/write)
-
sections¶ List of sections (read-only)
-
segments¶ List of segments (read-only)
-
session_data¶ Dictionary object where plugins can store arbitrary data associated with the view
-
classmethod
set_default_session_data(name, value)[source]¶ set_default_session_datasaves a variable to the BinaryView. :param name: name of the variable to be saved :param value: value of the variable to be savedExample: >>> BinaryView.set_default_session_data("variable_name", "value") >>> bv.session_data.variable_name 'value'
-
skip_and_return_value(addr, value, arch=None)[source]¶ skip_and_return_valueconvert thecallinstruction of architecturearchat the virtual addressaddrto the equivilent of returning a value.Parameters: - addr (int) – virtual address of the instruction to be modified
- value (int) – value to make the instruction return
- arch (Architecture) – (optional) the architecture of the instructions if different from the default
Returns: True on success, False on falure.
Return type: Example: >>> bv.get_disassembly(0x1000132a) 'call 0x1000134a' >>> bv.skip_and_return_value(0x1000132a, 42) True >>> #The return value from x86 functions is stored in eax thus: >>> bv.get_disassembly(0x1000132a) 'mov eax, 0x2a' >>>
-
start¶ Start offset of the binary (read-only)
-
store_metadata(key, md)[source]¶ store_metadata stores an object for the given key in the current BinaryView. Objects stored using store_metadata can be retrieved when the database is reopend. Objects stored are not arbitrary python objects! The values stored must be able to be held in a Metadata object. See
Metadatafor more information. Python objects could obviously be serialized using pickle but this intentionally a task left to the user since there is the potential security issues.Parameters: - key (string) – key value to associate the Metadata object with
- md (Varies) – object to store.
Return type: Example: >>> bv.store_metadata("integer", 1337) >>> bv.query_metadata("integer") 1337L >>> bv.store_metadata("list", [1,2,3]) >>> bv.query_metadata("list") [1L, 2L, 3L] >>> bv.store_metadata("string", "my_data") >>> bv.query_metadata("string") 'my_data'
-
strings¶ List of strings (read-only)
-
symbols¶ Dict of symbols (read-only)
-
types¶ List of defined types (read-only)
-
undefine_auto_symbol(sym)[source]¶ undefine_auto_symbolremoves a symbol from the internal list of automatically discovered Symbol objects.Parameters: sym (Symbol) – the symbol to undefine Return type: None
-
undefine_data_var(addr)[source]¶ undefine_data_varremoves the non-user data variable at the virtual addressaddr.Parameters: addr (int) – virtual address to define the data variable to be removed
Return type: Example: >>> bv.undefine_data_var(bv.entry_point) >>>
-
undefine_type(type_id)[source]¶ undefine_typeremoves aTypefrom the global list of types for the currentBinaryViewParameters: type_id (str) – Unique identifier of type to be undefined
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> type_id = Type.generate_auto_type_id("source", name) >>> bv.define_type(type_id, name, type) >>> bv.get_type_by_name(name) <type: int32_t> >>> bv.undefine_type(type_id) >>> bv.get_type_by_name(name) >>>
-
undefine_user_data_var(addr)[source]¶ undefine_user_data_varremoves the user data variable at the virtual addressaddr.Parameters: addr (int) – virtual address to define the data variable to be removed
Return type: Example: >>> bv.undefine_user_data_var(bv.entry_point) >>>
-
undefine_user_symbol(sym)[source]¶ undefine_user_symbolremoves a symbol from the internal list of user added Symbol objects.Parameters: sym (Symbol) – the symbol to undefine Return type: None
-
undefine_user_type(name)[source]¶ undefine_user_typeremoves aTypefrom the global list of user types for the currentBinaryViewParameters: name (QualifiedName) – Name of user type to be undefined
Return type: Example: >>> type, name = bv.parse_type_string("int foo") >>> bv.define_user_type(name, type) >>> bv.get_type_by_name(name) <type: int32_t> >>> bv.undefine_user_type(name) >>> bv.get_type_by_name(name) >>>
-
undo()[source]¶ undoundo the last commited action in the undo database.Return type: Example: >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.begin_undo_actions() >>> bv.convert_to_nop(0x100012f1) True >>> bv.commit_undo_actions() >>> bv.get_disassembly(0x100012f1) 'nop' >>> bv.undo() >>> bv.get_disassembly(0x100012f1) 'xor eax, eax' >>> bv.redo() >>> bv.get_disassembly(0x100012f1) 'nop' >>>
-
unregister_notification(notify)[source]¶ unregister_notification unregisters the
BinaryDataNotificationobject passed to register_notificationParameters: notify (BinaryDataNotification) – notify is a subclassed instance of BinaryDataNotification.Return type: None
-
update_analysis()[source]¶ update_analysisasynchronously starts the analysis running and returns immediately. Analysis of BinaryViews does not occur automatically, the user must start analysis by calling eitherupdate_analysis()orupdate_analysis_and_wait(). An analysis update must be run after changes are made which could change analysis results such as adding functions.Return type: None
-
update_analysis_and_wait()[source]¶ update_analysis_and_waitblocking call to update the analysis, this call returns when the analysis is complete. Analysis of BinaryViews does not occur automatically, the user must start analysis by calling eitherupdate_analysis()orupdate_analysis_and_wait(). An analysis update must be run after changes are made which could change analysis results such as adding functions.Return type: None
-
view¶
-
view_type¶ View type (read-only)
-
-
class
binaryninja.binaryview.BinaryViewType(handle)[source]¶ Bases:
object-
classmethod
get_view_of_file(filename, update_analysis=True)[source]¶ get_view_of_filereturns the first available, non-Raw BinaryView available.Parameters: Returns: returns a BinaryView object for the given filename.
Return type: BinaryView or None
-
list= [<view type: 'Raw'>, <view type: 'ELF'>, <view type: 'Mach-O'>, <view type: 'PE'>]¶
-
long_name¶ BinaryView long name (read-only)
-
name¶ BinaryView name (read-only)
-
classmethod
-
class
binaryninja.binaryview.BinaryWriter(view, endian=None)[source]¶ Bases:
objectclass BinaryWriteris a convenience class for writing binary data.BinaryWriter can be instantiated as follows and the rest of the document will start from this context
>>> from binaryninja import * >>> bv = BinaryViewType['Mach-O'].open("/bin/ls") >>> br = BinaryReader(bv) >>> bw = BinaryWriter(bv) >>>
Or using the optional endian parameter
>>> from binaryninja import * >>> br = BinaryReader(bv, Endianness.BigEndian) >>> bw = BinaryWriter(bv, Endianness.BigEndian) >>>
-
endianness¶ The Endianness to written data. (read/write)
Getter: returns the endianness of the reader Setter: sets the endianness of the reader (BigEndian or LittleEndian) Type: Endianness
-
offset¶ The current write offset (read/write).
Getter: returns the current internal offset Setter: sets the internal offset Type: int
-
seek(offset)[source]¶ seekupdate internal offset tooffset.Parameters: offset (int) – offset to set the internal offset to
Return type: Example: >>> hex(bw.offset) '0x100000008L' >>> bw.seek(0x100000000) >>> hex(bw.offset) '0x100000000L' >>>
-
seek_relative(offset)[source]¶ seek_relativeupdates the internal offset byoffset.Parameters: offset (int) – offset to add to the internal offset
Return type: Example: >>> hex(bw.offset) '0x100000008L' >>> bw.seek_relative(-8) >>> hex(bw.offset) '0x100000000L' >>>
-
write(value)[source]¶ writewriteslen(value)bytes to the internal offset, without regard to endianness.Parameters: value (str) – bytes to be written at current offset
Returns: boolean True on success, False on failure.
Return type: Example: >>> bw.write("AAAA") True >>> br.read(4) 'AAAA' >>>
-
write16(value)[source]¶ write16writes the lowest order two bytes from the integervalueto the current offset, using internal endianness.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write16be(value)[source]¶ write16bewrites the lowest order two bytes from the big endian integervalueto the current offset.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write16le(value)[source]¶ write16lewrites the lowest order two bytes from the little endian integervalueto the current offset.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write32(value)[source]¶ write32writes the lowest order four bytes from the integervalueto the current offset, using internal endianness.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write32be(value)[source]¶ write32bewrites the lowest order four bytes from the big endian integervalueto the current offset.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write32le(value)[source]¶ write32lewrites the lowest order four bytes from the little endian integervalueto the current offset.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write64(value)[source]¶ write64writes the lowest order eight bytes from the integervalueto the current offset, using internal endianness.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
write64be(value)[source]¶ write64bewrites the lowest order eight bytes from the big endian integervalueto the current offset.Parameters: value (int) – integer value to write. Returns: boolean True on success, False on failure. Return type: bool
-
-
class
binaryninja.binaryview.Section(name, section_type, start, length, linked_section, info_section, info_data, align, entry_size, semantics, auto_defined)[source]¶ Bases:
object-
end¶
-