Commit 7f4e6418 authored by Skylot's avatar Skylot

fix: skip duplicated block in complex if (#441)

parent 710245d5
...@@ -263,7 +263,18 @@ public class IfMakerHelper { ...@@ -263,7 +263,18 @@ public class IfMakerHelper {
result.setIfBlock(first.getIfBlock()); result.setIfBlock(first.getIfBlock());
result.merge(first, second); result.merge(first, second);
BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock(); BlockNode otherPathBlock;
if (followThenBranch) {
otherPathBlock = first.getElseBlock();
if (!otherPathBlock.equals(result.getElseBlock())) {
result.getSkipBlocks().add(otherPathBlock);
}
} else {
otherPathBlock = first.getThenBlock();
if (!otherPathBlock.equals(result.getThenBlock())) {
result.getSkipBlocks().add(otherPathBlock);
}
}
skipSimplePath(otherPathBlock, result.getSkipBlocks()); skipSimplePath(otherPathBlock, result.getSkipBlocks());
return result; return result;
} }
......
package jadx.tests.integration.conditions;
import org.junit.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestComplexIf extends SmaliTest {
/*
public final class TestComplexIf {
private String a;
private int b;
private float c;
public final boolean test() {
if (this.a.equals("GT-P6200") || this.a.equals("GT-P6210") || ... ) {
return true;
}
if (this.a.equals("SM-T810") || this.a.equals("SM-T813") || ...) {
return false;
}
return this.c > 160.0f ? true : this.c <= 0.0f && ((this.b & 15) == 4 ? 1 : null) != null;
}
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPkg("conditions", "TestComplexIf");
String code = cls.getCode().toString();
assertThat(code, containsOne("if (this.a.equals(\"GT-P6200\") || this.a.equals(\"GT-P6210\") || this.a.equals(\"A100\") " +
"|| this.a.equals(\"A101\") || this.a.equals(\"LIFETAB_S786X\") || this.a.equals(\"VS890 4G\")) {"));
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment