/** {@inheritDoc} */ @Override protected int getTypoidIdx(DexFile file) { ProtoIdsSection protoIds = file.getProtoIds(); return protoIds.indexOf(getMethodRef().getPrototype()); }
/** {@inheritDoc} */ @Override protected void orderItems() { int idx = 0; for (Object i : items()) { ((ProtoIdItem) i).setIndex(idx); idx++; } } }
/** * Gets the index of the given prototype, which must have * been added to this instance. * * @param prototype {@code non-null;} the prototype to look up * @return {@code >= 0;} the reference's index */ public int indexOf(Prototype prototype) { if (prototype == null) { throw new NullPointerException("prototype == null"); } throwIfNotPrepared(); ProtoIdItem item = protoIds.get(prototype); if (item == null) { throw new IllegalArgumentException("not found"); } return item.getIndex(); }
/** * 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(); int sz = protoIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (sz > 65536) { throw new UnsupportedOperationException("too many proto ids"); } if (out.annotates()) { out.annotate(4, "proto_ids_size: " + Hex.u4(sz)); out.annotate(4, "proto_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { super.addContents(file); ProtoIdsSection protoIds = file.getProtoIds(); protoIds.intern(getMethodRef().getPrototype()); }
/** * Interns an element into this instance. * * @param prototype {@code non-null;} the prototype to intern * @return {@code non-null;} the interned reference */ public synchronized ProtoIdItem intern(Prototype prototype) { if (prototype == null) { throw new NullPointerException("prototype == null"); } throwIfPrepared(); ProtoIdItem result = protoIds.get(prototype); if (result == null) { result = new ProtoIdItem(prototype); protoIds.put(prototype, result); } return result; }
/** * 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; }
file.getProtoIds().writeHeaderPart(out); file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out);
protoIds.prepare(); typeLists.prepare(); typeIds.prepare();
/** * 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(); int sz = protoIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (sz > 65536) { throw new UnsupportedOperationException("too many proto ids"); } if (out.annotates()) { out.annotate(4, "proto_ids_size: " + Hex.u4(sz)); out.annotate(4, "proto_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { super.addContents(file); ProtoIdsSection protoIds = file.getProtoIds(); protoIds.intern(getMethodRef().getPrototype()); }
/** * Interns an element into this instance. * * @param prototype {@code non-null;} the prototype to intern * @return {@code non-null;} the interned reference */ public synchronized ProtoIdItem intern(Prototype prototype) { if (prototype == null) { throw new NullPointerException("prototype == null"); } throwIfPrepared(); ProtoIdItem result = protoIds.get(prototype); if (result == null) { result = new ProtoIdItem(prototype); protoIds.put(prototype, result); } return result; }
/** * 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; }
file.getProtoIds().writeHeaderPart(out); file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out);
methodIds.prepare(); fieldIds.prepare(); protoIds.prepare(); typeLists.prepare(); typeIds.prepare();
/** * 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(); int sz = protoIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (sz > 65536) { throw new UnsupportedOperationException("too many proto ids"); } if (out.annotates()) { out.annotate(4, "proto_ids_size: " + Hex.u4(sz)); out.annotate(4, "proto_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
/** * Gets the index of the given prototype, which must have * been added to this instance. * * @param prototype {@code non-null;} the prototype to look up * @return {@code >= 0;} the reference's index */ public int indexOf(Prototype prototype) { if (prototype == null) { throw new NullPointerException("prototype == null"); } throwIfNotPrepared(); ProtoIdItem item = protoIds.get(prototype); if (item == null) { throw new IllegalArgumentException("not found"); } return item.getIndex(); }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { super.addContents(file); ProtoIdsSection protoIds = file.getProtoIds(); protoIds.intern(getMethodRef().getPrototype()); }
/** {@inheritDoc} */ @Override protected int getTypoidIdx(DexFile file) { ProtoIdsSection protoIds = file.getProtoIds(); return protoIds.indexOf(getMethodRef().getPrototype()); }
/** {@inheritDoc} */ @Override protected void orderItems() { int idx = 0; for (Object i : items()) { ((ProtoIdItem) i).setIndex(idx); idx++; } } }