Commit 58998089 authored by Skylot's avatar Skylot

core: redone 'if' structure checking

parent f0a73b32
......@@ -50,26 +50,16 @@ public class IfMakerHelper {
boolean badThen = !allPathsFromIf(thenBlock, info);
boolean badElse = !allPathsFromIf(elseBlock, info);
if (badThen && badElse) {
LOG.debug("Stop processing blocks after 'if': {}, method: {}", info, mth);
return null;
}
if (badThen || badElse) {
if (badElse && isPathExists(thenBlock, elseBlock)) {
info = new IfInfo(info.getCondition(), thenBlock, null);
info.setOutBlock(elseBlock);
} else if (badThen && isPathExists(elseBlock, thenBlock)) {
info = IfInfo.invert(info);
info = new IfInfo(info.getCondition(), info.getThenBlock(), null);
info.setOutBlock(thenBlock);
} else if (badElse) {
info = new IfInfo(info.getCondition(), thenBlock, null);
info.setOutBlock(null);
LOG.debug("Stop processing blocks after bad 'else' in 'if': {}, method: {}", info, mth);
} else {
info = IfInfo.invert(info);
info = new IfInfo(info.getCondition(), info.getThenBlock(), null);
info.setOutBlock(null);
LOG.debug("Stop processing blocks after bad 'then' in 'if': {}, method: {}", info, mth);
}
if (badElse) {
info = new IfInfo(info.getCondition(), thenBlock, null);
info.setOutBlock(elseBlock);
} else if (badThen) {
info = IfInfo.invert(info);
info = new IfInfo(info.getCondition(), elseBlock, null);
info.setOutBlock(thenBlock);
} else {
List<BlockNode> thenSC = thenBlock.getCleanSuccessors();
List<BlockNode> elseSC = elseBlock.getCleanSuccessors();
......
package jadx.tests.internal.others;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static jadx.tests.utils.JadxMatchers.countString;
import static org.junit.Assert.assertThat;
public class TestIfInTry extends InternalJadxTest {
public static class TestCls {
private File dir;
public int test() {
try {
int a = f();
if (a != 0) {
return a;
}
} catch (Exception e) {
// skip
}
try {
f();
return 1;
} catch (IOException e) {
return -1;
}
}
private int f() throws IOException {
return 0;
}
}
@Test
public void test() {
setOutputCFG();
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("if (a != 0) {"));
assertThat(code, containsOne("} catch (Exception e) {"));
assertThat(code, countString(2, "try {"));
assertThat(code, countString(3, "f()"));
assertThat(code, containsOne("return 1;"));
assertThat(code, containsOne("} catch (IOException e"));
assertThat(code, containsOne("return -1;"));
}
}
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