Commit 72a50eae authored by Skylot's avatar Skylot

core: fix missing blocks in loop region

parent fa37b90c
......@@ -138,6 +138,6 @@ public final class LoopRegion extends AbstractRegion {
@Override
public String toString() {
return "LOOP";
return "LOOP: " + baseString();
}
}
......@@ -213,7 +213,21 @@ public class RegionMaker {
}
stack.addExit(out);
BlockNode loopBody = condInfo.getThenBlock();
loopRegion.setBody(makeRegion(loopBody, stack));
Region body = makeRegion(loopBody, stack);
// add blocks from loop start to first condition block
BlockNode conditionBlock = condInfo.getIfBlock();
if (loopStart != conditionBlock) {
Set<BlockNode> blocks = BlockUtils.getAllPathsBlocks(loopStart, conditionBlock);
blocks.remove(conditionBlock);
for (BlockNode block : blocks) {
if (block.getInstructions().isEmpty()
&& !block.contains(AFlag.SKIP)
&& !RegionUtils.isRegionContainsBlock(body, block)) {
body.add(block);
}
}
}
loopRegion.setBody(body);
}
stack.pop();
return out;
......@@ -569,7 +583,7 @@ public class RegionMaker {
Set<BlockNode> exits = new HashSet<BlockNode>();
for (BlockNode splitter : splitters) {
for (BlockNode handler : blocks) {
List<BlockNode> s = splitter.getCleanSuccessors();
List<BlockNode> s = splitter.getSuccessors();
if (s.isEmpty()) {
LOG.debug(ErrorsCounter.formatErrorMsg(mth, "No successors for splitter: " + splitter));
continue;
......
package jadx.tests.internal.others;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.exceptions.DecodeException;
import java.io.EOFException;
import org.junit.Test;
import com.android.dex.Code;
import com.android.dx.io.instructions.DecodedInstruction;
import com.android.dx.io.instructions.ShortArrayCodeInput;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestLoopInTry2 extends InternalJadxTest {
public static class TestCls {
private MethodNode method;
private DexNode dex;
private DecodedInstruction[] insnArr;
public void test(Code mthCode) throws DecodeException {
short[] encodedInstructions = mthCode.getInstructions();
int size = encodedInstructions.length;
DecodedInstruction[] decoded = new DecodedInstruction[size];
ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);
try {
while (in.hasMore()) {
decoded[in.cursor()] = DecodedInstruction.decode(in);
}
} catch (EOFException e) {
throw new DecodeException(method, "", e);
}
insnArr = decoded;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("try {"));
assertThat(code, containsOne("while (in.hasMore()) {"));
assertThat(code, containsOne("decoded[in.cursor()] = DecodedInstruction.decode(in);"));
assertThat(code, containsOne("} catch (EOFException e) {"));
assertThat(code, containsOne("throw new DecodeException"));
}
}
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