Implemented verification for iget-object

git-svn-id: https://smali.googlecode.com/svn/trunk@595 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-01-27 02:16:52 +00:00
parent 9d92fd3748
commit 7a58f2434a

View File

@ -540,6 +540,8 @@ public class MethodAnalyzer {
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Short);
case IGET_WIDE:
return handleIgetWide(analyzedInstruction);
case IGET_OBJECT:
return handleIgetObject(analyzedInstruction);
}
assert false;
@ -1784,6 +1786,41 @@ public class MethodAnalyzer {
return true;
}
private boolean handleIgetObject(AnalyzedInstruction analyzedInstruction) {
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 (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()));
}
setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType);
return true;
}
private static boolean checkArrayFieldAssignment(RegisterType.Category arrayFieldCategory,
RegisterType.Category instructionCategory) {
if (arrayFieldCategory == instructionCategory) {