Commit fde431d1 authored by skylot's avatar skylot

Merge pull request #3 from 13-beta2/master

Core fix
parents b44a1e3a 272e0d37
...@@ -148,6 +148,8 @@ public class InsnGen { ...@@ -148,6 +148,8 @@ public class InsnGen {
String thisClass = mth.getParentClass().getFullName(); String thisClass = mth.getParentClass().getFullName();
if (thisClass.startsWith(field.getDeclClass().getFullName())) { if (thisClass.startsWith(field.getDeclClass().getFullName())) {
return field.getName(); return field.getName();
} else if (field.getDeclClass().getFullName().startsWith(mth.getParentClass().getPackage() + ".R")) {
return field.getDeclClass().getNameWithoutPackage() + '.' + field.getName();
} else { } else {
return useClass(field.getDeclClass()) + '.' + field.getName(); return useClass(field.getDeclClass()) + '.' + field.getName();
} }
......
...@@ -353,7 +353,6 @@ public class BlockMakerVisitor extends AbstractVisitor { ...@@ -353,7 +353,6 @@ public class BlockMakerVisitor extends AbstractVisitor {
// splice return block if several predecessors presents // splice return block if several predecessors presents
for (BlockNode block : mth.getExitBlocks()) { for (BlockNode block : mth.getExitBlocks()) {
if (block.getInstructions().size() == 1 if (block.getInstructions().size() == 1
&& block.getInstructions().get(0).getArgsCount() > 0
&& !block.getInstructions().get(0).getAttributes().contains(AttributeType.CATCH_BLOCK) && !block.getInstructions().get(0).getAttributes().contains(AttributeType.CATCH_BLOCK)
&& !block.getAttributes().contains(AttributeFlag.SYNTHETIC)) { && !block.getAttributes().contains(AttributeFlag.SYNTHETIC)) {
List<BlockNode> preds = new ArrayList<BlockNode>(block.getPredecessors()); List<BlockNode> preds = new ArrayList<BlockNode>(block.getPredecessors());
......
...@@ -86,6 +86,18 @@ public class ModVisitor extends AbstractVisitor { ...@@ -86,6 +86,18 @@ public class ModVisitor extends AbstractVisitor {
} else { } else {
replaceInsn(block, i, co); replaceInsn(block, i, co);
} }
} else {
if (inv.getArgsCount() > 0) {
for (int j = 0; j < inv.getArgsCount(); j++) {
InsnArg arg = inv.getArg(j);
if (arg.isLiteral()) {
f = parentClass.getConstFieldByLiteralArg((LiteralArg) arg);
if (f != null) {
arg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
}
}
}
}
} }
break; break;
......
...@@ -265,10 +265,10 @@ public class RegionMaker { ...@@ -265,10 +265,10 @@ public class RegionMaker {
&& r.getInstructions().size() > 0 && r.getInstructions().size() > 0
&& r.getInstructions().get(0).getType() == InsnType.RETURN) { && r.getInstructions().get(0).getType() == InsnType.RETURN) {
next.getAttributes().add(new ForceReturnAttr(r.getInstructions().get(0))); next.getAttributes().add(new ForceReturnAttr(r.getInstructions().get(0)));
} else { } /*/ else {
next.getAttributes().add(AttributeFlag.BREAK); next.getAttributes().add(AttributeFlag.BREAK);
stack.addExit(r); stack.addExit(r);
} } /**/
} else { } else {
stack.addExit(next); stack.addExit(next);
} }
...@@ -492,8 +492,10 @@ public class RegionMaker { ...@@ -492,8 +492,10 @@ public class RegionMaker {
IfCondition nestedCondition = IfCondition.fromIfNode(nestedIfInsn); IfCondition nestedCondition = IfCondition.fromIfNode(nestedIfInsn);
if (isPathExists(bElse, nestedIfBlock)) { if (isPathExists(bElse, nestedIfBlock)) {
// else branch // else branch
if (bThen != nbThen) { if (bThen != nbThen
if (bThen != nbElse) { && !isEqualReturns(bThen, nbThen)) {
if (bThen != nbElse
&& !isEqualReturns(bThen, nbElse)) {
// not connected conditions // not connected conditions
break; break;
} }
...@@ -503,8 +505,10 @@ public class RegionMaker { ...@@ -503,8 +505,10 @@ public class RegionMaker {
condition = IfCondition.merge(Mode.OR, condition, nestedCondition); condition = IfCondition.merge(Mode.OR, condition, nestedCondition);
} else { } else {
// then branch // then branch
if (bElse != nbElse) { if (bElse != nbElse
if (bElse != nbThen) { && !isEqualReturns(bElse, nbElse)) {
if (bElse != nbThen
&& !isEqualReturns(bElse, nbThen)) {
// not connected conditions // not connected conditions
break; break;
} }
...@@ -516,6 +520,8 @@ public class RegionMaker { ...@@ -516,6 +520,8 @@ public class RegionMaker {
result = new IfInfo(); result = new IfInfo();
result.setCondition(condition); result.setCondition(condition);
nestedIfBlock.getAttributes().add(AttributeFlag.SKIP); nestedIfBlock.getAttributes().add(AttributeFlag.SKIP);
bThen.getAttributes().add(AttributeFlag.SKIP);
if (merged != null) { if (merged != null) {
merged.add(nestedIfBlock); merged.add(nestedIfBlock);
} }
...@@ -683,4 +689,28 @@ public class RegionMaker { ...@@ -683,4 +689,28 @@ public class RegionMaker {
handler.getHandlerRegion().getAttributes().add(excHandlerAttr); handler.getHandlerRegion().getAttributes().add(excHandlerAttr);
} }
private boolean isEqualReturns(BlockNode b1, BlockNode b2) {
if (b1 == b2) {
return true;
}
if (b1 == null
|| b2 == null) {
return false;
}
if (b1.getInstructions().size()
+ b2.getInstructions().size() != 2) {
return false;
}
if (!b1.getAttributes().contains(AttributeFlag.RETURN)
|| !b2.getAttributes().contains(AttributeFlag.RETURN)) {
return false;
}
if (b1.getInstructions().get(0).getArgsCount() > 0) {
if (b1.getInstructions().get(0).getArg(0)
!= b2.getInstructions().get(0).getArg(0)) {
return false;
}
}
return true;
}
} }
...@@ -39,6 +39,16 @@ public class TestLoopCondition extends InternalJadxTest { ...@@ -39,6 +39,16 @@ public class TestLoopCondition extends InternalJadxTest {
} }
return i; return i;
} }
private void testMoreComplexIfInLoop(java.util.ArrayList<String> list) throws Exception {
for (int i = 0; i != 16 && i < 255; i++) {
list.set(i, "ABC");
if (i == 128) {
return;
}
list.set(i, "DEF");
}
}
} }
@Test @Test
...@@ -50,5 +60,7 @@ public class TestLoopCondition extends InternalJadxTest { ...@@ -50,5 +60,7 @@ public class TestLoopCondition extends InternalJadxTest {
assertThat(code, containsString("i < f.length()")); assertThat(code, containsString("i < f.length()"));
assertThat(code, containsString("while (a && i < 10) {")); assertThat(code, containsString("while (a && i < 10) {"));
assertThat(code, containsString("list.set(i, \"ABC\")"));
assertThat(code, containsString("list.set(i, \"DEF\")"));
} }
} }
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