Implemented verification for iget/iget-boolean/iget-byte/iget-char/iget-short

git-svn-id: https://smali.googlecode.com/svn/trunk@593 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-01-26 03:17:42 +00:00
parent 898e750048
commit 4f84e8f9e9

View File

@ -528,6 +528,16 @@ public class MethodAnalyzer {
return handleAputWide(analyzedInstruction); return handleAputWide(analyzedInstruction);
case APUT_OBJECT: case APUT_OBJECT:
return handleAputObject(analyzedInstruction); return handleAputObject(analyzedInstruction);
case IGET:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Integer);
case IGET_BOOLEAN:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Boolean);
case IGET_BYTE:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Byte);
case IGET_CHAR:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Char);
case IGET_SHORT:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Short);
} }
assert false; assert false;
@ -1696,6 +1706,43 @@ public class MethodAnalyzer {
return true; return true;
} }
private boolean handle32BitPrimitiveIget(AnalyzedInstruction analyzedInstruction,
RegisterType.Category instructionCategory) {
TwoRegisterInstruction instruction = (TwoRegisterInstruction)analyzedInstruction.instruction;
RegisterType objectRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterB());
assert objectRegisterType != null;
if (objectRegisterType.category == RegisterType.Category.Unknown) {
return false;
}
checkRegister(objectRegisterType, ReferenceCategories);
//TODO: check access
//TODO: allow an uninitialized "this" reference, if the current method is an <init> method
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()));
}
setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction,
RegisterType.getRegisterType(instructionCategory, null));
return true;
}
private static boolean checkArrayFieldAssignment(RegisterType.Category arrayFieldCategory, private static boolean checkArrayFieldAssignment(RegisterType.Category arrayFieldCategory,
RegisterType.Category instructionCategory) { RegisterType.Category instructionCategory) {
if (arrayFieldCategory == instructionCategory) { if (arrayFieldCategory == instructionCategory) {