/** {@inheritDoc} */ protected void writeItem(AnnotatedOutput out) { //yes, the code to write the item is duplicated. This eliminates the need to iterate over the list twice if (out.annotates()) { out.annotate(4, "size: 0x" + Integer.toHexString(typeList.length) + " (" + typeList.length +")"); for (TypeIdItem typeIdItem: typeList) { out.annotate(2, "type_id_item: " + typeIdItem.getTypeDescriptor()); } } out.writeInt(typeList.length); for (TypeIdItem typeIdItem: typeList) { int typeIndex = typeIdItem.getIndex(); if (typeIndex > 0xffff) { throw new RuntimeException(String.format("Error writing type_list entry. The type index of " + "type %s is too large", typeIdItem.getTypeDescriptor())); } out.writeShort(typeIndex); } }
/** * Returns a <code>TypeIdItem</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 typeDescriptor The <code>StringIdItem</code> containing the type descriptor that * this <code>TypeIdItem</code> represents * @return a <code>TypeIdItem</code> for the given values, and that has been interned into * the given <code>DexFile</code> */ public static TypeIdItem internTypeIdItem(DexFile dexFile, StringIdItem typeDescriptor) { TypeIdItem typeIdItem = new TypeIdItem(dexFile, typeDescriptor); return dexFile.TypeIdsSection.intern(typeIdItem); }
public static RegisterType getWideRegisterTypeForTypeIdItem(TypeIdItem typeIdItem, boolean firstRegister) { if (typeIdItem.getRegisterCount() == 1) { throw new RuntimeException("Cannot use this method for non-wide register type: " + typeIdItem.getTypeDescriptor()); } switch (typeIdItem.getTypeDescriptor().charAt(0)) { case 'J': if (firstRegister) { return getRegisterType(Category.LongLo, null); } else { return getRegisterType(Category.LongHi, null); } case 'D': if (firstRegister) { return getRegisterType(Category.DoubleLo, null); } else { return getRegisterType(Category.DoubleHi, null); } default: throw new RuntimeException("Invalid type: " + typeIdItem.getTypeDescriptor()); } }
/** {@inheritDoc} */ public String getConciseIdentity() { return "class_def_item: " + classType.getTypeDescriptor(); }
/** * calculate and cache the hashcode */ private void calcHashCode() { int hashCode = 1; for (TypeIdItem typeIdItem: typeList) { hashCode = 31 * hashCode + typeIdItem.hashCode(); } this.hashCode = hashCode; }
/** * @return the number of registers required for this <code>TypeListItem</code> */ public int getRegisterCount() { int wordCount = 0; for (TypeIdItem typeIdItem: typeList) { wordCount += typeIdItem.getRegisterCount(); } return wordCount; }
/** * @return a string consisting of the shorty form of the type descriptors in this * <code>TypeListItem</code> that are directly concatenated together */ public String getShortyString() { StringBuilder sb = new StringBuilder(); for (TypeIdItem typeIdItem: typeList) { sb.append(typeIdItem.toShorty()); } return sb.toString(); }
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))); } }
TypeIdItem fieldTypeItem = TypeIdItem.lookupTypeIdItem(dexFile, fieldType); if (fieldTypeItem == null) { return null; fieldClass = parents.get(i); TypeIdItem classTypeItem = TypeIdItem.lookupTypeIdItem(dexFile, fieldClass.getClassType()); if (classTypeItem == null) { continue;
/** {@inheritDoc} */ public String getConciseIdentity() { return "type_id_item: " + getTypeDescriptor(); }
@Override public int hashCode() { return value.hashCode(); } }
public static RegisterType getWideRegisterTypeForTypeIdItem(TypeIdItem typeIdItem, boolean firstRegister) { if (typeIdItem.getRegisterCount() == 1) { throw new RuntimeException("Cannot use this method for non-wide register type: " + typeIdItem.getTypeDescriptor()); } switch (typeIdItem.getTypeDescriptor().charAt(0)) { case 'J': if (firstRegister) { return getRegisterType(Category.LongLo, null); } else { return getRegisterType(Category.LongHi, null); } case 'D': if (firstRegister) { return getRegisterType(Category.DoubleLo, null); } else { return getRegisterType(Category.DoubleHi, null); } default: throw new RuntimeException("Invalid type: " + typeIdItem.getTypeDescriptor()); } }
public int compare(AnnotationItem annotationItem, AnnotationItem annotationItem2) { int annotationItemIndex = annotationItem.getEncodedAnnotation().annotationType.getIndex(); int annotationItemIndex2 = annotationItem2.getEncodedAnnotation().annotationType.getIndex(); if (annotationItemIndex < annotationItemIndex2) { return -1; } else if (annotationItemIndex == annotationItemIndex2) { return 0; } return 1; } });
private static RegisterType[] getParameterTypes(TypeListItem typeListItem, int parameterRegisterCount) { assert typeListItem != null; assert parameterRegisterCount == typeListItem.getRegisterCount(); RegisterType[] registerTypes = new RegisterType[parameterRegisterCount]; int registerNum = 0; for (TypeIdItem type: typeListItem.getTypes()) { if (type.getRegisterCount() == 2) { registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, true); registerTypes[registerNum++] = RegisterType.getWideRegisterTypeForTypeIdItem(type, false); } else { registerTypes[registerNum++] = RegisterType.getRegisterTypeForTypeIdItem(type); } } return registerTypes; }
/** * Creates a new <code>ProtoIdItem</code> with the given values * @param dexFile The <code>DexFile</code> that this item belongs to * @param returnType the return type * @param parameters a <code>TypeListItem</code> containing a list of the parameter types */ private ProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) { this(dexFile); String shortyString = returnType.toShorty(); if (parameters != null) { shortyString += parameters.getShortyString(); } this.shortyDescriptor = StringIdItem.internStringIdItem(dexFile, shortyString); this.returnType = returnType; this.parameters = parameters; }
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)); } } }
case 'F': case 'D': typeIdItem = TypeIdItem.lookupTypeIdItem(dexFile, methodParams.substring(i,i+1)); break; case 'L': typeIdItem = TypeIdItem.lookupTypeIdItem(dexFile, methodParams.substring(i, end+1)); i = end; break; typeIdItem = TypeIdItem.lookupTypeIdItem(dexFile, methodParams.substring(i, end+1)); i = end; break; TypeIdItem retType = TypeIdItem.lookupTypeIdItem(dexFile, methodRet); if (retType == null) { return null; TypeIdItem classTypeItem = TypeIdItem.lookupTypeIdItem(dexFile, methodClassDef.getClassType());
/** {@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()); }