fix: remove method with more than 255 args (#1026)
This commit is contained in:
@@ -14,6 +14,7 @@ import jadx.api.JadxArgs;
|
||||
import jadx.core.dex.visitors.AttachCommentsVisitor;
|
||||
import jadx.core.dex.visitors.AttachMethodDetails;
|
||||
import jadx.core.dex.visitors.AttachTryCatchVisitor;
|
||||
import jadx.core.dex.visitors.CheckCode;
|
||||
import jadx.core.dex.visitors.ClassModifier;
|
||||
import jadx.core.dex.visitors.ConstInlineVisitor;
|
||||
import jadx.core.dex.visitors.ConstructorVisitor;
|
||||
@@ -96,6 +97,7 @@ public class Jadx {
|
||||
}
|
||||
|
||||
List<IDexTreeVisitor> passes = new ArrayList<>();
|
||||
passes.add(new CheckCode());
|
||||
if (args.isDebugInfo()) {
|
||||
passes.add(new DebugInfoAttachVisitor());
|
||||
}
|
||||
|
||||
@@ -612,6 +612,11 @@ public class MethodNode extends NotificationAttrNode implements IMethodDetails,
|
||||
return noCode ? null : codeReader.getDebugInfo();
|
||||
}
|
||||
|
||||
public void ignoreMethod() {
|
||||
add(AFlag.DONT_GENERATE);
|
||||
noCode = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate instructions count at currect stage
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package jadx.core.dex.visitors;
|
||||
|
||||
import jadx.core.dex.info.MethodInfo;
|
||||
import jadx.core.dex.instructions.InsnType;
|
||||
import jadx.core.dex.nodes.InsnNode;
|
||||
import jadx.core.dex.nodes.MethodNode;
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
|
||||
@JadxVisitor(
|
||||
name = "CheckCode",
|
||||
desc = "Check and remove bad or incorrect code"
|
||||
)
|
||||
public class CheckCode extends AbstractVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodNode mth) throws JadxException {
|
||||
MethodInfo mthInfo = mth.getMethodInfo();
|
||||
if (mthInfo.getArgumentsTypes().size() > 255) {
|
||||
// java spec don't allow more than 255 args
|
||||
if (canRemoveMethod(mth)) {
|
||||
mth.ignoreMethod();
|
||||
} else {
|
||||
// TODO: convert args to array
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canRemoveMethod(MethodNode mth) {
|
||||
if (mth.getUseIn().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
InsnNode[] insns = mth.getInstructions();
|
||||
if (insns.length == 0) {
|
||||
return true;
|
||||
}
|
||||
for (InsnNode insn : insns) {
|
||||
if (insn != null && insn.getType() != InsnType.NOP) {
|
||||
if (insn.getType() == InsnType.RETURN && insn.getArgsCount() == 0) {
|
||||
// ignore void return
|
||||
} else {
|
||||
// found useful instruction
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user