Module Dex
module Dex: sig
.. end
This module provides utilities for manipulating Dalvik bytecode
and DEX files, including functions for navigating bytecode file
structures and generating new instruction sequences.
Types
exception Wrong_dex of string
raise if something is logically incorrect
exception Wrong_match of string
raise if there is no other cases for match block
exception NOT_YET of string
raise if something is not implemented yet
type
dex = {
}
The top-level representation of a DEX binary file
type
link =
encapsulation of in/direct access
= {
}
header_item format
type
endian =
type
section = {
}
type
proto_id_item = {
|
shorty :link ; |
|
mutable return_type :link ; |
|
parameter_off :link ; |
}
type
field_id_item = {
}
type
method_id_item = {
}
type
class_def_item = {
|
c_class_id :link ; |
|
mutable c_access_flag :int ; |
|
mutable superclass :link ; |
|
mutable interfaces :link ; |
|
source_file :link ; |
|
annotations :link ; |
|
mutable class_data :link ; |
|
static_values :link ; |
}
type
data_item =
items in the data pool, which appears in the d_data
type
map_item = {
}
map_item
format for map_list
, which appears in the d_data
type
type_code =
| |
|
| |
TYPE_STRING_ITEM |
| |
TYPE_TYPE_ID_ITEM |
| |
TYPE_PROTO_ID_ITEM |
| |
TYPE_FIELD_ID_ITEM |
| |
TYPE_METHOD_ID_ITEM |
| |
TYPE_CLASS_DEF_ITEM |
| |
TYPE_MAP_LIST |
| |
TYPE_TYPE_LIST |
| |
TYPE_ANNOTATION_SET_REF_LIST |
| |
TYPE_ANNOTATION_SET_ITEM |
| |
TYPE_CLASS_DATA_ITEM |
| |
TYPE_CODE_ITEM |
| |
TYPE_STRING_DATA_ITEM |
| |
TYPE_DEBUG_INFO_ITEM |
| |
TYPE_ANNOTATION_ITEM |
| |
TYPE_ENCODED_ARRAY_ITEM |
| |
TYPE_ANNOTATION_DIRECTORY_ITEM |
type
class_data_item = {
}
type
encoded_field = {
|
field_idx :link ; |
|
f_access_flag :int ; |
}
type
encoded_method = {
|
method_idx :link ; |
|
mutable m_access_flag :int ; |
|
code_off :link ; |
}
type
code_item = {
|
mutable registers_size :int ; |
|
mutable ins_size :int ; |
|
mutable outs_size :int ; |
|
mutable tries_size :int ; |
|
mutable debug_info_off :link ; |
|
mutable insns_size :int ; |
|
insns :link DynArray.t ; |
|
mutable tries :try_item list ; |
|
mutable c_handlers :encoded_catch_handler list ; |
}
type
switch = {
|
sw_base :link ; |
|
sw_size :int ; |
|
sw_keys :int list ; |
|
sw_targets :link list ; |
}
type
fill_array_data = {
}
type
try_item = {
}
type
encoded_catch_handler = {
}
type
type_addr_pair = {
}
type
debug_info_item = {
}
type
state_machine_instr =
| |
DBG_END_SEQUENCE |
| |
DBG_ADVANCE_PC |
| |
DBG_ADVANCE_LINE |
| |
DBG_START_LOCAL |
| |
DBG_START_LOCAL_EXTENDED |
| |
DBG_END_LOCAL |
| |
DBG_RESTART_LOCAL |
| |
DBG_SET_PROLOGUE_END |
| |
DBG_SET_EPILOGUE_BEGIN |
| |
DBG_SET_FILE |
| |
DBG_SPECIAL |
type
anno_dir_item = {
}
type
anno_off = {
}
type
annotation_item = {
}
type
visibility =
| |
VISIBILITY_BUILD |
| |
VISIBILITY_RUNTIME |
| |
VISIBILITY_SYSTEM |
Visibility
values
type
encoded_annotation = {
}
type
annotation_element = {
}
type
encoded_value =
| |
VALUE_BYTE of int64 |
| |
VALUE_SHORT of int64 |
| |
VALUE_CHAR of int64 |
| |
VALUE_INT of int64 |
| |
VALUE_LONG of int64 |
| |
VALUE_FLOAT of int64 |
| |
VALUE_DOUBLE of int64 |
| |
VALUE_STRING of int |
| |
VALUE_TYPE of int |
| |
VALUE_FIELD of int |
| |
VALUE_METHOD of int |
| |
VALUE_ENUM of int |
| |
VALUE_ARRAY of encoded_value list |
| |
VALUE_ANNOTATION of encoded_annotation |
| |
VALUE_NULL |
| |
VALUE_BOOLEAN of bool |
Utilities
val to_idx : int -> link
wrapping with Idx
val to_off : int -> link
wrapping with Off
val of_idx : link -> int
unwrapping Idx
val of_off : link -> int
unwrapping Off
val opr2idx : Instr.operand -> link
from OPR_INDEX
to Idx
val opr2off : Instr.operand -> link
from OPR_OFFSET
to Off
val idx2opr : link -> Instr.operand
from Idx
to OPR_INDEX
val off2opr : link -> Instr.operand
from Off
to OPR_OFFSET
val get_off : link -> Instr.offset
obtain 32-bits offset from Off
val str_to_endian : string -> endian
val endian_to_str : endian -> string
val to_type_code : int -> type_code
val of_type_code : type_code -> int
val type_code_to_str : type_code -> string
val machine_instr_to_str : state_machine_instr -> string
Access flags
type
access_flag =
| |
ACC_PUBLIC |
| |
ACC_PRIVATE |
| |
ACC_PROTECTED |
| |
ACC_STATIC |
| |
ACC_FINAL |
| |
ACC_SYNCHRONIZED |
| |
ACC_VOLATILE |
| |
ACC_BRIDGE |
| |
ACC_TRANSIENT |
| |
ACC_VARARGS |
| |
ACC_NATIVE |
| |
ACC_INTERFACE |
| |
ACC_ABSTRACT |
| |
ACC_STRICT |
| |
ACC_SYNTHETIC |
| |
ACC_ANNOTATION |
| |
ACC_ENUM |
| |
ACC_CONSTRUCTOR |
| |
ACC_DECLARED_SYNCHRONIZED |
indicate the accessibility
type
acc_kind =
| |
ACC_FOR_CLASSES |
| |
ACC_FOR_FIELDS |
| |
ACC_FOR_METHODS |
val to_acc_flag : acc_kind -> access_flag list -> int
val is_interface : int -> bool
true
if ACC_INTERFACE
is set
val pub : access_flag list
ACC_FOR_PUBLIC
val spub : access_flag list
Navigation
val no_index : int
0xffffffff (= -1 if signed int)
val no_offset : int
0x00000000
val no_idx : link
val no_off : link
val get_data_item : dex -> link -> data_item
val get_ins : dex -> link -> Instr.instr
val is_ins : dex -> link -> bool
val get_str : dex -> link -> string
val find_str : dex -> string -> link
find string id for given
string
,
Dex.no_idx
unless found
val get_ty_str : dex -> link -> string
get type name for given type id
val find_ty_str : dex -> string -> link
find type id for given
string
,
Dex.no_idx
unless found
val ty_comp : dex -> link -> link -> int
comparator for type ids
val get_ty_lst : dex -> link -> link list
val get_fit : dex -> link -> field_id_item
val get_mit : dex -> link -> method_id_item
val get_pit : dex -> method_id_item -> proto_id_item
val get_argv : dex -> method_id_item -> link list
get a list
of arguments for given method
val get_rety : dex -> method_id_item -> link
get return type for given method
val fld_comp : dex -> field_id_item -> field_id_item -> int
comparator for field signatures: field name and type
val ty_lst_comp : dex -> link list -> link list -> int
comparator for a list
of type ids
val ty_lst_comp_relaxed : dex -> link list -> link list -> int
comparator for a list
of type ids,
but ignore the package name for types.
val mtd_comp : dex -> method_id_item -> method_id_item -> int
comparator for method signatures: method name, return type, and arguments
val mtd_comp_relaxed : dex -> method_id_item -> method_id_item -> int
comparator for method signatures: method name, return type, and arguments,
but ignore the package name for return types and arguments.
val get_cid_from_fid : dex -> link -> link
get class id from field id
val get_cid_from_mid : dex -> link -> link
get class id from method id
val get_fld_name : dex -> link -> string
get name for given field
val get_mtd_name : dex -> link -> string
get name for given method
val get_cid : dex -> string -> link
val get_cdef : dex -> link -> class_def_item
val get_superclass : dex -> link -> link
get superclass id for given class,
Dex.no_idx
if it's at the top level
val get_superclasses : dex -> link -> link list
get superclasses for a given class.
val get_interfaces : dex -> link -> link list
get implemented interfaces of a given class
val in_hierarchy : dex -> (link -> bool) -> link -> bool
check that some property (given as a function
Dex.link
to
bool
)
holds in hierarchy starting from the given class
val is_superclass : dex -> link -> link -> bool
check whether some class is a superclass (up through the hierarchy)
of a given class.
val get_flds : dex -> link -> (link * field_id_item) list
get all fields, along with ids, for given class
val get_fldS : dex -> link -> (link * field_id_item) list
get all fields, along with ids, for given class and superclasses
val get_the_fld : dex -> link -> string -> link * field_id_item
get the specific field of given class and given field name
val own_the_fld : dex -> link -> link -> bool
true
if the class owns the field
val get_mtds : dex -> link -> (link * method_id_item) list
get all methods, along with ids, for given class
val get_mtdS : dex -> link -> (link * method_id_item) list
get all methods, along with ids, for given class and superclasses
val get_supermethod : dex -> link -> link -> link
get overriden method at the superclass for given class and method,
Dex.no_idx
unless overridable
val get_the_mtd : dex -> link -> string -> link * method_id_item
get the specific method of given class and given method name
val get_the_mtd_shorty : dex -> link -> string -> string -> link * method_id_item
get the specific method of given class, method name,
and shorty descriptor (useful for overloading)
val own_the_mtd : dex -> link -> link -> bool
true
if the class owns the method
val get_cdata : dex -> link -> link * class_data_item
val get_emtd : dex -> link -> link -> encoded_method
val get_citm : dex -> link -> link -> link * code_item
val calc_this : code_item -> int
calculate a register number that holds this
pointer
Modification helper
val empty_section : unit -> section
val empty_dex : unit -> dex
val empty_citm : unit -> code_item
val insrt_data : dex -> link -> data_item -> unit
val rm_data : dex -> link -> unit
val insrt_ins : dex -> link -> Instr.instr -> unit
val insrt_str : dex -> link -> string -> unit
insert string
into the data pool
val insrt_ty_lst : dex -> link -> link list -> unit
insert TYPE_LIST
into the data pool
val insrt_stt : dex -> link -> encoded_value list -> unit
insert STATIC_VALUE
into the data pool
val insrt_citm : dex -> link -> code_item -> unit
Web Accessibility