LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LIEF::assembly::Instruction Class Reference

This class represents an assembly instruction. More...

#include <Instruction.hpp>

Inheritance diagram for LIEF::assembly::Instruction:

Classes

class  Iterator
 Lazy-forward iterator that outputs Instruction More...
 

Public Types

enum class  MemoryAccess : uint8_t { NONE = 0 , READ = 1 << 0 , WRITE = 1 << 1 , READ_WRITE = READ | WRITE }
 Memory operation flags. More...
 

Public Member Functions

uint64_t address () const
 Address of the instruction.
 
size_t size () const
 Size of the instruction in bytes.
 
const std::vector< uint8_t > & raw () const
 Raw bytes of the current instruction.
 
std::string mnemonic () const
 Instruction mnemonic (e.g. br)
 
std::string to_string (bool with_address=true) const
 Representation of the current instruction in a pretty assembly way.
 
bool is_call () const
 True if the instruction is a call.
 
bool is_terminator () const
 True if the instruction marks the end of a basic block.
 
bool is_branch () const
 True if the instruction is a branch.
 
bool is_syscall () const
 True if the instruction is a syscall.
 
bool is_memory_access () const
 True if the instruction performs a memory access.
 
bool is_move_reg () const
 True if the instruction is a register to register move.
 
bool is_add () const
 True if the instruction performs an arithmetic addition.
 
bool is_trap () const
 True if the instruction is a trap.
 
bool is_barrier () const
 True if the instruction prevents executing the instruction that immediatly follows the current. This includes return or unconditional branch instructions.
 
bool is_return () const
 True if the instruction is a return.
 
bool is_indirect_branch () const
 True if the instruction is and indirect branch.
 
bool is_conditional_branch () const
 True if the instruction is conditionally jumping to the next instruction or an instruction into some other basic block.
 
bool is_unconditional_branch () const
 True if the instruction is jumping (unconditionally) to some other basic block.
 
bool is_compare () const
 True if the instruction is a comparison.
 
bool is_move_immediate () const
 True if the instruction is moving an immediate.
 
bool is_bitcast () const
 True if the instruction is doing a bitcast.
 
MemoryAccess memory_access () const
 Memory access flags.
 
result< uint64_t > branch_target () const
 Given a is_branch() instruction, try to evaluate the address of the destination.
 
const llvm::MCInst & mcinst () const
 Return the underlying llvm::MCInst implementation.
 
template<class T >
const T * as () const
 This function can be used to down cast an Instruction instance:
 
virtual ~Instruction ()
 

Detailed Description

This class represents an assembly instruction.

Member Enumeration Documentation

◆ MemoryAccess

enum class LIEF::assembly::Instruction::MemoryAccess : uint8_t
strong

Memory operation flags.

Enumerator
NONE 
READ 
WRITE 
READ_WRITE 

Constructor & Destructor Documentation

◆ ~Instruction()

Member Function Documentation

◆ address()

uint64_t LIEF::assembly::Instruction::address ( ) const

Address of the instruction.

◆ as()

template<class T >
const T * LIEF::assembly::Instruction::as ( ) const
inline

This function can be used to down cast an Instruction instance:

std::unique_ptr<assembly::Instruction> inst = get_inst();
if (const auto* arm = inst->as<assembly::arm::Instruction>()) {
const arm::OPCODE op = arm->opcode();
}
OPCODE
Definition arm/opcodes.hpp:23

◆ branch_target()

result< uint64_t > LIEF::assembly::Instruction::branch_target ( ) const

Given a is_branch() instruction, try to evaluate the address of the destination.

◆ is_add()

bool LIEF::assembly::Instruction::is_add ( ) const

True if the instruction performs an arithmetic addition.

◆ is_barrier()

bool LIEF::assembly::Instruction::is_barrier ( ) const

True if the instruction prevents executing the instruction that immediatly follows the current. This includes return or unconditional branch instructions.

◆ is_bitcast()

bool LIEF::assembly::Instruction::is_bitcast ( ) const

True if the instruction is doing a bitcast.

◆ is_branch()

bool LIEF::assembly::Instruction::is_branch ( ) const

True if the instruction is a branch.

◆ is_call()

bool LIEF::assembly::Instruction::is_call ( ) const

True if the instruction is a call.

◆ is_compare()

bool LIEF::assembly::Instruction::is_compare ( ) const

True if the instruction is a comparison.

◆ is_conditional_branch()

bool LIEF::assembly::Instruction::is_conditional_branch ( ) const

True if the instruction is conditionally jumping to the next instruction or an instruction into some other basic block.

◆ is_indirect_branch()

bool LIEF::assembly::Instruction::is_indirect_branch ( ) const

True if the instruction is and indirect branch.

This includes instructions that branch through a register (e.g. jmp rax, br x1).

◆ is_memory_access()

bool LIEF::assembly::Instruction::is_memory_access ( ) const

True if the instruction performs a memory access.

◆ is_move_immediate()

bool LIEF::assembly::Instruction::is_move_immediate ( ) const

True if the instruction is moving an immediate.

◆ is_move_reg()

bool LIEF::assembly::Instruction::is_move_reg ( ) const

True if the instruction is a register to register move.

◆ is_return()

bool LIEF::assembly::Instruction::is_return ( ) const

True if the instruction is a return.

◆ is_syscall()

bool LIEF::assembly::Instruction::is_syscall ( ) const

True if the instruction is a syscall.

◆ is_terminator()

bool LIEF::assembly::Instruction::is_terminator ( ) const

True if the instruction marks the end of a basic block.

◆ is_trap()

bool LIEF::assembly::Instruction::is_trap ( ) const

True if the instruction is a trap.

  • On x86/x86-64 this includes the ud1/ud2 instructions
  • On AArch64 this includes the brk/udf instructions

◆ is_unconditional_branch()

bool LIEF::assembly::Instruction::is_unconditional_branch ( ) const

True if the instruction is jumping (unconditionally) to some other basic block.

◆ mcinst()

const llvm::MCInst & LIEF::assembly::Instruction::mcinst ( ) const

Return the underlying llvm::MCInst implementation.

Warning
Because of ABI compatibility, this MCInst can only be used with the same version of LLVM used by LIEF.

◆ memory_access()

MemoryAccess LIEF::assembly::Instruction::memory_access ( ) const

Memory access flags.

◆ mnemonic()

std::string LIEF::assembly::Instruction::mnemonic ( ) const

Instruction mnemonic (e.g. br)

◆ raw()

const std::vector< uint8_t > & LIEF::assembly::Instruction::raw ( ) const

Raw bytes of the current instruction.

◆ size()

size_t LIEF::assembly::Instruction::size ( ) const

Size of the instruction in bytes.

◆ to_string()

std::string LIEF::assembly::Instruction::to_string ( bool with_address = true) const

Representation of the current instruction in a pretty assembly way.

Referenced by operator<<.


The documentation for this class was generated from the following file: