Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.file

public final Class DexFile

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.dex.DexOptions, org.droidparts.dexmaker.dx.rop.cst.*, org.droidparts.dexmaker.dx.rop.type.Type, org.droidparts.dexmaker.dx.util.ByteArrayAnnotatedOutput, .ExceptionWithContext, java.io.IOException, .OutputStream, .Writer, java.security.DigestException, .MessageDigest, .NoSuchAlgorithmException, java.util.zip.Adler32

Representation of an entire .dex (Dalvik EXecutable) file, which itself consists of a set of Dalvik classes.

Field Summary

Modifier and TypeField and Description
private final MixedItemSection
byteData

non-null; byte data section

private final MixedItemSection
classData

non-null; class data section

private final ClassDefsSection
classDefs

non-null; class definitions section

private DexOptions
dexOptions

options controlling the creation of the file

private int
dumpWidth

>= 40; maximum width of the file dump

private final FieldIdsSection
fieldIds

non-null; field identifiers section

private int
fileSize

>= -1; total file size or -1 if unknown

private final HeaderSection
header

non-null; file header

private final MixedItemSection
map

non-null; map section.

private final MethodIdsSection
methodIds

non-null; method identifiers section

private final ProtoIdsSection
protoIds

non-null; prototype identifiers section

private final Section[]
sections

non-null; array of sections in the order they will appear in the final output file

private final MixedItemSection
stringData

non-null; string data section

private final StringIdsSection
stringIds

non-null; string identifiers section

private final TypeIdsSection
typeIds

non-null; type identifiers section

private final MixedItemSection
typeLists

non-null; type lists section.

private final MixedItemSection
wordData

non-null; word data section

Constructor Summary

AccessConstructor and Description
public
DexFile(DexOptions dexOptions)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
public void
add(ClassDefItem
non-null; the class to add
clazz
)

Adds a class to this instance.

private static void
calcChecksum(byte[]
non-null; the bytes of the file
bytes
)

Calculates the checksum for the .dex file in the given array, and modify the array to contain it.

private static void
calcSignature(byte[]
non-null; the bytes of the file
bytes
)

Calculates the signature for the .dex file in the given array, and modify the array to contain it.

pack-priv IndexedItem

Returns:

null-ok; its corresponding item, if it has a corresponding item, or null if it's not that sort of constant
findItemOrNull
(Constant
non-null; the constant to look up
cst
)

Gets the IndexedItem corresponding to the given constant, if it is a constant that has such a correspondence, or return null if it isn't such a constant.

pack-priv MixedItemSection

Returns:

non-null; the byte data section
getByteData
()

Gets the byte data section.

pack-priv MixedItemSection

Returns:

non-null; the class data section
getClassData
()

Gets the class data section.

pack-priv ClassDefsSection

Returns:

non-null; the class definitions section
getClassDefs
()

Gets the class definitions section.

public ClassDefItem

Returns:

null-ok; the class with the given name, or null if there is no such class
getClassOrNull
(String
non-null; the class name to look for
name
)

Gets the class definition with the given name, if any.

public DexOptions
getDexOptions()

Gets the dex-creation options object.

pack-priv FieldIdsSection

Returns:

non-null; the field identifiers section
getFieldIds
()

Gets the field identifiers section.

pack-priv int

Returns:

>= 0; the total file size
getFileSize
()

Gets the total file size, if known.

pack-priv Section

Returns:

non-null; the section
getFirstDataSection
()

Gets the first section of the file that is to be considered part of the data section.

pack-priv Section

Returns:

non-null; the section
getLastDataSection
()

Gets the last section of the file that is to be considered part of the data section.

pack-priv MixedItemSection

Returns:

non-null; the map section
getMap
()

Gets the map section.

pack-priv MethodIdsSection

Returns:

non-null; the method identifiers section
getMethodIds
()

Gets the method identifiers section.

pack-priv ProtoIdsSection

Returns:

non-null; the prototype identifiers section
getProtoIds
()

Gets the prototype identifiers section.

public Statistics

Returns:

non-null; the statistics
getStatistics
()

Generates and returns statistics for all the items in the file.

pack-priv MixedItemSection

Returns:

non-null; the string data section
getStringData
()

Gets the string data section.

pack-priv StringIdsSection

Returns:

non-null; the string identifiers section
getStringIds
()

Gets the string identifiers section.

pack-priv TypeIdsSection

Returns:

non-null; the class identifiers section
getTypeIds
()

Gets the type identifiers section.

pack-priv MixedItemSection

Returns:

non-null; the word data section
getTypeLists
()

Gets the type lists section.

pack-priv MixedItemSection

Returns:

non-null; the word data section
getWordData
()

Gets the word data section.

pack-priv void
internIfAppropriate(Constant
non-null; constant to possibly intern
cst
)

Interns the given constant in the appropriate section of this instance, or do nothing if the given constant isn't the sort that should be interned.

public boolean
isEmpty()

Returns true if this dex doesn't contain any class defs.

public void
setDumpWidth(int
>= 40; the width
dumpWidth
)

Sets the maximum width of the human-oriented dump of the instance.

public byte[]

Returns:

non-null; a .dex file for this instance
toDex
(Writer
null-ok; where to write human-oriented output to
humanOut
,
boolean
whether to be verbose when writing human-oriented output
verbose
)

Returns the contents of this instance as a .dex file, in byte[] form.

private ByteArrayAnnotatedOutput

Returns:

non-null; a .dex file for this instance
toDex0
(boolean
whether or not to keep annotations
annotate
,
boolean
if annotating, whether to be verbose
verbose
)

Returns the contents of this instance as a .dex file, in a ByteArrayAnnotatedOutput instance.

public void
writeTo(OutputStream
null-ok; where to write to
out
,
Writer
null-ok; where to write human-oriented output to
humanOut
,
boolean
whether to be verbose when writing human-oriented output
verbose
)

Writes the contents of this instance as either a binary or a human-readable form, or both.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

byteDataback to summary
private final MixedItemSection byteData

non-null; byte data section

classDataback to summary
private final MixedItemSection classData

non-null; class data section

classDefsback to summary
private final ClassDefsSection classDefs

non-null; class definitions section

dexOptionsback to summary
private DexOptions dexOptions

options controlling the creation of the file

dumpWidthback to summary
private int dumpWidth

>= 40; maximum width of the file dump

fieldIdsback to summary
private final FieldIdsSection fieldIds

non-null; field identifiers section

fileSizeback to summary
private int fileSize

>= -1; total file size or -1 if unknown

mapback to summary
private final MixedItemSection map

non-null; map section. The map needs to be in a section by itself for the self-reference mechanics to work in a reasonably straightforward way. See MapItem#addMap for more detail.

methodIdsback to summary
private final MethodIdsSection methodIds

non-null; method identifiers section

protoIdsback to summary
private final ProtoIdsSection protoIds

non-null; prototype identifiers section

sectionsback to summary
private final Section[] sections

non-null; array of sections in the order they will appear in the final output file

stringDataback to summary
private final MixedItemSection stringData

non-null; string data section

stringIdsback to summary
private final StringIdsSection stringIds

non-null; string identifiers section

typeIdsback to summary
private final TypeIdsSection typeIds

non-null; type identifiers section

typeListsback to summary
private final MixedItemSection typeLists

non-null; type lists section. This is word data, but separating it from wordData helps break what would otherwise be a circular dependency between the that and protoIds.

wordDataback to summary
private final MixedItemSection wordData

non-null; word data section

Constructor Detail

DexFileback to summary
public DexFile(DexOptions dexOptions)

Constructs an instance. It is initially empty.

Method Detail

addback to summary
public void add(ClassDefItem clazz)

Adds a class to this instance. It is illegal to attempt to add more than one class with the same name.

Parameters
clazz:ClassDefItem

non-null; the class to add

calcChecksumback to summary
private static void calcChecksum(byte[] bytes)

Calculates the checksum for the .dex file in the given array, and modify the array to contain it.

Parameters
bytes:byte[]

non-null; the bytes of the file

calcSignatureback to summary
private static void calcSignature(byte[] bytes)

Calculates the signature for the .dex file in the given array, and modify the array to contain it.

Parameters
bytes:byte[]

non-null; the bytes of the file

findItemOrNullback to summary
pack-priv IndexedItem findItemOrNull(Constant cst)

Gets the IndexedItem corresponding to the given constant, if it is a constant that has such a correspondence, or return null if it isn't such a constant. This will throw an exception if the given constant should have been found but wasn't.

Parameters
cst:Constant

non-null; the constant to look up

Returns:IndexedItem

null-ok; its corresponding item, if it has a corresponding item, or null if it's not that sort of constant

getByteDataback to summary
pack-priv MixedItemSection getByteData()

Gets the byte data section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MixedItemSection

non-null; the byte data section

getClassDataback to summary
pack-priv MixedItemSection getClassData()

Gets the class data section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MixedItemSection

non-null; the class data section

getClassDefsback to summary
pack-priv ClassDefsSection getClassDefs()

Gets the class definitions section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:ClassDefsSection

non-null; the class definitions section

getClassOrNullback to summary
public ClassDefItem getClassOrNull(String name)

Gets the class definition with the given name, if any.

Parameters
name:String

non-null; the class name to look for

Returns:ClassDefItem

null-ok; the class with the given name, or null if there is no such class

getDexOptionsback to summary
public DexOptions getDexOptions()

Gets the dex-creation options object.

getFieldIdsback to summary
pack-priv FieldIdsSection getFieldIds()

Gets the field identifiers section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:FieldIdsSection

non-null; the field identifiers section

getFileSizeback to summary
pack-priv int getFileSize()

Gets the total file size, if known.

This is package-scope in order to allow the HeaderSection to set itself up properly.

Returns:int

>= 0; the total file size

Exceptions
RuntimeException:
thrown if the file size is not yet known
getFirstDataSectionback to summary
pack-priv Section getFirstDataSection()

Gets the first section of the file that is to be considered part of the data section.

This is package-scope in order to allow the header section to query it.

Returns:Section

non-null; the section

getLastDataSectionback to summary
pack-priv Section getLastDataSection()

Gets the last section of the file that is to be considered part of the data section.

This is package-scope in order to allow the header section to query it.

Returns:Section

non-null; the section

getMapback to summary
pack-priv MixedItemSection getMap()

Gets the map section.

This is package-scope in order to allow the header section to query it.

Returns:MixedItemSection

non-null; the map section

getMethodIdsback to summary
pack-priv MethodIdsSection getMethodIds()

Gets the method identifiers section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MethodIdsSection

non-null; the method identifiers section

getProtoIdsback to summary
pack-priv ProtoIdsSection getProtoIds()

Gets the prototype identifiers section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:ProtoIdsSection

non-null; the prototype identifiers section

getStatisticsback to summary
public Statistics getStatistics()

Generates and returns statistics for all the items in the file.

Returns:Statistics

non-null; the statistics

getStringDataback to summary
pack-priv MixedItemSection getStringData()

Gets the string data section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MixedItemSection

non-null; the string data section

getStringIdsback to summary
pack-priv StringIdsSection getStringIds()

Gets the string identifiers section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:StringIdsSection

non-null; the string identifiers section

getTypeIdsback to summary
pack-priv TypeIdsSection getTypeIds()

Gets the type identifiers section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:TypeIdsSection

non-null; the class identifiers section

getTypeListsback to summary
pack-priv MixedItemSection getTypeLists()

Gets the type lists section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MixedItemSection

non-null; the word data section

getWordDataback to summary
pack-priv MixedItemSection getWordData()

Gets the word data section.

This is package-scope in order to allow the various Item instances to add items to the instance.

Returns:MixedItemSection

non-null; the word data section

internIfAppropriateback to summary
pack-priv void internIfAppropriate(Constant cst)

Interns the given constant in the appropriate section of this instance, or do nothing if the given constant isn't the sort that should be interned.

Parameters
cst:Constant

non-null; constant to possibly intern

isEmptyback to summary
public boolean isEmpty()

Returns true if this dex doesn't contain any class defs.

setDumpWidthback to summary
public void setDumpWidth(int dumpWidth)

Sets the maximum width of the human-oriented dump of the instance.

Parameters
dumpWidth:int

>= 40; the width

toDexback to summary
public byte[] toDex(Writer humanOut, boolean verbose) throws IOException

Returns the contents of this instance as a .dex file, in byte[] form.

Parameters
humanOut:Writer

null-ok; where to write human-oriented output to

verbose:boolean

whether to be verbose when writing human-oriented output

Returns:byte[]

non-null; a .dex file for this instance

toDex0back to summary
private ByteArrayAnnotatedOutput toDex0(boolean annotate, boolean verbose)

Returns the contents of this instance as a .dex file, in a ByteArrayAnnotatedOutput instance.

Parameters
annotate:boolean

whether or not to keep annotations

verbose:boolean

if annotating, whether to be verbose

Returns:ByteArrayAnnotatedOutput

non-null; a .dex file for this instance

writeToback to summary
public void writeTo(OutputStream out, Writer humanOut, boolean verbose) throws IOException

Writes the contents of this instance as either a binary or a human-readable form, or both.

Parameters
out:OutputStream

null-ok; where to write to

humanOut:Writer

null-ok; where to write human-oriented output to

verbose:boolean

whether to be verbose when writing human-oriented output