use of org.jf.dexlib2.analysis.ClassPath in project smali by JesusFreke.
the class MethodAnalyzer method canPropagateTypeAfterInstanceOf.
static boolean canPropagateTypeAfterInstanceOf(AnalyzedInstruction analyzedInstanceOfInstruction, AnalyzedInstruction analyzedIfInstruction, ClassPath classPath) {
if (!classPath.isArt()) {
return false;
}
Instruction ifInstruction = analyzedIfInstruction.instruction;
if (((Instruction21t) ifInstruction).getRegisterA() == analyzedInstanceOfInstruction.getDestinationRegister()) {
Reference reference = ((Instruction22c) analyzedInstanceOfInstruction.getInstruction()).getReference();
RegisterType registerType = RegisterType.getRegisterType(classPath, (TypeReference) reference);
try {
if (registerType.type != null && !registerType.type.isInterface()) {
int objectRegister = ((TwoRegisterInstruction) analyzedInstanceOfInstruction.getInstruction()).getRegisterB();
RegisterType originalType = analyzedIfInstruction.getPreInstructionRegisterType(objectRegister);
return isNotWideningConversion(originalType, registerType);
}
} catch (UnresolvedClassException ex) {
return false;
}
}
return false;
}
use of org.jf.dexlib2.analysis.ClassPath in project smali by JesusFreke.
the class MethodAnalyzer method analyzeNewArray.
private void analyzeNewArray(@Nonnull AnalyzedInstruction analyzedInstruction) {
ReferenceInstruction instruction = (ReferenceInstruction) analyzedInstruction.instruction;
TypeReference type = (TypeReference) instruction.getReference();
if (type.getType().charAt(0) != '[') {
throw new AnalysisException("new-array used with non-array type");
}
RegisterType arrayType = RegisterType.getRegisterType(classPath, type);
setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, arrayType);
}
use of org.jf.dexlib2.analysis.ClassPath in project smali by JesusFreke.
the class MethodAnalyzer method analyzeCheckCast.
private void analyzeCheckCast(@Nonnull AnalyzedInstruction analyzedInstruction) {
ReferenceInstruction instruction = (ReferenceInstruction) analyzedInstruction.instruction;
TypeReference reference = (TypeReference) instruction.getReference();
RegisterType castRegisterType = RegisterType.getRegisterType(classPath, reference);
setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, castRegisterType);
}
use of org.jf.dexlib2.analysis.ClassPath in project smali by JesusFreke.
the class MethodAnalyzer method analyzeMoveResult.
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
AnalyzedInstruction previousInstruction = null;
if (analyzedInstruction.instructionIndex > 0) {
previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex - 1);
}
if (previousInstruction == null || !previousInstruction.instruction.getOpcode().setsResult()) {
throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " + "invoke-*/fill-new-array instruction");
}
RegisterType resultRegisterType;
ReferenceInstruction invokeInstruction = (ReferenceInstruction) previousInstruction.instruction;
Reference reference = invokeInstruction.getReference();
if (reference instanceof MethodReference) {
resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference) reference).getReturnType());
} else {
resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference) reference);
}
setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
use of org.jf.dexlib2.analysis.ClassPath in project smali by JesusFreke.
the class AnalysisTest method runTest.
public void runTest(String test, boolean registerInfo, boolean isArt) throws IOException, URISyntaxException {
String dexFilePath = String.format("%s%sclasses.dex", test, File.separatorChar);
DexFile dexFile = DexFileFactory.loadDexFile(findResource(dexFilePath), Opcodes.getDefault());
BaksmaliOptions options = new BaksmaliOptions();
if (registerInfo) {
options.registerInfo = BaksmaliOptions.ALL | BaksmaliOptions.FULLMERGE;
if (isArt) {
options.classPath = new ClassPath(new ArrayList<ClassProvider>(), true, 56);
} else {
options.classPath = new ClassPath();
}
}
options.implicitReferences = false;
for (ClassDef classDef : dexFile.getClasses()) {
StringWriter stringWriter = new StringWriter();
IndentingWriter writer = new IndentingWriter(stringWriter);
ClassDefinition classDefinition = new ClassDefinition(options, classDef);
classDefinition.writeTo(writer);
writer.close();
String className = classDef.getType();
String smaliPath = String.format("%s%s%s.smali", test, File.separatorChar, className.substring(1, className.length() - 1));
String smaliContents = readResource(smaliPath);
Assert.assertEquals(TextUtils.normalizeWhitespace(smaliContents), TextUtils.normalizeWhitespace((stringWriter.toString())));
}
}
Aggregations