use of org.jf.dexlib2.iface.instruction.Instruction in project atlas by alibaba.
the class PreInstructionRegisterInfoMethodItem method writeFullMerge.
private void writeFullMerge(IndentingWriter writer, int registerNum) throws IOException {
registerFormatter.writeTo(writer, registerNum);
writer.write('=');
analyzedInstruction.getPreInstructionRegisterType(registerNum).writeTo(writer);
writer.write(":merge{");
boolean first = true;
for (AnalyzedInstruction predecessor : analyzedInstruction.getPredecessors()) {
RegisterType predecessorRegisterType = predecessor.getPostInstructionRegisterType(registerNum);
if (!first) {
writer.write(',');
}
if (predecessor.getInstructionIndex() == -1) {
//the fake "StartOfMethod" instruction
writer.write("Start:");
} else {
writer.write("0x");
writer.printUnsignedLongAsHex(methodAnalyzer.getInstructionAddress(predecessor));
writer.write(':');
}
predecessorRegisterType.writeTo(writer);
first = false;
}
writer.write('}');
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MethodAnalyzer method analyzeIputIgetQuick.
private boolean analyzeIputIgetQuick(@Nonnull AnalyzedInstruction analyzedInstruction) {
Instruction22cs instruction = (Instruction22cs) analyzedInstruction.instruction;
int fieldOffset = instruction.getFieldOffset();
RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitCategories);
if (objectRegisterType.category == RegisterType.NULL) {
return false;
}
TypeProto objectRegisterTypeProto = objectRegisterType.type;
assert objectRegisterTypeProto != null;
TypeProto classTypeProto = classPath.getClass(objectRegisterTypeProto.getType());
FieldReference resolvedField = classTypeProto.getFieldByOffset(fieldOffset);
if (resolvedField == null) {
throw new AnalysisException("Could not resolve the field in class %s at offset %d", objectRegisterType.type.getType(), fieldOffset);
}
ClassDef thisClass = classPath.getClassDef(method.getDefiningClass());
if (!TypeUtils.canAccessClass(thisClass.getType(), classPath.getClassDef(resolvedField.getDefiningClass()))) {
// the class is not accessible. So we start looking at objectRegisterTypeProto (which may be different
// than resolvedField.getDefiningClass()), and walk up the class hierarchy.
ClassDef fieldClass = classPath.getClassDef(objectRegisterTypeProto.getType());
while (!TypeUtils.canAccessClass(thisClass.getType(), fieldClass)) {
String superclass = fieldClass.getSuperclass();
if (superclass == null) {
throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s", ReferenceUtil.getShortFieldDescriptor(resolvedField));
}
fieldClass = classPath.getClassDef(superclass);
}
// fieldClass is now the first accessible class found. Now. we need to make sure that the field is
// actually valid for this class
FieldReference newResolvedField = classPath.getClass(fieldClass.getType()).getFieldByOffset(fieldOffset);
if (newResolvedField == null) {
throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s", ReferenceUtil.getShortFieldDescriptor(resolvedField));
}
resolvedField = new ImmutableFieldReference(fieldClass.getType(), newResolvedField.getName(), newResolvedField.getType());
}
String fieldType = resolvedField.getType();
Opcode opcode = classPath.getFieldInstructionMapper().getAndCheckDeodexedOpcode(fieldType, instruction.getOpcode());
Instruction22c deodexedInstruction = new ImmutableInstruction22c(opcode, (byte) instruction.getRegisterA(), (byte) instruction.getRegisterB(), resolvedField);
analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
analyzeInstruction(analyzedInstruction);
return true;
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MethodAnalyzer method analyzeExecuteInlineRange.
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
if (inlineResolver == null) {
throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
}
Instruction3rmi instruction = (Instruction3rmi) analyzedInstruction.instruction;
Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);
Opcode deodexedOpcode;
int acccessFlags = resolvedMethod.getAccessFlags();
if (AccessFlags.STATIC.isSet(acccessFlags)) {
deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
} else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
} else {
deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
}
Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(), instruction.getRegisterCount(), resolvedMethod);
analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
analyzeInstruction(analyzedInstruction);
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MethodAnalyzer method analyzeExecuteInline.
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
if (inlineResolver == null) {
throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
}
Instruction35mi instruction = (Instruction35mi) analyzedInstruction.instruction;
Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);
Opcode deodexedOpcode;
int acccessFlags = resolvedMethod.getAccessFlags();
if (AccessFlags.STATIC.isSet(acccessFlags)) {
deodexedOpcode = Opcode.INVOKE_STATIC;
} else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
deodexedOpcode = Opcode.INVOKE_DIRECT;
} else {
deodexedOpcode = Opcode.INVOKE_VIRTUAL;
}
Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);
analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
analyzeInstruction(analyzedInstruction);
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class MethodAnalyzer method analyzeInvokeVirtual.
private boolean analyzeInvokeVirtual(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isRange) {
MethodReference targetMethod;
if (!normalizeVirtualMethods) {
return true;
}
if (isRange) {
Instruction3rc instruction = (Instruction3rc) analyzedInstruction.instruction;
targetMethod = (MethodReference) instruction.getReference();
} else {
Instruction35c instruction = (Instruction35c) analyzedInstruction.instruction;
targetMethod = (MethodReference) instruction.getReference();
}
MethodReference replacementMethod = normalizeMethodReference(targetMethod);
if (replacementMethod == null || replacementMethod.equals(targetMethod)) {
return true;
}
Instruction deodexedInstruction;
if (isRange) {
Instruction3rc instruction = (Instruction3rc) analyzedInstruction.instruction;
deodexedInstruction = new ImmutableInstruction3rc(instruction.getOpcode(), instruction.getStartRegister(), instruction.getRegisterCount(), replacementMethod);
} else {
Instruction35c instruction = (Instruction35c) analyzedInstruction.instruction;
deodexedInstruction = new ImmutableInstruction35c(instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), replacementMethod);
}
analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
return true;
}
Aggregations