diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/MethodAnalyzer.java b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/MethodAnalyzer.java index 1139d870..3d71f592 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/MethodAnalyzer.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/MethodAnalyzer.java @@ -524,6 +524,8 @@ public class MethodAnalyzer { return handle32BitPrimitiveAput(analyzedInstruction, RegisterType.Category.Char); case APUT_SHORT: return handle32BitPrimitiveAput(analyzedInstruction, RegisterType.Category.Short); + case APUT_WIDE: + return handleAputWide(analyzedInstruction); } assert false; @@ -1591,6 +1593,57 @@ public class MethodAnalyzer { return true; } + private boolean handleAputWide(AnalyzedInstruction analyzedInstruction) { + ThreeRegisterInstruction instruction = (ThreeRegisterInstruction)analyzedInstruction.instruction; + + RegisterType indexRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterC()); + assert indexRegisterType != null; + if (indexRegisterType.category == RegisterType.Category.Unknown) { + return false; + } + checkRegister(indexRegisterType, Primitive32BitCategories); + + RegisterType sourceRegisterType = getAndCheckWideSourcePair(analyzedInstruction, instruction.getRegisterA()); + if (sourceRegisterType.category == RegisterType.Category.Unknown) { + return false; + } + + RegisterType arrayRegisterType = analyzedInstruction.getPreInstructionRegisterType(instruction.getRegisterB()); + assert arrayRegisterType != null; + if (indexRegisterType.category == RegisterType.Category.Unknown) { + return false; + } + + if (arrayRegisterType.category != RegisterType.Category.Null) { + if (arrayRegisterType.category != RegisterType.Category.Reference) { + throw new ValidationException(String.format("Cannot use aput-wide with non-array type %s", + arrayRegisterType.category.toString())); + } + + assert arrayRegisterType.type != null; + if (arrayRegisterType.type.getClassType().charAt(0) != '[') { + throw new ValidationException(String.format("Cannot use aput-wide with non-array type %s", + arrayRegisterType.type.getClassType())); + } + + assert arrayRegisterType.type instanceof ClassPath.ArrayClassDef; + ClassPath.ArrayClassDef arrayClassDef = (ClassPath.ArrayClassDef)arrayRegisterType.type; + + if (arrayClassDef.getArrayDimensions() != 1) { + throw new ValidationException(String.format("Cannot use aput-wide with multi-dimensional array type %s", + arrayRegisterType.type.getClassType())); + } + + char arrayBaseType = arrayClassDef.getBaseElementClass().getClassType().charAt(0); + if (arrayBaseType != 'J' && arrayBaseType != 'D') { + throw new ValidationException(String.format("Cannot use aput-wide with array type %s. Incorrect " + + "array type for the instruction.", arrayRegisterType.type.getClassType())); + } + } + + return true; + } + private static boolean checkArrayFieldAssignment(RegisterType.Category arrayFieldCategory, RegisterType.Category instructionCategory) { if (arrayFieldCategory == instructionCategory) {