org.ow2.asmdex.lowLevelUtils
Class BasicDexFileReader

java.lang.Object
  extended by org.ow2.asmdex.lowLevelUtils.BasicDexFileReader
Direct Known Subclasses:
DexFileReader

public class BasicDexFileReader
extends java.lang.Object

Reads the basic structure of a DEX file and builds a representation of this file.

Author:
Pierre Crégut, Julien Névo (little modifications)

Field Summary
 long adler32Checksum
          ADLER 32 checksum of the DEX file
static int CLASS_DEF_ITEM_SIZE
          Size of a class definition in the pool in bytes
protected  int classDefinitionsOffset
          Offset of class definition table
protected  int classDefinitionsSize
          Size of class definition table
protected  java.lang.String[] constantPoolStrings
          The Strings Constant Pool.
protected  java.lang.String[] constantPoolTypes
          The Types Constant Pool.
static int FIELD_ID_ITEM_SIZE
          Size of a field definition in the pool in bytes
protected  int fieldIdsOffset
          Offset of field ids table
protected  int fieldIdsSize
          Size of field ids table
protected static int FILE_SIZE_OFFSET
          Offset to the file size field
 byte[] formatVersionNumber
          Format version number
protected static int HEADER_NOMINAL_SIZE
          Header size
protected  boolean isStandardEndian
          Standard or reverse endianess
 int linkTableSize
          Size of the link table (but undefined otherwise)
static int METHOD_ID_ITEM_SIZE
          Size of a method declaration in the pool in bytes
protected  int methodIdsOffset
          Offset of method ids table
protected  int methodIdsSize
          Size of method ids table
static int NO_INDEX
          Constant representing the absence of an index in a table especially for super class.
static int PROTO_ID_ITEM_SIZE
          Size of a prototype definition in the pool in bytes
protected  int protoIdsOffset
          Offset of prototype ids table
protected  int protoIdsSize
          Size of prototypes ids table
protected  DalvikValueReader reader
          The stream of code.
protected static int REVERSE_ENDIAN_VALUE
          Reverse endian marker
 byte[] signature
          Signature of the DEX file
protected static int STANDARD_ENDIAN_VALUE
          Standard endianess marker
static int STRING_ID_ITEM_SIZE
          Size of a string decl in the pool in bytes
protected  int stringIdsOffset
          Offset of string ids table
protected  int stringIdsSize
          Size of string ids table
static int TYPE_ID_ITEM_SIZE
          Size of a type declaration in the pool in bytes
protected  int typeIdsOffset
          Offset of type ids table
protected  int typeIdsSize
          Size of type ids table
 
Constructor Summary
BasicDexFileReader()
          Constructor.
 
Method Summary
 int getClassDefinitionOffset(int itemIndex)
          Returns the offset (from the beginning of the file) of a Class Id Item (class_def_item structure) whose index is given.
 int getClassDefinitionsOffset()
          Position of the class table
 int getClassDefinitionsSize()
          Number of class declaration
 int getFieldIdsOffset()
          Position of the field table
 int getFieldIdsSize()
          Number of field declaration
 byte[] getFormatVersionNumber()
          Version of the format used by the file
 int getMethodIdsOffset()
          Position of the method table
 int getMethodIdsSize()
          Number of methods declared
 int getOffsetFieldIdItem(int itemIndex)
          Returns the offset (from the beginning of the file) of a Field Id Item (field_id_item structure) whose index is given.
 int getOffsetMethodIdItem(int itemIndex)
          Returns the offset (from the beginning of the file) of a Method Id Item (method_id_item structure) whose index is given.
 int getOffsetProtoIdItem(int itemIndex)
          Returns the offset (from the beginning of the file) of a Prototype Id Item (proto_id_item structure) whose index is given.
 int getOffsetStringIdItem(int itemIndex)
          Returns the offset (from the beginning of the file) of a String Id Item (string_id_item structure) whose index is given.
 int getOffsetTypeIdItem(int itemIndex)
          Returns the offset (from the beginning of the file) of a Type Id Item (type_id_item structure) whose index is given.
 int getProtoIdsOffset()
          Position of prototype ids table
 int getProtoIdsSize()
          Number of prototype ids
 int getStringIdsOffset()
          Position of string table
 int getStringIdsSize()
          Number of string ids in the pool
 int getTypeIdsOffset()
          Position of type id table
 int getTypeIdsSize()
          Number of type ids.
 boolean isStandardEndian()
          Endianess of the file
 void parse(byte[] dexBytes)
          Takes a byte array corresponding to a Dex file and populate the structure.
protected  void readHeader()
          Reads the Header of the previously loaded Dex file.
protected  void readStrings()
          Reads the string index table, and populates constantPoolStrings.
protected  void readTypes()
          Reads the types index table, and populates constantPoolTypes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_INDEX

public static final int NO_INDEX
Constant representing the absence of an index in a table especially for super class.

See Also:
Constant Field Values

reader

protected DalvikValueReader reader
The stream of code.


FILE_SIZE_OFFSET

protected static final int FILE_SIZE_OFFSET
Offset to the file size field

See Also:
Constant Field Values

HEADER_NOMINAL_SIZE

protected static final int HEADER_NOMINAL_SIZE
Header size

See Also:
Constant Field Values

STANDARD_ENDIAN_VALUE

protected static final int STANDARD_ENDIAN_VALUE
Standard endianess marker

See Also:
Constant Field Values

REVERSE_ENDIAN_VALUE

protected static final int REVERSE_ENDIAN_VALUE
Reverse endian marker

See Also:
Constant Field Values

adler32Checksum

public long adler32Checksum
ADLER 32 checksum of the DEX file


signature

public byte[] signature
Signature of the DEX file


isStandardEndian

protected boolean isStandardEndian
Standard or reverse endianess


formatVersionNumber

public byte[] formatVersionNumber
Format version number


linkTableSize

public int linkTableSize
Size of the link table (but undefined otherwise)


stringIdsSize

protected int stringIdsSize
Size of string ids table


stringIdsOffset

protected int stringIdsOffset
Offset of string ids table


typeIdsSize

protected int typeIdsSize
Size of type ids table


typeIdsOffset

protected int typeIdsOffset
Offset of type ids table


protoIdsSize

protected int protoIdsSize
Size of prototypes ids table


protoIdsOffset

protected int protoIdsOffset
Offset of prototype ids table


fieldIdsSize

protected int fieldIdsSize
Size of field ids table


fieldIdsOffset

protected int fieldIdsOffset
Offset of field ids table


methodIdsSize

protected int methodIdsSize
Size of method ids table


methodIdsOffset

protected int methodIdsOffset
Offset of method ids table


classDefinitionsSize

protected int classDefinitionsSize
Size of class definition table


classDefinitionsOffset

protected int classDefinitionsOffset
Offset of class definition table


constantPoolStrings

protected java.lang.String[] constantPoolStrings
The Strings Constant Pool.


constantPoolTypes

protected java.lang.String[] constantPoolTypes
The Types Constant Pool.


CLASS_DEF_ITEM_SIZE

public static final int CLASS_DEF_ITEM_SIZE
Size of a class definition in the pool in bytes

See Also:
Constant Field Values

FIELD_ID_ITEM_SIZE

public static final int FIELD_ID_ITEM_SIZE
Size of a field definition in the pool in bytes

See Also:
Constant Field Values

STRING_ID_ITEM_SIZE

public static final int STRING_ID_ITEM_SIZE
Size of a string decl in the pool in bytes

See Also:
Constant Field Values

TYPE_ID_ITEM_SIZE

public static final int TYPE_ID_ITEM_SIZE
Size of a type declaration in the pool in bytes

See Also:
Constant Field Values

METHOD_ID_ITEM_SIZE

public static final int METHOD_ID_ITEM_SIZE
Size of a method declaration in the pool in bytes

See Also:
Constant Field Values

PROTO_ID_ITEM_SIZE

public static final int PROTO_ID_ITEM_SIZE
Size of a prototype definition in the pool in bytes

See Also:
Constant Field Values
Constructor Detail

BasicDexFileReader

public BasicDexFileReader()
Constructor.

Method Detail

parse

public void parse(byte[] dexBytes)
           throws java.lang.IllegalArgumentException,
                  java.io.IOException
Takes a byte array corresponding to a Dex file and populate the structure.

Parameters:
dexBytes - the code
Throws:
java.io.IOException
java.lang.IllegalArgumentException

readHeader

protected void readHeader()
                   throws java.lang.IllegalArgumentException
Reads the Header of the previously loaded Dex file.

Throws:
java.lang.IllegalArgumentException

readStrings

protected void readStrings()
Reads the string index table, and populates constantPoolStrings. The table must have its offset set before (by readHeader).


readTypes

protected void readTypes()
Reads the types index table, and populates constantPoolTypes. The table must have its offset set before (by readHeader), and readStrings must have been called.


getOffsetFieldIdItem

public int getOffsetFieldIdItem(int itemIndex)
Returns the offset (from the beginning of the file) of a Field Id Item (field_id_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the Field Id Item.
Returns:
the offset of the Field Id Item.

getOffsetStringIdItem

public int getOffsetStringIdItem(int itemIndex)
Returns the offset (from the beginning of the file) of a String Id Item (string_id_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the String Id Item.
Returns:
the offset of the String Id Item.

getOffsetTypeIdItem

public int getOffsetTypeIdItem(int itemIndex)
Returns the offset (from the beginning of the file) of a Type Id Item (type_id_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the Type Id Item.
Returns:
the offset of the Type Id Item.

getOffsetMethodIdItem

public int getOffsetMethodIdItem(int itemIndex)
Returns the offset (from the beginning of the file) of a Method Id Item (method_id_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the Method Id Item.
Returns:
the offset of the Method Id Item.

getOffsetProtoIdItem

public int getOffsetProtoIdItem(int itemIndex)
Returns the offset (from the beginning of the file) of a Prototype Id Item (proto_id_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the Method Id Item.
Returns:
the offset of the Method Id Item.

getClassDefinitionOffset

public int getClassDefinitionOffset(int itemIndex)
Returns the offset (from the beginning of the file) of a Class Id Item (class_def_item structure) whose index is given. The Dex file header must have been parsed.

Parameters:
itemIndex - index of the Method Id Item.
Returns:
the offset of the Method Id Item.

isStandardEndian

public boolean isStandardEndian()
Endianess of the file

Returns:
true if standard endian

getStringIdsSize

public int getStringIdsSize()
Number of string ids in the pool

Returns:
number

getStringIdsOffset

public int getStringIdsOffset()
Position of string table

Returns:
position

getTypeIdsSize

public int getTypeIdsSize()
Number of type ids.

Returns:
positive or null number

getTypeIdsOffset

public int getTypeIdsOffset()
Position of type id table

Returns:
positive or null number

getProtoIdsSize

public int getProtoIdsSize()
Number of prototype ids

Returns:
positive or null number

getProtoIdsOffset

public int getProtoIdsOffset()
Position of prototype ids table

Returns:
offset

getFieldIdsSize

public int getFieldIdsSize()
Number of field declaration

Returns:
positive or null number

getFieldIdsOffset

public int getFieldIdsOffset()
Position of the field table

Returns:
offset

getMethodIdsSize

public int getMethodIdsSize()
Number of methods declared

Returns:
positive or null number

getMethodIdsOffset

public int getMethodIdsOffset()
Position of the method table

Returns:
offset

getClassDefinitionsSize

public int getClassDefinitionsSize()
Number of class declaration

Returns:
positive or null number

getClassDefinitionsOffset

public int getClassDefinitionsOffset()
Position of the class table

Returns:
offset

getFormatVersionNumber

public byte[] getFormatVersionNumber()
Version of the format used by the file

Returns:
enumeration