Java Code Examples for com.android.dx.util.AnnotatedOutput#writeInt()
The following examples show how to use
com.android.dx.util.AnnotatedOutput#writeInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UniformListItem.java From buck with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int size = items.size(); if (out.annotates()) { out.annotate(0, offsetString() + " " + typeName()); out.annotate(4, " size: " + Hex.u4(size)); } out.writeInt(size); for (OffsettedItem i : items) { i.writeTo(file, out); } }
Example 2
Source File: TypeIdsSection.java From Box with Apache License 2.0 | 6 votes |
/** * 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 = typeIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (sz > DexFormat.MAX_TYPE_IDX + 1) { throw new DexIndexOverflowException( String.format("Too many type identifiers to fit in one dex file: %1$d; max is %2$d.%n" + "You may try using multi-dex. If multi-dex is enabled then the list of " + "classes for the main dex list is too large.", items().size(), DexFormat.MAX_MEMBER_IDX + 1)); } if (out.annotates()) { out.annotate(4, "type_ids_size: " + Hex.u4(sz)); out.annotate(4, "type_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
Example 3
Source File: UniformListItem.java From Box with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int size = items.size(); if (out.annotates()) { out.annotate(0, offsetString() + " " + typeName()); out.annotate(4, " size: " + Hex.u4(size)); } out.writeInt(size); for (OffsettedItem i : items) { i.writeTo(file, out); } }
Example 4
Source File: TypeListItem.java From Box with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { TypeIdsSection typeIds = file.getTypeIds(); int sz = list.size(); if (out.annotates()) { out.annotate(0, offsetString() + " type_list"); out.annotate(HEADER_SIZE, " size: " + Hex.u4(sz)); for (int i = 0; i < sz; i++) { Type one = list.getType(i); int idx = typeIds.indexOf(one); out.annotate(ELEMENT_SIZE, " " + Hex.u2(idx) + " // " + one.toHuman()); } } out.writeInt(sz); for (int i = 0; i < sz; i++) { out.writeShort(typeIds.indexOf(list.getType(i))); } }
Example 5
Source File: TypeListItem.java From buck with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { TypeIdsSection typeIds = file.getTypeIds(); int sz = list.size(); if (out.annotates()) { out.annotate(0, offsetString() + " type_list"); out.annotate(HEADER_SIZE, " size: " + Hex.u4(sz)); for (int i = 0; i < sz; i++) { Type one = list.getType(i); int idx = typeIds.indexOf(one); out.annotate(ELEMENT_SIZE, " " + Hex.u2(idx) + " // " + one.toHuman()); } } out.writeInt(sz); for (int i = 0; i < sz; i++) { out.writeShort(typeIds.indexOf(list.getType(i))); } }
Example 6
Source File: TypeListItem.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { TypeIdsSection typeIds = file.getTypeIds(); int sz = list.size(); if (out.annotates()) { out.annotate(0, offsetString() + " type_list"); out.annotate(HEADER_SIZE, " size: " + Hex.u4(sz)); for (int i = 0; i < sz; i++) { Type one = list.getType(i); int idx = typeIds.indexOf(one); out.annotate(ELEMENT_SIZE, " " + Hex.u2(idx) + " // " + one.toHuman()); } } out.writeInt(sz); for (int i = 0; i < sz; i++) { out.writeShort(typeIds.indexOf(list.getType(i))); } }
Example 7
Source File: AnnotationSetItem.java From Box with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { boolean annotates = out.annotates(); int size = items.length; if (annotates) { out.annotate(0, offsetString() + " annotation set"); out.annotate(4, " size: " + Hex.u4(size)); } out.writeInt(size); for (int i = 0; i < size; i++) { AnnotationItem item = items[i]; int offset = item.getAbsoluteOffset(); if (annotates) { out.annotate(4, " entries[" + Integer.toHexString(i) + "]: " + Hex.u4(offset)); items[i].annotateTo(out, " "); } out.writeInt(offset); } }
Example 8
Source File: AnnotationSetRefItem.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int annotationsOff = annotations.getAbsoluteOffset(); if (out.annotates()) { out.annotate(4, " annotations_off: " + Hex.u4(annotationsOff)); } out.writeInt(annotationsOff); }
Example 9
Source File: FieldIdsSection.java From Box with Apache License 2.0 | 5 votes |
/** * 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 = fieldIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (out.annotates()) { out.annotate(4, "field_ids_size: " + Hex.u4(sz)); out.annotate(4, "field_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
Example 10
Source File: TypeIdItem.java From buck with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void writeTo(DexFile file, AnnotatedOutput out) { CstType type = getDefiningClass(); CstString descriptor = type.getDescriptor(); int idx = file.getStringIds().indexOf(descriptor); if (out.annotates()) { out.annotate(0, indexString() + ' ' + descriptor.toHuman()); out.annotate(4, " descriptor_idx: " + Hex.u4(idx)); } out.writeInt(idx); }
Example 11
Source File: StringIdsSection.java From Box with Apache License 2.0 | 5 votes |
/** * 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 = strings.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (out.annotates()) { out.annotate(4, "string_ids_size: " + Hex.u4(sz)); out.annotate(4, "string_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
Example 12
Source File: StringIdItem.java From buck with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void writeTo(DexFile file, AnnotatedOutput out) { int dataOff = data.getAbsoluteOffset(); if (out.annotates()) { out.annotate(0, indexString() + ' ' + value.toQuoted(100)); out.annotate(4, " string_data_off: " + Hex.u4(dataOff)); } out.writeInt(dataOff); }
Example 13
Source File: MapItem.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int value = type.getMapValue(); int offset; if (firstItem == null) { offset = section.getFileOffset(); } else { offset = section.getAbsoluteItemOffset(firstItem); } if (out.annotates()) { out.annotate(0, offsetString() + ' ' + type.getTypeName() + " map"); out.annotate(2, " type: " + Hex.u2(value) + " // " + type.toString()); out.annotate(2, " unused: 0"); out.annotate(4, " size: " + Hex.u4(itemCount)); out.annotate(4, " offset: " + Hex.u4(offset)); } out.writeShort(value); out.writeShort(0); // unused out.writeInt(itemCount); out.writeInt(offset); }
Example 14
Source File: MethodIdsSection.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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 = methodIds.size(); int offset = (sz == 0) ? 0 : getFileOffset(); if (out.annotates()) { out.annotate(4, "method_ids_size: " + Hex.u4(sz)); out.annotate(4, "method_ids_off: " + Hex.u4(offset)); } out.writeInt(sz); out.writeInt(offset); }
Example 15
Source File: ProtoIdItem.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void writeTo(DexFile file, AnnotatedOutput out) { int shortyIdx = file.getStringIds().indexOf(shortForm); int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType()); int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes); if (out.annotates()) { StringBuilder sb = new StringBuilder(); sb.append(prototype.getReturnType().toHuman()); sb.append(" proto("); StdTypeList params = prototype.getParameterTypes(); int size = params.size(); for (int i = 0; i < size; i++) { if (i != 0) { sb.append(", "); } sb.append(params.getType(i).toHuman()); } sb.append(")"); out.annotate(0, indexString() + ' ' + sb.toString()); out.annotate(4, " shorty_idx: " + Hex.u4(shortyIdx) + " // " + shortForm.toQuoted()); out.annotate(4, " return_type_idx: " + Hex.u4(returnIdx) + " // " + prototype.getReturnType().toHuman()); out.annotate(4, " parameters_off: " + Hex.u4(paramsOff)); } out.writeInt(shortyIdx); out.writeInt(returnIdx); out.writeInt(paramsOff); }
Example 16
Source File: MixedItemSection.java From Box with Apache License 2.0 | 5 votes |
/** * 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); }
Example 17
Source File: CatchStructs.java From Box with Apache License 2.0 | 5 votes |
/** * Writes this instance to the given stream. * * @param file {@code non-null;} file this instance is part of * @param out {@code non-null;} where to write to */ public void writeTo(DexFile file, AnnotatedOutput out) { finishProcessingIfNecessary(); if (out.annotates()) { annotateEntries(" ", null, out); } int tableSize = table.size(); for (int i = 0; i < tableSize; i++) { CatchTable.Entry one = table.get(i); int start = one.getStart(); int end = one.getEnd(); int insnCount = end - start; if (insnCount >= 65536) { throw new UnsupportedOperationException( "bogus exception range: " + Hex.u4(start) + ".." + Hex.u4(end)); } out.writeInt(start); out.writeShort(insnCount); out.writeShort(handlerOffsets.get(one.getHandlers())); } out.write(encodedHandlers); }
Example 18
Source File: CatchStructs.java From Box with Apache License 2.0 | 5 votes |
/** * Writes this instance to the given stream. * * @param file {@code non-null;} file this instance is part of * @param out {@code non-null;} where to write to */ public void writeTo(DexFile file, AnnotatedOutput out) { finishProcessingIfNecessary(); if (out.annotates()) { annotateEntries(" ", null, out); } int tableSize = table.size(); for (int i = 0; i < tableSize; i++) { CatchTable.Entry one = table.get(i); int start = one.getStart(); int end = one.getEnd(); int insnCount = end - start; if (insnCount >= 65536) { throw new UnsupportedOperationException( "bogus exception range: " + Hex.u4(start) + ".." + Hex.u4(end)); } out.writeInt(start); out.writeShort(insnCount); out.writeShort(handlerOffsets.get(one.getHandlers())); } out.write(encodedHandlers); }
Example 19
Source File: CodeItem.java From Box with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { boolean annotates = out.annotates(); int regSz = getRegistersSize(); int outsSz = getOutsSize(); int insSz = getInsSize(); int insnsSz = code.getInsns().codeSize(); boolean needPadding = (insnsSz & 1) != 0; int triesSz = (catches == null) ? 0 : catches.triesSize(); int debugOff = (debugInfo == null) ? 0 : debugInfo.getAbsoluteOffset(); if (annotates) { out.annotate(0, offsetString() + ' ' + ref.toHuman()); out.annotate(2, " registers_size: " + Hex.u2(regSz)); out.annotate(2, " ins_size: " + Hex.u2(insSz)); out.annotate(2, " outs_size: " + Hex.u2(outsSz)); out.annotate(2, " tries_size: " + Hex.u2(triesSz)); out.annotate(4, " debug_off: " + Hex.u4(debugOff)); out.annotate(4, " insns_size: " + Hex.u4(insnsSz)); // This isn't represented directly here, but it is useful to see. int size = throwsList.size(); if (size != 0) { out.annotate(0, " throws " + StdTypeList.toHuman(throwsList)); } } out.writeShort(regSz); out.writeShort(insSz); out.writeShort(outsSz); out.writeShort(triesSz); out.writeInt(debugOff); out.writeInt(insnsSz); writeCodes(file, out); if (catches != null) { if (needPadding) { if (annotates) { out.annotate(2, " padding: 0"); } out.writeShort(0); } catches.writeTo(file, out); } if (annotates) { /* * These are pointed at in the code header (above), but it's less * distracting to expand on them at the bottom of the code. */ if (debugInfo != null) { out.annotate(0, " debug info"); debugInfo.annotateTo(file, out, " "); } } }
Example 20
Source File: HeaderItem.java From Box with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void writeTo(DexFile file, AnnotatedOutput out) { int mapOff = file.getMap().getFileOffset(); Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection(); int dataOff = firstDataSection.getFileOffset(); int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff; String magic = file.getDexOptions().getMagic(); if (out.annotates()) { out.annotate(8, "magic: " + new CstString(magic).toQuoted()); out.annotate(4, "checksum"); out.annotate(20, "signature"); out.annotate(4, "file_size: " + Hex.u4(file.getFileSize())); out.annotate(4, "header_size: " + Hex.u4(SizeOf.HEADER_ITEM)); out.annotate(4, "endian_tag: " + Hex.u4(DexFormat.ENDIAN_TAG)); out.annotate(4, "link_size: 0"); out.annotate(4, "link_off: 0"); out.annotate(4, "map_off: " + Hex.u4(mapOff)); } // Write the magic number. for (int i = 0; i < 8; i++) { out.writeByte(magic.charAt(i)); } // Leave space for the checksum and signature. out.writeZeroes(24); out.writeInt(file.getFileSize()); out.writeInt(SizeOf.HEADER_ITEM); out.writeInt(DexFormat.ENDIAN_TAG); /* * Write zeroes for the link size and data, as the output * isn't a staticly linked file. */ out.writeZeroes(8); out.writeInt(mapOff); // Write out each section's respective header part. file.getStringIds().writeHeaderPart(out); file.getTypeIds().writeHeaderPart(out); file.getProtoIds().writeHeaderPart(out); file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out); file.getClassDefs().writeHeaderPart(out); if (out.annotates()) { out.annotate(4, "data_size: " + Hex.u4(dataSize)); out.annotate(4, "data_off: " + Hex.u4(dataOff)); } out.writeInt(dataSize); out.writeInt(dataOff); }