/** * Looks up a <code>FieldIdItem</code> from the given <code>DexFile</code> for the given * values * @param dexFile The <code>DexFile</code> that this item belongs to * @param classType the class that the field is a member of * @param fieldType the type of the field * @param fieldName the name of the field * @return a <code>FieldIdItem</code> from the given <code>DexFile</code> for the given * values, or null if it doesn't exist */ public static FieldIdItem lookupFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType, StringIdItem fieldName) { FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName); return dexFile.FieldIdsSection.getInternedItem(fieldIdItem); }
@Override public int hashCode() { //there's a small possibility that the actual hash code will be 0. If so, we'll //just end up recalculating it each time if (hashCode == 0) calcHashCode(); return hashCode; }
/** * Compares this <code>EncodedField</code> to another, based on the comparison of the associated * <code>FieldIdItem</code> * @param other The <code>EncodedField</code> to compare against * @return a standard integer comparison value indicating the relationship */ public int compareTo(EncodedField other) { return field.compareTo(other.field); }
private void verifySgetObject(AnalyzedInstruction analyzedInstruction) { //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (fieldType.category != RegisterType.Category.Reference) { throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " + "for the instruction.", analyzedInstruction.instruction.opcode.name, field.getFieldString())); } }
private String[][] loadInstanceFields(ClassDataItem classDataItem) { EncodedField[] encodedFields = classDataItem.getInstanceFields(); if (encodedFields != null && encodedFields.length > 0) { String[][] instanceFields = new String[encodedFields.length][2]; for (int i=0; i<encodedFields.length; i++) { EncodedField encodedField = encodedFields[i]; instanceFields[i][0] = encodedField.field.getFieldName().getStringValue(); instanceFields[i][1] = encodedField.field.getFieldType().getTypeDescriptor(); } return instanceFields; } return null; } }
private void verifyIgetObject(AnalyzedInstruction analyzedInstruction) { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitThisCategories); //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; if (objectRegisterType.category != RegisterType.Category.Null && !objectRegisterType.type.extendsClass(ClassPath.getClassDef(field.getContainingClass()))) { throw new ValidationException(String.format("Cannot access field %s through type %s", field.getFieldString(), objectRegisterType.type.getClassType())); } RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (fieldType.category != RegisterType.Category.Reference) { throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " + "for the instruction.", analyzedInstruction.instruction.opcode.name, field.getFieldString())); } }
/** * Writes the <code>EncodedField</code> to the given <code>AnnotatedOutput</code> object * @param out the <code>AnnotatedOutput</code> object to write to * @param previousEncodedField The previous <code>EncodedField</code> in the list containing this * <code>EncodedField</code>. */ private void writeTo(AnnotatedOutput out, EncodedField previousEncodedField) { int previousIndex = previousEncodedField==null?0:previousEncodedField.field.getIndex(); if (out.annotates()) { out.annotate("field: " + field.getFieldString()); out.writeUnsignedLeb128(field.getIndex() - previousIndex); out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForField(accessFlags)); out.writeUnsignedLeb128(accessFlags); }else { out.writeUnsignedLeb128(field.getIndex() - previousIndex); out.writeUnsignedLeb128(accessFlags); } }
out.annotate(4, "field: " + fieldAnnotationFields[i].getFieldName().getStringValue() + ":" + fieldAnnotationFields[i].getFieldType().getTypeDescriptor()); out.annotate(4, "annotations_off: 0x" + Integer.toHexString(fieldAnnotations[i].getOffset())); out.deindent(); out.writeInt(fieldAnnotationFields[i].getIndex()); out.writeInt(fieldAnnotations[i].getOffset());
/** {@inheritDoc} */ public String getConciseIdentity() { return getFieldString(); }
private void analyzeSgetWideObject(AnalyzedInstruction analyzedInstruction) { Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType); }
@Override public int hashCode() { return value.hashCode(); } }
FieldIdItem fieldIdItem = FieldIdItem.lookupFieldIdItem(dexFile, classTypeItem, fieldTypeItem, fieldNameItem); if (fieldIdItem != null) { return fieldIdItem;
private void verifyIgetWide(AnalyzedInstruction analyzedInstruction) { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitThisCategories); //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; if (objectRegisterType.category != RegisterType.Category.Null && !objectRegisterType.type.extendsClass(ClassPath.getClassDef(field.getContainingClass()))) { throw new ValidationException(String.format("Cannot access field %s through type %s", field.getFieldString(), objectRegisterType.type.getClassType())); } RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (!WideLowCategories.contains(fieldType.category)) { throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " + "for the instruction.", analyzedInstruction.instruction.opcode.name, field.getFieldString())); } }
private void verifySgetWide(AnalyzedInstruction analyzedInstruction) { //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (fieldType.category != RegisterType.Category.LongLo && fieldType.category != RegisterType.Category.DoubleLo) { throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " + "for the instruction.", analyzedInstruction.instruction.opcode.name, field.getFieldString())); } }
/** {@inheritDoc} */ public void writeValue(AnnotatedOutput out) { byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex()); if (out.annotates()) { out.annotate(1, "value_type=" + ValueType.VALUE_ENUM.name() + ",value_arg=" + (bytes.length - 1)); out.annotate(bytes.length, "value: " + value.getFieldString()); } out.writeByte(ValueType.VALUE_ENUM.value | ((bytes.length - 1) << 5)); out.write(bytes); }
private String[][] loadInstanceFields(ClassDataItem classDataItem) { List<EncodedField> encodedFields = classDataItem.getInstanceFields(); if (encodedFields.size() > 0) { String[][] instanceFields = new String[encodedFields.size()][2]; for (int i=0; i<encodedFields.size(); i++) { EncodedField encodedField = encodedFields.get(i); instanceFields[i][0] = encodedField.field.getFieldName().getStringValue(); instanceFields[i][1] = encodedField.field.getFieldType().getTypeDescriptor(); } return instanceFields; } return null; } }
/** * Iterates over the field annotations, calling delegate.processFieldAnnotations for each * @param delegate the delegate to call */ public void iterateFieldAnnotations(FieldAnnotationIteratorDelegate delegate) { for (int i=0; i<fieldAnnotationFields.length; i++) { try { delegate.processFieldAnnotations(fieldAnnotationFields[i], fieldAnnotations[i]); } catch (Exception ex) { throw addExceptionContext(ExceptionWithContext.withContext(ex, "Error occured while processing field annotations for field: " + fieldAnnotationFields[i].getFieldString())); } } }
private void analyzeIgetWideObject(AnalyzedInstruction analyzedInstruction) { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType); }