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); }
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 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); }
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())); } }
private void verify32BitPrimitiveSget(AnalyzedInstruction analyzedInstruction, RegisterType.Category instructionCategory) { //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (!checkArrayFieldAssignment(fieldType.category, instructionCategory)) { 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 verifySputWide(AnalyzedInstruction analyzedInstruction) { SingleRegisterInstruction instruction = (SingleRegisterInstruction)analyzedInstruction.instruction; getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterA(), WideLowCategories); //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; 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())); } }
staticFieldInitializer.field.field.getFieldType().getTypeDescriptor())) != 0)) { lastIndex = i; break; if (encodedValue == null) { encodedValue = TypeUtils.makeDefaultValueForType(dexFile, staticFieldInitializer.field.field.getFieldType().getTypeDescriptor());
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 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 verifyIputWide(AnalyzedInstruction analyzedInstruction) { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitThisCategories); getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterA(), WideLowCategories); //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 verifySputObject(AnalyzedInstruction analyzedInstruction) { SingleRegisterInstruction instruction = (SingleRegisterInstruction)analyzedInstruction.instruction; RegisterType sourceRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterA(), ReferenceCategories); //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())); } if (sourceRegisterType.category != RegisterType.Category.Null && !fieldType.type.isInterface() && !sourceRegisterType.type.extendsClass(fieldType.type)) { throw new ValidationException(String.format("Cannot store a value of type %s into a field of type %s", sourceRegisterType.type.getClassType(), fieldType.type.getClassType())); } }
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())); } }
private void verify32BitPrimitiveIget(AnalyzedInstruction analyzedInstruction, RegisterType.Category instructionCategory) { 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 (!checkArrayFieldAssignment(fieldType.category, instructionCategory)) { 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 verify32BitPrimitiveSput(AnalyzedInstruction analyzedInstruction, RegisterType.Category instructionCategory) { SingleRegisterInstruction instruction = (SingleRegisterInstruction)analyzedInstruction.instruction; RegisterType sourceRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterA()); assert sourceRegisterType != null; //per CodeVerify.c in dalvik: //java generates synthetic functions that write byte values into boolean fields if (sourceRegisterType.category == RegisterType.Category.Byte && instructionCategory == RegisterType.Category.Boolean) { sourceRegisterType = RegisterType.getRegisterType(RegisterType.Category.Boolean, null); } RegisterType instructionRegisterType = RegisterType.getRegisterType(instructionCategory, null); if (!sourceRegisterType.canBeAssignedTo(instructionRegisterType)) { throw new ValidationException(String.format("Cannot use %s with source register type %s.", analyzedInstruction.instruction.opcode.name, sourceRegisterType.toString())); } //TODO: check access Item referencedItem = ((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem(); assert referencedItem instanceof FieldIdItem; FieldIdItem field = (FieldIdItem)referencedItem; RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType()); if (!checkArrayFieldAssignment(fieldType.category, instructionCategory)) { throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " + "for the instruction.", analyzedInstruction.instruction.opcode.name, field.getFieldString())); } }
private boolean analyzeIputIgetQuick(AnalyzedInstruction analyzedInstruction) { Instruction22cs instruction = (Instruction22cs)analyzedInstruction.instruction; int fieldOffset = instruction.getFieldOffset(); RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitCategories); if (objectRegisterType.category == RegisterType.Category.Null) { return false; } FieldIdItem fieldIdItem = deodexUtil.lookupField(objectRegisterType.type, fieldOffset); if (fieldIdItem == null) { throw new ValidationException(String.format("Could not resolve the field in class %s at offset %d", objectRegisterType.type.getClassType(), fieldOffset)); } String fieldType = fieldIdItem.getFieldType().getTypeDescriptor(); Opcode opcode = OdexedFieldInstructionMapper.getAndCheckDeodexedOpcodeForOdexedOpcode(fieldType, instruction.opcode); Instruction22c deodexedInstruction = new Instruction22c(opcode, (byte)instruction.getRegisterA(), (byte)instruction.getRegisterB(), fieldIdItem); analyzedInstruction.setDeodexedInstruction(deodexedInstruction); analyzeInstruction(analyzedInstruction); return true; }
private void verifyIputObject(AnalyzedInstruction analyzedInstruction) { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitThisCategories); RegisterType sourceRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterA(), ReferenceCategories); //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())); } if (sourceRegisterType.category != RegisterType.Category.Null && !fieldType.type.isInterface() && !sourceRegisterType.type.extendsClass(fieldType.type)) { throw new ValidationException(String.format("Cannot store a value of type %s into a field of type %s", sourceRegisterType.type.getClassType(), fieldType.type.getClassType())); } }
RegisterType fieldType = RegisterType.getRegisterTypeForTypeIdItem(field.getFieldType());
fieldAnnotationFields[i].getFieldType().getTypeDescriptor()); out.annotate(4, "annotations_off: 0x" + Integer.toHexString(fieldAnnotations[i].getOffset())); out.deindent();
private boolean analyzePutGetVolatile(AnalyzedInstruction analyzedInstruction) { FieldIdItem fieldIdItem = (FieldIdItem)(((InstructionWithReference)analyzedInstruction.instruction).getReferencedItem()); String fieldType = fieldIdItem.getFieldType().getTypeDescriptor(); Opcode opcode = OdexedFieldInstructionMapper.getAndCheckDeodexedOpcodeForOdexedOpcode(fieldType, analyzedInstruction.instruction.opcode); Instruction deodexedInstruction; if (analyzedInstruction.instruction.opcode.isOdexedStaticVolatile()) { SingleRegisterInstruction instruction = (SingleRegisterInstruction)analyzedInstruction.instruction; if (analyzedInstruction.instruction.opcode.format == Format.Format21c) { deodexedInstruction = new Instruction21c(opcode, (byte)instruction.getRegisterA(), fieldIdItem); } else { assert(analyzedInstruction.instruction.opcode.format == Format.Format41c); deodexedInstruction = new Instruction41c(opcode, (byte)instruction.getRegisterA(), fieldIdItem); } } else { TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction; if (analyzedInstruction.instruction.opcode.format == Format.Format22c) { deodexedInstruction = new Instruction22c(opcode, (byte)instruction.getRegisterA(), (byte)instruction.getRegisterB(), fieldIdItem); } else { assert(analyzedInstruction.instruction.opcode.format == Format.Format52c); deodexedInstruction = new Instruction52c(opcode, (byte)instruction.getRegisterA(), (byte)instruction.getRegisterB(), fieldIdItem); } } analyzedInstruction.setDeodexedInstruction(deodexedInstruction); analyzeInstruction(analyzedInstruction); return true; }
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())); } }