dex++ 0.3.1
C++ and C API reference
Loading...
Searching...
No Matches
dexpp.h File Reference

C API for code analysis and APK metadata. More...

#include <stddef.h>
#include <stdint.h>

Classes

struct  DexppText
 A string constant of the analysed program. More...
 
struct  DexppMethodId
 The identity of a method: its class, name and prototype. More...
 
struct  DexppFieldId
 The identity of a field: its class, name and type. More...
 
struct  DexppValue
 An annotation element value, or the initial value of a static field. More...
 
struct  DexppAnnotationElement
 One name = value pair of an annotation. More...
 
struct  DexppAnnotation
 One annotation on a class, a method or a field. More...
 
struct  DexppParameterRegister
 An incoming argument and the register it arrives in. More...
 
struct  DexppMethodCall
 One call in a method's code. More...
 
struct  DexppFieldAccess
 One field read or write in a method's code. More...
 
struct  DexppStringLoad
 One const-string instruction in a method's code. More...
 
struct  DexppTypeUse
 One instruction in a method's code that names a type. More...
 
struct  DexppCatchHandler
 One typed catch clause of a try block. More...
 
struct  DexppTryBlock
 A range of code covered by exception handlers. More...
 
struct  DexppSwitchCase
 One case of a switch instruction. More...
 
struct  DexppInstruction
 One decoded instruction. More...
 
struct  DexppCfgEdge
 An edge from one basic block to another. More...
 
struct  DexppBasicBlock
 A run of instructions entered at its first and left at its last one. More...
 
struct  DexppCallNode
 A node of the call graph: a method, or an invoke-custom call site. More...
 
struct  DexppCallEdge
 One call-site edge. More...
 
struct  DexppMethodXref
 One invoke instruction that calls a method. More...
 
struct  DexppFieldXref
 One instruction that reads or writes a field. More...
 
struct  DexppStringXref
 One const-string instruction. More...
 
struct  DexppTypeXref
 One instruction that names a type. More...
 
struct  DexppMethodRefGroup
 The call sites of one method, as found by name. More...
 
struct  DexppIntentFilter
 An <intent-filter> of a component. More...
 
struct  DexppComponent
 An activity, service, receiver or provider declared in the manifest. More...
 
struct  DexppDeclaredPermission
 A permission the app declares. More...
 
struct  DexppManifest
 The decoded AndroidManifest.xml. More...
 
struct  DexppResourceName
 The full name of a resource: package:type/entry. More...
 
struct  DexppCertificate
 An X.509 certificate that signed the APK. More...
 
struct  DexppSigningInfo
 Which signature schemes the APK carries, and their certificates. More...
 

Typedefs

Handles
typedef struct DexppContext DexppContext
 The code of a program: one or more DEX files loaded together.
 
typedef struct DexppApk DexppApk
 An APK: archive, manifest, resources and signatures.
 
typedef struct DexppClass DexppClass
 A class defined in a loaded DEX file.
 
typedef struct DexppClassRef DexppClassRef
 A reference to a class by descriptor; the class may not be loaded.
 
typedef struct DexppMethod DexppMethod
 A method defined by a loaded class.
 
typedef struct DexppField DexppField
 A field declared by a loaded class.
 
typedef struct DexppCallGraph DexppCallGraph
 The whole-program call graph.
 
typedef struct DexppClassHierarchy DexppClassHierarchy
 The whole-program class hierarchy.
 
typedef struct DexppXrefs DexppXrefs
 The whole-program cross-reference index.
 

Functions

Loading and the analysis context
DexppContext * dexpp_context_from_dex (const char *path, DexppError **err)
 Load one DEX file.
 
DexppContext * dexpp_context_from_dex_files (const char *const *paths, size_t count, DexppError **err)
 Load several DEX files into one context, for example the unpacked files of a multidex app.
 
DexppContext * dexpp_context_from_apk (const char *path, uint32_t threads, DexppError **err)
 Load every top-level classes*.dex of an APK, in multidex order.
 
void dexpp_context_free (DexppContext *ctx)
 Free a context.
 
DexppClass ** dexpp_context_classes (const DexppContext *ctx, size_t *count)
 Every class of every loaded DEX file, in file order.
 
DexppClass * dexpp_context_find_class (const DexppContext *ctx, const char *descriptor)
 The class with this descriptor (e.g. "Lcom/example/Foo;"), or NULL when no loaded file defines it.
 
DexppText * dexpp_context_strings (const DexppContext *ctx, size_t *count)
 Every string of every loaded DEX file's string table, including names of classes and members.
 
DexppCallGraph * dexpp_context_call_graph (const DexppContext *ctx, DexppError **err)
 The call graph of the whole program, built on the first call and kept.
 
DexppClassHierarchy * dexpp_context_class_hierarchy (const DexppContext *ctx, DexppError **err)
 The class hierarchy of the whole program, built on the first call and kept.
 
DexppXrefs * dexpp_context_xrefs (const DexppContext *ctx, DexppError **err)
 The cross-reference index of the whole program, built on the first call and kept.
 
Classes and class references
char * dexpp_class_descriptor (const DexppClass *cls)
 The class descriptor, e.g. "Lcom/example/Foo;".
 
char * dexpp_class_package (const DexppClass *cls)
 The package in Java source form, with dots between its parts, e.g.
 
DexppClassRef * dexpp_class_superclass (const DexppClass *cls)
 The direct superclass, or NULL for java.lang.Object itself.
 
DexppClassRef ** dexpp_class_interfaces (const DexppClass *cls, size_t *count)
 The interfaces the class implements directly, in declaration order.
 
uint32_t dexpp_class_access_flags (const DexppClass *cls)
 The access flags (see DexppAccessFlag).
 
int dexpp_class_is_interface (const DexppClass *cls)
 1 when the class is an interface, otherwise 0.
 
int dexpp_class_is_abstract (const DexppClass *cls)
 1 when the class is abstract, otherwise 0.
 
char * dexpp_class_source_file (const DexppClass *cls)
 The source file name recorded for the class, or NULL.
 
DexppMethod ** dexpp_class_methods (const DexppClass *cls, size_t *count)
 The methods the class defines: direct methods first, then virtual ones.
 
DexppField ** dexpp_class_fields (const DexppClass *cls, size_t *count)
 The fields the class declares: static fields first, then instance fields.
 
DexppAnnotation * dexpp_class_annotations (const DexppClass *cls, size_t *count)
 The annotations on the class.
 
void dexpp_class_free (DexppClass *cls)
 Free a class handle.
 
void dexpp_class_array_free (DexppClass **classes, size_t count)
 Free an array of class handles and every handle in it.
 
char * dexpp_class_ref_descriptor (const DexppClassRef *ref)
 The descriptor the reference names.
 
int dexpp_class_ref_is_resolved (const DexppClassRef *ref)
 1 when the class is defined in a loaded DEX file, otherwise 0.
 
DexppClass * dexpp_class_ref_resolve (const DexppClassRef *ref)
 The referenced class, or NULL when no loaded file defines it.
 
void dexpp_class_ref_free (DexppClassRef *ref)
 Free a class reference.
 
void dexpp_class_ref_array_free (DexppClassRef **refs, size_t count)
 Free an array of class references and every reference in it.
 
Fields
char * dexpp_field_name (const DexppField *f)
 The field name.
 
DexppClassRef * dexpp_field_declaring_class (const DexppField *f)
 The class that declares the field.
 
char * dexpp_field_type (const DexppField *f)
 The field's type descriptor.
 
void dexpp_field_id (const DexppField *f, DexppFieldId *out)
 Fill out with the field's identity: its class, name and type (release with dexpp_field_id_clear()).
 
uint32_t dexpp_field_access_flags (const DexppField *f)
 The access flags (see DexppAccessFlag).
 
DexppAnnotation * dexpp_field_annotations (const DexppField *f, size_t *count)
 The annotations on the field.
 
int dexpp_field_initial_value (const DexppField *f, DexppValue *out)
 The constant a static field starts with.
 
void dexpp_field_free (DexppField *f)
 Free a field handle.
 
void dexpp_field_array_free (DexppField **fields, size_t count)
 Free an array of field handles and every handle in it.
 
Class hierarchy
char ** dexpp_class_hierarchy_supertypes (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 The direct superclass, then the directly implemented interfaces.
 
char * dexpp_class_hierarchy_superclass_of (const DexppClassHierarchy *h, const char *descriptor)
 The direct superclass, or NULL when none is recorded (java.lang.Object, a class outside the loaded files, or a descriptor the hierarchy does not know).
 
char ** dexpp_class_hierarchy_direct_interfaces (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 The interfaces implemented (or, for an interface, extended) directly.
 
char ** dexpp_class_hierarchy_subclasses (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 The classes that directly extend the class.
 
char ** dexpp_class_hierarchy_implementers (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 The classes that directly implement the interface.
 
char ** dexpp_class_hierarchy_all_supertypes (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 Every ancestor class and interface; the class itself is not included.
 
char ** dexpp_class_hierarchy_all_descendants (const DexppClassHierarchy *h, const char *descriptor, size_t *count)
 Everything below the class, through extends and implements; the class itself is not included.
 
int dexpp_class_hierarchy_is_subtype_of (const DexppClassHierarchy *h, const char *sub, const char *super)
 1 when sub is super or has it among its ancestors.
 
int dexpp_class_hierarchy_is_loaded (const DexppClassHierarchy *h, const char *descriptor)
 1 when the class is defined in a loaded file.
 
int dexpp_class_hierarchy_is_interface (const DexppClassHierarchy *h, const char *descriptor)
 1 when the class is loaded and is an interface.
 
int dexpp_class_hierarchy_empty (const DexppClassHierarchy *h)
 1 when the hierarchy has no classes.
 
void dexpp_class_hierarchy_free (DexppClassHierarchy *h)
 Free a class-hierarchy handle.
 

Errors

enum  DexppErrorCode {
  DEXPP_ERROR_FILE_NOT_FOUND = 1 , DEXPP_ERROR_CANNOT_READ = 2 , DEXPP_ERROR_CANNOT_WRITE = 3 , DEXPP_ERROR_INVALID_APK = 4 ,
  DEXPP_ERROR_INVALID_DEX = 5 , DEXPP_ERROR_UNSUPPORTED_DEX = 6 , DEXPP_ERROR_INVALID_MODEL = 7 , DEXPP_ERROR_POOL_OVERFLOW = 8 ,
  DEXPP_ERROR_VERSION_TOO_LOW = 9 , DEXPP_ERROR_MODEL = 10 , DEXPP_ERROR_INTERNAL = 11
}
 What went wrong in a failed call. More...
 
typedef enum DexppErrorCode DexppErrorCode
 What went wrong in a failed call.
 
typedef struct DexppError DexppError
 An error reported by a failed call.
 
DexppErrorCode dexpp_error_code (const DexppError *error)
 The kind of the error.
 
const char * dexpp_error_message (const DexppError *error)
 The error message.
 
size_t dexpp_error_problem_count (const DexppError *error)
 How many problems an error with code DEXPP_ERROR_INVALID_MODEL lists (0 for every other code).
 
const char * dexpp_error_problem_where (const DexppError *error, size_t index)
 Where problem index is, e.g. "Lcom/a/B;->run()V, item 12"; empty for a problem with the whole file.
 
const char * dexpp_error_problem_message (const DexppError *error, size_t index)
 What is wrong in problem index.
 
void dexpp_error_free (DexppError *error)
 Free an error.
 

Enums

enum  DexppAccessFlag {
  DEXPP_ACC_PUBLIC = 0x0001 , DEXPP_ACC_PRIVATE = 0x0002 , DEXPP_ACC_PROTECTED = 0x0004 , DEXPP_ACC_STATIC = 0x0008 ,
  DEXPP_ACC_FINAL = 0x0010 , DEXPP_ACC_SYNCHRONIZED = 0x0020 , DEXPP_ACC_VOLATILE = 0x0040 , DEXPP_ACC_BRIDGE = 0x0040 ,
  DEXPP_ACC_TRANSIENT = 0x0080 , DEXPP_ACC_VARARGS = 0x0080 , DEXPP_ACC_NATIVE = 0x0100 , DEXPP_ACC_INTERFACE = 0x0200 ,
  DEXPP_ACC_ABSTRACT = 0x0400 , DEXPP_ACC_STRICT = 0x0800 , DEXPP_ACC_SYNTHETIC = 0x1000 , DEXPP_ACC_ANNOTATION = 0x2000 ,
  DEXPP_ACC_ENUM = 0x4000 , DEXPP_ACC_CONSTRUCTOR = 0x10000 , DEXPP_ACC_DECLARED_SYNCHRONIZED = 0x20000
}
 Access flags of a class, a method or a field, as the DEX format stores them. More...
 
enum  DexppInvokeKind {
  DEXPP_INVOKE_VIRTUAL = 0 , DEXPP_INVOKE_SUPER = 1 , DEXPP_INVOKE_DIRECT = 2 , DEXPP_INVOKE_STATIC = 3 ,
  DEXPP_INVOKE_INTERFACE = 4 , DEXPP_INVOKE_POLYMORPHIC = 5 , DEXPP_INVOKE_CUSTOM = 6
}
 The kind of invoke instruction at a call site. More...
 
enum  DexppEdgeOrigin { DEXPP_EDGE_DECLARED = 0 , DEXPP_EDGE_INHERITED_RESOLUTION = 1 }
 How a call-graph edge came to point at its callee. More...
 
enum  DexppCallNodeKind { DEXPP_CALL_NODE_DEFINED = 0 , DEXPP_CALL_NODE_EXTERNAL = 1 , DEXPP_CALL_NODE_CALL_SITE = 2 }
 What a call-graph node stands for. More...
 
enum  DexppCfgEdgeKind {
  DEXPP_CFG_FALLTHROUGH = 0 , DEXPP_CFG_GOTO = 1 , DEXPP_CFG_BRANCH_TAKEN = 2 , DEXPP_CFG_BRANCH_NOT_TAKEN = 3 ,
  DEXPP_CFG_SWITCH_CASE = 4 , DEXPP_CFG_SWITCH_DEFAULT = 5 , DEXPP_CFG_EXCEPTION = 6 , DEXPP_CFG_EXCEPTION_CATCH_ALL = 7
}
 The kind of an edge between two basic blocks. More...
 
enum  DexppTypeUseKind {
  DEXPP_TYPE_USE_CONST_CLASS = 0 , DEXPP_TYPE_USE_CHECK_CAST = 1 , DEXPP_TYPE_USE_INSTANCE_OF = 2 , DEXPP_TYPE_USE_NEW_INSTANCE = 3 ,
  DEXPP_TYPE_USE_NEW_ARRAY = 4 , DEXPP_TYPE_USE_FILLED_NEW_ARRAY = 5
}
 What an instruction does with the type it names. More...
 
enum  DexppOperandWidth { DEXPP_WIDTH_SINGLE = 0 , DEXPP_WIDTH_PAIR = 1 }
 How many registers a value takes. More...
 
enum  DexppAnnotationVisibility { DEXPP_VISIBILITY_BUILD = 0 , DEXPP_VISIBILITY_RUNTIME = 1 , DEXPP_VISIBILITY_SYSTEM = 2 }
 Who can see an annotation. More...
 
enum  DexppMethodHandleKind {
  DEXPP_METHOD_HANDLE_STATIC_PUT = 0 , DEXPP_METHOD_HANDLE_STATIC_GET = 1 , DEXPP_METHOD_HANDLE_INSTANCE_PUT = 2 , DEXPP_METHOD_HANDLE_INSTANCE_GET = 3 ,
  DEXPP_METHOD_HANDLE_INVOKE_STATIC = 4 , DEXPP_METHOD_HANDLE_INVOKE_INSTANCE = 5 , DEXPP_METHOD_HANDLE_INVOKE_CONSTRUCTOR = 6 , DEXPP_METHOD_HANDLE_INVOKE_DIRECT = 7 ,
  DEXPP_METHOD_HANDLE_INVOKE_INTERFACE = 8
}
 What a method handle does: the method_handle_type codes of the DEX format. More...
 
enum  DexppComponentKind { DEXPP_COMPONENT_ACTIVITY = 0 , DEXPP_COMPONENT_SERVICE = 1 , DEXPP_COMPONENT_RECEIVER = 2 , DEXPP_COMPONENT_PROVIDER = 3 }
 The kind of a manifest component. More...
 
typedef enum DexppAccessFlag DexppAccessFlag
 Access flags of a class, a method or a field, as the DEX format stores them.
 
typedef enum DexppInvokeKind DexppInvokeKind
 The kind of invoke instruction at a call site.
 
typedef enum DexppEdgeOrigin DexppEdgeOrigin
 How a call-graph edge came to point at its callee.
 
typedef enum DexppCallNodeKind DexppCallNodeKind
 What a call-graph node stands for.
 
typedef enum DexppCfgEdgeKind DexppCfgEdgeKind
 The kind of an edge between two basic blocks.
 
typedef enum DexppTypeUseKind DexppTypeUseKind
 What an instruction does with the type it names.
 
typedef enum DexppOperandWidth DexppOperandWidth
 How many registers a value takes.
 
typedef enum DexppAnnotationVisibility DexppAnnotationVisibility
 Who can see an annotation.
 
typedef enum DexppMethodHandleKind DexppMethodHandleKind
 What a method handle does: the method_handle_type codes of the DEX format.
 
typedef enum DexppComponentKind DexppComponentKind
 The kind of a manifest component.
 

Annotations and values

enum  DexppValueKind {
  DEXPP_VALUE_NULL = 0 , DEXPP_VALUE_BOOL = 1 , DEXPP_VALUE_INT = 2 , DEXPP_VALUE_FLOAT = 3 ,
  DEXPP_VALUE_STRING = 4 , DEXPP_VALUE_TYPE = 5 , DEXPP_VALUE_ENUM = 6 , DEXPP_VALUE_FIELD = 7 ,
  DEXPP_VALUE_METHOD = 8 , DEXPP_VALUE_METHOD_TYPE = 9 , DEXPP_VALUE_METHOD_HANDLE = 10 , DEXPP_VALUE_ARRAY = 11 ,
  DEXPP_VALUE_ANNOTATION = 12
}
 The kind of a DexppValue. More...
 
typedef enum DexppValueKind DexppValueKind
 The kind of a DexppValue.
 
typedef struct DexppValue DexppValue
 An annotation element value, or the initial value of a static field.
 
typedef struct DexppAnnotationElement DexppAnnotationElement
 One name = value pair of an annotation.
 
typedef struct DexppAnnotation DexppAnnotation
 One annotation on a class, a method or a field.
 
void dexpp_value_clear (DexppValue *value)
 Free everything a DexppValue owns and reset it to a NULL value.
 
void dexpp_annotation_array_free (DexppAnnotation *annotations, size_t count)
 Free an array of annotations and everything they own.
 

Instructions

enum  DexppInstructionKind {
  DEXPP_INSN_NOP = 0 , DEXPP_INSN_GOTO = 1 , DEXPP_INSN_IF = 2 , DEXPP_INSN_IF_ZERO = 3 ,
  DEXPP_INSN_SWITCH = 4 , DEXPP_INSN_RETURN = 5 , DEXPP_INSN_THROW = 6 , DEXPP_INSN_MOVE = 7 ,
  DEXPP_INSN_CONST = 8 , DEXPP_INSN_CONST_STRING = 9 , DEXPP_INSN_CONST_CLASS = 10 , DEXPP_INSN_CONST_METHOD_HANDLE = 11 ,
  DEXPP_INSN_TYPE = 12 , DEXPP_INSN_FILLED_NEW_ARRAY = 13 , DEXPP_INSN_MONITOR = 14 , DEXPP_INSN_FILL_ARRAY = 15 ,
  DEXPP_INSN_COMPARE = 16 , DEXPP_INSN_ARRAY_OP = 17 , DEXPP_INSN_FIELD = 18 , DEXPP_INSN_INVOKE = 19 ,
  DEXPP_INSN_INVOKE_CUSTOM = 20 , DEXPP_INSN_UNARY_OP = 21 , DEXPP_INSN_BINARY_OP = 22 , DEXPP_INSN_BINARY_LIT = 23 ,
  DEXPP_INSN_CONST_METHOD_TYPE = 24 , DEXPP_INSN_INVOKE_POLYMORPHIC = 25 , DEXPP_INSN_ARRAY_LENGTH = 26 , DEXPP_INSN_INVALID = 27
}
 The kind of a decoded instruction: one per instruction family, the same families as the C++ and Python APIs. More...
 
typedef enum DexppInstructionKind DexppInstructionKind
 The kind of a decoded instruction: one per instruction family, the same families as the C++ and Python APIs.
 
typedef struct DexppSwitchCase DexppSwitchCase
 One case of a switch instruction.
 
typedef struct DexppInstruction DexppInstruction
 One decoded instruction.
 
DexppInstruction * dexpp_method_instructions (const DexppMethod *m, size_t *count)
 The decoded bytecode of a method, in order.
 
void dexpp_instruction_array_free (DexppInstruction *insns, size_t count)
 Free an array of instructions.
 
const char * dexpp_opcode_name (uint8_t opcode)
 The name of a Dalvik opcode byte, such as "invoke-virtual".
 
char * dexpp_instruction_to_string (const DexppInstruction *insn)
 One instruction as text: the opcode name, then its operands, with pool operands as raw indices (string@12).
 

Memory

typedef struct DexppText DexppText
 A string constant of the analysed program.
 
void dexpp_string_free (char *s)
 Free a string returned by any dexpp function.
 
void dexpp_string_array_free (char **strings, size_t count)
 Free an array of strings and every string in it.
 
void dexpp_text_clear (DexppText *text)
 Free the bytes of one DexppText and set its members to NULL and 0.
 
void dexpp_text_array_free (DexppText *texts, size_t count)
 Free an array of DexppText and every text in it.
 
void dexpp_buffer_free (uint8_t *buffer)
 Free a byte buffer returned by dexpp_apk_read() or dexpp_model_write().
 
void dexpp_index_array_free (uint32_t *indices, size_t count)
 Free an array of indices (node, edge or block numbers).
 

Identities

typedef struct DexppMethodId DexppMethodId
 The identity of a method: its class, name and prototype.
 
typedef struct DexppFieldId DexppFieldId
 The identity of a field: its class, name and type.
 
void dexpp_method_id_clear (DexppMethodId *id)
 Free the strings of one DexppMethodId and set them to NULL.
 
void dexpp_field_id_clear (DexppFieldId *id)
 Free the strings of one DexppFieldId and set them to NULL.
 
void dexpp_method_id_array_free (DexppMethodId *ids, size_t count)
 Free an array of DexppMethodId.
 

Methods

typedef struct DexppParameterRegister DexppParameterRegister
 An incoming argument and the register it arrives in.
 
typedef struct DexppMethodCall DexppMethodCall
 One call in a method's code.
 
typedef struct DexppFieldAccess DexppFieldAccess
 One field read or write in a method's code.
 
typedef struct DexppStringLoad DexppStringLoad
 One const-string instruction in a method's code.
 
typedef struct DexppTypeUse DexppTypeUse
 One instruction in a method's code that names a type.
 
typedef struct DexppCatchHandler DexppCatchHandler
 One typed catch clause of a try block.
 
typedef struct DexppTryBlock DexppTryBlock
 A range of code covered by exception handlers.
 
char * dexpp_method_name (const DexppMethod *m)
 The method name.
 
char * dexpp_method_proto (const DexppMethod *m)
 The prototype: the parameter types inside parentheses, then the return type, e.g. "(Ljava/lang/String;I)V".
 
DexppClassRef * dexpp_method_declaring_class (const DexppMethod *m)
 The class that defines the method.
 
void dexpp_method_id (const DexppMethod *m, DexppMethodId *out)
 Fill out with the method's identity: its class, name and prototype (release with dexpp_method_id_clear()).
 
char * dexpp_method_return_type (const DexppMethod *m)
 The return type descriptor; "V" for void.
 
char ** dexpp_method_parameters (const DexppMethod *m, size_t *count)
 The declared parameter types, in order (this is not included).
 
uint32_t dexpp_method_access_flags (const DexppMethod *m)
 The access flags (see DexppAccessFlag).
 
int dexpp_method_has_code (const DexppMethod *m)
 1 when the method has bytecode (it is neither abstract nor native).
 
int dexpp_method_is_static (const DexppMethod *m)
 1 when the method is static.
 
int dexpp_method_is_constructor (const DexppMethod *m)
 1 for <init> and <clinit>.
 
uint16_t dexpp_method_register_count (const DexppMethod *m)
 The number of registers in the method's frame; 0 without code.
 
DexppParameterRegister * dexpp_method_parameter_registers (const DexppMethod *m, size_t *count)
 The incoming arguments and their registers, this first for an instance method.
 
DexppMethodCall * dexpp_method_calls (const DexppMethod *m, size_t *count)
 Every call in the method's code, in order.
 
DexppFieldAccess * dexpp_method_field_accesses (const DexppMethod *m, size_t *count)
 Every field read and write in the method's code, in order.
 
DexppStringLoad * dexpp_method_string_loads (const DexppMethod *m, size_t *count)
 Every const-string in the method's code, in order.
 
DexppTypeUse * dexpp_method_type_uses (const DexppMethod *m, size_t *count)
 Every instruction that names a type, in order.
 
DexppTryBlock * dexpp_method_try_blocks (const DexppMethod *m, size_t *count)
 The try blocks and their handlers.
 
DexppAnnotation * dexpp_method_annotations (const DexppMethod *m, size_t *count)
 The annotations on the method.
 
void dexpp_method_free (DexppMethod *m)
 Free a method handle.
 
void dexpp_method_array_free (DexppMethod **methods, size_t count)
 Free an array of method handles and every handle in it.
 
void dexpp_parameter_register_array_free (DexppParameterRegister *regs, size_t count)
 Free an array of DexppParameterRegister.
 
void dexpp_method_call_array_free (DexppMethodCall *calls, size_t count)
 Free an array of DexppMethodCall.
 
void dexpp_field_access_array_free (DexppFieldAccess *accesses, size_t count)
 Free an array of DexppFieldAccess.
 
void dexpp_string_load_array_free (DexppStringLoad *loads, size_t count)
 Free an array of DexppStringLoad.
 
void dexpp_type_use_array_free (DexppTypeUse *uses, size_t count)
 Free an array of DexppTypeUse.
 
void dexpp_try_block_array_free (DexppTryBlock *blocks, size_t count)
 Free an array of DexppTryBlock and their handlers.
 

Control-flow graph

typedef struct DexppCfgEdge DexppCfgEdge
 An edge from one basic block to another.
 
typedef struct DexppBasicBlock DexppBasicBlock
 A run of instructions entered at its first and left at its last one.
 
DexppBasicBlock * dexpp_method_cfg (const DexppMethod *m, size_t *count)
 The method's control-flow graph: blocks ordered by offset, block 0 is the entry.
 
void dexpp_basic_block_array_free (DexppBasicBlock *blocks, size_t count)
 Free an array of basic blocks and the edges they own.
 

Call graph

typedef struct DexppCallNode DexppCallNode
 A node of the call graph: a method, or an invoke-custom call site.
 
typedef struct DexppCallEdge DexppCallEdge
 One call-site edge.
 
size_t dexpp_call_graph_node_count (const DexppCallGraph *g)
 Number of nodes.
 
size_t dexpp_call_graph_edge_count (const DexppCallGraph *g)
 Number of edges.
 
DexppCallNode * dexpp_call_graph_nodes (const DexppCallGraph *g, size_t *count)
 Every node, in index order.
 
int dexpp_call_graph_node (const DexppCallGraph *g, uint32_t node, DexppCallNode *out)
 Fill out with node node (release with dexpp_call_node_clear()).
 
DexppCallEdge * dexpp_call_graph_edges (const DexppCallGraph *g, size_t *count)
 Every edge, in index order.
 
int dexpp_call_graph_edge (const DexppCallGraph *g, uint32_t edge, DexppCallEdge *out)
 Fill out with edge edge.
 
int64_t dexpp_call_graph_find (const DexppCallGraph *g, const char *class_descriptor, const char *name, const char *proto)
 The index of the node with this identity, or -1 when the graph has none.
 
uint32_t * dexpp_call_graph_out_edges (const DexppCallGraph *g, uint32_t node, size_t *count)
 Indices of the edges that leave node node (its call sites).
 
uint32_t * dexpp_call_graph_in_edges (const DexppCallGraph *g, uint32_t node, size_t *count)
 Indices of the edges that enter node node (the calls into it).
 
uint32_t * dexpp_call_graph_dispatch_targets (const DexppCallGraph *g, uint32_t node, size_t *count)
 Nodes a virtual or interface call declared against node may dispatch to, besides itself and its own resolution.
 
uint32_t * dexpp_call_graph_dispatch_sources (const DexppCallGraph *g, uint32_t node, size_t *count)
 The reverse of dexpp_call_graph_dispatch_targets().
 
uint32_t * dexpp_call_graph_callees (const DexppCallGraph *g, uint32_t node, size_t *count)
 Every node node may call, dispatch targets included; no duplicates.
 
uint32_t * dexpp_call_graph_callers (const DexppCallGraph *g, uint32_t node, size_t *count)
 Every node that may call node, through dispatch included.
 
uint32_t * dexpp_call_graph_edge_dispatch_targets (const DexppCallGraph *g, uint32_t edge, size_t *count)
 The dispatch targets that apply at edge edge: those of its callee for a DECLARED virtual or interface edge, none for every other edge.
 
uint32_t * dexpp_call_graph_edges_where (const DexppCallGraph *g, int origin, int kind, size_t *count)
 Indices of the edges that match both filters.
 
DexppMethod * dexpp_call_graph_method_for (const DexppCallGraph *g, uint32_t node)
 The method behind a DEFINED node, or NULL for an EXTERNAL or CALL_SITE node or an index out of range.
 
void dexpp_call_graph_free (DexppCallGraph *g)
 Free a call-graph handle.
 
void dexpp_call_node_clear (DexppCallNode *node)
 Free the strings of one DexppCallNode.
 
void dexpp_call_node_array_free (DexppCallNode *nodes, size_t count)
 Free an array of DexppCallNode.
 
void dexpp_call_edge_array_free (DexppCallEdge *edges, size_t count)
 Free an array of DexppCallEdge.
 

Cross-references

typedef struct DexppMethodXref DexppMethodXref
 One invoke instruction that calls a method.
 
typedef struct DexppFieldXref DexppFieldXref
 One instruction that reads or writes a field.
 
typedef struct DexppStringXref DexppStringXref
 One const-string instruction.
 
typedef struct DexppTypeXref DexppTypeXref
 One instruction that names a type.
 
typedef struct DexppMethodRefGroup DexppMethodRefGroup
 The call sites of one method, as found by name.
 
size_t dexpp_xrefs_referrer_count (const DexppXrefs *x)
 Number of referrers: methods that contain an indexed instruction.
 
DexppMethodId * dexpp_xrefs_referrers (const DexppXrefs *x, size_t *count)
 The identity of every referrer, in index order.
 
int dexpp_xrefs_referrer_id (const DexppXrefs *x, uint32_t referrer, DexppMethodId *out)
 Fill out with the identity of one referrer (release with dexpp_method_id_clear()).
 
DexppMethod * dexpp_xrefs_referrer_method (const DexppXrefs *x, uint32_t referrer)
 The method of one referrer, or NULL when referrer is out of range.
 
DexppMethodXref * dexpp_xrefs_method_refs (const DexppXrefs *x, const char *class_descriptor, const char *name, const char *proto, size_t *count)
 The call sites whose target, as the bytecode names it, is exactly this method.
 
DexppMethodRefGroup * dexpp_xrefs_method_refs_by_name (const DexppXrefs *x, const char *name, size_t *count)
 The call sites of every method with this name, in any class and with any prototype, grouped by called method.
 
DexppFieldXref * dexpp_xrefs_field_refs (const DexppXrefs *x, const char *class_descriptor, const char *name, const char *type, size_t *count)
 Every read and write of this field.
 
DexppFieldXref * dexpp_xrefs_field_reads (const DexppXrefs *x, const char *class_descriptor, const char *name, const char *type, size_t *count)
 Only the reads of this field.
 
DexppFieldXref * dexpp_xrefs_field_writes (const DexppXrefs *x, const char *class_descriptor, const char *name, const char *type, size_t *count)
 Only the writes of this field.
 
DexppStringXref * dexpp_xrefs_string_refs (const DexppXrefs *x, const char *value, size_t length, size_t *count)
 The const-string instructions that load exactly this string, given as length bytes (it may contain NUL bytes).
 
DexppText * dexpp_xrefs_referenced_strings (const DexppXrefs *x, size_t *count)
 Every distinct string that some const-string instruction loads.
 
DexppTypeXref * dexpp_xrefs_type_refs (const DexppXrefs *x, const char *descriptor, size_t *count)
 The instructions that name this type.
 
int dexpp_xrefs_empty (const DexppXrefs *x)
 1 when nothing is indexed.
 
void dexpp_xrefs_free (DexppXrefs *x)
 Free a cross-reference handle.
 
void dexpp_method_xref_array_free (DexppMethodXref *xrefs, size_t count)
 Free an array of DexppMethodXref.
 
void dexpp_method_ref_group_array_free (DexppMethodRefGroup *groups, size_t count)
 Free an array of DexppMethodRefGroup and their sites.
 
void dexpp_field_xref_array_free (DexppFieldXref *xrefs, size_t count)
 Free an array of DexppFieldXref.
 
void dexpp_string_xref_array_free (DexppStringXref *xrefs, size_t count)
 Free an array of DexppStringXref.
 
void dexpp_type_xref_array_free (DexppTypeXref *xrefs, size_t count)
 Free an array of DexppTypeXref.
 

APK, manifest, resources and signing

typedef struct DexppIntentFilter DexppIntentFilter
 An <intent-filter> of a component.
 
typedef struct DexppComponent DexppComponent
 An activity, service, receiver or provider declared in the manifest.
 
typedef struct DexppDeclaredPermission DexppDeclaredPermission
 A permission the app declares.
 
typedef struct DexppManifest DexppManifest
 The decoded AndroidManifest.xml.
 
typedef struct DexppResourceName DexppResourceName
 The full name of a resource: package:type/entry.
 
typedef struct DexppCertificate DexppCertificate
 An X.509 certificate that signed the APK.
 
typedef struct DexppSigningInfo DexppSigningInfo
 Which signature schemes the APK carries, and their certificates.
 
DexppApk * dexpp_apk_open (const char *path, DexppError **err)
 Open an APK file.
 
DexppApk * dexpp_apk_open_buffer (const uint8_t *bytes, size_t len, const char *label, DexppError **err)
 Open an APK from its bytes in memory, for example bytes received over the network.
 
void dexpp_apk_free (DexppApk *apk)
 Free an APK handle.
 
char ** dexpp_apk_entries (const DexppApk *apk, size_t *count)
 The name of every archive entry.
 
int dexpp_apk_read (const DexppApk *apk, const char *name, uint8_t **out, size_t *length)
 The uncompressed bytes of the entry name.
 
char * dexpp_apk_package (const DexppApk *apk)
 The manifest's package name, or NULL when there is no decodable manifest.
 
int dexpp_apk_manifest (const DexppApk *apk, DexppManifest *out)
 Fill out with the decoded manifest.
 
void dexpp_manifest_clear (DexppManifest *manifest)
 Free everything a DexppManifest owns.
 
int dexpp_apk_has_resources (const DexppApk *apk)
 1 when the APK has a decodable resources.arsc table.
 
int dexpp_apk_resources_empty (const DexppApk *apk)
 1 when the APK has no resource table, or the table has no entries.
 
int dexpp_apk_resource_name (const DexppApk *apk, uint32_t id, DexppResourceName *out)
 Fill out with the name of resource id (release with dexpp_resource_name_clear()).
 
void dexpp_resource_name_clear (DexppResourceName *name)
 Free the strings of a DexppResourceName.
 
int dexpp_apk_resolve_string (const DexppApk *apk, uint32_t id, DexppText *out)
 The value of string resource id: returns 1 and fills out (release with dexpp_text_clear()); returns 0 when the id is missing or its value is not a string.
 
int dexpp_apk_resolve_bool (const DexppApk *apk, uint32_t id, int *out)
 The value of resource id as a boolean: a bool resource, or any integer-typed value (nonzero is true), as Android reads it.
 
int dexpp_apk_resolve_int (const DexppApk *apk, uint32_t id, int64_t *out)
 The value of resource id as an integer: an integer resource, or any other integer-typed value, read as its signed 32-bit data.
 
int dexpp_apk_resource_id (const DexppApk *apk, const char *type, const char *entry, uint32_t *out)
 The id of the resource with this type and entry name.
 
void dexpp_apk_signing (const DexppApk *apk, DexppSigningInfo *out)
 Fill out with the signature schemes and certificates (release with dexpp_signing_info_clear()).
 
void dexpp_signing_info_clear (DexppSigningInfo *info)
 Free everything a DexppSigningInfo owns.
 
DexppContext * dexpp_apk_analysis (const DexppApk *apk, uint32_t threads, DexppError **err)
 A code-analysis context over every classes*.dex of the APK, in multidex order, loaded from the bytes the APK handle already holds.
 

Detailed Description

C API for code analysis and APK metadata.

This is the interop boundary for programs that cannot call C++ directly (Go through cgo, and other languages with a C foreign-function interface). It covers what the Python binding covers: loading, classes, methods and fields, decoded bytecode, control-flow graphs, try blocks, annotations, the call graph, the class hierarchy, cross-references, the manifest, resources, archive entries and signing. The editable model is in dexpp_model.h.

Conventions, the same for every function:

  • Errors. A function that can fail takes a DexppError **err as its last argument. On failure it returns NULL (or 0) and, when err is not NULL, sets *err to a new error object. On success it sets *err to NULL. So the caller can always pass the result to dexpp_error_free(), which accepts NULL. err may be NULL when the caller does not want the details.
  • Handles (DexppContext, DexppApk, DexppClass, DexppClassRef, DexppMethod, DexppField, DexppCallGraph, DexppClassHierarchy, DexppXrefs) are opaque pointers. Free each one with its _free function. Every handle keeps the analysis it came from alive, so it stays valid after the context or APK handle it came from is freed. A handle must not be NULL when it is passed to a function, unless the function says so.
  • Strings are UTF-8, returned as malloc'd copies; free them with dexpp_string_free(). String constants of the analysed program can hold NUL bytes, so they come back as DexppText, which carries its length.
  • Arrays come with a count in *count. An empty array is returned as NULL with *count set to 0. Free an array with the _array_free function named for its type; it frees everything the elements own, and accepts NULL. An array of handles is one block from malloc(): a caller that keeps the handles, to free each one later with its _free function, frees the block alone with the array's _array_free function and a count of 0. free() also works when the library is linked statically, but not across the boundary of a Windows DLL, where the library and the caller can use different C runtimes.
  • Structs filled through an out-pointer own malloc'd members; release them with the matching _clear function, which frees the members (not the struct) and sets them to NULL.
  • Thread safety. Reading from one analysis on several threads at once is safe, as in C++. A single handle must not be freed while another thread uses it.

Typedef Documentation

◆ DexppErrorCode

What went wrong in a failed call.

The names match the Python exceptions.

◆ DexppError

typedef struct DexppError DexppError

An error reported by a failed call.

Free it with dexpp_error_free().

◆ DexppText

typedef struct DexppText DexppText

A string constant of the analysed program.

data is malloc'd and also NUL-terminated, but the string itself may contain NUL bytes: length is the number of bytes.

◆ DexppAccessFlag

Access flags of a class, a method or a field, as the DEX format stores them.

Two pairs share a bit: VOLATILE/BRIDGE and TRANSIENT/VARARGS.

◆ DexppInvokeKind

The kind of invoke instruction at a call site.

◆ DexppEdgeOrigin

How a call-graph edge came to point at its callee.

◆ DexppCallNodeKind

What a call-graph node stands for.

◆ DexppCfgEdgeKind

The kind of an edge between two basic blocks.

◆ DexppTypeUseKind

What an instruction does with the type it names.

◆ DexppOperandWidth

How many registers a value takes.

◆ DexppAnnotationVisibility

Who can see an annotation.

◆ DexppMethodHandleKind

What a method handle does: the method_handle_type codes of the DEX format.

The four field kinds read or write a field; the five invoke kinds call a method.

◆ DexppComponentKind

The kind of a manifest component.

◆ DexppMethodId

typedef struct DexppMethodId DexppMethodId

The identity of a method: its class, name and prototype.

The members are malloc'd strings owned by the struct or array that holds it.

◆ DexppFieldId

typedef struct DexppFieldId DexppFieldId

The identity of a field: its class, name and type.

◆ DexppContext

typedef struct DexppContext DexppContext

The code of a program: one or more DEX files loaded together.

◆ DexppApk

typedef struct DexppApk DexppApk

An APK: archive, manifest, resources and signatures.

◆ DexppClass

typedef struct DexppClass DexppClass

A class defined in a loaded DEX file.

◆ DexppClassRef

typedef struct DexppClassRef DexppClassRef

A reference to a class by descriptor; the class may not be loaded.

◆ DexppMethod

typedef struct DexppMethod DexppMethod

A method defined by a loaded class.

◆ DexppField

typedef struct DexppField DexppField

A field declared by a loaded class.

◆ DexppCallGraph

The whole-program call graph.

◆ DexppClassHierarchy

The whole-program class hierarchy.

◆ DexppXrefs

typedef struct DexppXrefs DexppXrefs

The whole-program cross-reference index.

◆ DexppValueKind

The kind of a DexppValue.

◆ DexppValue

typedef struct DexppValue DexppValue

An annotation element value, or the initial value of a static field.

Only the members named by kind are set; the others are 0 or NULL.

◆ DexppAnnotationElement

One name = value pair of an annotation.

◆ DexppAnnotation

One annotation on a class, a method or a field.

Elements left at their default value are not listed.

◆ DexppParameterRegister

An incoming argument and the register it arrives in.

◆ DexppMethodCall

One call in a method's code.

◆ DexppFieldAccess

One field read or write in a method's code.

◆ DexppStringLoad

One const-string instruction in a method's code.

◆ DexppTypeUse

typedef struct DexppTypeUse DexppTypeUse

One instruction in a method's code that names a type.

◆ DexppCatchHandler

One typed catch clause of a try block.

◆ DexppTryBlock

typedef struct DexppTryBlock DexppTryBlock

A range of code covered by exception handlers.

◆ DexppInstructionKind

The kind of a decoded instruction: one per instruction family, the same families as the C++ and Python APIs.

◆ DexppSwitchCase

One case of a switch instruction.

◆ DexppInstruction

One decoded instruction.

offset, opcode and size are set for every kind; the other members only for the kinds DexppInstructionKind lists for them, and are 0 or NULL otherwise. Offsets are in 16-bit code units. Pool indices (string_index, type_index, ...) are raw indices into the DEX file's tables; dexpp_method_calls() and the other reference functions give resolved names.

◆ DexppCfgEdge

typedef struct DexppCfgEdge DexppCfgEdge

An edge from one basic block to another.

◆ DexppBasicBlock

A run of instructions entered at its first and left at its last one.

◆ DexppCallNode

typedef struct DexppCallNode DexppCallNode

A node of the call graph: a method, or an invoke-custom call site.

◆ DexppCallEdge

typedef struct DexppCallEdge DexppCallEdge

One call-site edge.

A call site has one DECLARED edge, and an INHERITED_RESOLUTION edge when the named class does not define the method itself.

◆ DexppMethodXref

One invoke instruction that calls a method.

referrer is an index into dexpp_xrefs_referrers().

◆ DexppFieldXref

One instruction that reads or writes a field.

◆ DexppStringXref

One const-string instruction.

◆ DexppTypeXref

typedef struct DexppTypeXref DexppTypeXref

One instruction that names a type.

◆ DexppMethodRefGroup

The call sites of one method, as found by name.

◆ DexppIntentFilter

An <intent-filter> of a component.

◆ DexppComponent

An activity, service, receiver or provider declared in the manifest.

◆ DexppDeclaredPermission

A permission the app declares.

◆ DexppManifest

typedef struct DexppManifest DexppManifest

The decoded AndroidManifest.xml.

Release with dexpp_manifest_clear().

A boolean or integer attribute may be written as a resource reference, such as android:debuggable="@bool/debug". The value is then the one the APK's resource table gives, in its default configuration, and the matching *_reference member holds the reference id. When the reference cannot be resolved, the value reads as absent (has_* is 0, or -1) while the *_reference member still holds the id: the attribute is set, but its value is unknown. A *_reference member is 0 for a plain value or a missing attribute.

◆ DexppResourceName

The full name of a resource: package:type/entry.

Release with dexpp_resource_name_clear().

◆ DexppCertificate

An X.509 certificate that signed the APK.

◆ DexppSigningInfo

Which signature schemes the APK carries, and their certificates.

The signatures are not verified. Release with dexpp_signing_info_clear().

Enumeration Type Documentation

◆ DexppErrorCode

What went wrong in a failed call.

The names match the Python exceptions.

Enumerator
DEXPP_ERROR_FILE_NOT_FOUND 

The path does not exist.

DEXPP_ERROR_CANNOT_READ 

The path exists but cannot be read (a directory).

DEXPP_ERROR_CANNOT_WRITE 

The file cannot be created or written.

DEXPP_ERROR_INVALID_APK 

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

DEXPP_ERROR_INVALID_DEX 

A DEX file cannot be parsed.

DEXPP_ERROR_UNSUPPORTED_DEX 

A DEX format the model does not read (version 41).

DEXPP_ERROR_INVALID_MODEL 

A model breaks rules of the format; see the problems.

DEXPP_ERROR_POOL_OVERFLOW 

A table of the written file would be too large.

DEXPP_ERROR_VERSION_TOO_LOW 

A model uses a feature its DEX version lacks.

DEXPP_ERROR_MODEL 

A class to move or copy is missing, or already there.

DEXPP_ERROR_INTERNAL 

An unexpected failure, such as running out of memory.

◆ DexppAccessFlag

Access flags of a class, a method or a field, as the DEX format stores them.

Two pairs share a bit: VOLATILE/BRIDGE and TRANSIENT/VARARGS.

Enumerator
DEXPP_ACC_PUBLIC 
DEXPP_ACC_PRIVATE 
DEXPP_ACC_PROTECTED 
DEXPP_ACC_STATIC 
DEXPP_ACC_FINAL 
DEXPP_ACC_SYNCHRONIZED 
DEXPP_ACC_VOLATILE 

Fields.

DEXPP_ACC_BRIDGE 

Methods; the same bit as VOLATILE.

DEXPP_ACC_TRANSIENT 

Fields.

DEXPP_ACC_VARARGS 

Methods; the same bit as TRANSIENT.

DEXPP_ACC_NATIVE 
DEXPP_ACC_INTERFACE 
DEXPP_ACC_ABSTRACT 
DEXPP_ACC_STRICT 
DEXPP_ACC_SYNTHETIC 
DEXPP_ACC_ANNOTATION 
DEXPP_ACC_ENUM 
DEXPP_ACC_CONSTRUCTOR 
DEXPP_ACC_DECLARED_SYNCHRONIZED 

◆ DexppInvokeKind

The kind of invoke instruction at a call site.

Enumerator
DEXPP_INVOKE_VIRTUAL 
DEXPP_INVOKE_SUPER 
DEXPP_INVOKE_DIRECT 
DEXPP_INVOKE_STATIC 
DEXPP_INVOKE_INTERFACE 
DEXPP_INVOKE_POLYMORPHIC 
DEXPP_INVOKE_CUSTOM 

◆ DexppEdgeOrigin

How a call-graph edge came to point at its callee.

Enumerator
DEXPP_EDGE_DECLARED 

The target the bytecode names.

DEXPP_EDGE_INHERITED_RESOLUTION 

The nearest definition in a loaded ancestor.

◆ DexppCallNodeKind

What a call-graph node stands for.

Enumerator
DEXPP_CALL_NODE_DEFINED 

A method defined in a loaded file.

DEXPP_CALL_NODE_EXTERNAL 

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

DEXPP_CALL_NODE_CALL_SITE 

An invoke-custom call site.

Its id is opaque: it only keeps call sites apart and names no method.

◆ DexppCfgEdgeKind

The kind of an edge between two basic blocks.

Enumerator
DEXPP_CFG_FALLTHROUGH 
DEXPP_CFG_GOTO 
DEXPP_CFG_BRANCH_TAKEN 
DEXPP_CFG_BRANCH_NOT_TAKEN 
DEXPP_CFG_SWITCH_CASE 

One case of a switch; the edge's case_key is its key.

DEXPP_CFG_SWITCH_DEFAULT 
DEXPP_CFG_EXCEPTION 

To the handler of one exception class; the edge's catch_type names it.

DEXPP_CFG_EXCEPTION_CATCH_ALL 

To a handler that catches every exception.

◆ DexppTypeUseKind

What an instruction does with the type it names.

Enumerator
DEXPP_TYPE_USE_CONST_CLASS 
DEXPP_TYPE_USE_CHECK_CAST 
DEXPP_TYPE_USE_INSTANCE_OF 
DEXPP_TYPE_USE_NEW_INSTANCE 
DEXPP_TYPE_USE_NEW_ARRAY 

The descriptor is the array type.

DEXPP_TYPE_USE_FILLED_NEW_ARRAY 

The descriptor is the array type.

◆ DexppOperandWidth

How many registers a value takes.

Enumerator
DEXPP_WIDTH_SINGLE 

32 bits or a reference: one register.

DEXPP_WIDTH_PAIR 

long or double: two registers.

◆ DexppAnnotationVisibility

Who can see an annotation.

Enumerator
DEXPP_VISIBILITY_BUILD 
DEXPP_VISIBILITY_RUNTIME 
DEXPP_VISIBILITY_SYSTEM 

◆ DexppMethodHandleKind

What a method handle does: the method_handle_type codes of the DEX format.

The four field kinds read or write a field; the five invoke kinds call a method.

Enumerator
DEXPP_METHOD_HANDLE_STATIC_PUT 

Writes a static field.

DEXPP_METHOD_HANDLE_STATIC_GET 

Reads a static field.

DEXPP_METHOD_HANDLE_INSTANCE_PUT 

Writes an instance field.

DEXPP_METHOD_HANDLE_INSTANCE_GET 

Reads an instance field.

DEXPP_METHOD_HANDLE_INVOKE_STATIC 

Calls a static method.

DEXPP_METHOD_HANDLE_INVOKE_INSTANCE 

Calls an instance method, with dispatch.

DEXPP_METHOD_HANDLE_INVOKE_CONSTRUCTOR 

Creates an object with a constructor.

DEXPP_METHOD_HANDLE_INVOKE_DIRECT 

Calls an instance method without dispatch.

DEXPP_METHOD_HANDLE_INVOKE_INTERFACE 

Calls an interface method.

◆ DexppComponentKind

The kind of a manifest component.

Enumerator
DEXPP_COMPONENT_ACTIVITY 
DEXPP_COMPONENT_SERVICE 
DEXPP_COMPONENT_RECEIVER 
DEXPP_COMPONENT_PROVIDER 

◆ DexppValueKind

The kind of a DexppValue.

Enumerator
DEXPP_VALUE_NULL 
DEXPP_VALUE_BOOL 

bool_value.

DEXPP_VALUE_INT 

int_value: every integer type, widened.

DEXPP_VALUE_FLOAT 

float_value: float and double, widened.

DEXPP_VALUE_STRING 

string_value.

DEXPP_VALUE_TYPE 

type_descriptor: a class literal.

DEXPP_VALUE_ENUM 

field: the enum constant's static field.

DEXPP_VALUE_FIELD 

field.

DEXPP_VALUE_METHOD 

method.

DEXPP_VALUE_METHOD_TYPE 

proto.

DEXPP_VALUE_METHOD_HANDLE 

method_handle_kind, and field or method.

DEXPP_VALUE_ARRAY 

elements and element_count.

DEXPP_VALUE_ANNOTATION 

annotation: a nested annotation.

◆ DexppInstructionKind

The kind of a decoded instruction: one per instruction family, the same families as the C++ and Python APIs.

Enumerator
DEXPP_INSN_NOP 

nop.

DEXPP_INSN_GOTO 

branch_offset.

DEXPP_INSN_IF 

branch_offset, reg_a, reg_b.

DEXPP_INSN_IF_ZERO 

branch_offset, reg.

DEXPP_INSN_SWITCH 

payload_offset, reg, is_packed, cases.

DEXPP_INSN_RETURN 

has_reg, reg, width.

DEXPP_INSN_THROW 

reg.

DEXPP_INSN_MOVE 

dest, has_src, src, width.

DEXPP_INSN_CONST 

dest, value, width.

DEXPP_INSN_CONST_STRING 

dest, string_index.

DEXPP_INSN_CONST_CLASS 

dest, type_index.

DEXPP_INSN_CONST_METHOD_HANDLE 

dest, method_handle_index.

DEXPP_INSN_TYPE 

type_index, dest, has_src, src.

DEXPP_INSN_FILLED_NEW_ARRAY 

type_index, arg_regs.

DEXPP_INSN_MONITOR 

reg, is_enter.

DEXPP_INSN_FILL_ARRAY 

reg, payload_offset.

DEXPP_INSN_COMPARE 

dest, src_a, src_b, src_width.

DEXPP_INSN_ARRAY_OP 

value_reg, array_reg, index_reg, is_write, width.

DEXPP_INSN_FIELD 

field_index, value_reg, has_object_reg, object_reg, is_static, is_write, width.

DEXPP_INSN_INVOKE 

method_index, arg_regs.

DEXPP_INSN_INVOKE_CUSTOM 

call_site_index, arg_regs.

DEXPP_INSN_UNARY_OP 

dest, src, dest_width, src_width.

DEXPP_INSN_BINARY_OP 

dest, src_a, src_b, width.

DEXPP_INSN_BINARY_LIT 

dest, src, literal.

DEXPP_INSN_CONST_METHOD_TYPE 

dest, proto_index.

DEXPP_INSN_INVOKE_POLYMORPHIC 

method_index, proto_index, arg_regs.

DEXPP_INSN_ARRAY_LENGTH 

dest, array_reg.

DEXPP_INSN_INVALID 

An opcode the format does not use; only offset, opcode (the raw byte) and size (1).

Function Documentation

◆ dexpp_error_code()

DexppErrorCode dexpp_error_code ( const DexppError *  error)

The kind of the error.

◆ dexpp_error_message()

const char * dexpp_error_message ( const DexppError *  error)

The error message.

The string belongs to the error and lives until dexpp_error_free().

◆ dexpp_error_problem_count()

size_t dexpp_error_problem_count ( const DexppError *  error)

How many problems an error with code DEXPP_ERROR_INVALID_MODEL lists (0 for every other code).

◆ dexpp_error_problem_where()

const char * dexpp_error_problem_where ( const DexppError *  error,
size_t  index 
)

Where problem index is, e.g. "Lcom/a/B;->run()V, item 12"; empty for a problem with the whole file.

NULL when index is out of range. The string belongs to the error.

◆ dexpp_error_problem_message()

const char * dexpp_error_problem_message ( const DexppError *  error,
size_t  index 
)

What is wrong in problem index.

NULL when index is out of range. The string belongs to the error.

◆ dexpp_error_free()

void dexpp_error_free ( DexppError *  error)

Free an error.

Accepts NULL.

◆ dexpp_string_free()

void dexpp_string_free ( char *  s)

Free a string returned by any dexpp function.

Accepts NULL.

◆ dexpp_string_array_free()

void dexpp_string_array_free ( char **  strings,
size_t  count 
)

Free an array of strings and every string in it.

Accepts NULL.

◆ dexpp_text_clear()

void dexpp_text_clear ( DexppText *  text)

Free the bytes of one DexppText and set its members to NULL and 0.

◆ dexpp_text_array_free()

void dexpp_text_array_free ( DexppText *  texts,
size_t  count 
)

Free an array of DexppText and every text in it.

Accepts NULL.

◆ dexpp_buffer_free()

void dexpp_buffer_free ( uint8_t *  buffer)

Free a byte buffer returned by dexpp_apk_read() or dexpp_model_write().

Accepts NULL.

◆ dexpp_index_array_free()

void dexpp_index_array_free ( uint32_t *  indices,
size_t  count 
)

Free an array of indices (node, edge or block numbers).

Accepts NULL.

◆ dexpp_method_id_clear()

void dexpp_method_id_clear ( DexppMethodId *  id)

Free the strings of one DexppMethodId and set them to NULL.

◆ dexpp_field_id_clear()

void dexpp_field_id_clear ( DexppFieldId *  id)

Free the strings of one DexppFieldId and set them to NULL.

◆ dexpp_method_id_array_free()

void dexpp_method_id_array_free ( DexppMethodId *  ids,
size_t  count 
)

Free an array of DexppMethodId.

Accepts NULL.

◆ dexpp_value_clear()

void dexpp_value_clear ( DexppValue *  value)

Free everything a DexppValue owns and reset it to a NULL value.

◆ dexpp_annotation_array_free()

void dexpp_annotation_array_free ( DexppAnnotation *  annotations,
size_t  count 
)

Free an array of annotations and everything they own.

Accepts NULL.

◆ dexpp_context_from_dex()

DexppContext * dexpp_context_from_dex ( const char *  path,
DexppError **  err 
)

Load one DEX file.

Errors: FILE_NOT_FOUND, CANNOT_READ, INVALID_DEX.

◆ dexpp_context_from_dex_files()

DexppContext * dexpp_context_from_dex_files ( const char *const *  paths,
size_t  count,
DexppError **  err 
)

Load several DEX files into one context, for example the unpacked files of a multidex app.

Errors as dexpp_context_from_dex().

◆ dexpp_context_from_apk()

DexppContext * dexpp_context_from_apk ( const char *  path,
uint32_t  threads,
DexppError **  err 
)

Load every top-level classes*.dex of an APK, in multidex order.

threads is the number of threads for decompressing and, later, for building the call graph: 0 lets the library choose, 1 keeps all work on the calling thread. Errors: FILE_NOT_FOUND, CANNOT_READ, INVALID_APK, INVALID_DEX.

◆ dexpp_context_free()

void dexpp_context_free ( DexppContext *  ctx)

Free a context.

Handles that came from it stay valid. Accepts NULL.

◆ dexpp_context_classes()

DexppClass ** dexpp_context_classes ( const DexppContext *  ctx,
size_t *  count 
)

Every class of every loaded DEX file, in file order.

Free with dexpp_class_array_free().

◆ dexpp_context_find_class()

DexppClass * dexpp_context_find_class ( const DexppContext *  ctx,
const char *  descriptor 
)

The class with this descriptor (e.g. "Lcom/example/Foo;"), or NULL when no loaded file defines it.

◆ dexpp_context_strings()

DexppText * dexpp_context_strings ( const DexppContext *  ctx,
size_t *  count 
)

Every string of every loaded DEX file's string table, including names of classes and members.

Decodes the whole table. Free with dexpp_text_array_free().

◆ dexpp_context_call_graph()

DexppCallGraph * dexpp_context_call_graph ( const DexppContext *  ctx,
DexppError **  err 
)

The call graph of the whole program, built on the first call and kept.

Free the handle with dexpp_call_graph_free(). Errors: INTERNAL.

◆ dexpp_context_class_hierarchy()

DexppClassHierarchy * dexpp_context_class_hierarchy ( const DexppContext *  ctx,
DexppError **  err 
)

The class hierarchy of the whole program, built on the first call and kept.

Free with dexpp_class_hierarchy_free(). Errors: INTERNAL.

◆ dexpp_context_xrefs()

DexppXrefs * dexpp_context_xrefs ( const DexppContext *  ctx,
DexppError **  err 
)

The cross-reference index of the whole program, built on the first call and kept.

Free with dexpp_xrefs_free(). Errors: INTERNAL.

◆ dexpp_class_descriptor()

char * dexpp_class_descriptor ( const DexppClass *  cls)

The class descriptor, e.g. "Lcom/example/Foo;".

◆ dexpp_class_package()

char * dexpp_class_package ( const DexppClass *  cls)

The package in Java source form, with dots between its parts, e.g.

"com.example" (the same form as the manifest's package); empty for the default package.

◆ dexpp_class_superclass()

DexppClassRef * dexpp_class_superclass ( const DexppClass *  cls)

The direct superclass, or NULL for java.lang.Object itself.

Free with dexpp_class_ref_free().

◆ dexpp_class_interfaces()

DexppClassRef ** dexpp_class_interfaces ( const DexppClass *  cls,
size_t *  count 
)

The interfaces the class implements directly, in declaration order.

Free with dexpp_class_ref_array_free().

◆ dexpp_class_access_flags()

uint32_t dexpp_class_access_flags ( const DexppClass *  cls)

The access flags (see DexppAccessFlag).

◆ dexpp_class_is_interface()

int dexpp_class_is_interface ( const DexppClass *  cls)

1 when the class is an interface, otherwise 0.

◆ dexpp_class_is_abstract()

int dexpp_class_is_abstract ( const DexppClass *  cls)

1 when the class is abstract, otherwise 0.

◆ dexpp_class_source_file()

char * dexpp_class_source_file ( const DexppClass *  cls)

The source file name recorded for the class, or NULL.

◆ dexpp_class_methods()

DexppMethod ** dexpp_class_methods ( const DexppClass *  cls,
size_t *  count 
)

The methods the class defines: direct methods first, then virtual ones.

Free with dexpp_method_array_free().

◆ dexpp_class_fields()

DexppField ** dexpp_class_fields ( const DexppClass *  cls,
size_t *  count 
)

The fields the class declares: static fields first, then instance fields.

Free with dexpp_field_array_free().

◆ dexpp_class_annotations()

DexppAnnotation * dexpp_class_annotations ( const DexppClass *  cls,
size_t *  count 
)

The annotations on the class.

Free with dexpp_annotation_array_free().

◆ dexpp_class_free()

void dexpp_class_free ( DexppClass *  cls)

Free a class handle.

Accepts NULL.

◆ dexpp_class_array_free()

void dexpp_class_array_free ( DexppClass **  classes,
size_t  count 
)

Free an array of class handles and every handle in it.

Accepts NULL. With count 0 it frees the array alone and the handles stay valid.

◆ dexpp_class_ref_descriptor()

char * dexpp_class_ref_descriptor ( const DexppClassRef *  ref)

The descriptor the reference names.

◆ dexpp_class_ref_is_resolved()

int dexpp_class_ref_is_resolved ( const DexppClassRef *  ref)

1 when the class is defined in a loaded DEX file, otherwise 0.

◆ dexpp_class_ref_resolve()

DexppClass * dexpp_class_ref_resolve ( const DexppClassRef *  ref)

The referenced class, or NULL when no loaded file defines it.

◆ dexpp_class_ref_free()

void dexpp_class_ref_free ( DexppClassRef *  ref)

Free a class reference.

Accepts NULL.

◆ dexpp_class_ref_array_free()

void dexpp_class_ref_array_free ( DexppClassRef **  refs,
size_t  count 
)

Free an array of class references and every reference in it.

Accepts NULL. With count 0 it frees the array alone and the references stay valid.

◆ dexpp_method_name()

char * dexpp_method_name ( const DexppMethod *  m)

The method name.

Constructors are <init>, the static initializer is <clinit>.

◆ dexpp_method_proto()

char * dexpp_method_proto ( const DexppMethod *  m)

The prototype: the parameter types inside parentheses, then the return type, e.g. "(Ljava/lang/String;I)V".

It is the proto of the method's DexppMethodId.

◆ dexpp_method_declaring_class()

DexppClassRef * dexpp_method_declaring_class ( const DexppMethod *  m)

The class that defines the method.

Free with dexpp_class_ref_free().

◆ dexpp_method_id()

void dexpp_method_id ( const DexppMethod *  m,
DexppMethodId *  out 
)

Fill out with the method's identity: its class, name and prototype (release with dexpp_method_id_clear()).

It is the identity the call graph and the cross-references use.

◆ dexpp_method_return_type()

char * dexpp_method_return_type ( const DexppMethod *  m)

The return type descriptor; "V" for void.

◆ dexpp_method_parameters()

char ** dexpp_method_parameters ( const DexppMethod *  m,
size_t *  count 
)

The declared parameter types, in order (this is not included).

Free with dexpp_string_array_free().

◆ dexpp_method_access_flags()

uint32_t dexpp_method_access_flags ( const DexppMethod *  m)

The access flags (see DexppAccessFlag).

◆ dexpp_method_has_code()

int dexpp_method_has_code ( const DexppMethod *  m)

1 when the method has bytecode (it is neither abstract nor native).

◆ dexpp_method_is_static()

int dexpp_method_is_static ( const DexppMethod *  m)

1 when the method is static.

◆ dexpp_method_is_constructor()

int dexpp_method_is_constructor ( const DexppMethod *  m)

1 for <init> and <clinit>.

◆ dexpp_method_register_count()

uint16_t dexpp_method_register_count ( const DexppMethod *  m)

The number of registers in the method's frame; 0 without code.

◆ dexpp_method_parameter_registers()

DexppParameterRegister * dexpp_method_parameter_registers ( const DexppMethod *  m,
size_t *  count 
)

The incoming arguments and their registers, this first for an instance method.

Free with dexpp_parameter_register_array_free().

◆ dexpp_method_calls()

DexppMethodCall * dexpp_method_calls ( const DexppMethod *  m,
size_t *  count 
)

Every call in the method's code, in order.

Free with dexpp_method_call_array_free().

◆ dexpp_method_field_accesses()

DexppFieldAccess * dexpp_method_field_accesses ( const DexppMethod *  m,
size_t *  count 
)

Every field read and write in the method's code, in order.

Free with dexpp_field_access_array_free().

◆ dexpp_method_string_loads()

DexppStringLoad * dexpp_method_string_loads ( const DexppMethod *  m,
size_t *  count 
)

Every const-string in the method's code, in order.

Free with dexpp_string_load_array_free().

◆ dexpp_method_type_uses()

DexppTypeUse * dexpp_method_type_uses ( const DexppMethod *  m,
size_t *  count 
)

Every instruction that names a type, in order.

Free with dexpp_type_use_array_free().

◆ dexpp_method_try_blocks()

DexppTryBlock * dexpp_method_try_blocks ( const DexppMethod *  m,
size_t *  count 
)

The try blocks and their handlers.

Free with dexpp_try_block_array_free().

◆ dexpp_method_annotations()

DexppAnnotation * dexpp_method_annotations ( const DexppMethod *  m,
size_t *  count 
)

The annotations on the method.

Free with dexpp_annotation_array_free().

◆ dexpp_method_free()

void dexpp_method_free ( DexppMethod *  m)

Free a method handle.

Accepts NULL.

◆ dexpp_method_array_free()

void dexpp_method_array_free ( DexppMethod **  methods,
size_t  count 
)

Free an array of method handles and every handle in it.

Accepts NULL. With count 0 it frees the array alone and the handles stay valid.

◆ dexpp_parameter_register_array_free()

void dexpp_parameter_register_array_free ( DexppParameterRegister *  regs,
size_t  count 
)

Free an array of DexppParameterRegister.

Accepts NULL.

◆ dexpp_method_call_array_free()

void dexpp_method_call_array_free ( DexppMethodCall *  calls,
size_t  count 
)

Free an array of DexppMethodCall.

Accepts NULL.

◆ dexpp_field_access_array_free()

void dexpp_field_access_array_free ( DexppFieldAccess *  accesses,
size_t  count 
)

Free an array of DexppFieldAccess.

Accepts NULL.

◆ dexpp_string_load_array_free()

void dexpp_string_load_array_free ( DexppStringLoad *  loads,
size_t  count 
)

Free an array of DexppStringLoad.

Accepts NULL.

◆ dexpp_type_use_array_free()

void dexpp_type_use_array_free ( DexppTypeUse *  uses,
size_t  count 
)

Free an array of DexppTypeUse.

Accepts NULL.

◆ dexpp_try_block_array_free()

void dexpp_try_block_array_free ( DexppTryBlock *  blocks,
size_t  count 
)

Free an array of DexppTryBlock and their handlers.

Accepts NULL.

◆ dexpp_field_name()

char * dexpp_field_name ( const DexppField *  f)

The field name.

◆ dexpp_field_declaring_class()

DexppClassRef * dexpp_field_declaring_class ( const DexppField *  f)

The class that declares the field.

Free with dexpp_class_ref_free().

◆ dexpp_field_type()

char * dexpp_field_type ( const DexppField *  f)

The field's type descriptor.

◆ dexpp_field_id()

void dexpp_field_id ( const DexppField *  f,
DexppFieldId *  out 
)

Fill out with the field's identity: its class, name and type (release with dexpp_field_id_clear()).

It is the identity the cross-references use.

◆ dexpp_field_access_flags()

uint32_t dexpp_field_access_flags ( const DexppField *  f)

The access flags (see DexppAccessFlag).

◆ dexpp_field_annotations()

DexppAnnotation * dexpp_field_annotations ( const DexppField *  f,
size_t *  count 
)

The annotations on the field.

Free with dexpp_annotation_array_free().

◆ dexpp_field_initial_value()

int dexpp_field_initial_value ( const DexppField *  f,
DexppValue *  out 
)

The constant a static field starts with.

Returns 1 and fills out (release with dexpp_value_clear()) when the field has a recorded value; returns 0 when it has none, which means the type's default (0 or null).

◆ dexpp_field_free()

void dexpp_field_free ( DexppField *  f)

Free a field handle.

Accepts NULL.

◆ dexpp_field_array_free()

void dexpp_field_array_free ( DexppField **  fields,
size_t  count 
)

Free an array of field handles and every handle in it.

Accepts NULL. With count 0 it frees the array alone and the handles stay valid.

◆ dexpp_method_instructions()

DexppInstruction * dexpp_method_instructions ( const DexppMethod *  m,
size_t *  count 
)

The decoded bytecode of a method, in order.

Free with dexpp_instruction_array_free().

◆ dexpp_instruction_array_free()

void dexpp_instruction_array_free ( DexppInstruction *  insns,
size_t  count 
)

Free an array of instructions.

Accepts NULL.

◆ dexpp_opcode_name()

const char * dexpp_opcode_name ( uint8_t  opcode)

The name of a Dalvik opcode byte, such as "invoke-virtual".

An unused opcode gives "unused-XX". The string is static: do not free it.

◆ dexpp_instruction_to_string()

char * dexpp_instruction_to_string ( const DexppInstruction *  insn)

One instruction as text: the opcode name, then its operands, with pool operands as raw indices (string@12).

A kind this header does not list gives the opcode name alone, and a width other than DEXPP_WIDTH_PAIR counts as DEXPP_WIDTH_SINGLE.

◆ dexpp_method_cfg()

DexppBasicBlock * dexpp_method_cfg ( const DexppMethod *  m,
size_t *  count 
)

The method's control-flow graph: blocks ordered by offset, block 0 is the entry.

Empty for a method without code. Free with dexpp_basic_block_array_free().

◆ dexpp_basic_block_array_free()

void dexpp_basic_block_array_free ( DexppBasicBlock *  blocks,
size_t  count 
)

Free an array of basic blocks and the edges they own.

Accepts NULL.

◆ dexpp_call_graph_node_count()

size_t dexpp_call_graph_node_count ( const DexppCallGraph *  g)

Number of nodes.

◆ dexpp_call_graph_edge_count()

size_t dexpp_call_graph_edge_count ( const DexppCallGraph *  g)

Number of edges.

◆ dexpp_call_graph_nodes()

DexppCallNode * dexpp_call_graph_nodes ( const DexppCallGraph *  g,
size_t *  count 
)

Every node, in index order.

Free with dexpp_call_node_array_free().

◆ dexpp_call_graph_node()

int dexpp_call_graph_node ( const DexppCallGraph *  g,
uint32_t  node,
DexppCallNode *  out 
)

Fill out with node node (release with dexpp_call_node_clear()).

Returns 0 when node is out of range.

◆ dexpp_call_graph_edges()

DexppCallEdge * dexpp_call_graph_edges ( const DexppCallGraph *  g,
size_t *  count 
)

Every edge, in index order.

Free with dexpp_call_edge_array_free().

◆ dexpp_call_graph_edge()

int dexpp_call_graph_edge ( const DexppCallGraph *  g,
uint32_t  edge,
DexppCallEdge *  out 
)

Fill out with edge edge.

Returns 0 when it is out of range.

◆ dexpp_call_graph_find()

int64_t dexpp_call_graph_find ( const DexppCallGraph *  g,
const char *  class_descriptor,
const char *  name,
const char *  proto 
)

The index of the node with this identity, or -1 when the graph has none.

◆ dexpp_call_graph_out_edges()

uint32_t * dexpp_call_graph_out_edges ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

Indices of the edges that leave node node (its call sites).

Free with dexpp_index_array_free(). Empty when node is out of range.

◆ dexpp_call_graph_in_edges()

uint32_t * dexpp_call_graph_in_edges ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

Indices of the edges that enter node node (the calls into it).

◆ dexpp_call_graph_dispatch_targets()

uint32_t * dexpp_call_graph_dispatch_targets ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

Nodes a virtual or interface call declared against node may dispatch to, besides itself and its own resolution.

◆ dexpp_call_graph_dispatch_sources()

uint32_t * dexpp_call_graph_dispatch_sources ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

◆ dexpp_call_graph_callees()

uint32_t * dexpp_call_graph_callees ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

Every node node may call, dispatch targets included; no duplicates.

◆ dexpp_call_graph_callers()

uint32_t * dexpp_call_graph_callers ( const DexppCallGraph *  g,
uint32_t  node,
size_t *  count 
)

Every node that may call node, through dispatch included.

◆ dexpp_call_graph_edge_dispatch_targets()

uint32_t * dexpp_call_graph_edge_dispatch_targets ( const DexppCallGraph *  g,
uint32_t  edge,
size_t *  count 
)

The dispatch targets that apply at edge edge: those of its callee for a DECLARED virtual or interface edge, none for every other edge.

◆ dexpp_call_graph_edges_where()

uint32_t * dexpp_call_graph_edges_where ( const DexppCallGraph *  g,
int  origin,
int  kind,
size_t *  count 
)

Indices of the edges that match both filters.

origin is a DexppEdgeOrigin or -1 for any; kind is a DexppInvokeKind or -1 for any. The filtering runs in C++.

◆ dexpp_call_graph_method_for()

DexppMethod * dexpp_call_graph_method_for ( const DexppCallGraph *  g,
uint32_t  node 
)

The method behind a DEFINED node, or NULL for an EXTERNAL or CALL_SITE node or an index out of range.

Free with dexpp_method_free().

◆ dexpp_call_graph_free()

void dexpp_call_graph_free ( DexppCallGraph *  g)

Free a call-graph handle.

Accepts NULL.

◆ dexpp_call_node_clear()

void dexpp_call_node_clear ( DexppCallNode *  node)

Free the strings of one DexppCallNode.

◆ dexpp_call_node_array_free()

void dexpp_call_node_array_free ( DexppCallNode *  nodes,
size_t  count 
)

Free an array of DexppCallNode.

Accepts NULL.

◆ dexpp_call_edge_array_free()

void dexpp_call_edge_array_free ( DexppCallEdge *  edges,
size_t  count 
)

Free an array of DexppCallEdge.

Accepts NULL.

◆ dexpp_class_hierarchy_supertypes()

char ** dexpp_class_hierarchy_supertypes ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

The direct superclass, then the directly implemented interfaces.

Free string arrays with dexpp_string_array_free().

◆ dexpp_class_hierarchy_superclass_of()

char * dexpp_class_hierarchy_superclass_of ( const DexppClassHierarchy *  h,
const char *  descriptor 
)

The direct superclass, or NULL when none is recorded (java.lang.Object, a class outside the loaded files, or a descriptor the hierarchy does not know).

◆ dexpp_class_hierarchy_direct_interfaces()

char ** dexpp_class_hierarchy_direct_interfaces ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

The interfaces implemented (or, for an interface, extended) directly.

◆ dexpp_class_hierarchy_subclasses()

char ** dexpp_class_hierarchy_subclasses ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

The classes that directly extend the class.

◆ dexpp_class_hierarchy_implementers()

char ** dexpp_class_hierarchy_implementers ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

The classes that directly implement the interface.

◆ dexpp_class_hierarchy_all_supertypes()

char ** dexpp_class_hierarchy_all_supertypes ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

Every ancestor class and interface; the class itself is not included.

◆ dexpp_class_hierarchy_all_descendants()

char ** dexpp_class_hierarchy_all_descendants ( const DexppClassHierarchy *  h,
const char *  descriptor,
size_t *  count 
)

Everything below the class, through extends and implements; the class itself is not included.

◆ dexpp_class_hierarchy_is_subtype_of()

int dexpp_class_hierarchy_is_subtype_of ( const DexppClassHierarchy *  h,
const char *  sub,
const char *  super 
)

1 when sub is super or has it among its ancestors.

◆ dexpp_class_hierarchy_is_loaded()

int dexpp_class_hierarchy_is_loaded ( const DexppClassHierarchy *  h,
const char *  descriptor 
)

1 when the class is defined in a loaded file.

◆ dexpp_class_hierarchy_is_interface()

int dexpp_class_hierarchy_is_interface ( const DexppClassHierarchy *  h,
const char *  descriptor 
)

1 when the class is loaded and is an interface.

◆ dexpp_class_hierarchy_empty()

int dexpp_class_hierarchy_empty ( const DexppClassHierarchy *  h)

1 when the hierarchy has no classes.

◆ dexpp_class_hierarchy_free()

void dexpp_class_hierarchy_free ( DexppClassHierarchy *  h)

Free a class-hierarchy handle.

Accepts NULL.

◆ dexpp_xrefs_referrer_count()

size_t dexpp_xrefs_referrer_count ( const DexppXrefs *  x)

Number of referrers: methods that contain an indexed instruction.

◆ dexpp_xrefs_referrers()

DexppMethodId * dexpp_xrefs_referrers ( const DexppXrefs *  x,
size_t *  count 
)

The identity of every referrer, in index order.

Free with dexpp_method_id_array_free().

◆ dexpp_xrefs_referrer_id()

int dexpp_xrefs_referrer_id ( const DexppXrefs *  x,
uint32_t  referrer,
DexppMethodId *  out 
)

Fill out with the identity of one referrer (release with dexpp_method_id_clear()).

Returns 0 when referrer is out of range.

◆ dexpp_xrefs_referrer_method()

DexppMethod * dexpp_xrefs_referrer_method ( const DexppXrefs *  x,
uint32_t  referrer 
)

The method of one referrer, or NULL when referrer is out of range.

Free with dexpp_method_free().

◆ dexpp_xrefs_method_refs()

DexppMethodXref * dexpp_xrefs_method_refs ( const DexppXrefs *  x,
const char *  class_descriptor,
const char *  name,
const char *  proto,
size_t *  count 
)

The call sites whose target, as the bytecode names it, is exactly this method.

Free with dexpp_method_xref_array_free().

◆ dexpp_xrefs_method_refs_by_name()

DexppMethodRefGroup * dexpp_xrefs_method_refs_by_name ( const DexppXrefs *  x,
const char *  name,
size_t *  count 
)

The call sites of every method with this name, in any class and with any prototype, grouped by called method.

Free with dexpp_method_ref_group_array_free().

◆ dexpp_xrefs_field_refs()

DexppFieldXref * dexpp_xrefs_field_refs ( const DexppXrefs *  x,
const char *  class_descriptor,
const char *  name,
const char *  type,
size_t *  count 
)

Every read and write of this field.

Free with dexpp_field_xref_array_free().

◆ dexpp_xrefs_field_reads()

DexppFieldXref * dexpp_xrefs_field_reads ( const DexppXrefs *  x,
const char *  class_descriptor,
const char *  name,
const char *  type,
size_t *  count 
)

Only the reads of this field.

◆ dexpp_xrefs_field_writes()

DexppFieldXref * dexpp_xrefs_field_writes ( const DexppXrefs *  x,
const char *  class_descriptor,
const char *  name,
const char *  type,
size_t *  count 
)

Only the writes of this field.

◆ dexpp_xrefs_string_refs()

DexppStringXref * dexpp_xrefs_string_refs ( const DexppXrefs *  x,
const char *  value,
size_t  length,
size_t *  count 
)

The const-string instructions that load exactly this string, given as length bytes (it may contain NUL bytes).

Free with dexpp_string_xref_array_free().

◆ dexpp_xrefs_referenced_strings()

DexppText * dexpp_xrefs_referenced_strings ( const DexppXrefs *  x,
size_t *  count 
)

Every distinct string that some const-string instruction loads.

Free with dexpp_text_array_free().

◆ dexpp_xrefs_type_refs()

DexppTypeXref * dexpp_xrefs_type_refs ( const DexppXrefs *  x,
const char *  descriptor,
size_t *  count 
)

The instructions that name this type.

Free with dexpp_type_xref_array_free().

◆ dexpp_xrefs_empty()

int dexpp_xrefs_empty ( const DexppXrefs *  x)

1 when nothing is indexed.

◆ dexpp_xrefs_free()

void dexpp_xrefs_free ( DexppXrefs *  x)

Free a cross-reference handle.

Accepts NULL.

◆ dexpp_method_xref_array_free()

void dexpp_method_xref_array_free ( DexppMethodXref *  xrefs,
size_t  count 
)

Free an array of DexppMethodXref.

Accepts NULL.

◆ dexpp_method_ref_group_array_free()

void dexpp_method_ref_group_array_free ( DexppMethodRefGroup *  groups,
size_t  count 
)

Free an array of DexppMethodRefGroup and their sites.

Accepts NULL.

◆ dexpp_field_xref_array_free()

void dexpp_field_xref_array_free ( DexppFieldXref *  xrefs,
size_t  count 
)

Free an array of DexppFieldXref.

Accepts NULL.

◆ dexpp_string_xref_array_free()

void dexpp_string_xref_array_free ( DexppStringXref *  xrefs,
size_t  count 
)

Free an array of DexppStringXref.

Accepts NULL.

◆ dexpp_type_xref_array_free()

void dexpp_type_xref_array_free ( DexppTypeXref *  xrefs,
size_t  count 
)

Free an array of DexppTypeXref.

Accepts NULL.

◆ dexpp_apk_open()

DexppApk * dexpp_apk_open ( const char *  path,
DexppError **  err 
)

Open an APK file.

Errors: FILE_NOT_FOUND, CANNOT_READ, INVALID_APK.

◆ dexpp_apk_open_buffer()

DexppApk * dexpp_apk_open_buffer ( const uint8_t *  bytes,
size_t  len,
const char *  label,
DexppError **  err 
)

Open an APK from its bytes in memory, for example bytes received over the network.

The len bytes at bytes are copied, so the caller may free them as soon as this returns. They get the same checks as a file given to dexpp_apk_open(), and the APK handle then works the same.

label names the bytes at the start of error messages, where dexpp_apk_open() puts the path, and is also used by the errors of dexpp_apk_analysis(); NULL gives "<apk>". bytes may be NULL when len is 0 (no bytes are not an APK, so this fails with INVALID_APK); NULL with a nonzero len also fails with INVALID_APK. Errors: INVALID_APK.

◆ dexpp_apk_free()

void dexpp_apk_free ( DexppApk *  apk)

Free an APK handle.

Accepts NULL.

◆ dexpp_apk_entries()

char ** dexpp_apk_entries ( const DexppApk *  apk,
size_t *  count 
)

The name of every archive entry.

Free with dexpp_string_array_free().

◆ dexpp_apk_read()

int dexpp_apk_read ( const DexppApk *  apk,
const char *  name,
uint8_t **  out,
size_t *  length 
)

The uncompressed bytes of the entry name.

Returns 1 and sets out (free with dexpp_buffer_free(); NULL for an empty entry) and length when the entry exists; returns 0 when it does not.

◆ dexpp_apk_package()

char * dexpp_apk_package ( const DexppApk *  apk)

The manifest's package name, or NULL when there is no decodable manifest.

◆ dexpp_apk_manifest()

int dexpp_apk_manifest ( const DexppApk *  apk,
DexppManifest *  out 
)

Fill out with the decoded manifest.

Returns 0 when the APK has no manifest or it cannot be decoded (then out is untouched).

◆ dexpp_manifest_clear()

void dexpp_manifest_clear ( DexppManifest *  manifest)

Free everything a DexppManifest owns.

◆ dexpp_apk_has_resources()

int dexpp_apk_has_resources ( const DexppApk *  apk)

1 when the APK has a decodable resources.arsc table.

◆ dexpp_apk_resources_empty()

int dexpp_apk_resources_empty ( const DexppApk *  apk)

1 when the APK has no resource table, or the table has no entries.

◆ dexpp_apk_resource_name()

int dexpp_apk_resource_name ( const DexppApk *  apk,
uint32_t  id,
DexppResourceName *  out 
)

Fill out with the name of resource id (release with dexpp_resource_name_clear()).

Returns 0 when there is no such id.

◆ dexpp_resource_name_clear()

void dexpp_resource_name_clear ( DexppResourceName *  name)

Free the strings of a DexppResourceName.

◆ dexpp_apk_resolve_string()

int dexpp_apk_resolve_string ( const DexppApk *  apk,
uint32_t  id,
DexppText *  out 
)

The value of string resource id: returns 1 and fills out (release with dexpp_text_clear()); returns 0 when the id is missing or its value is not a string.

A resource that refers to another resource is followed to the end.

◆ dexpp_apk_resolve_bool()

int dexpp_apk_resolve_bool ( const DexppApk *  apk,
uint32_t  id,
int *  out 
)

The value of resource id as a boolean: a bool resource, or any integer-typed value (nonzero is true), as Android reads it.

Returns 1 and sets out to 1 or 0; returns 0 when there is no resource table, the id is missing, or its value is of another type, such as a string. A resource that refers to another resource is followed to the end.

◆ dexpp_apk_resolve_int()

int dexpp_apk_resolve_int ( const DexppApk *  apk,
uint32_t  id,
int64_t *  out 
)

The value of resource id as an integer: an integer resource, or any other integer-typed value, read as its signed 32-bit data.

Returns 1 and sets out; returns 0 when there is no resource table, the id is missing, or its value is of another type. A resource that refers to another resource is followed to the end.

◆ dexpp_apk_resource_id()

int dexpp_apk_resource_id ( const DexppApk *  apk,
const char *  type,
const char *  entry,
uint32_t *  out 
)

The id of the resource with this type and entry name.

Returns 1 and sets out, or 0 when there is none.

◆ dexpp_apk_signing()

void dexpp_apk_signing ( const DexppApk *  apk,
DexppSigningInfo *  out 
)

Fill out with the signature schemes and certificates (release with dexpp_signing_info_clear()).

An unsigned APK gives all zeros.

◆ dexpp_signing_info_clear()

void dexpp_signing_info_clear ( DexppSigningInfo *  info)

Free everything a DexppSigningInfo owns.

◆ dexpp_apk_analysis()

DexppContext * dexpp_apk_analysis ( const DexppApk *  apk,
uint32_t  threads,
DexppError **  err 
)

A code-analysis context over every classes*.dex of the APK, in multidex order, loaded from the bytes the APK handle already holds.

threads is as for dexpp_context_from_apk(): 0 lets the library choose, 1 keeps all work, the call graph included, on the calling thread.

The analysis is built on the first call and kept, one for each value of threads: a later call with the same value gives a new handle to the same analysis, so its call graph and other structures are built once. A call with another value builds a second analysis, which holds its own copy of the DEX files. So use one value in a program. Free the handle with dexpp_context_free(). Errors: INVALID_APK, INVALID_DEX.