Implemented verification for iget-wide

git-svn-id: https://smali.googlecode.com/svn/trunk@594 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-01-27 01:53:53 +00:00
parent 4f84e8f9e9
commit 9d92fd3748

View File

@ -538,6 +538,8 @@ public class MethodAnalyzer {
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Char);
case IGET_SHORT:
return handle32BitPrimitiveIget(analyzedInstruction, RegisterType.Category.Short);
case IGET_WIDE:
return handleIgetWide(analyzedInstruction);
}
assert false;
@ -1743,6 +1745,45 @@ public class MethodAnalyzer {
return true;
}
private boolean handleIgetWide(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);
getAndCheckWideSourcePair(analyzedInstruction, instruction.getRegisterB());
//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());
try {
checkRegister(fieldType, WideLowCategories);
} catch (ValidationException ex) {
throw new ValidationException(String.format("Cannot use %s with field %s. Incorrect field type " +
"for the instruction.", analyzedInstruction.instruction.opcode.name,
field.getFieldString()));
}
setWideDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType);
return true;
}
private static boolean checkArrayFieldAssignment(RegisterType.Category arrayFieldCategory,
RegisterType.Category instructionCategory) {
if (arrayFieldCategory == instructionCategory) {