fix: correct args shift for instance invoke-custom (#1816)

This commit is contained in:
Skylot
2023-04-16 20:10:57 +01:00
parent 4230cd5b5a
commit 3fa3e5acec
2 changed files with 38 additions and 1 deletions
@@ -1014,9 +1014,10 @@ public class InsnGen {
// force set external arg names into call method args
int extArgsCount = customNode.getArgsCount();
int startArg = customNode.getHandleType() == MethodHandleType.INVOKE_STATIC ? 0 : 1; // skip 'this' arg
int callArg = 0;
for (int i = startArg; i < extArgsCount; i++) {
RegisterArg extArg = (RegisterArg) customNode.getArg(i);
RegisterArg callRegArg = callArgs.get(i);
RegisterArg callRegArg = callArgs.get(callArg++);
callRegArg.getSVar().setCodeVar(extArg.getSVar().getCodeVar());
}
code.add(" -> {");
@@ -0,0 +1,36 @@
package jadx.tests.integration.java8;
import org.junit.jupiter.api.Test;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestLambdaInstance2 extends IntegrationTest {
public static class TestCls {
private String field;
public Runnable test(String str, int i) {
return () -> call(str, i);
}
public void call(String str, int i) {
field = str + '=' + i;
}
public void check() throws Exception {
field = "";
test("num", 7).run();
assertThat(field).isEqualTo("num=7");
}
}
@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("lambda$")
.containsOne("call(str, i)");
}
}