dex++ 0.3.1
C++ and C API reference
Loading...
Searching...
No Matches
dex Namespace Reference

Namespaces

namespace  apk
 APK-level entry point: package metadata that exists independently of the bytecode.
 
namespace  axml
 Parser for Android binary XML (AXML), the format of AndroidManifest.xml inside an APK.
 
namespace  model
 An editable, in-memory model of one DEX file.
 

Classes

class  AnalysisContext
 The entry point for analysis. More...
 
struct  Annotation
 A resolved annotation instance attached to a class, method, or field. More...
 
struct  AnnotationElement
 One name = value pair of an annotation. More...
 
struct  AnnotationValue
 A fully resolved annotation element value. More...
 
struct  ApkLoadOptions
 How an APK's DEX files are loaded by AnalysisContext::from_apk / from_apk_buffer and by apk::Apk::analysis. More...
 
struct  ArrayLengthInstruction
 array-length (0x21): the length of the array in array_reg. More...
 
struct  ArrayOpInstruction
 aget*, aput* (0x44–0x51). More...
 
struct  BasicBlock
 A maximal sequence of instructions with a single entry and a single normal exit. More...
 
struct  BinaryLitInstruction
 add-int/lit16, rsub-int, ..., ushr-int/lit8 (0xd0–0xe2). More...
 
struct  BinaryOpInstruction
 add-int, sub-int, ..., rem-double/2addr (0x90–0xcf). More...
 
struct  CallEdge
 A single call-site edge from one method to another. More...
 
class  CallGraph
 Whole-program call graph for an AnalysisContext. More...
 
struct  CallNode
 A node in the call graph: a defined method, an external method that defined code calls, or an invoke-custom call site (see CallNodeKind). More...
 
struct  CatchHandler
 One typed catch clause within a TryBlock. More...
 
class  Cfg
 Control-flow graph for a single method. More...
 
struct  CfgEdge
 A single outgoing edge from one basic block to another. More...
 
class  Class
 A lightweight handle to a single DEX class definition. More...
 
class  ClassHierarchy
 Whole-program inheritance and interface-implementation graph. More...
 
class  ClassRef
 A reference to a class by its type descriptor, which may or may not be defined in the loaded DEX files: the superclass, the interfaces and the declaring class of a member are ClassRefs, because they can name a class from outside the app, such as "Ljava/lang/Object;". More...
 
struct  CompareInstruction
 cmpl-float, cmpg-float, cmpl-double, cmpg-double, cmp-long (0x2d–0x31). More...
 
struct  ConstClassInstruction
 const-class (0x1c). More...
 
struct  ConstInstruction
 const/4 . More...
 
struct  ConstMethodHandleInstruction
 const-method-handle (0xfe): load a java.lang.invoke.MethodHandle. More...
 
struct  ConstMethodTypeInstruction
 const-method-type (0xff): load a java.lang.invoke.MethodType. More...
 
struct  ConstStringInstruction
 const-string, const-string/jumbo (0x1a–0x1b). More...
 
struct  Error
 Why a call failed. More...
 
class  Field
 A lightweight handle to a single DEX field. More...
 
struct  FieldAccess
 One field read or write in a method's body. More...
 
struct  FieldId
 Canonical, DEX-portable identity for a field reference. More...
 
struct  FieldIdHash
 Hash functor for FieldId; suitable for std::unordered_map / std::unordered_set. More...
 
struct  FieldInstruction
 iget*, iput*, sget*, sput* (0x52–0x6d). More...
 
struct  FieldXref
 One field-access instruction (iget* / iput* / sget* / sput*). More...
 
struct  FillArrayInstruction
 fill-array-data (0x26). More...
 
struct  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  GotoInstruction
 goto, goto/16, goto/32 (0x28–0x2a). More...
 
struct  IfInstruction
 if-eq . More...
 
struct  IfZeroInstruction
 if-eqz . More...
 
struct  InstructionBase
 Fields shared by every concrete instruction type. More...
 
struct  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  InvokeCustomInstruction
 invoke-custom, invoke-custom/range (0xfc–0xfd). More...
 
struct  InvokeInstruction
 invoke-virtual/super/direct/static/interface and their /range variants (0x6e–0x72, 0x74–0x78). More...
 
struct  InvokePolymorphicInstruction
 invoke-polymorphic, invoke-polymorphic/range (0xfa–0xfb): a call through a signature-polymorphic method such as MethodHandle.invokeExact. More...
 
class  Method
 A lightweight handle to a single DEX method. More...
 
struct  MethodCall
 One outgoing call site in a method's body. More...
 
struct  MethodId
 Canonical, DEX-portable identity for a method reference. More...
 
struct  MethodIdHash
 Hash functor for MethodId; suitable for std::unordered_map / std::unordered_set. More...
 
struct  MethodXref
 One invoke instruction referencing a method (by its declared target). More...
 
struct  MonitorInstruction
 monitor-enter, monitor-exit (0x1d–0x1e). More...
 
struct  MoveInstruction
 move, move-wide, move-object, move-result, move-exception (0x01–0x0d). More...
 
struct  NopInstruction
 nop (0x00). More...
 
struct  ParameterRegister
 An incoming parameter and the register that holds it on method entry. More...
 
struct  Problem
 One rule of the DEX format that a model breaks, and where. More...
 
struct  ReturnInstruction
 return-void, return, return-wide, return-object (0x0e–0x11). More...
 
struct  StringLoad
 One const-string load in a method's body. More...
 
struct  StringXref
 One string-loading instruction (const-string / const-string/jumbo). More...
 
struct  SwitchCase
 A single case of a packed-switch / sparse-switch payload. More...
 
struct  SwitchInstruction
 packed-switch, sparse-switch (0x2b–0x2c). More...
 
struct  ThrowInstruction
 throw (0x27). More...
 
struct  TryBlock
 A try region and its handlers, decoded from the method's code item. More...
 
struct  TypeInstruction
 check-cast, instance-of, new-instance, new-array (0x1f–0x23). More...
 
struct  TypeUse
 One type reference (const-class / check-cast / instance-of / new-instance / new-array / filled-new-array) in a method's body. More...
 
struct  TypeXref
 One type-referencing instruction (see TypeUseKind). More...
 
struct  UnaryOpInstruction
 neg-int, not-int, int-to-long, long-to-int, etc. More...
 
class  Xrefs
 Whole-program cross-reference index for an AnalysisContext. More...
 

Typedefs

using 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  AccessFlags : uint32_t {
  Public = 0x0001 , Private = 0x0002 , Protected = 0x0004 , Static = 0x0008 ,
  Final = 0x0010 , Synchronized = 0x0020 , Volatile = 0x0040 , Bridge = 0x0040 ,
  Transient = 0x0080 , Varargs = 0x0080 , Native = 0x0100 , Interface = 0x0200 ,
  Abstract = 0x0400 , Strict = 0x0800 , Synthetic = 0x1000 , Annotation = 0x2000 ,
  Enum = 0x4000 , Constructor = 0x10000 , DeclaredSynchronized = 0x20000
}
 Bitmask of DEX access flags, applicable to classes, methods, and fields. More...
 
enum class  AnnotationVisibility : uint8_t { Build = 0x00 , Runtime = 0x01 , System = 0x02 }
 Who can see an annotation at runtime, per the DEX visibility byte. More...
 
enum class  ErrorCode : uint8_t {
  FileNotFound , CannotRead , CannotWrite , InvalidApk ,
  InvalidDex , UnsupportedDex , InvalidModel , PoolOverflow ,
  VersionTooLow , InvalidXml , InvalidResources
}
 What went wrong in a call that failed. More...
 
enum class  InvokeKind : uint8_t {
  Virtual , Super , Direct , Static ,
  Interface , Polymorphic , Custom
}
 Kind of invoke instruction at a call site, derived from the opcode. More...
 
enum class  EdgeOrigin : uint8_t { Declared , InheritedResolution }
 How an edge came to point at its callee. More...
 
enum class  CallNodeKind : uint8_t { Defined , External , CallSite }
 What a call-graph node stands for. More...
 
enum class  CfgEdgeKind : uint8_t {
  Fallthrough , Goto , BranchTaken , BranchNotTaken ,
  SwitchCase , SwitchDefault , Exception , ExceptionCatchAll
}
 Kind of edge between two basic blocks. More...
 
enum class  OperandWidth : uint8_t { Single , Pair }
 Distinguishes 32-bit (single-register) from 64-bit (register-pair) operands. More...
 
enum class  TypeUseKind : uint8_t {
  ConstClass , CheckCast , InstanceOf , NewInstance ,
  NewArray , FilledNewArray
}
 What a type-referencing instruction does with its type operand. More...
 

Functions

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

Typedef Documentation

◆ Instruction

Enumeration Type Documentation

◆ AccessFlags

enum class dex::AccessFlags : uint32_t
strong

Bitmask of DEX access flags, applicable to classes, methods, and fields.

Values mirror the DEX specification (JVMS §4.1, §4.6, §4.7 extended by the Android runtime for Annotation, Enum, Constructor, and DeclaredSynchronized).

Enumerator
Public 
Private 
Protected 
Static 
Final 
Synchronized 
Volatile 

Fields only.

Bridge 

Methods only (same bit as Volatile).

Transient 

Fields only.

Varargs 

Methods only (same bit as Transient).

Native 
Interface 
Abstract 
Strict 
Synthetic 
Annotation 
Enum 
Constructor 
DeclaredSynchronized 

◆ AnnotationVisibility

enum class dex::AnnotationVisibility : uint8_t
strong

Who can see an annotation at runtime, per the DEX visibility byte.

Enumerator
Build 

Compile-time only (e.g. @Override); stripped semantics.

Runtime 

Visible to reflection (RetentionPolicy.RUNTIME).

System 

dalvik.annotation.* metadata (signatures, defaults, ...).

◆ ErrorCode

enum class dex::ErrorCode : uint8_t
strong

What went wrong in a call that failed.

Every function of the library that can fail returns a std::expected with an Error, and Error::code is one of these. The names match the exceptions of the Python binding (InvalidDex is InvalidDexError) and the error codes of the C API (InvalidDex is DEXPP_ERROR_INVALID_DEX).

Enumerator
FileNotFound 

The path does not exist.

CannotRead 

The path exists but cannot be read: a directory, no permission, an I/O error.

CannotWrite 

The file cannot be created or written: a missing folder, a directory, no permission, a full disk.

InvalidApk 

Not a ZIP archive, a damaged entry, or an APK with no classes.dex.

InvalidDex 

A DEX file that cannot be parsed.

UnsupportedDex 

A DEX file the editable model does not read: a DEX 041 container or a big-endian file.

InvalidModel 

A model breaks rules of the DEX format.

Error::problems lists every rule it breaks.

PoolOverflow 

Part of the DEX file to write would be bigger than the format can encode: a table with too many entries (more than 65535 types, for example), a method whose code is too long, or too many try ranges or exception handlers in one method.

VersionTooLow 

A model uses a feature that its DEX version does not have.

InvalidXml 

Not an Android binary XML document, or a damaged one (axml::parse).

InvalidResources 

Not a compiled resource table (resources.arsc), or a damaged one (apk::ResourceTable::parse).

◆ InvokeKind

enum class dex::InvokeKind : uint8_t
strong

Kind of invoke instruction at a call site, derived from the opcode.

Enumerator
Virtual 

invoke-virtual / invoke-virtual/range (0x6e, 0x74)

Super 

invoke-super / invoke-super/range (0x6f, 0x75)

Direct 

invoke-direct / invoke-direct/range (0x70, 0x76)

Static 

invoke-static / invoke-static/range (0x71, 0x77)

Interface 

invoke-interface / invoke-interface/range (0x72, 0x78)

Polymorphic 

invoke-polymorphic / invoke-polymorphic/range (0xfa, 0xfb)

Custom 

invoke-custom / invoke-custom/range (0xfc, 0xfd)

◆ EdgeOrigin

enum class dex::EdgeOrigin : uint8_t
strong

How an edge came to point at its callee.

Enumerator
Declared 

The invoke's literal declared target (the method_id in the bytecode).

Exactly one per call site.

InheritedResolution 

Upward resolution of the declared method_id: the declared class defines no matching method, and this edge points at the nearest definition a loaded ancestor (superclass chain, then superinterfaces) provides — what Dalvik resolution finds at runtime.

At most one per call site.

◆ CallNodeKind

enum class dex::CallNodeKind : uint8_t
strong

What a call-graph node stands for.

Enumerator
Defined 

A method defined in a loaded DEX file.

CallGraph::method_for() gives its Method.

External 

A method that loaded code calls but no loaded DEX file defines, such as a framework method.

CallSite 

An invoke-custom call site: the target is chosen at runtime by the call site's bootstrap method, so the node is the call site itself.

Its id is opaque: it only keeps call sites apart, does not name a method, and may change between versions.

◆ CfgEdgeKind

enum class dex::CfgEdgeKind : uint8_t
strong

Kind of edge between two basic blocks.

Enumerator
Fallthrough 

Straight-line continuation; only when the predecessor's last instruction is not a terminator.

Goto 

Unconditional goto / goto/16 / goto/32.

BranchTaken 

if-* / if-*z taken edge.

BranchNotTaken 

if-* / if-*z fall-through edge.

SwitchCase 

Outgoing edge for one packed/sparse case; CfgEdge::case_key is its key.

SwitchDefault 

Outgoing edge for switch fall-through (the "default" case).

Exception 

try-region → handler of one exception class; CfgEdge::catch_type names it.

ExceptionCatchAll 

try-region → handler that catches every exception (a catch-all, as Java compiles finally).

◆ OperandWidth

enum class dex::OperandWidth : uint8_t
strong

Distinguishes 32-bit (single-register) from 64-bit (register-pair) operands.

Enumerator
Single 

32-bit value — occupies 1 register

Pair 

64-bit value — occupies register pair (vN:vN+1)

◆ TypeUseKind

enum class dex::TypeUseKind : uint8_t
strong

What a type-referencing instruction does with its type operand.

Enumerator
ConstClass 

const-class (0x1c)

CheckCast 

check-cast (0x1f)

InstanceOf 

instance-of (0x20)

NewInstance 

new-instance (0x22)

NewArray 

new-array — descriptor is the array type, e.g. "[I" (0x23)

FilledNewArray 

filled-new-array / filled-new-array/range (0x24, 0x25)

Function Documentation

◆ operator|()

AccessFlags dex::operator| ( AccessFlags  a,
AccessFlags  b 
)
inline

◆ operator&()

AccessFlags dex::operator& ( AccessFlags  a,
AccessFlags  b 
)
inline

◆ has_flag()

bool dex::has_flag ( AccessFlags  flags,
AccessFlags  flag 
)
inline

Returns true if flag is set in flags.

◆ base_of()

const InstructionBase & dex::base_of ( const Instruction &  insn)
inline

Extract the common base fields without std::visit boilerplate.

◆ is_terminator()

bool dex::is_terminator ( const Instruction &  insn)

Returns true for goto / if-* / switch / return / throw (basic block terminators).

◆ opcode_name()

std::string_view dex::opcode_name ( uint8_t  opcode)

Mnemonic for a raw Dalvik opcode byte (e.g. 0x6e -> "invoke-virtual").

Unused / reserved opcodes return "unused-XX". Always a valid, static view.

◆ to_string()

std::string dex::to_string ( const Instruction &  insn)

Render one decoded instruction as "<mnemonic> <operands>" (no leading code offset).

Constant-pool operands appear as raw indices — string@N, type@N, method@N, field@N, proto@N, method_handle@N, site@N — because this function has no AnalysisContext to resolve them; use the analysis layer when you need resolved names.

◆ decode_instructions()

std::vector< Instruction > dex::decode_instructions ( std::span< const uint16_t >  insns)

Decode a raw insns[] array (16-bit code units) into typed instructions.

Payload pseudo-instructions (packed-switch/sparse-switch/fill-array-data data blocks) are detected and skipped — they do not appear in the result. An unused opcode becomes an InvalidInstruction one code unit long.

Parameters
insnsRaw code units from CodeItem::insns.
Returns
Vector of typed instructions in execution order.