Mips

Instruction

class Instruction : public LIEF::assembly::Instruction

This class represents a Mips instruction (including mips64, mips32).

Public Types

using operands_it = iterator_range<Operand::Iterator>

Public Functions

OPCODE opcode() const

The instruction opcode as defined in LLVM.

operands_it operands() const

Iterator over the operands of the current instruction.

virtual ~Instruction() override = default

Public Static Functions

static bool classof(const assembly::Instruction *inst)

True if inst is an effective instance of mips::Instruction.

Opcodes

See LIEF::assembly::mips::OPCODE in include/asm/mips/opcodes.hpp

Operands

class Operand

This class represents an operand for a Mips instruction.

Subclassed by LIEF::assembly::mips::operands::Immediate, LIEF::assembly::mips::operands::Memory, LIEF::assembly::mips::operands::PCRelative, LIEF::assembly::mips::operands::Register

Public Functions

std::string to_string() const

Pretty representation of the operand.

template<class T>
inline const T *as() const

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

std::unique_ptr<assembly::mips::Operand> op = ...;
if (const auto* imm = inst->as<assembly::mips::operands::Immediate>()) {
  const int64_t value = imm->value();
}
virtual ~Operand()

Friends

inline friend std::ostream &operator<<(std::ostream &os, const Operand &op)
class Iterator : public LIEF::iterator_facade_base<Iterator, std::forward_iterator_tag, Operand, std::ptrdiff_t, const Operand*, const Operand&>

Forward iterator that lazily disassembles mips Operand.

Public Types

using implementation = details::OperandIt

Public Functions

Iterator()
Iterator(std::unique_ptr<details::OperandIt> impl)
Iterator(const Iterator&)
Iterator &operator=(const Iterator&)
Iterator(Iterator&&) noexcept
Iterator &operator=(Iterator&&) noexcept
~Iterator()
Iterator &operator++()
const Operand &operator*() const
const Operand *operator->() const
std::unique_ptr<Operand> yield()

Transfer ownership of the operand at the current position to the caller. Returns nullptr if the iterator is past-the-end.

inline DerivedT operator++(int)

Friends

friend bool operator==(const Iterator &LHS, const Iterator &RHS)
inline friend bool operator!=(const Iterator &LHS, const Iterator &RHS)

Immediate

class Immediate : public LIEF::assembly::mips::Operand

This class represents an immediate operand (i.e. a constant).

For instance:

addiu $4, $5, 8
              |
              +---> Immediate(8)

Public Functions

int64_t value() const

The constant value wrapped by this operand.

~Immediate() override = default

Public Static Functions

static bool classof(const Operand *op)

Register

class Register : public LIEF::assembly::mips::Operand

This class represents a register operand.

For instance:

move $4, $5
      |   |
      |   +---------> Register($5)
      |
      +-------------> Register($4)

Public Functions

REG value() const

The effective REG wrapped by this operand.

~Register() override = default

Public Static Functions

static bool classof(const Operand *op)

Memory

class Memory : public LIEF::assembly::mips::Operand

This class represents a memory operand.

MIPS has two addressing forms:

lw    $4, 8($5)            ldxc1  $f2, $4($7)
       |  | |                      |   |  |
+------+  | +---+          +-------+   |  +-----+
|         |     |          |           |        |
v         v     v          v           v        v
Reg      Disp  Base       Reg         Index    Base

Public Functions

REG base() const

The base register.

For lw $4, 8($5) it would return $5.

offset_t offset() const

The addressing offset.

It can be either:

  • A register (e.g. ldxc1 $f2, $4($7))

  • A displacement (e.g. lw $4, 8($5))

~Memory() override = default

Public Static Functions

static bool classof(const Operand *op)
struct offset_t

Wraps the memory offset as either an integer displacement or an index register.

Public Types

enum class TYPE

Enum type used to discriminate the anonymous union.

Values:

enumerator NONE = 0
enumerator REG

The union holds the REG attribute.

enumerator DISP

The union holds the displacement attribute (int64_t).

Public Members

REG reg

Register offset (index register).

int64_t displacement = 0

Integer offset.

union LIEF::assembly::mips::operands::Memory::offset_t::[anonymous] [anonymous]
TYPE type = TYPE::NONE

PCRelative

class PCRelative : public LIEF::assembly::mips::Operand

This class represents a PC-relative operand.

bal 0x100
    |
    v
 PC Relative operand

Public Functions

int64_t value() const

The effective value that is relative to the current pc register.

~PCRelative() override = default

Public Static Functions

static bool classof(const Operand *op)