提交 02213802 编写于 作者: S Skylot

fix: make correct replacement for synthetic constructor (#808)

上级 83658554
......@@ -2,6 +2,8 @@ package jadx.core.dex.visitors;
import java.util.ArrayList;
import org.jetbrains.annotations.Nullable;
import jadx.core.codegen.TypeGen;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.InsnType;
......@@ -105,8 +107,12 @@ public class ConstructorVisitor extends AbstractVisitor {
}
/**
* Replace call of synthetic constructor
* Replace call of synthetic constructor with all 'null' args
* to a non-synthetic or default constructor if possible.
*
* @return insn for replacement or null if replace not needed or not possible.
*/
@Nullable
private static ConstructorInsn processConstructor(MethodNode mth, ConstructorInsn co) {
MethodNode callMth = mth.dex().resolveMethod(co.getCallMth());
if (callMth == null
......@@ -125,11 +131,11 @@ public class ConstructorVisitor extends AbstractVisitor {
boolean passThis = instanceArg.isThis();
String ctrId = "<init>(" + (passThis ? TypeGen.signature(instanceArg.getInitType()) : "") + ")V";
MethodNode defCtr = classNode.searchMethodByShortId(ctrId);
if (defCtr == null) {
if (defCtr == null || defCtr.equals(callMth) || defCtr.getAccessFlags().isSynthetic()) {
return null;
}
ConstructorInsn newInsn = new ConstructorInsn(defCtr.getMethodInfo(), co.getCallType());
newInsn.setResult(co.getResult());
newInsn.setResult(co.getResult().duplicate());
return newInsn;
}
......
package jadx.tests.integration.others;
import org.junit.jupiter.api.Test;
import jadx.tests.api.SmaliTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestSyntheticConstructor extends SmaliTest {
// @formatter:off
/*
public class Test {
static {
new BuggyConstructor();
}
}
*/
// @formatter:on
@Test
public void test() {
disableCompilation();
assertThat(getClassNodeFromSmaliFiles("Test"))
.code()
.containsLine(2, "new BuggyConstructor();");
}
}
.class public LBuggyConstructor;
.super Ljava/lang/Object;
.source "BuggyConstructor.java"
#.implements LInterfaceClass;
.method public synthetic constructor <init>()V
.locals 0
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.class public Lothers/Test;
.super Ljava/lang/Object;
.source "Test.java"
.field public static final A00:Ljava/lang/Object;
.method public static constructor <clinit>()V
.locals 1
new-instance v0, LBuggyConstructor;
invoke-direct {v0}, LBuggyConstructor;-><init>()V
.end method
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册