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.
  • Constructor Details

    • 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 Details

    • 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
    • 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();