dex++ 0.3.1
C++ and C API reference
Loading...
Searching...
No Matches
instruction.hpp File Reference
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <variant>
#include <vector>

Classes

struct  dex::InstructionBase
 Fields shared by every concrete instruction type. More...
 
struct  dex::NopInstruction
 nop (0x00). More...
 
struct  dex::InvalidInstruction
 An opcode the Dalvik format does not use (0x3e–0x43, 0x73, 0x79–0x7a, 0xe3–0xf9), as found in a damaged or deliberately broken method. More...
 
struct  dex::GotoInstruction
 goto, goto/16, goto/32 (0x28–0x2a). More...
 
struct  dex::IfInstruction
 if-eq . More...
 
struct  dex::IfZeroInstruction
 if-eqz . More...
 
struct  dex::SwitchCase
 A single case of a packed-switch / sparse-switch payload. More...
 
struct  dex::SwitchInstruction
 packed-switch, sparse-switch (0x2b–0x2c). More...
 
struct  dex::ReturnInstruction
 return-void, return, return-wide, return-object (0x0e–0x11). More...
 
struct  dex::ThrowInstruction
 throw (0x27). More...
 
struct  dex::MoveInstruction
 move, move-wide, move-object, move-result, move-exception (0x01–0x0d). More...
 
struct  dex::ConstInstruction
 const/4 . More...
 
struct  dex::ConstStringInstruction
 const-string, const-string/jumbo (0x1a–0x1b). More...
 
struct  dex::ConstClassInstruction
 const-class (0x1c). More...
 
struct  dex::ConstMethodHandleInstruction
 const-method-handle (0xfe): load a java.lang.invoke.MethodHandle. More...
 
struct  dex::ConstMethodTypeInstruction
 const-method-type (0xff): load a java.lang.invoke.MethodType. More...
 
struct  dex::TypeInstruction
 check-cast, instance-of, new-instance, new-array (0x1f–0x23). More...
 
struct  dex::FilledNewArrayInstruction
 filled-new-array, filled-new-array/range (0x24–0x25): build an array of type_index from the element registers, like an invoke's argument list. More...
 
struct  dex::MonitorInstruction
 monitor-enter, monitor-exit (0x1d–0x1e). More...
 
struct  dex::FillArrayInstruction
 fill-array-data (0x26). More...
 
struct  dex::CompareInstruction
 cmpl-float, cmpg-float, cmpl-double, cmpg-double, cmp-long (0x2d–0x31). More...
 
struct  dex::ArrayOpInstruction
 aget*, aput* (0x44–0x51). More...
 
struct  dex::FieldInstruction
 iget*, iput*, sget*, sput* (0x52–0x6d). More...
 
struct  dex::InvokeInstruction
 invoke-virtual/super/direct/static/interface and their /range variants (0x6e–0x72, 0x74–0x78). More...
 
struct  dex::InvokePolymorphicInstruction
 invoke-polymorphic, invoke-polymorphic/range (0xfa–0xfb): a call through a signature-polymorphic method such as MethodHandle.invokeExact. More...
 
struct  dex::InvokeCustomInstruction
 invoke-custom, invoke-custom/range (0xfc–0xfd). More...
 
struct  dex::ArrayLengthInstruction
 array-length (0x21): the length of the array in array_reg. More...
 
struct  dex::UnaryOpInstruction
 neg-int, not-int, int-to-long, long-to-int, etc. More...
 
struct  dex::BinaryOpInstruction
 add-int, sub-int, ..., rem-double/2addr (0x90–0xcf). More...
 
struct  dex::BinaryLitInstruction
 add-int/lit16, rsub-int, ..., ushr-int/lit8 (0xd0–0xe2). More...
 

Namespaces

namespace  dex
 

Typedefs

using dex::Instruction = std::variant< NopInstruction, GotoInstruction, IfInstruction, IfZeroInstruction, SwitchInstruction, ReturnInstruction, ThrowInstruction, MoveInstruction, ConstInstruction, ConstStringInstruction, ConstClassInstruction, ConstMethodHandleInstruction, ConstMethodTypeInstruction, TypeInstruction, FilledNewArrayInstruction, MonitorInstruction, FillArrayInstruction, CompareInstruction, ArrayOpInstruction, ArrayLengthInstruction, FieldInstruction, InvokeInstruction, InvokePolymorphicInstruction, InvokeCustomInstruction, UnaryOpInstruction, BinaryOpInstruction, BinaryLitInstruction, InvalidInstruction >
 A single decoded Dalvik instruction.
 

Enumerations

enum class  dex::OperandWidth : uint8_t { dex::Single , dex::Pair }
 Distinguishes 32-bit (single-register) from 64-bit (register-pair) operands. More...
 

Functions

const InstructionBase & dex::base_of (const Instruction &insn)
 Extract the common base fields without std::visit boilerplate.
 
bool dex::is_terminator (const Instruction &insn)
 Returns true for goto / if-* / switch / return / throw (basic block terminators).
 
std::string_view dex::opcode_name (uint8_t opcode)
 Mnemonic for a raw Dalvik opcode byte (e.g. 0x6e -> "invoke-virtual").
 
std::string dex::to_string (const Instruction &insn)
 Render one decoded instruction as "<mnemonic> <operands>" (no leading code offset).
 
std::vector< Instruction > dex::decode_instructions (std::span< const uint16_t > insns)
 Decode a raw insns[] array (16-bit code units) into typed instructions.