libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
BasicBlock

[python api] All information about the BasicBlock Python object.

Description


This object is used to represent a basic block of instructions.

Example

>>> block = BasicBlock([
... Instruction(b"\xc9"),
... Instruction(b"\xc3")
... ])
>>> print(block)
0x0: <not disassembled>
0x1: <not disassembled>
>>> # Disassemble a block
>>> ctx.disassembly(block)
>>> print(block)
0x0: leave
0x1: ret
>>> # Disassemble a block with a given base address
>>> ctx.disassembly(block, 0x400000)
>>> print(block)
0x400000: leave
0x400001: ret
>>> hex(block.getFirstAddress())
'0x400000'
>>> hex(block.getLastAddress())
'0x400001'
# Remove an instruction in the block
>>> block.remove(1)
True
>>> print(block)
0x400000: leave
# Add instructions in the block
>>> block.add(Instruction(b"\x90"))
>>> block.add(Instruction(b"\xc3"))
>>> ctx.disassembly(block, 0x400000)
>>> print(block)
0x400000: leave
0x400001: nop
0x400002: ret
# Process a block
>>> ctx.processing(block)
0

Constructor

# Constructor by default
>>> block = BasicBlock()
>>> block.add(Instruction(b"\xc9"))
>>> block.add(Instruction(b"\xc3"))
>>>
# Constructor with a list of instructions
>>> block = BasicBlock([
... Instruction(b"\xc9"),
... Instruction(b"\xc3")
... ])
>>>

Python API - Methods of the BasicBlock class


  • void add(Instruction inst)
    Adds an instruction to the block.
  • integer getFirstAddress(void)
    Returns the first instruction's address of the block.
  • [Instruction, ...] getInstructions(void)
    Returns all instructions of the block.
  • integer getLastAddress(void)
    Returns the last instruction's address of the block.
  • integer getSize(void)
    Returns the number of instruction in the block.
  • bool remove(integer position)
    Removes the instruction in the block at a given position. Returns true if successed.