Search in sources :

Example 6 with ExcHandlerAttr

use of jadx.core.dex.trycatch.ExcHandlerAttr in project jadx by skylot.

the class BlockFinish method fixSplitterBlock.

/**
	 * For evey exception handler must be only one splitter block,
	 * select correct one and remove others if necessary.
	 */
private static void fixSplitterBlock(BlockNode block) {
    ExcHandlerAttr excHandlerAttr = block.get(AType.EXC_HANDLER);
    if (excHandlerAttr == null) {
        return;
    }
    BlockNode handlerBlock = excHandlerAttr.getHandler().getHandlerBlock();
    if (handlerBlock.getPredecessors().size() < 2) {
        return;
    }
    Map<BlockNode, SplitterBlockAttr> splitters = new HashMap<BlockNode, SplitterBlockAttr>();
    for (BlockNode pred : handlerBlock.getPredecessors()) {
        pred = BlockUtils.skipSyntheticPredecessor(pred);
        SplitterBlockAttr splitterAttr = pred.get(AType.SPLITTER_BLOCK);
        if (splitterAttr != null && pred == splitterAttr.getBlock()) {
            splitters.put(pred, splitterAttr);
        }
    }
    if (splitters.size() < 2) {
        return;
    }
    BlockNode topSplitter = BlockUtils.getTopBlock(splitters.keySet());
    if (topSplitter == null) {
        LOG.warn("Unknown top splitter block from list: {}", splitters);
        return;
    }
    for (Map.Entry<BlockNode, SplitterBlockAttr> entry : splitters.entrySet()) {
        BlockNode pred = entry.getKey();
        SplitterBlockAttr splitterAttr = entry.getValue();
        if (pred == topSplitter) {
            block.addAttr(splitterAttr);
        } else {
            pred.remove(AType.SPLITTER_BLOCK);
            for (BlockNode s : pred.getCleanSuccessors()) {
                s.remove(AType.SPLITTER_BLOCK);
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ExcHandlerAttr(jadx.core.dex.trycatch.ExcHandlerAttr) SplitterBlockAttr(jadx.core.dex.trycatch.SplitterBlockAttr) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ExcHandlerAttr (jadx.core.dex.trycatch.ExcHandlerAttr)6 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)4 BlockNode (jadx.core.dex.nodes.BlockNode)3 InsnNode (jadx.core.dex.nodes.InsnNode)3 ArgType (jadx.core.dex.instructions.args.ArgType)2 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 SplitterBlockAttr (jadx.core.dex.trycatch.SplitterBlockAttr)2 TryCatchBlock (jadx.core.dex.trycatch.TryCatchBlock)2 CatchHandler (com.android.dex.Code.CatchHandler)1 Try (com.android.dex.Code.Try)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 NamedArg (jadx.core.dex.instructions.args.NamedArg)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 CatchAttr (jadx.core.dex.trycatch.CatchAttr)1 InstructionRemover (jadx.core.utils.InstructionRemover)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1