use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class SignatureProcessor method checkArgTypes.
private List<ArgType> checkArgTypes(MethodNode mth, SignatureParser sp, List<ArgType> parsedArgTypes) {
MethodInfo mthInfo = mth.getMethodInfo();
List<ArgType> mthArgTypes = mthInfo.getArgumentsTypes();
int len = parsedArgTypes.size();
if (len != mthArgTypes.size()) {
if (mth.getParentClass().getAccessFlags().isEnum()) {
// ignore for enums
return null;
}
if (mthInfo.isConstructor() && !mthArgTypes.isEmpty() && !parsedArgTypes.isEmpty()) {
// add synthetic arg for outer class (see test TestGeneric8)
ArrayList<ArgType> newArgTypes = new ArrayList<>(parsedArgTypes);
newArgTypes.add(0, mthArgTypes.get(0));
if (newArgTypes.size() == mthArgTypes.size()) {
return newArgTypes;
}
}
mth.addDebugComment("Incorrect args count in method signature: " + sp.getSignature());
return null;
}
for (int i = 0; i < len; i++) {
ArgType parsedType = parsedArgTypes.get(i);
ArgType mthArgType = mthArgTypes.get(i);
if (!validateParsedType(parsedType, mthArgType)) {
mth.addWarnComment("Incorrect types in method signature: " + sp.getSignature());
return null;
}
}
return parsedArgTypes;
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class DeboxingVisitor method checkForReplace.
private InsnNode checkForReplace(InvokeNode insnNode) {
if (insnNode.getInvokeType() != InvokeType.STATIC || insnNode.getResult() == null) {
return null;
}
MethodInfo callMth = insnNode.getCallMth();
if (valueOfMths.contains(callMth)) {
RegisterArg resArg = insnNode.getResult();
InsnArg arg = insnNode.getArg(0);
if (arg.isLiteral()) {
ArgType primitiveType = callMth.getArgumentsTypes().get(0);
ArgType boxType = callMth.getReturnType();
if (isNeedExplicitCast(resArg, primitiveType, boxType)) {
arg.add(AFlag.EXPLICIT_PRIMITIVE_TYPE);
}
arg.setType(primitiveType);
boolean forbidInline;
if (canChangeTypeToPrimitive(resArg)) {
resArg.setType(primitiveType);
forbidInline = false;
} else {
forbidInline = true;
}
InsnNode constInsn = new InsnNode(InsnType.CONST, 1);
constInsn.addArg(arg);
constInsn.setResult(resArg);
if (forbidInline) {
constInsn.add(AFlag.DONT_INLINE);
}
return constInsn;
}
}
return null;
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class InlineMethods method updateUsageInfo.
private void updateUsageInfo(MethodNode mth, MethodNode inlinedMth, InsnNode insn) {
inlinedMth.getUseIn().remove(mth);
insn.visitInsns(innerInsn -> {
// TODO: share code with UsageInfoVisitor
switch(innerInsn.getType()) {
case INVOKE:
case CONSTRUCTOR:
MethodInfo callMth = ((BaseInvokeNode) innerInsn).getCallMth();
MethodNode callMthNode = mth.root().resolveMethod(callMth);
if (callMthNode != null) {
callMthNode.setUseIn(ListUtils.safeReplace(callMthNode.getUseIn(), inlinedMth, mth));
replaceClsUsage(mth, inlinedMth, callMthNode.getParentClass());
}
break;
case IGET:
case IPUT:
case SPUT:
case SGET:
FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) innerInsn).getIndex();
FieldNode fieldNode = mth.root().resolveField(fieldInfo);
if (fieldNode != null) {
fieldNode.setUseIn(ListUtils.safeReplace(fieldNode.getUseIn(), inlinedMth, mth));
replaceClsUsage(mth, inlinedMth, fieldNode.getParentClass());
}
break;
}
});
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class EnumVisitor method removeEnumMethods.
private void removeEnumMethods(ClassNode cls, ArgType clsType, FieldNode valuesField) {
String valuesMethod = "values()" + TypeGen.signature(ArgType.array(clsType));
FieldInfo valuesFieldInfo = valuesField.getFieldInfo();
// remove compiler generated methods
for (MethodNode mth : cls.getMethods()) {
MethodInfo mi = mth.getMethodInfo();
if (mi.isClassInit()) {
continue;
}
String shortId = mi.getShortId();
if (mi.isConstructor()) {
if (isDefaultConstructor(mth, shortId)) {
mth.add(AFlag.DONT_GENERATE);
}
markArgsForSkip(mth);
} else if (shortId.equals(valuesMethod) || usesValuesField(mth, valuesFieldInfo) || simpleValueOfMth(mth, clsType)) {
mth.add(AFlag.DONT_GENERATE);
}
}
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class AnonymousClassVisitor method getArgsToFieldsMapping.
private static Map<InsnArg, FieldNode> getArgsToFieldsMapping(MethodNode mth, List<InsnNode> usedInsns) {
MethodInfo callMth = mth.getMethodInfo();
ClassNode cls = mth.getParentClass();
List<RegisterArg> argList = mth.getArgRegs();
ClassNode outerCls = mth.getUseIn().get(0).getParentClass();
int startArg = 0;
if (callMth.getArgsCount() != 0 && callMth.getArgumentsTypes().get(0).equals(outerCls.getClassInfo().getType())) {
startArg = 1;
}
Map<InsnArg, FieldNode> map = new LinkedHashMap<>();
int argsCount = argList.size();
for (int i = startArg; i < argsCount; i++) {
RegisterArg arg = argList.get(i);
InsnNode useInsn = getParentInsnSkipMove(arg);
if (useInsn == null) {
return Collections.emptyMap();
}
switch(useInsn.getType()) {
case IPUT:
FieldNode fieldNode = cls.searchField((FieldInfo) ((IndexInsnNode) useInsn).getIndex());
if (fieldNode == null || !fieldNode.getAccessFlags().isSynthetic()) {
return Collections.emptyMap();
}
map.put(arg, fieldNode);
usedInsns.add(useInsn);
break;
case CONSTRUCTOR:
ConstructorInsn superConstr = (ConstructorInsn) useInsn;
if (!superConstr.isSuper()) {
return Collections.emptyMap();
}
usedInsns.add(useInsn);
break;
default:
return Collections.emptyMap();
}
}
return map;
}
Aggregations