use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class LoopRegionVisitor method fixIterableType.
private static boolean fixIterableType(MethodNode mth, InsnArg iterableArg, RegisterArg iterVar) {
ArgType iterableType = iterableArg.getType();
ArgType varType = iterVar.getType();
if (iterableType.isGeneric()) {
ArgType[] genericTypes = iterableType.getGenericTypes();
if (genericTypes == null || genericTypes.length != 1) {
return false;
}
ArgType gType = genericTypes[0];
if (gType.equals(varType)) {
return true;
}
if (gType.isGenericType()) {
iterVar.setType(gType);
return true;
}
if (ArgType.isInstanceOf(mth.dex(), gType, varType)) {
return true;
}
ArgType wildcardType = gType.getWildcardType();
if (wildcardType != null && gType.getWildcardBounds() == 1 && ArgType.isInstanceOf(mth.dex(), wildcardType, varType)) {
return true;
}
LOG.warn("Generic type differs: '{}' and '{}' in {}", gType, varType, mth);
return false;
}
if (!iterableArg.isRegister()) {
return true;
}
// TODO: add checks
iterableType = ArgType.generic(iterableType.getObject(), new ArgType[] { varType });
iterableArg.setType(iterableType);
return true;
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class TypeInference method visit.
@Override
public void visit(MethodNode mth) throws JadxException {
if (mth.isNoCode()) {
return;
}
DexNode dex = mth.dex();
for (SSAVar var : mth.getSVars()) {
// inference variable type
ArgType type = processType(dex, var);
if (type == null) {
type = ArgType.UNKNOWN;
}
var.setType(type);
// search variable name
String name = processVarName(var);
var.setName(name);
}
// fix type for vars used only in Phi nodes
for (SSAVar sVar : mth.getSVars()) {
PhiInsn phi = sVar.getUsedInPhi();
if (phi != null) {
processPhiNode(phi);
}
}
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class TypeInference method processPhiNode.
private static void processPhiNode(PhiInsn phi) {
ArgType type = phi.getResult().getType();
if (!type.isTypeKnown()) {
for (InsnArg arg : phi.getArguments()) {
if (arg.getType().isTypeKnown()) {
type = arg.getType();
break;
}
}
}
phi.getResult().setType(type);
for (int i = 0; i < phi.getArgsCount(); i++) {
RegisterArg arg = phi.getArg(i);
arg.setType(type);
SSAVar sVar = arg.getSVar();
if (sVar != null) {
sVar.setName(phi.getResult().getName());
}
}
}
Aggregations