core: fix invoke args skipping
This commit is contained in:
@@ -29,7 +29,6 @@ import jadx.core.dex.instructions.args.InsnWrapArg;
|
||||
import jadx.core.dex.instructions.args.LiteralArg;
|
||||
import jadx.core.dex.instructions.args.Named;
|
||||
import jadx.core.dex.instructions.args.RegisterArg;
|
||||
import jadx.core.dex.instructions.args.SSAVar;
|
||||
import jadx.core.dex.instructions.mods.ConstructorInsn;
|
||||
import jadx.core.dex.instructions.mods.TernaryInsn;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
@@ -645,20 +644,17 @@ public class InsnGen {
|
||||
boolean overloaded = callMth != null && callMth.isArgsOverload();
|
||||
for (int i = k; i < argsCount; i++) {
|
||||
InsnArg arg = insn.getArg(i);
|
||||
if (arg.isRegister()) {
|
||||
SSAVar sVar = ((RegisterArg) arg).getSVar();
|
||||
if (sVar != null && sVar.contains(AFlag.SKIP_ARG)) {
|
||||
continue;
|
||||
}
|
||||
if (arg.contains(AFlag.SKIP_ARG)) {
|
||||
continue;
|
||||
}
|
||||
if (i != k) {
|
||||
code.add(", ");
|
||||
}
|
||||
boolean cast = overloaded && processOverloadedArg(code, callMth, arg, i - startArgNum);
|
||||
if (!cast && i == argsCount - 1 && processVarArg(code, callMth, arg)) {
|
||||
continue;
|
||||
}
|
||||
addArg(code, arg, false);
|
||||
if (i < argsCount - 1) {
|
||||
code.add(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
code.add(')');
|
||||
|
||||
@@ -27,10 +27,13 @@ public abstract class AttrNode implements IAttributeNode {
|
||||
|
||||
@Override
|
||||
public void copyAttributesFrom(AttrNode attrNode) {
|
||||
initStorage().addAll(attrNode.storage);
|
||||
AttributeStorage copyFrom = attrNode.storage;
|
||||
if (!copyFrom.isEmpty()) {
|
||||
initStorage().addAll(copyFrom);
|
||||
}
|
||||
}
|
||||
|
||||
AttributeStorage initStorage() {
|
||||
private AttributeStorage initStorage() {
|
||||
AttributeStorage store = storage;
|
||||
if (store == EMPTY_ATTR_STORAGE) {
|
||||
store = new AttributeStorage();
|
||||
|
||||
@@ -111,6 +111,10 @@ public class AttributeStorage {
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return flags.isEmpty() && attributes.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
List<String> list = getAttributeStrings();
|
||||
|
||||
@@ -53,6 +53,11 @@ public final class EmptyAttrStorage extends AttributeStorage {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
|
||||
@@ -79,6 +79,7 @@ public class RegisterArg extends InsnArg implements Named {
|
||||
public RegisterArg duplicate() {
|
||||
RegisterArg dup = new RegisterArg(getRegNum(), getType());
|
||||
dup.setSVar(sVar);
|
||||
dup.copyAttributesFrom(this);
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package jadx.core.dex.instructions.args;
|
||||
|
||||
import jadx.core.dex.attributes.AttrNode;
|
||||
import jadx.core.dex.nodes.DexNode;
|
||||
|
||||
public abstract class Typed {
|
||||
public abstract class Typed extends AttrNode {
|
||||
|
||||
protected ArgType type;
|
||||
|
||||
|
||||
@@ -277,8 +277,8 @@ public class ModVisitor extends AbstractVisitor {
|
||||
if (sVar != null) {
|
||||
sVar.add(AFlag.FINAL);
|
||||
sVar.add(AFlag.DONT_INLINE);
|
||||
sVar.add(AFlag.SKIP_ARG);
|
||||
}
|
||||
reg.add(AFlag.SKIP_ARG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package jadx.tests.integration.inner;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestAnonymousClass11 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public void test() {
|
||||
final int a = new Random().nextInt();
|
||||
final long l = new Random().nextLong();
|
||||
func(new A(l) {
|
||||
@Override
|
||||
public void m() {
|
||||
System.out.println(a);
|
||||
}
|
||||
});
|
||||
System.out.println("a" + a);
|
||||
print(a);
|
||||
print2(1, a);
|
||||
print3(1, l);
|
||||
}
|
||||
|
||||
public abstract class A {
|
||||
public A(long l) {
|
||||
}
|
||||
|
||||
public abstract void m();
|
||||
|
||||
}
|
||||
|
||||
private void func(A a) {
|
||||
}
|
||||
|
||||
private void print(int a) {
|
||||
}
|
||||
|
||||
private void print2(int i, int a) {
|
||||
}
|
||||
|
||||
private void print3(int i, long l) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("System.out.println(\"a\" + a);"));
|
||||
assertThat(code, containsOne("print(a);"));
|
||||
assertThat(code, not(containsString("synthetic")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user