Commit e46dfc55 authored by Skylot's avatar Skylot

core: redone return blocks splitting for fix issue #4

parent e54b7645
package jadx.core.dex.visitors.regions;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.IBlock;
import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.LoopRegion;
import java.util.Iterator;
import java.util.List;
public class FinishRegions extends TracedRegionVisitor {
@Override
......@@ -21,6 +17,8 @@ public class FinishRegions extends TracedRegionVisitor {
BlockNode block = (BlockNode) container;
// remove last return in void functions
/*
BlockNode block = (BlockNode) container;
if (block.getCleanSuccessors().isEmpty()
&& mth.getReturnType().equals(ArgType.VOID)) {
List<InsnNode> insns = block.getInstructions();
......@@ -33,6 +31,7 @@ public class FinishRegions extends TracedRegionVisitor {
}
}
}
*/
}
private boolean blockNotInLoop(MethodNode mth, BlockNode block) {
......
......@@ -4,7 +4,6 @@ import jadx.core.Consts;
import jadx.core.dex.attributes.AttributeFlag;
import jadx.core.dex.attributes.AttributeType;
import jadx.core.dex.attributes.AttributesList;
import jadx.core.dex.attributes.ForceReturnAttr;
import jadx.core.dex.attributes.IAttribute;
import jadx.core.dex.attributes.LoopAttr;
import jadx.core.dex.instructions.IfNode;
......@@ -258,6 +257,7 @@ public class RegionMaker {
while (next != null) {
if (isPathExists(loopExit, next)) {
// found cross
/*
if (next.getCleanSuccessors().size() == 1) {
BlockNode r = BlockUtils.getNextBlock(next);
if (r != null
......@@ -265,13 +265,14 @@ public class RegionMaker {
&& r.getInstructions().size() > 0
&& r.getInstructions().get(0).getType() == InsnType.RETURN) {
next.getAttributes().add(new ForceReturnAttr(r.getInstructions().get(0)));
} /*/ else {
} else {
next.getAttributes().add(AttributeFlag.BREAK);
stack.addExit(r);
} /**/
}
} else {
stack.addExit(next);
}
*/
break;
}
next = BlockUtils.getNextBlock(next);
......
......@@ -67,8 +67,7 @@ public class TypeResolver extends AbstractVisitor {
state.assignReg(insn.getResult());
}
if (block.getSuccessors().size() > 0)
block.setEndState(new BlockRegState(state));
block.setEndState(new BlockRegState(state));
}
}
......
package jadx.samples;
public class TestCF4 extends AbstractTest {
int c;
String d;
String f;
public void testComplexIf(String a, int b) {
if (d == null || (c == 0 && b != -1 && d.length() == 0)) {
c = a.codePointAt(c);
} else {
if (a.length() != 2) {
c = f.compareTo(a);
}
}
}
public void checkComplexIf() {
d = null;
f = null;
c = 2;
testComplexIf("abcdef", 0);
assertEquals(c, (int) 'c');
d = "";
f = null;
c = 0;
testComplexIf("abcdef", 0);
assertEquals(c, (int) 'a');
d = "";
f = "1";
c = 777;
testComplexIf("ab", -1);
assertEquals(c, 777);
}
@Override
public boolean testRun() throws Exception {
checkComplexIf();
return true;
}
public static void main(String[] args) throws Exception {
new TestCF4().testRun();
}
}
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