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

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

Description


This object is used to represent an Instruction.

>>> from __future__ import print_function
>>> from triton import TritonContext, ARCH, Instruction, OPERAND, EXCEPTION
>>> trace = [
... (0x400000, b"\x48\x8b\x05\xb8\x13\x00\x00"), # mov rax, QWORD PTR [rip+0x13b8]
... (0x400007, b"\x48\x8d\x34\xc3"), # lea rsi, [rbx+rax*8]
... (0x40000b, b"\x67\x48\x8D\x74\xC3\x0A"), # lea rsi, [ebx+eax*8+0xa]
... (0x400011, b"\x66\x0F\xD7\xD1"), # pmovmskb edx, xmm1
... (0x400015, b"\x89\xd0"), # mov eax, edx
... (0x400017, b"\x80\xf4\x99"), # xor ah, 0x99
... ]
>>> ctxt = TritonContext()
# Set the arch
>>> ctxt.setArchitecture(ARCH.X86_64)
>>> for (addr, opcode) in trace:
...
... # Build an instruction
... inst = Instruction()
...
... # Setup opcode
... inst.setOpcode(opcode)
...
... # Setup Address
... inst.setAddress(addr)
...
... # Process everything
... if ctxt.processing(inst) == EXCEPTION.FAULT_UD:
... print("Fail an instruction")
...
... print(inst)
... for op in inst.getOperands():
... print(' %s' % (op))
... if op.getType() == OPERAND.MEM:
... print(' base : %s' % (op.getBaseRegister()))
... print(' index : %s' % (op.getIndexRegister()))
... print(' disp : %s' % (op.getDisplacement()))
... print(' scale : %s' % (op.getScale()))
... print('')
0x400000: mov rax, qword ptr [rip + 0x13b8]
rax:64 bv[63..0]
[@0x4013bf]:64 bv[63..0]
base : rip:64 bv[63..0]
index : unknown:1 bv[0..0]
disp : 0x13b8:64 bv[63..0]
scale : 0x1:64 bv[63..0]
<BLANKLINE>
0x400007: lea rsi, [rbx + rax*8]
rsi:64 bv[63..0]
[@0x0]:64 bv[63..0]
base : rbx:64 bv[63..0]
index : rax:64 bv[63..0]
disp : 0x0:64 bv[63..0]
scale : 0x8:64 bv[63..0]
<BLANKLINE>
0x40000b: lea rsi, [ebx + eax*8 + 0xa]
rsi:64 bv[63..0]
[@0xa]:64 bv[63..0]
base : ebx:32 bv[31..0]
index : eax:32 bv[31..0]
disp : 0xa:32 bv[31..0]
scale : 0x8:32 bv[31..0]
<BLANKLINE>
0x400011: pmovmskb edx, xmm1
edx:32 bv[31..0]
xmm1:128 bv[127..0]
<BLANKLINE>
0x400015: mov eax, edx
eax:32 bv[31..0]
edx:32 bv[31..0]
<BLANKLINE>
0x400017: xor ah, 0x99
ah:8 bv[15..8]
0x99:8 bv[7..0]
<BLANKLINE>

Constructor

>>> inst = Instruction()
>>> inst.setAddress(0x40000)
>>> inst.setOpcode(b"\x48\xC7\xC0\x01\x00\x00\x00")
>>> ctxt.processing(inst)
0
>>> print(inst)
0x40000: mov rax, 1
>>> inst = Instruction(b"\x48\xC7\xC0\x01\x00\x00\x00")
>>> inst.setAddress(0x40000)
>>> ctxt.processing(inst)
0
>>> print(inst)
0x40000: mov rax, 1
>>> inst = Instruction(0x40000, b"\x48\xC7\xC0\x01\x00\x00\x00")
>>> ctxt.processing(inst)
0
>>> print(inst)
0x40000: mov rax, 1

Python API - Methods of the Instruction class


  • integer getAddress(void)
    Returns the address of the instruction.
  • integer getCodeCondition(void)
    Returns the code condition of the instruction (mainly used for AArch64).
  • string getDisassembly(void)
    Returns the disassembly of the instruction.
  • [tuple, ...] getLoadAccess(void)
    Returns the list of all implicit and explicit LOAD accesses as a list of tuple <MemoryAccess, AstNode>.
  • integer getNextAddress(void)
    Returns the next address of the instruction.
  • bytes getOpcode(void)
    Returns the opcode of the instruction.
  • [Immediate, MemoryAccess, Register, ...] getOperands(void)
    Returns the operands of the instruction as a list of Immediate, MemoryAccess or Register.
  • PREFIX getPrefix(void)
    Returns the instruction prefix. Mainly used for X86.
  • [tuple, ...] getReadImmediates(void)
    Returns a list of tuple <Immediate, AstNode> which represents all implicit and explicit immediate inputs.
  • [tuple, ...] getReadRegisters(void)
    Returns a list of tuple <Register, AstNode> which represents all implicit and explicit register (flags includes) inputs.
  • integer getSize(void)
    Returns the size of the instruction.
  • [tuple, ...] getStoreAccess(void)
    Returns the list of all implicit and explicit STORE accesses as a list of tuple <MemoryAccess, AstNode>.
  • [SymbolicExpression, ...] getSymbolicExpressions(void)
    Returns the list of symbolic expressions of the instruction.
  • integer getThreadId(void)
    Returns the thread id of the instruction.
  • OPCODE getType(void)
    Returns the type of the instruction.
  • [Register, ...] getUndefinedRegisters(void)
    Returns a list Register which represents all implicit and explicit undefined registers.
  • [tuple, ...] getWrittenRegisters(void)
    Returns a list of tuples <Register, AstNode> which represents all implicit and explicit register (flags includes) outputs.
  • bool isBranch(void)
    Returns true if the instruction is a branch (i.e x86: JUMP, JCC).
  • bool isConditionTaken(void)
    Returns true if the condition is taken (i.e x86: JCC, CMOVCC, SETCC, ...).
  • bool isControlFlow(void)
    Returns true if the instruction modifies the control flow (i.e x86: JUMP, JCC, CALL, RET).
  • bool isMemoryRead(void)
    Returns true if the instruction contains an expression which reads the memory.
  • bool isMemoryWrite(void)
    Returns true if the instruction contains an expression which writes into the memory.
  • bool isPrefixed(void)
    Returns true if the instruction has a prefix.
  • bool isSymbolized(void)
    Returns true if at least one of its SymbolicExpression contains a symbolic variable.
  • bool isTainted(void)
    Returns true if at least one of its SymbolicExpression is tainted.
  • bool isWriteBack(void)
    Returns true if the instruction performs a write back. Mainly used for AArch64 instructions like LDR.
  • bool isUpdateFlag(void)
    Returns true if the instruction updates flags. Mainly used for AArch64 instructions like ADDS.
  • bool isThumb(void)
    Returns true if the instruction is a Thumb instruction.
  • void setAddress(integer addr)
    Sets the address of the instruction.
  • void setOpcode(bytes opcode)
    Sets the opcode of the instruction.
  • void setThreadId(integer tid)
    Sets the thread id of the instruction.