From 55d43e36eb862bf86ceaf9c664789ce2c4d92af8 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Mon, 25 Jan 2010 01:55:07 +0000 Subject: [PATCH] Implemented verification for aput-wide git-svn-id: https://smali.googlecode.com/svn/trunk@591 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../dexlib/Code/Analysis/MethodAnalyzer.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) 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) {