/** * Adds an item to this instance. This will in turn tell the given item * that it has been added to this instance. It is invalid to add the * same item to more than one instance, nor to add the same items * multiple times to a single instance. * * @param item {@code non-null;} the item to add */ public void add(OffsettedItem item) { throwIfPrepared(); try { if (item.getAlignment() > getAlignment()) { throw new IllegalArgumentException( "incompatible item alignment"); } } catch (NullPointerException ex) { // Elucidate the exception. throw new NullPointerException("item == null"); } items.add(item); }
/** {@inheritDoc} */ @Override protected void prepare0() { DexFile file = getFile(); /* * It's okay for new items to be added as a result of an * addContents() call; we just have to deal with the possibility. */ int i = 0; for (;;) { int sz = items.size(); if (i >= sz) { break; } for (/*i*/; i < sz; i++) { OffsettedItem one = items.get(i); one.addContents(file); } } }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { MixedItemSection wordData = file.getWordData(); annotations = wordData.intern(annotations); }
classData.prepare(); wordData.prepare(); byteData.prepare(); methodIds.prepare(); fieldIds.prepare(); protoIds.prepare(); typeLists.prepare(); typeIds.prepare(); stringIds.prepare(); stringData.prepare(); header.prepare(); map.prepare(); ((MixedItemSection) one).placeItems(); wordData.writeIndexAnnotation(out, ItemType.TYPE_CODE_ITEM, "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out);
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { throwIfNotPrepared(); if (writeSize == -1) { throw new RuntimeException("write size not yet set"); } int sz = writeSize; int offset = (sz == 0) ? 0 : getFileOffset(); String name = getName(); if (name == null) { name = "<unnamed>"; } int spaceCount = 15 - name.length(); char[] spaceArr = new char[spaceCount]; Arrays.fill(spaceArr, ' '); String spaces = new String(spaceArr); if (out.annotates()) { out.annotate(4, name + "_size:" + spaces + Hex.u4(sz)); out.annotate(4, name + "_off: " + spaces + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { if (data == null) { // The string data hasn't yet been added, so add it. MixedItemSection stringData = file.getStringData(); data = new StringDataItem(value); stringData.add(data); } }
/** {@inheritDoc} */ @Override public int writeSize() { throwIfNotPrepared(); return writeSize; }
/** * Constructs an instance. It is initially empty. */ public DexFile(DexOptions dexOptions) { this.dexOptions = dexOptions; header = new HeaderSection(this); typeLists = new MixedItemSection(null, this, 4, SortType.NONE); wordData = new MixedItemSection("word_data", this, 4, SortType.TYPE); stringData = new MixedItemSection("string_data", this, 1, SortType.INSTANCE); classData = new MixedItemSection(null, this, 1, SortType.NONE); byteData = new MixedItemSection("byte_data", this, 1, SortType.TYPE); stringIds = new StringIdsSection(this); typeIds = new TypeIdsSection(this); protoIds = new ProtoIdsSection(this); fieldIds = new FieldIdsSection(this); methodIds = new MethodIdsSection(this); classDefs = new ClassDefsSection(this); map = new MixedItemSection("map", this, 4, SortType.NONE); /* * This is the list of sections in the order they appear in * the final output. */ sections = new Section[] { header, stringIds, typeIds, protoIds, fieldIds, methodIds, classDefs, wordData, typeLists, stringData, byteData, classData, map }; fileSize = -1; dumpWidth = 79; }
int mapOff = file.getMap().getFileOffset(); Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection();
classData.prepare(); wordData.prepare(); byteData.prepare(); methodIds.prepare(); fieldIds.prepare(); protoIds.prepare(); typeLists.prepare(); typeIds.prepare(); stringIds.prepare(); stringData.prepare(); header.prepare(); map.prepare(); ((MixedItemSection) one).placeItems(); wordData.writeIndexAnnotation(out, ItemType.TYPE_CODE_ITEM, "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out);
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { throwIfNotPrepared(); if (writeSize == -1) { throw new RuntimeException("write size not yet set"); } int sz = writeSize; int offset = (sz == 0) ? 0 : getFileOffset(); String name = getName(); if (name == null) { name = "<unnamed>"; } int spaceCount = 15 - name.length(); char[] spaceArr = new char[spaceCount]; Arrays.fill(spaceArr, ' '); String spaces = new String(spaceArr); if (out.annotates()) { out.annotate(4, name + "_size:" + spaces + Hex.u4(sz)); out.annotate(4, name + "_off: " + spaces + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { if (data == null) { // The string data hasn't yet been added, so add it. MixedItemSection stringData = file.getStringData(); data = new StringDataItem(value); stringData.add(data); } }
/** {@inheritDoc} */ @Override public int writeSize() { throwIfNotPrepared(); return writeSize; }
/** * Constructs an instance. It is initially empty. */ public DexFile(DexOptions dexOptions) { this.dexOptions = dexOptions; header = new HeaderSection(this); typeLists = new MixedItemSection(null, this, 4, SortType.NONE); wordData = new MixedItemSection("word_data", this, 4, SortType.TYPE); stringData = new MixedItemSection("string_data", this, 1, SortType.INSTANCE); classData = new MixedItemSection(null, this, 1, SortType.NONE); byteData = new MixedItemSection("byte_data", this, 1, SortType.TYPE); stringIds = new StringIdsSection(this); typeIds = new TypeIdsSection(this); protoIds = new ProtoIdsSection(this); fieldIds = new FieldIdsSection(this); methodIds = new MethodIdsSection(this); classDefs = new ClassDefsSection(this); map = new MixedItemSection("map", this, 4, SortType.NONE); /* * This is the list of sections in the order they appear in * the final output. */ sections = new Section[] { header, stringIds, typeIds, protoIds, fieldIds, methodIds, classDefs, wordData, typeLists, stringData, byteData, classData, map }; fileSize = -1; dumpWidth = 79; }
int mapOff = file.getMap().getFileOffset(); Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection();
classData.prepare(); wordData.prepare(); byteData.prepare(); methodIds.prepare(); fieldIds.prepare(); protoIds.prepare(); typeLists.prepare(); typeIds.prepare(); stringIds.prepare(); stringData.prepare(); header.prepare(); map.prepare(); ((MixedItemSection) one).placeItems(); wordData.writeIndexAnnotation(out, ItemType.TYPE_CODE_ITEM, "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out);
/** * Writes the portion of the file header that refers to this instance. * * @param out {@code non-null;} where to write */ public void writeHeaderPart(AnnotatedOutput out) { throwIfNotPrepared(); if (writeSize == -1) { throw new RuntimeException("write size not yet set"); } int sz = writeSize; int offset = (sz == 0) ? 0 : getFileOffset(); String name = getName(); if (name == null) { name = "<unnamed>"; } int spaceCount = 15 - name.length(); char[] spaceArr = new char[spaceCount]; Arrays.fill(spaceArr, ' '); String spaces = new String(spaceArr); if (out.annotates()) { out.annotate(4, name + "_size:" + spaces + Hex.u4(sz)); out.annotate(4, name + "_off: " + spaces + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** * Adds an item to this instance. This will in turn tell the given item * that it has been added to this instance. It is invalid to add the * same item to more than one instance, nor to add the same items * multiple times to a single instance. * * @param item {@code non-null;} the item to add */ public void add(OffsettedItem item) { throwIfPrepared(); try { if (item.getAlignment() > getAlignment()) { throw new IllegalArgumentException( "incompatible item alignment"); } } catch (NullPointerException ex) { // Elucidate the exception. throw new NullPointerException("item == null"); } items.add(item); }