use of jadx.core.dex.attributes.nodes.TmpEdgeAttr in project jadx by skylot.
the class BlockExceptionHandler method initExcHandlers.
@SuppressWarnings("ForLoopReplaceableByForEach")
private static void initExcHandlers(MethodNode mth) {
List<BlockNode> blocks = mth.getBasicBlocks();
int blocksCount = blocks.size();
for (int i = 0; i < blocksCount; i++) {
// will add new blocks to list end
BlockNode block = blocks.get(i);
InsnNode firstInsn = BlockUtils.getFirstInsn(block);
if (firstInsn == null) {
continue;
}
ExcHandlerAttr excHandlerAttr = firstInsn.get(AType.EXC_HANDLER);
if (excHandlerAttr == null) {
continue;
}
firstInsn.remove(AType.EXC_HANDLER);
TmpEdgeAttr tmpEdgeAttr = block.get(AType.TMP_EDGE);
if (tmpEdgeAttr != null) {
// remove temp connection
BlockSplitter.removeConnection(tmpEdgeAttr.getBlock(), block);
block.remove(AType.TMP_EDGE);
}
ExceptionHandler excHandler = excHandlerAttr.getHandler();
if (block.getPredecessors().isEmpty()) {
excHandler.setHandlerBlock(block);
block.addAttr(excHandlerAttr);
excHandler.addBlock(block);
BlockUtils.collectBlocksDominatedByWithExcHandlers(mth, block, block).forEach(excHandler::addBlock);
} else {
// ignore already connected handlers -> make catch empty
BlockNode emptyHandlerBlock = BlockSplitter.startNewBlock(mth, block.getStartOffset());
emptyHandlerBlock.add(AFlag.SYNTHETIC);
emptyHandlerBlock.addAttr(excHandlerAttr);
BlockSplitter.connect(emptyHandlerBlock, block);
excHandler.setHandlerBlock(emptyHandlerBlock);
excHandler.addBlock(emptyHandlerBlock);
}
fixMoveExceptionInsn(block, excHandlerAttr);
}
}
use of jadx.core.dex.attributes.nodes.TmpEdgeAttr in project jadx by skylot.
the class BlockSplitter method addTempConnectionsForExcHandlers.
/**
* Connect exception handlers to the throw block.
* This temporary connection needed to build close to final dominators tree.
* Will be used and removed in {@code jadx.core.dex.visitors.blocks.BlockExceptionHandler}
*/
private static void addTempConnectionsForExcHandlers(MethodNode mth, Map<Integer, BlockNode> blocksMap) {
for (BlockNode block : mth.getBasicBlocks()) {
for (InsnNode insn : block.getInstructions()) {
CatchAttr catchAttr = insn.get(AType.EXC_CATCH);
if (catchAttr == null) {
continue;
}
for (ExceptionHandler handler : catchAttr.getHandlers()) {
BlockNode handlerBlock = getBlock(handler.getHandlerOffset(), blocksMap);
if (!handlerBlock.contains(AType.TMP_EDGE)) {
List<BlockNode> preds = block.getPredecessors();
if (preds.isEmpty()) {
throw new JadxRuntimeException("Unexpected missing predecessor for block: " + block);
}
BlockNode start = preds.size() == 1 ? preds.get(0) : block;
if (!start.getSuccessors().contains(handlerBlock)) {
connect(start, handlerBlock);
handlerBlock.addAttr(new TmpEdgeAttr(start));
}
}
}
}
}
}
Aggregations