mirror of
https://github.com/revanced/smali.git
synced 2025-05-05 09:04:25 +02:00
Implemented verification for packed-switch and sparse-switch
git-svn-id: https://smali.googlecode.com/svn/trunk@580 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
898edda7ce
commit
cda44f70cf
@ -473,6 +473,10 @@ public class MethodAnalyzer {
|
|||||||
case GOTO_32:
|
case GOTO_32:
|
||||||
//nothing to do
|
//nothing to do
|
||||||
return true;
|
return true;
|
||||||
|
case PACKED_SWITCH:
|
||||||
|
return handleSwitch(analyzedInstruction, Format.PackedSwitchData);
|
||||||
|
case SPARSE_SWITCH:
|
||||||
|
return handleSwitch(analyzedInstruction, Format.SparseSwitchData);
|
||||||
}
|
}
|
||||||
assert false;
|
assert false;
|
||||||
return false;
|
return false;
|
||||||
@ -1167,6 +1171,31 @@ public class MethodAnalyzer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean handleSwitch(AnalyzedInstruction analyzedInstruction, Format expectedSwitchDataFormat) {
|
||||||
|
int register = ((SingleRegisterInstruction)analyzedInstruction.instruction).getRegisterA();
|
||||||
|
int switchCodeAddressOffset = ((OffsetInstruction)analyzedInstruction.instruction).getTargetAddressOffset();
|
||||||
|
|
||||||
|
RegisterType registerType = analyzedInstruction.getPreInstructionRegisterType(register);
|
||||||
|
assert registerType != null;
|
||||||
|
|
||||||
|
if (registerType.category == RegisterType.Category.Unknown) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkRegister(registerType, Primitive32BitCategories);
|
||||||
|
|
||||||
|
int switchDataCodeAddress = this.getInstructionAddress(analyzedInstruction) + switchCodeAddressOffset;
|
||||||
|
AnalyzedInstruction switchDataAnalyzedInstruction = instructions.get(switchDataCodeAddress);
|
||||||
|
|
||||||
|
if (switchDataAnalyzedInstruction == null ||
|
||||||
|
switchDataAnalyzedInstruction.instruction.getFormat() != expectedSwitchDataFormat) {
|
||||||
|
throw new ValidationException(String.format("There is no %s structure at code address 0x%x",
|
||||||
|
expectedSwitchDataFormat.name(), switchDataCodeAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkRegister(RegisterType registerType, EnumSet validCategories) {
|
private static void checkRegister(RegisterType registerType, EnumSet validCategories) {
|
||||||
if (!validCategories.contains(registerType.category)) {
|
if (!validCategories.contains(registerType.category)) {
|
||||||
//TODO: add expected categories to error message
|
//TODO: add expected categories to error message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user