Skip to content

Commit

Permalink
fix: field increment (PR #550)
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour authored and skylot committed Apr 2, 2019
1 parent e6e8f63 commit bae7f1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,36 @@ public void visit(MethodNode mth) {
for (int i = 0; i < list.size(); i++) {
InsnNode modInsn = simplifyInsn(mth, list.get(i));
if (modInsn != null) {
if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) {

InsnNode mergedNode = simplifyOneArgConsecutive(
list.get(i - 1), list.get(i), (ArithNode) modInsn);

if (mergedNode != null) {
list.remove(i - 1);
modInsn = mergedNode;
i--;
}
}
list.set(i, modInsn);
}
}
}
}

private static InsnNode simplifyOneArgConsecutive(InsnNode insn1, InsnNode insn2, ArithNode modInsn) {
if (insn1.getType() == InsnType.IGET
&& insn2.getType() == InsnType.IPUT
&& insn1.getResult().getSVar().getUseCount() == 2
&& insn2.getArg(1).equals(insn1.getResult())) {

FieldInfo field = (FieldInfo) ((IndexInsnNode) insn2).getIndex();
FieldArg fArg = new FieldArg(field, new InsnWrapArg(insn1));
return new ArithNode(modInsn.getOp(), fArg, modInsn.getArg(1));
}
return null;
}

private static InsnNode simplifyInsn(MethodNode mth, InsnNode insn) {
if (insn.contains(AFlag.DONT_GENERATE)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.Test;

import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;

Expand Down Expand Up @@ -33,15 +32,6 @@ public void test() {
String code = cls.getCode().toString();

assertThat(code, containsString("this.a.f += n;"));
assertThat(code, containsString("a2.f *= n;"));
}

@Test
@NotYetImplemented
public void test2() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();

assertThat(code, containsString("this.a.f *= n;"));
}
}

0 comments on commit bae7f1b

Please sign in to comment.