public ClassData readClassData(ClassDef classDef) { int offset = classDef.classDataOffset; if (offset == 0) { throw new IllegalArgumentException("offset == 0"); } return openSection(offset).readClassData(); }
public Code readCode(ClassData.Method method) { int offset = method.codeOffset; if (offset == 0) { throw new IllegalArgumentException("offset == 0"); } return openSection(offset).readCode(); }
/** * <b>IMPORTANT</b> To open a dex section by {@code TableOfContents.Section}, * please use {@code openSection(TableOfContents.Section tocSec)} instead of * passing tocSec.off to this method. * * <b>Because dex section returned by this method never checks * tocSec's bound when reading or writing data.</b> */ public Section openSection(int position) { if (position < 0 || position >= data.capacity()) { throw new IllegalArgumentException( "position=" + position + " length=" + data.capacity() ); } ByteBuffer sectionData = data.duplicate(); sectionData.order(ByteOrder.LITTLE_ENDIAN); // necessary? sectionData.position(position); sectionData.limit(data.capacity()); return new Section("temp-section", sectionData); }
ClassData oldClassData = oldDex.openSection(oldClassDataOffset).readClassData(); ClassData newClassData = newDex.openSection(newClassDataOffset).readClassData();
private boolean isSameAnnotationSet( Dex oldDex, Dex newDex, int oldAnnotationSetOffset, int newAnnotationSetOffset ) { if (oldAnnotationSetOffset == 0 && newAnnotationSetOffset == 0) { return true; } if (oldAnnotationSetOffset == 0 || newAnnotationSetOffset == 0) { return false; } AnnotationSet oldClassAnnotationSet = oldDex.openSection(oldAnnotationSetOffset).readAnnotationSet(); AnnotationSet newClassAnnotationSet = newDex.openSection(newAnnotationSetOffset).readAnnotationSet(); int oldAnnotationOffsetCount = oldClassAnnotationSet.annotationOffsets.length; int newAnnotationOffsetCount = newClassAnnotationSet.annotationOffsets.length; if (oldAnnotationOffsetCount != newAnnotationOffsetCount) { return false; } for (int i = 0; i < oldAnnotationOffsetCount; ++i) { if (!isSameAnnotation( oldDex, newDex, oldClassAnnotationSet.annotationOffsets[i], newClassAnnotationSet.annotationOffsets[i] )) { return false; } } return true; }
public void writeHeader(Dex.Section out) throws IOException { out.write(DexFormat.apiToMagic(DexFormat.API_NO_EXTENDED_OPCODES).getBytes("UTF-8")); out.writeInt(checksum); out.write(signature); out.writeInt(fileSize); out.writeInt(SizeOf.HEADER_ITEM); out.writeInt(DexFormat.ENDIAN_TAG); out.writeInt(linkSize); out.writeInt(linkOff); out.writeInt(mapList.off); out.writeInt(stringIds.size); out.writeInt((stringIds.exists() ? stringIds.off : 0)); out.writeInt(typeIds.size); out.writeInt((typeIds.exists() ? typeIds.off : 0)); out.writeInt(protoIds.size); out.writeInt((protoIds.exists() ? protoIds.off : 0)); out.writeInt(fieldIds.size); out.writeInt((fieldIds.exists() ? fieldIds.off : 0)); out.writeInt(methodIds.size); out.writeInt((methodIds.exists() ? methodIds.off : 0)); out.writeInt(classDefs.size); out.writeInt((classDefs.exists() ? classDefs.off : 0)); out.writeInt(dataSize); out.writeInt(dataOff); }
/** * <b>IMPORTANT</b> To open a dex section by {@code TableOfContents.Section}, * please use {@code openSection(TableOfContents.Section tocSec)} instead of * passing tocSec.off to this method. * * <b>Because dex section returned by this method never checks * tocSec's bound when reading or writing data.</b> */ public Section openSection(int position) { if (position < 0 || position >= data.capacity()) { throw new IllegalArgumentException( "position=" + position + " length=" + data.capacity() ); } ByteBuffer sectionData = data.duplicate(); sectionData.order(ByteOrder.LITTLE_ENDIAN); // necessary? sectionData.position(position); sectionData.limit(data.capacity()); return new Section("temp-section", sectionData); }
public void writeMap(Dex.Section out) throws IOException { int count = 0; for (Section section : sections) { if (section.exists()) { count++; } } out.writeInt(count); for (Section section : sections) { if (section.exists()) { out.writeShort(section.type); out.writeShort((short) 0); out.writeInt(section.size); out.writeInt(section.off); } } }
public Section openSection(TableOfContents.Section tocSec) { int position = tocSec.off; if (position < 0 || position >= data.capacity()) { throw new IllegalArgumentException( "position=" + position + " length=" + data.capacity() ); } ByteBuffer sectionData = data.duplicate(); sectionData.order(ByteOrder.LITTLE_ENDIAN); // necessary? sectionData.position(position); sectionData.limit(position + tocSec.byteCount); return new Section("section", sectionData); }
/** * @inheritDoc */ @Override public int writeEncodedArray(EncodedValue encodedValue) { ensureFourBytesAligned(tableOfContents.encodedArrays, true); return super.writeEncodedArray(encodedValue); } }
/** * @inheritDoc */ @Override public int writeAnnotationSet(AnnotationSet annotationSet) { ensureFourBytesAligned(tableOfContents.annotationSets, true); return super.writeAnnotationSet(annotationSet); }
/** * @inheritDoc */ @Override public int writeAnnotation(Annotation annotation) { ensureFourBytesAligned(tableOfContents.annotations, true); return super.writeAnnotation(annotation); }
/** * @inheritDoc */ @Override public int writeClassData(ClassData classData) { ensureFourBytesAligned(tableOfContents.classDatas, true); return super.writeClassData(classData); }
/** * @inheritDoc */ @Override public int writeClassDef(ClassDef classDef) { ensureFourBytesAligned(tableOfContents.classDefs, true); return super.writeClassDef(classDef); }
/** * @inheritDoc */ @Override public int writeProtoId(ProtoId protoId) { ensureFourBytesAligned(tableOfContents.protoIds, true); return super.writeProtoId(protoId); }
/** * @inheritDoc */ @Override public int writeMethodId(MethodId methodId) { ensureFourBytesAligned(tableOfContents.methodIds, true); return super.writeMethodId(methodId); }
/** * @inheritDoc */ @Override public int writeFieldId(FieldId fieldId) { ensureFourBytesAligned(tableOfContents.fieldIds, true); return super.writeFieldId(fieldId); }
/** * @inheritDoc */ @Override public Annotation readAnnotation() { ensureFourBytesAligned(tableOfContents.annotations, false); return super.readAnnotation(); }
/** * @inheritDoc */ @Override public DebugInfoItem readDebugInfoItem() { ensureFourBytesAligned(tableOfContents.debugInfos, false); return super.readDebugInfoItem(); }