From e9591efd7e9d504ec40661b904c653851307e6f2 Mon Sep 17 00:00:00 2001 From: Skylot Date: Tue, 25 Dec 2018 17:27:42 +0300 Subject: [PATCH] fix: search exception handler splitter block by offset if jump source unknown (#406) --- .../dex/visitors/blocksmaker/BlockSplitter.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java b/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java index d800a0f4760..5e4d3d6804a 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockSplitter.java @@ -223,12 +223,13 @@ private static void setupConnections(MethodNode mth, Map blo BlockNode thisBlock = getBlock(jump.getDest(), blocksMap); connect(srcBlock, thisBlock); } - connectExceptionHandlers(block, insn); + connectExceptionHandlers(block, insn, blocksMap); } } } - private static void connectExceptionHandlers(BlockNode block, InsnNode insn) { + private static void connectExceptionHandlers(BlockNode block, InsnNode insn, + Map blocksMap) { CatchAttr catches = insn.get(AType.CATCH_BLOCK); SplitterBlockAttr spl = block.get(AType.SPLITTER_BLOCK); if (catches == null || spl == null) { @@ -237,7 +238,7 @@ private static void connectExceptionHandlers(BlockNode block, InsnNode insn) { BlockNode splitterBlock = spl.getBlock(); boolean tryEnd = insn.contains(AFlag.TRY_LEAVE); for (ExceptionHandler h : catches.getTryBlock().getHandlers()) { - BlockNode handlerBlock = h.getHandlerBlock(); + BlockNode handlerBlock = initHandlerBlock(h, blocksMap); // skip self loop in handler if (splitterBlock != handlerBlock) { if (!handlerBlock.contains(AType.SPLITTER_BLOCK)) { @@ -251,6 +252,16 @@ private static void connectExceptionHandlers(BlockNode block, InsnNode insn) { } } + private static BlockNode initHandlerBlock(ExceptionHandler excHandler, Map blocksMap) { + BlockNode handlerBlock = excHandler.getHandlerBlock(); + if (handlerBlock != null) { + return handlerBlock; + } + BlockNode blockByOffset = getBlock(excHandler.getHandleOffset(), blocksMap); + excHandler.setHandlerBlock(blockByOffset); + return blockByOffset; + } + private static boolean isSplitByJump(InsnNode prevInsn, InsnNode currentInsn) { List pJumps = prevInsn.getAll(AType.JUMP); for (JumpInfo jump : pJumps) {