Package com.android.dex
Class Dex
- java.lang.Object
-
- 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
Nested Classes Modifier and Type Class Description classDex.Section
-
Constructor Summary
Constructors Constructor Description Dex(byte[] data)Creates a new dex that reads fromdata.Dex(int byteCount)Creates a new empty dex of the specified size.Dex(File file)Creates a new dex buffer from the dex filefile.Dex(InputStream in)Creates a new dex buffer of the dex inin, and closesin.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intannotationDirectoryOffsetFromClassDefIndex(int classDefIndex)Look up an annotation directory offset from a class def index.Dex.SectionappendSection(int maxByteCount, String name)Iterable<ClassDef>classDefs()intcomputeChecksum()Returns the checksum of all but the first 12 bytes ofdex.byte[]computeSignature()Returns the signature of all but the first 32 bytes of this dex.static Dexcreate(ByteBuffer data)Creates a new dex from the contents ofbytes.intdeclaringClassIndexFromMethodIndex(int methodIndex)Look up a method id declaring class index from a method index.intdescriptorIndexFromTypeIndex(int typeIndex)Look up a descriptor index from a type index.List<FieldId>fieldIds()intfindClassDefIndexFromTypeIndex(int typeIndex)intfindFieldIndex(FieldId fieldId)intfindMethodIndex(MethodId methodId)intfindStringIndex(String s)intfindTypeIndex(String descriptor)byte[]getBytes()Returns a copy of the the bytes of this dex.intgetLength()intgetNextSectionStart()TableOfContentsgetTableOfContents()short[]interfaceTypeIndicesFromClassDefIndex(int classDefIndex)Look up interface types indices from a return type index from a method index.List<MethodId>methodIds()intnameIndexFromFieldIndex(int fieldIndex)Look up a field id name index from a field index.intnameIndexFromMethodIndex(int methodIndex)Look up a method id name index from a method index.Dex.Sectionopen(int position)short[]parameterTypeIndicesFromMethodIndex(int methodIndex)Look up a parameter type ids from a method index.List<ProtoId>protoIds()ClassDatareadClassData(ClassDef classDef)CodereadCode(ClassData.Method method)TypeListreadTypeList(int offset)intreturnTypeIndexFromMethodIndex(int methodIndex)Look up a method id return type index from a method index.List<String>strings()List<Integer>typeIds()inttypeIndexFromClassDefIndex(int classDefIndex)Look up a type index index from a class def index.inttypeIndexFromFieldIndex(int fieldIndex)Look up a field id type index from a field index.List<String>typeNames()voidwriteHashes()Generates the signature and checksum of the dex fileoutand writes them to the file.voidwriteTo(File dexOut)voidwriteTo(OutputStream out)
-
-
-
Constructor Detail
-
Dex
public Dex(byte[] data) throws IOExceptionCreates a new dex that reads fromdata. It is an error to modifydataafter using it to create a dex buffer.- Throws:
IOException
-
Dex
public Dex(int byteCount) throws IOExceptionCreates 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 inin, and closesin.- Throws:
IOException
-
Dex
public Dex(File file) throws IOException
Creates a new dex buffer from the dex filefile.- Throws:
IOException
-
-
Method Detail
-
create
public static Dex create(ByteBuffer data) throws IOException
Creates a new dex from the contents ofbytes. This API supports both.dexand.odexinput. Calling this constructor transfers ownership ofbytesto 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.
-
readTypeList
public TypeList readTypeList(int offset)
-
readCode
public Code readCode(ClassData.Method method)
-
computeSignature
public byte[] computeSignature() throws IOExceptionReturns 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 IOExceptionReturns the checksum of all but the first 12 bytes ofdex.- Throws:
IOException
-
writeHashes
public void writeHashes() throws IOExceptionGenerates the signature and checksum of the dex fileoutand 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();
-
-