Skip to content

Commit

Permalink
fix: adjust insn reorder check in code shrink visitor (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jul 7, 2019
1 parent ed8c662 commit 3eee83c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,21 @@ private boolean canMove(int from, int to) {
movedSet.set(arg.getRegNum());
}
}
boolean canReorder = startInfo.insn.canReorder();
for (int i = start; i < to; i++) {
ArgsInfo argsInfo = argsList.get(i);
if (argsInfo.getInlinedInsn() == this) {
continue;
}
InsnNode curInsn = argsInfo.insn;
if (!curInsn.canReorder() || usedArgAssign(curInsn, movedSet)) {
return false;
if (canReorder) {
if (usedArgAssign(curInsn, movedSet)) {
return false;
}
} else {
if (!curInsn.canReorder() || usedArgAssign(curInsn, movedSet)) {
return false;
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package jadx.tests.integration.conditions;

import org.junit.jupiter.api.Test;

import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;

import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat;

public class TestConditions18 extends SmaliTest {

// @formatter:off
/*
public static class TestConditions18 {
private Map map;
public boolean test(Object obj) {
return this == obj || ((obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map));
}
private static boolean st(Object obj, Object obj2) {
return false;
}
}
*/
// @formatter:on

@Test
public void test() {
ClassNode cls = getClassNodeFromSmali();
String code = cls.getCode().toString();

assertThat(code, containsOne("return this == obj"
+ " || ((obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map));"));
}
}

This file was deleted.

45 changes: 45 additions & 0 deletions jadx-core/src/test/smali/conditions/TestConditions18.smali
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.class public final Lconditions/TestConditions18;
.super Ljava/lang/Object;

.field private map:Ljava/util/Map;

.method public test(Ljava/lang/Object;)Z
.locals 1

if-eq p0, p1, :cond_1

instance-of v0, p1, Lconditions/TestConditions18;

if-eqz v0, :cond_0

check-cast p1, Lconditions/TestConditions18;

iget-object v0, p0, Lconditions/TestConditions18;->map:Ljava/util/Map;

iget-object p1, p1, Lconditions/TestConditions18;->map:Ljava/util/Map;

invoke-static {v0, p1}, Lconditions/TestConditions18;->st(Ljava/lang/Object;Ljava/lang/Object;)Z

move-result p1

if-eqz p1, :cond_0

goto :goto_0

:cond_0
const/4 p1, 0x0

return p1

:cond_1
:goto_0
const/4 p1, 0x1

return p1
.end method

.method private static st(Ljava/lang/Object;Ljava/lang/Object;)Z
.locals 1
const/4 v0, 0x0
return v0
.end method

0 comments on commit 3eee83c

Please sign in to comment.