Package org.jf.dexlib2.writer
Class DexWriter<StringKey extends CharSequence,StringRef extends StringReference,TypeKey extends CharSequence,TypeRef extends TypeReference,ProtoRefKey extends MethodProtoReference,FieldRefKey extends FieldReference,MethodRefKey extends MethodReference,ClassKey extends Comparable<? super ClassKey>,CallSiteKey extends CallSiteReference,MethodHandleKey extends MethodHandleReference,AnnotationKey extends Annotation,AnnotationSetKey,TypeListKey,FieldKey,MethodKey,EncodedArrayKey,EncodedValue,AnnotationElement extends AnnotationElement,StringSectionType extends StringSection<StringKey,StringRef>,TypeSectionType extends TypeSection<StringKey,TypeKey,TypeRef>,ProtoSectionType extends ProtoSection<StringKey,TypeKey,ProtoRefKey,TypeListKey>,FieldSectionType extends FieldSection<StringKey,TypeKey,FieldRefKey,FieldKey>,MethodSectionType extends MethodSection<StringKey,TypeKey,ProtoRefKey,MethodRefKey,MethodKey>,ClassSectionType extends ClassSection<StringKey,TypeKey,TypeListKey,ClassKey,FieldKey,MethodKey,AnnotationSetKey,EncodedArrayKey>,CallSiteSectionType extends CallSiteSection<CallSiteKey,EncodedArrayKey>,MethodHandleSectionType extends MethodHandleSection<MethodHandleKey,FieldRefKey,MethodRefKey>,TypeListSectionType extends TypeListSection<TypeKey,TypeListKey>,AnnotationSectionType extends AnnotationSection<StringKey,TypeKey,AnnotationKey,AnnotationElement,EncodedValue>,AnnotationSetSectionType extends AnnotationSetSection<AnnotationKey,AnnotationSetKey>,EncodedArraySectionType extends EncodedArraySection<EncodedArrayKey,EncodedValue>>
java.lang.Object
org.jf.dexlib2.writer.DexWriter<StringKey,StringRef,TypeKey,TypeRef,ProtoRefKey,FieldRefKey,MethodRefKey,ClassKey,CallSiteKey,MethodHandleKey,AnnotationKey,AnnotationSetKey,TypeListKey,FieldKey,MethodKey,EncodedArrayKey,EncodedValue,AnnotationElement,StringSectionType,TypeSectionType,ProtoSectionType,FieldSectionType,MethodSectionType,ClassSectionType,CallSiteSectionType,MethodHandleSectionType,TypeListSectionType,AnnotationSectionType,AnnotationSetSectionType,EncodedArraySectionType>
- Direct Known Subclasses:
DexBuilder,DexPool
public abstract class DexWriter<StringKey extends CharSequence,StringRef extends StringReference,TypeKey extends CharSequence,TypeRef extends TypeReference,ProtoRefKey extends MethodProtoReference,FieldRefKey extends FieldReference,MethodRefKey extends MethodReference,ClassKey extends Comparable<? super ClassKey>,CallSiteKey extends CallSiteReference,MethodHandleKey extends MethodHandleReference,AnnotationKey extends Annotation,AnnotationSetKey,TypeListKey,FieldKey,MethodKey,EncodedArrayKey,EncodedValue,AnnotationElement extends AnnotationElement,StringSectionType extends StringSection<StringKey,StringRef>,TypeSectionType extends TypeSection<StringKey,TypeKey,TypeRef>,ProtoSectionType extends ProtoSection<StringKey,TypeKey,ProtoRefKey,TypeListKey>,FieldSectionType extends FieldSection<StringKey,TypeKey,FieldRefKey,FieldKey>,MethodSectionType extends MethodSection<StringKey,TypeKey,ProtoRefKey,MethodRefKey,MethodKey>,ClassSectionType extends ClassSection<StringKey,TypeKey,TypeListKey,ClassKey,FieldKey,MethodKey,AnnotationSetKey,EncodedArrayKey>,CallSiteSectionType extends CallSiteSection<CallSiteKey,EncodedArrayKey>,MethodHandleSectionType extends MethodHandleSection<MethodHandleKey,FieldRefKey,MethodRefKey>,TypeListSectionType extends TypeListSection<TypeKey,TypeListKey>,AnnotationSectionType extends AnnotationSection<StringKey,TypeKey,AnnotationKey,AnnotationElement,EncodedValue>,AnnotationSetSectionType extends AnnotationSetSection<AnnotationKey,AnnotationSetKey>,EncodedArraySectionType extends EncodedArraySection<EncodedArrayKey,EncodedValue>>
extends Object
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprotected classprivate static classclass -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intfinal AnnotationSectionTypeprotected intprotected intfinal AnnotationSetSectionTypeprotected intprivate Comparator<Map.Entry<? extends CallSiteKey, Integer>> final CallSiteSectionTypeprotected intprotected intprotected intfinal ClassSectionTypeprotected intprotected intfinal EncodedArraySectionTypeprotected intfinal FieldSectionTypeprotected intprotected booleanprotected intprotected intstatic final intfinal MethodHandleSectionTypeprotected intfinal MethodSectionTypeprotected intstatic final intstatic final intprotected intprotected intprotected intprotected intprotected intprotected final Opcodesprivate final IndexSection<?>[]final ProtoSectionTypeprotected intprotected intprotected intfinal StringSectionTypeprivate static Comparator<Map.Entry> final TypeListSectionTypeprotected intfinal TypeSectionTypeprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intprivate static <T extends Comparable<? super T>>
Comparator<Map.Entry<? extends T, ?>> private voidfixInstructions(MutableMethodImplementation methodImplementation) private intprotected abstract DexWriter<StringKey,StringRef, TypeKey, TypeRef, ProtoRefKey, FieldRefKey, MethodRefKey, ClassKey, CallSiteKey, MethodHandleKey, AnnotationKey, AnnotationSetKey, TypeListKey, FieldKey, MethodKey, EncodedArrayKey, EncodedValue, AnnotationElement, StringSectionType, TypeSectionType, ProtoSectionType, FieldSectionType, MethodSectionType, ClassSectionType, CallSiteSectionType, MethodHandleSectionType, TypeListSectionType, AnnotationSectionType, AnnotationSetSectionType, EncodedArraySectionType>.SectionProvider booleanChecks whether any of the size-sensitive constant pools have overflowed and have more than 64Ki entries.booleanhasOverflowed(int maxPoolSize) Checks whether any of the size-sensitive constant pools have more than the supplied maximum number of entries.private static DexDataWriteroutputAt(DexDataStore dataStore, int filePosition) private booleanprivate booleanprivate voidupdateChecksum(DexDataStore dataStore) private voidupdateSignature(DexDataStore dataStore) private voidprivate voidwriteAnnotations(DexDataWriter writer) private voidwriteAnnotationSetRefs(DexDataWriter writer) private voidwriteAnnotationSets(DexDataWriter writer) private voidwriteCallSites(DexDataWriter writer) private intwriteClass(DexDataWriter indexWriter, DexDataWriter offsetWriter, int nextIndex, Map.Entry<? extends ClassKey, Integer> entry) Writes out the class_def_item and class_data_item for the given class.private voidwriteClasses(DexDataStore dataStore, DexDataWriter indexWriter, DexDataWriter offsetWriter) private intwriteCodeItem(DexDataWriter writer, ByteArrayOutputStream ehBuf, MethodKey methodKey, List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks, Iterable<? extends Instruction> instructions, int debugItemOffset) private voidwriteDebugAndCodeItems(DexDataWriter offsetWriter, DeferredOutputStream temp) private intwriteDebugItem(DexDataWriter writer, DebugWriter<StringKey, TypeKey> debugWriter, Iterable<? extends StringKey> parameterNames, Iterable<? extends DebugItem> debugItems) private voidwriteEncodedArrays(DexDataWriter writer) private voidwriteEncodedFields(DexDataWriter writer, Collection<? extends FieldKey> fields) private voidwriteEncodedMethods(DexDataWriter writer, Collection<? extends MethodKey> methods) protected abstract voidwriteEncodedValue(DexWriter<StringKey, StringRef, TypeKey, TypeRef, ProtoRefKey, FieldRefKey, MethodRefKey, ClassKey, CallSiteKey, MethodHandleKey, AnnotationKey, AnnotationSetKey, TypeListKey, FieldKey, MethodKey, EncodedArrayKey, EncodedValue, AnnotationElement, StringSectionType, TypeSectionType, ProtoSectionType, FieldSectionType, MethodSectionType, ClassSectionType, CallSiteSectionType, MethodHandleSectionType, TypeListSectionType, AnnotationSectionType, AnnotationSetSectionType, EncodedArraySectionType>.InternalEncodedValueWriter writer, EncodedValue encodedValue) private voidwriteFields(DexDataWriter writer) private voidwriteHeader(DexDataWriter writer, int dataOffset, int fileSize) private voidwriteMapItem(DexDataWriter writer) private voidwriteMapItem(DexDataWriter writer, int type, int size, int offset) private voidwriteMethodHandles(DexDataWriter writer) private voidwriteMethods(DexDataWriter writer) private voidwriteProtos(DexDataWriter writer) private voidwriteSectionInfo(DexDataWriter writer, int numItems, int offset) private voidwriteStrings(DexDataWriter indexWriter, DexDataWriter offsetWriter) voidwriteTo(DexDataStore dest) voidwriteTo(DexDataStore dest, DeferredOutputStreamFactory tempFactory) private voidwriteTypeLists(DexDataWriter writer) private voidwriteTypes(DexDataWriter writer)
-
Field Details
-
NO_INDEX
public static final int NO_INDEX- See Also:
-
NO_OFFSET
public static final int NO_OFFSET- See Also:
-
MAX_POOL_SIZE
public static final int MAX_POOL_SIZE- See Also:
-
opcodes
-
stringIndexSectionOffset
protected int stringIndexSectionOffset -
typeSectionOffset
protected int typeSectionOffset -
protoSectionOffset
protected int protoSectionOffset -
fieldSectionOffset
protected int fieldSectionOffset -
methodSectionOffset
protected int methodSectionOffset -
classIndexSectionOffset
protected int classIndexSectionOffset -
callSiteSectionOffset
protected int callSiteSectionOffset -
methodHandleSectionOffset
protected int methodHandleSectionOffset -
stringDataSectionOffset
protected int stringDataSectionOffset -
classDataSectionOffset
protected int classDataSectionOffset -
typeListSectionOffset
protected int typeListSectionOffset -
encodedArraySectionOffset
protected int encodedArraySectionOffset -
annotationSectionOffset
protected int annotationSectionOffset -
annotationSetSectionOffset
protected int annotationSetSectionOffset -
annotationSetRefSectionOffset
protected int annotationSetRefSectionOffset -
annotationDirectorySectionOffset
protected int annotationDirectorySectionOffset -
debugSectionOffset
protected int debugSectionOffset -
codeSectionOffset
protected int codeSectionOffset -
mapSectionOffset
protected int mapSectionOffset -
hasHiddenApiRestrictions
protected boolean hasHiddenApiRestrictions -
numAnnotationSetRefItems
protected int numAnnotationSetRefItems -
numAnnotationDirectoryItems
protected int numAnnotationDirectoryItems -
numDebugInfoItems
protected int numDebugInfoItems -
numCodeItemItems
protected int numCodeItemItems -
numClassDataItems
protected int numClassDataItems -
stringSection
-
typeSection
-
protoSection
public final ProtoSectionType extends ProtoSection<StringKey,TypeKey, protoSectionProtoRefKey, TypeListKey> -
fieldSection
public final FieldSectionType extends FieldSection<StringKey,TypeKey, fieldSectionFieldRefKey, FieldKey> -
methodSection
public final MethodSectionType extends MethodSection<StringKey,TypeKey, methodSectionProtoRefKey, MethodRefKey, MethodKey> -
classSection
public final ClassSectionType extends ClassSection<StringKey,TypeKey, classSectionTypeListKey, ClassKey, FieldKey, MethodKey, AnnotationSetKey, EncodedArrayKey> -
callSiteSection
public final CallSiteSectionType extends CallSiteSection<CallSiteKey,EncodedArrayKey> callSiteSection -
methodHandleSection
public final MethodHandleSectionType extends MethodHandleSection<MethodHandleKey,FieldRefKey, methodHandleSectionMethodRefKey> -
typeListSection
-
annotationSection
public final AnnotationSectionType extends AnnotationSection<StringKey,TypeKey, annotationSectionAnnotationKey, AnnotationElement, EncodedValue> -
annotationSetSection
public final AnnotationSetSectionType extends AnnotationSetSection<AnnotationKey,AnnotationSetKey> annotationSetSection -
encodedArraySection
public final EncodedArraySectionType extends EncodedArraySection<EncodedArrayKey,EncodedValue> encodedArraySection -
overflowableSections
-
callSiteComparator
private Comparator<Map.Entry<? extends CallSiteKey extends CallSiteReference,Integer>> callSiteComparator -
toStringKeyComparator
-
-
Constructor Details
-
DexWriter
-
-
Method Details
-
getSectionProvider
@Nonnull protected abstract DexWriter<StringKey,StringRef, getSectionProvider()TypeKey, TypeRef, ProtoRefKey, FieldRefKey, MethodRefKey, ClassKey, CallSiteKey, MethodHandleKey, AnnotationKey, AnnotationSetKey, TypeListKey, FieldKey, MethodKey, EncodedArrayKey, EncodedValue, AnnotationElement, StringSectionType, TypeSectionType, ProtoSectionType, FieldSectionType, MethodSectionType, ClassSectionType, CallSiteSectionType, MethodHandleSectionType, TypeListSectionType, AnnotationSectionType, AnnotationSetSectionType, EncodedArraySectionType>.SectionProvider -
writeEncodedValue
protected abstract void writeEncodedValue(@Nonnull DexWriter<StringKey, StringRef, throws IOExceptionTypeKey, TypeRef, ProtoRefKey, FieldRefKey, MethodRefKey, ClassKey, CallSiteKey, MethodHandleKey, AnnotationKey, AnnotationSetKey, TypeListKey, FieldKey, MethodKey, EncodedArrayKey, EncodedValue, AnnotationElement, StringSectionType, TypeSectionType, ProtoSectionType, FieldSectionType, MethodSectionType, ClassSectionType, CallSiteSectionType, MethodHandleSectionType, TypeListSectionType, AnnotationSectionType, AnnotationSetSectionType, EncodedArraySectionType>.InternalEncodedValueWriter writer, @Nonnull EncodedValue encodedValue) - Throws:
IOException
-
comparableKeyComparator
private static <T extends Comparable<? super T>> Comparator<Map.Entry<? extends T,?>> comparableKeyComparator() -
getDataSectionOffset
private int getDataSectionOffset() -
getMethodReferences
-
getFieldReferences
-
getTypeReferences
-
hasOverflowed
public boolean hasOverflowed()Checks whether any of the size-sensitive constant pools have overflowed and have more than 64Ki entries. Note that even if this returns true, it may still be possible to successfully write the dex file, if the overflowed items are not referenced anywhere that uses a 16-bit index.- Returns:
- true if any of the size-sensitive constant pools have overflowed
-
hasOverflowed
public boolean hasOverflowed(int maxPoolSize) Checks whether any of the size-sensitive constant pools have more than the supplied maximum number of entries.- Parameters:
maxPoolSize- the maximum number of entries allowed in any of the size-sensitive constant pools- Returns:
- true if any of the size-sensitive constant pools have overflowed the supplied size limit
-
writeTo
- Throws:
IOException
-
writeTo
public void writeTo(@Nonnull DexDataStore dest, @Nonnull DeferredOutputStreamFactory tempFactory) throws IOException - Throws:
IOException
-
updateSignature
- Throws:
IOException
-
updateChecksum
- Throws:
IOException
-
outputAt
- Throws:
IOException
-
writeStrings
private void writeStrings(@Nonnull DexDataWriter indexWriter, @Nonnull DexDataWriter offsetWriter) throws IOException - Throws:
IOException
-
writeTypes
- Throws:
IOException
-
writeProtos
- Throws:
IOException
-
writeFields
- Throws:
IOException
-
writeMethods
- Throws:
IOException
-
writeClasses
private void writeClasses(@Nonnull DexDataStore dataStore, @Nonnull DexDataWriter indexWriter, @Nonnull DexDataWriter offsetWriter) throws IOException - Throws:
IOException
-
shouldWriteHiddenApiRestrictions
private boolean shouldWriteHiddenApiRestrictions() -
writeClass
private int writeClass(@Nonnull DexDataWriter indexWriter, @Nonnull DexDataWriter offsetWriter, int nextIndex, @Nullable Map.Entry<? extends ClassKey, Integer> entry) throws IOExceptionWrites out the class_def_item and class_data_item for the given class. This will recursively write out any unwritten superclass/interface before writing the class itself, as per the dex specification.- Returns:
- the index for the next class to be written
- Throws:
IOException
-
writeCallSites
- Throws:
IOException
-
writeMethodHandles
- Throws:
IOException
-
writeEncodedFields
private void writeEncodedFields(@Nonnull DexDataWriter writer, @Nonnull Collection<? extends FieldKey> fields) throws IOException - Throws:
IOException
-
writeEncodedMethods
private void writeEncodedMethods(@Nonnull DexDataWriter writer, @Nonnull Collection<? extends MethodKey> methods) throws IOException - Throws:
IOException
-
writeTypeLists
- Throws:
IOException
-
writeEncodedArrays
- Throws:
IOException
-
writeAnnotations
- Throws:
IOException
-
writeAnnotationSets
- Throws:
IOException
-
writeAnnotationSetRefs
- Throws:
IOException
-
writeAnnotationDirectories
- Throws:
IOException
-
writeDebugAndCodeItems
private void writeDebugAndCodeItems(@Nonnull DexDataWriter offsetWriter, @Nonnull DeferredOutputStream temp) throws IOException - Throws:
IOException
-
fixInstructions
-
writeDebugItem
private int writeDebugItem(@Nonnull DexDataWriter writer, @Nonnull DebugWriter<StringKey, TypeKey> debugWriter, @Nullable Iterable<? extends StringKey> parameterNames, @Nullable Iterable<? extends DebugItem> debugItems) throws IOException- Throws:
IOException
-
writeCodeItem
private int writeCodeItem(@Nonnull DexDataWriter writer, @Nonnull ByteArrayOutputStream ehBuf, @Nonnull MethodKey methodKey, @Nonnull List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks, @Nullable Iterable<? extends Instruction> instructions, int debugItemOffset) throws IOException - Throws:
IOException
-
calcNumItems
private int calcNumItems() -
writeMapItem
- Throws:
IOException
-
writeMapItem
private void writeMapItem(@Nonnull DexDataWriter writer, int type, int size, int offset) throws IOException - Throws:
IOException
-
writeHeader
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException - Throws:
IOException
-
writeSectionInfo
- Throws:
IOException
-
shouldCreateEmptyAnnotationSet
private boolean shouldCreateEmptyAnnotationSet()
-