com.android.dex
Class Dex

java.lang.Object
  extended by com.android.dex.Dex

public final class Dex
extends Object

The bytes of a dex file in memory for reading and writing. All int offsets are unsigned.


Nested Class Summary
 class Dex.Section
           
 
Constructor Summary
Dex(byte[] data)
          Creates a new dex that reads from data.
Dex(File file)
          Creates a new dex buffer from the dex file file.
Dex(InputStream in)
          Creates a new dex buffer of the dex in in, and closes in.
Dex(int byteCount)
          Creates a new empty dex of the specified size.
 
Method Summary
 int annotationDirectoryOffsetFromClassDefIndex(int classDefIndex)
          Look up an annotation directory offset from a class def index.
 Dex.Section appendSection(int maxByteCount, String name)
           
 Iterable<ClassDef> classDefs()
           
 int computeChecksum()
          Returns the checksum of all but the first 12 bytes of dex.
 byte[] computeSignature()
          Returns the signature of all but the first 32 bytes of this dex.
static Dex create(ByteBuffer data)
          Creates a new dex from the contents of bytes.
 int declaringClassIndexFromMethodIndex(int methodIndex)
          Look up a method id declaring class index from a method index.
 int descriptorIndexFromTypeIndex(int typeIndex)
          Look up a descriptor index from a type index.
 List<FieldId> fieldIds()
           
 int findClassDefIndexFromTypeIndex(int typeIndex)
           
 int findFieldIndex(FieldId fieldId)
           
 int findMethodIndex(MethodId methodId)
           
 int findStringIndex(String s)
           
 int findTypeIndex(String descriptor)
           
 byte[] getBytes()
          Returns a copy of the the bytes of this dex.
 int getLength()
           
 int getNextSectionStart()
           
 TableOfContents getTableOfContents()
           
 short[] interfaceTypeIndicesFromClassDefIndex(int classDefIndex)
          Look up interface types indices from a return type index from a method index.
 List<MethodId> methodIds()
           
 int nameIndexFromFieldIndex(int fieldIndex)
          Look up a field id name index from a field index.
 int nameIndexFromMethodIndex(int methodIndex)
          Look up a method id name index from a method index.
 Dex.Section open(int position)
           
 short[] parameterTypeIndicesFromMethodIndex(int methodIndex)
          Look up a parameter type ids from a method index.
 List<ProtoId> protoIds()
           
 ClassData readClassData(ClassDef classDef)
           
 Code readCode(ClassData.Method method)
           
 TypeList readTypeList(int offset)
           
 int returnTypeIndexFromMethodIndex(int methodIndex)
          Look up a method id return type index from a method index.
 List<String> strings()
           
 List<Integer> typeIds()
           
 int typeIndexFromClassDefIndex(int classDefIndex)
          Look up a type index index from a class def index.
 int typeIndexFromFieldIndex(int fieldIndex)
          Look up a field id type index from a field index.
 List<String> typeNames()
           
 void writeHashes()
          Generates the signature and checksum of the dex file out and writes them to the file.
 void writeTo(File dexOut)
           
 void writeTo(OutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dex

public Dex(byte[] data)
    throws IOException
Creates a new dex that reads from data. It is an error to modify data after using it to create a dex buffer.

Throws:
IOException

Dex

public Dex(int byteCount)
    throws IOException
Creates a new empty dex of the specified size.

Throws:
IOException

Dex

public Dex(InputStream in)
    throws IOException
Creates a new dex buffer of the dex in in, and closes in.

Throws:
IOException

Dex

public Dex(File file)
    throws IOException
Creates a new dex buffer from the dex file file.

Throws:
IOException
Method Detail

create

public static Dex create(ByteBuffer data)
                  throws IOException
Creates a new dex from the contents of bytes. This API supports both .dex and .odex input. Calling this constructor transfers ownership of bytes to the returned Dex: it is an error to access the buffer after calling this method.

Throws:
IOException

writeTo

public void writeTo(OutputStream out)
             throws IOException
Throws:
IOException

writeTo

public void writeTo(File dexOut)
             throws IOException
Throws:
IOException

getTableOfContents

public TableOfContents getTableOfContents()

open

public Dex.Section open(int position)

appendSection

public Dex.Section appendSection(int maxByteCount,
                                 String name)

getLength

public int getLength()

getNextSectionStart

public int getNextSectionStart()

getBytes

public byte[] getBytes()
Returns a copy of the the bytes of this dex.


strings

public List<String> strings()

typeIds

public List<Integer> typeIds()

typeNames

public List<String> typeNames()

protoIds

public List<ProtoId> protoIds()

fieldIds

public List<FieldId> fieldIds()

methodIds

public List<MethodId> methodIds()

classDefs

public Iterable<ClassDef> classDefs()

readTypeList

public TypeList readTypeList(int offset)

readClassData

public ClassData readClassData(ClassDef classDef)

readCode

public Code readCode(ClassData.Method method)

computeSignature

public byte[] computeSignature()
                        throws IOException
Returns the signature of all but the first 32 bytes of this dex. The first 32 bytes of dex files are not specified to be included in the signature.

Throws:
IOException

computeChecksum

public int computeChecksum()
                    throws IOException
Returns the checksum of all but the first 12 bytes of dex.

Throws:
IOException

writeHashes

public void writeHashes()
                 throws IOException
Generates the signature and checksum of the dex file out and writes them to the file.

Throws:
IOException

nameIndexFromFieldIndex

public int nameIndexFromFieldIndex(int fieldIndex)
Look up a field id name index from a field index. Cheaper than: fieldIds().get(fieldDexIndex).getNameIndex();


findStringIndex

public int findStringIndex(String s)

findTypeIndex

public int findTypeIndex(String descriptor)

findFieldIndex

public int findFieldIndex(FieldId fieldId)

findMethodIndex

public int findMethodIndex(MethodId methodId)

findClassDefIndexFromTypeIndex

public int findClassDefIndexFromTypeIndex(int typeIndex)

typeIndexFromFieldIndex

public int typeIndexFromFieldIndex(int fieldIndex)
Look up a field id type index from a field index. Cheaper than: fieldIds().get(fieldDexIndex).getTypeIndex();


declaringClassIndexFromMethodIndex

public int declaringClassIndexFromMethodIndex(int methodIndex)
Look up a method id declaring class index from a method index. Cheaper than: methodIds().get(methodIndex).getDeclaringClassIndex();


nameIndexFromMethodIndex

public int nameIndexFromMethodIndex(int methodIndex)
Look up a method id name index from a method index. Cheaper than: methodIds().get(methodIndex).getNameIndex();


parameterTypeIndicesFromMethodIndex

public short[] parameterTypeIndicesFromMethodIndex(int methodIndex)
Look up a parameter type ids from a method index. Cheaper than: readTypeList(protoIds.get(methodIds().get(methodDexIndex).getProtoIndex()).getParametersOffset()).getTypes();


returnTypeIndexFromMethodIndex

public int returnTypeIndexFromMethodIndex(int methodIndex)
Look up a method id return type index from a method index. Cheaper than: protoIds().get(methodIds().get(methodDexIndex).getProtoIndex()).getReturnTypeIndex();


descriptorIndexFromTypeIndex

public int descriptorIndexFromTypeIndex(int typeIndex)
Look up a descriptor index from a type index. Cheaper than: open(tableOfContents.typeIds.off + (index * SizeOf.TYPE_ID_ITEM)).readInt();


typeIndexFromClassDefIndex

public int typeIndexFromClassDefIndex(int classDefIndex)
Look up a type index index from a class def index.


annotationDirectoryOffsetFromClassDefIndex

public int annotationDirectoryOffsetFromClassDefIndex(int classDefIndex)
Look up an annotation directory offset from a class def index.


interfaceTypeIndicesFromClassDefIndex

public short[] interfaceTypeIndicesFromClassDefIndex(int classDefIndex)
Look up interface types indices from a return type index from a method index. Cheaper than: ...getClassDef(classDefIndex).getInterfaces();



Copyright © 2015. All rights reserved.