public class Dex
extends java.lang.Object
This class represents the DEX file being processed by JEB.
To better understand the methods of this class as well as the objects returned by these methods, it is encouraged to read the specifications for the DEX format.
Although it is assumed that the reader is familiar with the aforementioned document, here are three examples of fully-qualified names:
Lcom/foo/bar/Blob;
Lcom/foo/bar/Blob;->methodX([BILjava/lang/String;)V
Lcom/foo/bar/Blob;->var:J
This class also defines constants for class/field/method access types, see ACC_xxx
constants.
Modifier and Type | Field and Description |
---|---|
static int |
ACC_ABSTRACT |
static int |
ACC_ANNOTATION |
static int |
ACC_BRIDGE |
static int |
ACC_CONSTRUCTOR |
static int |
ACC_DECLARED_SYNCHRONIZED |
static int |
ACC_ENUM |
static int |
ACC_FINAL |
static int |
ACC_INTERFACE |
static int |
ACC_NATIVE |
static int |
ACC_PRIVATE |
static int |
ACC_PROTECTED |
static int |
ACC_PUBLIC |
static int |
ACC_STATIC |
static int |
ACC_STRICT |
static int |
ACC_SYNCHRONIZED |
static int |
ACC_SYNTHETIC |
static int |
ACC_TRANSIENT |
static int |
ACC_VARARGS |
static int |
ACC_VOLATILE |
static int |
FLAG_ALERT |
static int |
FLAG_CONST |
static int |
FLAG_LIBRARY |
static int |
FLAG_LIBRARY_EXT |
Constructor and Description |
---|
Dex(java.lang.Object dex_data)
Internal constructor, do not use.
|
Modifier and Type | Method and Description |
---|---|
DexField |
addFieldReference(java.lang.String signature)
Create or retrieve a new field reference.
|
DexMethod |
addMethodReference(java.lang.String signature)
Create or retrieve a new method reference.
|
int |
addString(java.lang.String str)
Create a new string.
|
int |
addType(java.lang.String typestr)
Create a new type.
|
DexClass |
getClass(int index)
Get a class object by index.
|
DexClass |
getClass(java.lang.String name)
Get a class object by name.
|
int |
getClassCount()
Get the number of classes defined in the DEX file.
|
java.util.List<java.lang.String> |
getClassSignatures(boolean effective)
Get the full list of class signatures.
|
java.util.Set<java.lang.Long> |
getConstants()
Convenience method to retrieve all constants defined in the DEX file.
|
byte[] |
getData()
Get a copy of the entire DEX file.
|
int |
getDexStringCount()
Get the number of strings contained in the original (non-augmented) string pool.
|
int |
getDexTypeCount()
Get the number of types contained in the original (non-augmented) type pool.
|
DexField |
getField(int index)
Get a field description by index.
|
int |
getFieldCount()
Get the number of fields described in the DEX file.
|
DexFieldData |
getFieldData(java.lang.String name)
Retrieve a field definition by name.
|
java.util.List<java.lang.Integer> |
getFieldReferences(int index)
Retrieve the list of methods that reference the provided field.
|
java.util.List<java.lang.String> |
getFieldSignatures(boolean effective)
Get the full list of field signatures.
|
DexMethod |
getMethod(int index)
Get a method description by index.
|
int |
getMethodCount()
Get the number of methods described in the DEX file.
|
DexMethodData |
getMethodData(java.lang.String name)
Retrieve a method definition by name.
|
java.util.List<java.lang.Integer> |
getMethodReferences(int index)
Retrieve the list of methods that reference the provided method.
|
java.util.List<java.lang.String> |
getMethodSignatures(boolean effective)
Get the full list of method signatures.
|
DexPrototype |
getPrototype(int index)
Get a prototype by index.
|
int |
getPrototypeCount()
Get the number of prototypes contained in the DEX file.
|
java.lang.String |
getString(int index)
Get a string from the DEX string pool.
|
int |
getStringCount()
Get the number of strings in the string pool.
|
java.util.List<java.lang.String> |
getStrings()
Retrieve all strings from the DEX pool.
|
java.lang.String |
getType(int index)
Retrieve a type from the type manager.
|
java.lang.String |
getType(int index,
boolean effective)
Retrieve a type from the type manager.
|
int |
getTypeCount()
Get the number of types contained in the type manager.
|
java.util.List<java.lang.Integer> |
getTypeReferences(int index)
Retrieve the list of methods that reference the provided type.
|
boolean |
setString(int index,
java.lang.String string)
Replace a string in the DEX string pool.
|
public static final int ACC_PUBLIC
public static final int ACC_PRIVATE
public static final int ACC_PROTECTED
public static final int ACC_STATIC
public static final int ACC_FINAL
public static final int ACC_SYNCHRONIZED
public static final int ACC_VOLATILE
public static final int ACC_BRIDGE
public static final int ACC_TRANSIENT
public static final int ACC_VARARGS
public static final int ACC_NATIVE
public static final int ACC_INTERFACE
public static final int ACC_ABSTRACT
public static final int ACC_STRICT
public static final int ACC_SYNTHETIC
public static final int ACC_ANNOTATION
public static final int ACC_ENUM
public static final int ACC_CONSTRUCTOR
public static final int ACC_DECLARED_SYNCHRONIZED
public static final int FLAG_CONST
public static final int FLAG_LIBRARY
public static final int FLAG_LIBRARY_EXT
public static final int FLAG_ALERT
public Dex(java.lang.Object dex_data)
Internal constructor, do not use.
Clients should not create instances of this class directly.
Use the JebInstance.getDex()
method to retrieve
a reference on the currently processed DEX file.
dex_data
- opaque DEX datapublic byte[] getData()
Get a copy of the entire DEX file.
public java.lang.String getString(int index)
Get a string from the DEX string pool.
index
- string indexpublic java.util.List<java.lang.String> getStrings()
Retrieve all strings from the DEX pool. The strings returned are the strings contained in the current pool, not the original DEX file pool. For example, if the original pool was: ["A", "XYZ", "bla"], and that the strings "foo" and "bar" were added, this function will return: ["A", "XYZ", "bla", "foo", "bar"]. The order matters.
public int getStringCount()
Get the number of strings in the string pool. The pool may have been augmented (see the documentation for getStrings()), in which case, the number returned would be greater than the original number.
public int getDexStringCount()
Get the number of strings contained in the original (non-augmented) string pool.
public boolean setString(int index, java.lang.String string)
Replace a string in the DEX string pool.
This method modifies the DEX representation, and should be used with care.
It is not recommended to replace strings representing class/field/method/type names.
Replacing strings might break code logic.
Updated strings are NOT saved to a JEB database.
index
- string indexstring
- new stringpublic java.lang.String getType(int index)
Retrieve a type from the type manager.
Equivalent to getType(index, true)
.
index
- the type indexpublic java.lang.String getType(int index, boolean effective)
Retrieve a type from the type manager.
The type manager contains the DEX types as well as artificial types. (An artificial type was added by JEB; it is not contained in the type pool.)
index
- the type indexeffective
- true to get the effective (current) type signature, false to get the original signatureLcom/farm/Animal;
or [[I
public int getTypeCount()
Get the number of types contained in the type manager.
public int getDexTypeCount()
Get the number of types contained in the original (non-augmented) type pool.
public DexPrototype getPrototype(int index)
Get a prototype by index.
index
- prototype indexpublic int getPrototypeCount()
Get the number of prototypes contained in the DEX file.
public DexField getField(int index)
Get a field description by index.
The field can be internal (defined in the DEX file, in which case there is an associated FieldData object) or external (simple reference)
index
- field indexpublic int getFieldCount()
Get the number of fields described in the DEX file.
public DexMethod getMethod(int index)
Get a method description by index.
The method can be internal (defined in the DEX file, in which case there is an associated MethodData object) or external (simple reference.)
index
- method indexpublic int getMethodCount()
Get the number of methods described in the DEX file.
public DexFieldData getFieldData(java.lang.String name)
Retrieve a field definition by name.
Only internal fields have an associated FieldData object
(see encoded_field
in the DEX file specification.)
name
- field name (can be partial or fully-qualified)public DexMethodData getMethodData(java.lang.String name)
Retrieve a method definition by name.
Only internal methods have an associated MethodData object
(see encoded_method
in the DEX file specification.)
name
- method name (can be partial or fully-qualified)public DexClass getClass(int index)
Get a class object by index.
Every class defined in the DEX file has an associated class object.
index
- the class indexpublic DexClass getClass(java.lang.String name)
Get a class object by name.
name
- class name (can be partial or fully-qualified)public int getClassCount()
Get the number of classes defined in the DEX file.
public java.util.List<java.lang.String> getClassSignatures(boolean effective)
Get the full list of class signatures.
effective
- indicates if the current names or real names should be retrievedpublic java.util.List<java.lang.String> getMethodSignatures(boolean effective)
Get the full list of method signatures.
effective
- indicates if the current names or real names should be retrievedpublic java.util.List<java.lang.String> getFieldSignatures(boolean effective)
Get the full list of field signatures.
effective
- indicates if the current names or real names should be retrievedpublic java.util.Set<java.lang.Long> getConstants()
Convenience method to retrieve all constants defined in the DEX file.
This method has no equivalent in the DEX file format. The DEX parser will build a list of numeric literals used by Dalvik instructions and populate this "artificial" pool with these literals.
public java.util.List<java.lang.Integer> getTypeReferences(int index)
Retrieve the list of methods that reference the provided type.
index
- type indexpublic java.util.List<java.lang.Integer> getFieldReferences(int index)
Retrieve the list of methods that reference the provided field.
index
- field indexpublic java.util.List<java.lang.Integer> getMethodReferences(int index)
Retrieve the list of methods that reference the provided method.
index
- method indexpublic int addString(java.lang.String str)
Create a new string. The string is added to the string pool.
str
- mandatory stringpublic int addType(java.lang.String typestr)
Create a new type. The type is added to the type pool.
typestr
- full signature of the fieldjava.lang.IllegalArgumentException
- if the type string is invalid and cannot be added to the poolpublic DexField addFieldReference(java.lang.String signature)
Create or retrieve a new field reference.
signature
- full signature of the fieldpublic DexMethod addMethodReference(java.lang.String signature)
Create or retrieve a new method reference.
signature
- full signature of the method