mirror of
https://github.com/revanced/smali.git
synced 2025-06-13 04:27:38 +02:00
Implemented verification for iput/iput-boolean/iput-byte/iput-char/iput-short
git-svn-id: https://smali.googlecode.com/svn/trunk@596 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
@ -542,6 +542,16 @@ public class MethodAnalyzer {
|
|||||||
return handleIgetWide(analyzedInstruction);
|
return handleIgetWide(analyzedInstruction);
|
||||||
case IGET_OBJECT:
|
case IGET_OBJECT:
|
||||||
return handleIgetObject(analyzedInstruction);
|
return handleIgetObject(analyzedInstruction);
|
||||||
|
case IPUT:
|
||||||
|
return handle32BitPrimitiveIput(analyzedInstruction, RegisterType.Category.Integer);
|
||||||
|
case IPUT_BOOLEAN:
|
||||||
|
return handle32BitPrimitiveIput(analyzedInstruction, RegisterType.Category.Boolean);
|
||||||
|
case IPUT_BYTE:
|
||||||
|
return handle32BitPrimitiveIput(analyzedInstruction, RegisterType.Category.Byte);
|
||||||
|
case IPUT_CHAR:
|
||||||
|
return handle32BitPrimitiveIput(analyzedInstruction, RegisterType.Category.Char);
|
||||||
|
case IPUT_SHORT:
|
||||||
|
return handle32BitPrimitiveIput(analyzedInstruction, RegisterType.Category.Short);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert false;
|
assert false;
|
||||||
@ -1821,6 +1831,61 @@ public class MethodAnalyzer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean handle32BitPrimitiveIput(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);
|
||||||
|
|
||||||
|
RegisterType sourceRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterA());
|
||||||
|
assert sourceRegisterType != null;
|
||||||
|
if (sourceRegisterType.category == RegisterType.Category.Unknown) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
|
//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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Reference in New Issue
Block a user