/** {@inheritDoc} */ public void writeValue(AnnotatedOutput out) { byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex()); if (out.annotates()) { out.annotate(1, "value_type=" + ValueType.VALUE_STRING.name() + ",value_arg=" + (bytes.length - 1)); out.annotate(bytes.length, "value: \"" + Utf8Utils.escapeString(value.getStringValue()) + "\""); } out.writeByte(ValueType.VALUE_STRING.value | ((bytes.length - 1) << 5)); out.write(bytes); }
/** * Returns a <code>StringIdItem</code> for the given values, and that has been interned into * the given <code>DexFile</code> * @param dexFile The <code>DexFile</code> that this item will belong to * @param stringValue The string value that this item represents * @return a <code>StringIdItem</code> for the given values, and that has been interned into * the given <code>DexFile</code> */ public static StringIdItem internStringIdItem(DexFile dexFile, String stringValue) { StringDataItem stringDataItem = StringDataItem.internStringDataItem(dexFile, stringValue); if (stringDataItem == null) { return null; } StringIdItem stringIdItem = new StringIdItem(dexFile, stringDataItem); return dexFile.StringIdsSection.intern(stringIdItem); }
/** {@inheritDoc} */ public int compareTo(TypeIdItem o) { //sort by the index of the StringIdItem return typeDescriptor.compareTo(o.typeDescriptor); }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, typeDescriptor.getConciseIdentity()); } out.writeInt(typeDescriptor.getIndex()); }
/** * Returns the type descriptor as a <code>String</code> for this type * @return the type descriptor as a <code>String</code> for this type */ public String getTypeDescriptor() { return typeDescriptor.getStringValue(); }
public void emit(DexFile dexFile, Output out, List<Item> referencedItems) { emitAdvancePC(out, address); emitSetFile(out); if (fileName != null) { referencedItems.add(StringIdItem.internStringIdItem(dexFile, fileName)); } } }
@Override public int hashCode() { return value.hashCode(); } }
/** * Looks up the <code>TypeIdItem</code> from the given <code>DexFile</code> for the given * type descriptor * @param dexFile the <code>Dexfile</code> to find the type in * @param typeDescriptor The string containing the type descriptor to look up * @return a <code>TypeIdItem</code> from the given <code>DexFile</code> for the given * type descriptor, or null if it doesn't exist */ public static TypeIdItem lookupTypeIdItem(DexFile dexFile, String typeDescriptor) { StringIdItem stringIdItem = StringIdItem.lookupStringIdItem(dexFile, typeDescriptor); if (stringIdItem == null) { return null; } TypeIdItem typeIdItem = new TypeIdItem(dexFile, stringIdItem); return dexFile.TypeIdsSection.getInternedItem(typeIdItem); }
/** {@inheritDoc} */ public int compareTo(StringIdItem o) { //sort by the string value return getStringValue().compareTo(o.getStringValue()); }
public void emit(DexFile dexFile, Output out, List<Item> referencedItems) { emitAdvancePC(out, address); emitStartLocal(out, registerNum); referencedItems.add(localName==null?null:StringIdItem.internStringIdItem(dexFile, localName)); referencedItems.add(localType==null?null:TypeIdItem.internTypeIdItem(dexFile, StringIdItem.internStringIdItem(dexFile, localType))); } }
@Override public int hashCode() { return typeDescriptor.hashCode(); }
/** {@inheritDoc} */ public int placeValue(int offset) { return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1; }
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(4, typeDescriptor.getConciseIdentity()); } out.writeInt(typeDescriptor.getIndex()); }
String fieldType = field.type; StringIdItem fieldNameItem = StringIdItem.lookupStringIdItem(dexFile, fieldName); if (fieldNameItem == null) { return null;
/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { if (out.annotates()) { out.annotate(2, "class_type: " + classType.getTypeDescriptor()); out.annotate(2, "field_type: " + fieldType.getTypeDescriptor()); out.annotate(4, "field_name: " + fieldName.getStringValue()); } int classIndex = classType.getIndex(); if (classIndex > 0xffff) { throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of " + "defining class %s is too large", getFieldString(), classType.getTypeDescriptor())); } out.writeShort(classIndex); int typeIndex = fieldType.getIndex(); if (typeIndex > 0xffff) { throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of field " + "type %s is too large", getFieldString(), fieldType.getTypeDescriptor())); } out.writeShort(typeIndex); out.writeInt(fieldName.getIndex()); }
/** {@inheritDoc} */ public String getConciseIdentity() { return "string_id_item: " + Utf8Utils.escapeString(getStringValue()); }
public void emit(DexFile dexFile, Output out, List<Item> referencedItems) { emitAdvancePC(out, address); emitStartLocalExtended(out, registerNum); if (localName != null) { referencedItems.add(StringIdItem.internStringIdItem(dexFile, localName)); } if (localType != null) { referencedItems.add(TypeIdItem.internTypeIdItem(dexFile, StringIdItem.internStringIdItem(dexFile, localType))); } if (signature != null) { referencedItems.add(StringIdItem.internStringIdItem(dexFile, signature)); } } }
/** * calculate and cache the hashcode */ private void calcHashCode() { hashCode = annotationType.hashCode(); for (int i=0; i<names.length; i++) { hashCode = 31 * hashCode + names[i].hashCode(); hashCode = 31 * hashCode + values[i].hashCode(); } }
/** {@inheritDoc} */ public int placeValue(int offset) { offset = offset + Leb128Utils.unsignedLeb128Size(annotationType.getIndex()); offset = offset + Leb128Utils.unsignedLeb128Size(names.length); for (int i=0; i<names.length; i++) { offset = offset + Leb128Utils.unsignedLeb128Size(names[i].getIndex()); offset = values[i].placeValue(offset); } return offset; }