From f6783e8f5ec06602d9ba60911516a03658b80f01 Mon Sep 17 00:00:00 2001 From: Skylot Date: Tue, 2 Feb 2021 16:26:16 +0000 Subject: [PATCH] fix: implement 'copy' and 'isSame' methods in InvokeCustomNode --- .../dex/instructions/InvokeCustomNode.java | 32 +++++++++++++++ .../integration/java8/TestLambdaInArray.java | 40 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 jadx-core/src/test/java/jadx/tests/integration/java8/TestLambdaInArray.java diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeCustomNode.java b/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeCustomNode.java index c308eed8e..c943941f1 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeCustomNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeCustomNode.java @@ -20,6 +20,38 @@ public class InvokeCustomNode extends InvokeNode { super(lambdaInfo, insn, InvokeType.CUSTOM, instanceCall, isRange); } + private InvokeCustomNode(MethodInfo mth, InvokeType invokeType, int argsCount) { + super(mth, invokeType, argsCount); + } + + @Override + public InsnNode copy() { + InvokeCustomNode copy = new InvokeCustomNode(getCallMth(), getInvokeType(), getArgsCount()); + copyCommonParams(copy); + copy.setImplMthInfo(implMthInfo); + copy.setHandleType(handleType); + copy.setCallInsn(callInsn); + copy.setInlineInsn(inlineInsn); + copy.setUseRef(useRef); + return copy; + } + + @Override + public boolean isSame(InsnNode obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof InvokeCustomNode) || !super.isSame(obj)) { + return false; + } + InvokeCustomNode other = (InvokeCustomNode) obj; + return handleType == other.handleType + && implMthInfo.equals(other.implMthInfo) + && callInsn.isSame(other.callInsn) + && inlineInsn == other.inlineInsn + && useRef == other.useRef; + } + public MethodInfo getImplMthInfo() { return implMthInfo; } diff --git a/jadx-core/src/test/java/jadx/tests/integration/java8/TestLambdaInArray.java b/jadx-core/src/test/java/jadx/tests/integration/java8/TestLambdaInArray.java new file mode 100644 index 000000000..6eaac7c1a --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/java8/TestLambdaInArray.java @@ -0,0 +1,40 @@ +package jadx.tests.integration.java8; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; + +import org.junit.jupiter.api.Test; + +import jadx.tests.api.IntegrationTest; + +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + +public class TestLambdaInArray extends IntegrationTest { + + public static class TestCls { + + public List> test() { + return Arrays.asList(this::call1, this::call2); + } + + private Integer call1(String s) { + return null; + } + + private Integer call2(String s) { + return null; + } + + public void check() throws Exception { + assertThat(test()).hasSize(2); + } + } + + @Test + public void test() { + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return Arrays.asList(this::call1, this::call2);"); + } +}