未验证 提交 96f90e18 编写于 作者: S Skylot

fix: improve exception handlers attach

上级 8ff18e63
...@@ -390,15 +390,23 @@ public class BlockExceptionHandler { ...@@ -390,15 +390,23 @@ public class BlockExceptionHandler {
private static BlockNode searchTopBlock(MethodNode mth, List<BlockNode> blocks) { private static BlockNode searchTopBlock(MethodNode mth, List<BlockNode> blocks) {
BlockNode top = BlockUtils.getTopBlock(blocks); BlockNode top = BlockUtils.getTopBlock(blocks);
if (top != null) { if (top != null) {
return top; return adjustTopBlock(top);
} }
BlockNode topDom = BlockUtils.getCommonDominator(mth, blocks); BlockNode topDom = BlockUtils.getCommonDominator(mth, blocks);
if (topDom != null) { if (topDom != null) {
return topDom; return adjustTopBlock(topDom);
} }
throw new JadxRuntimeException("Failed to find top block for try-catch from: " + blocks); throw new JadxRuntimeException("Failed to find top block for try-catch from: " + blocks);
} }
private static BlockNode adjustTopBlock(BlockNode topBlock) {
if (topBlock.getSuccessors().size() == 1 && !topBlock.contains(AType.EXC_CATCH)) {
// top block can be lifted by other exception handlers included in blocks list, trying to undo that
return topBlock.getSuccessors().get(0);
}
return topBlock;
}
@Nullable @Nullable
private static BlockNode searchBottomBlock(MethodNode mth, List<BlockNode> blocks) { private static BlockNode searchBottomBlock(MethodNode mth, List<BlockNode> blocks) {
// search common post-dominator block inside input set // search common post-dominator block inside input set
......
...@@ -140,7 +140,7 @@ public class SSATransform extends AbstractVisitor { ...@@ -140,7 +140,7 @@ public class SSATransform extends AbstractVisitor {
stack.push(initState); stack.push(initState);
while (!stack.isEmpty()) { while (!stack.isEmpty()) {
RenameState state = stack.pop(); RenameState state = stack.pop();
renameVarsInBlock(state); renameVarsInBlock(mth, state);
for (BlockNode dominated : state.getBlock().getDominatesOn()) { for (BlockNode dominated : state.getBlock().getDominatesOn()) {
stack.push(RenameState.copyFrom(state, dominated)); stack.push(RenameState.copyFrom(state, dominated));
} }
...@@ -156,7 +156,7 @@ public class SSATransform extends AbstractVisitor { ...@@ -156,7 +156,7 @@ public class SSATransform extends AbstractVisitor {
} }
} }
private static void renameVarsInBlock(RenameState state) { private static void renameVarsInBlock(MethodNode mth, RenameState state) {
BlockNode block = state.getBlock(); BlockNode block = state.getBlock();
for (InsnNode insn : block.getInstructions()) { for (InsnNode insn : block.getInstructions()) {
if (insn.getType() != InsnType.PHI) { if (insn.getType() != InsnType.PHI) {
...@@ -168,8 +168,9 @@ public class SSATransform extends AbstractVisitor { ...@@ -168,8 +168,9 @@ public class SSATransform extends AbstractVisitor {
int regNum = reg.getRegNum(); int regNum = reg.getRegNum();
SSAVar var = state.getVar(regNum); SSAVar var = state.getVar(regNum);
if (var == null) { if (var == null) {
throw new JadxRuntimeException("Not initialized variable reg: " + regNum // TODO: in most cases issue in incorrectly attached exception handlers
+ ", insn: " + insn + ", block:" + block); mth.addWarnComment("Not initialized variable reg: " + regNum + ", insn: " + insn + ", block:" + block);
var = state.startVar(reg);
} }
var.use(reg); var.use(reg);
} }
......
...@@ -55,7 +55,6 @@ public class TestTryCatchFinally8 extends IntegrationTest { ...@@ -55,7 +55,6 @@ public class TestTryCatchFinally8 extends IntegrationTest {
} }
@Test @Test
@NotYetImplemented
public void test2() { public void test2() {
disableCompilation(); disableCompilation();
ClassNode cls = getClassNode(TestCls.class); ClassNode cls = getClassNode(TestCls.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册