Search in sources :

Example 11 with TryCatchBlockAttr

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

the class BlockExceptionHandler method connectSplittersAndHandlers.

private static void connectSplittersAndHandlers(TryCatchBlockAttr tryCatchBlock, BlockNode topSplitterBlock, @Nullable BlockNode bottomSplitterBlock) {
    for (ExceptionHandler handler : tryCatchBlock.getHandlers()) {
        BlockNode handlerBlock = handler.getHandlerBlock();
        BlockSplitter.connect(topSplitterBlock, handlerBlock);
        if (bottomSplitterBlock != null) {
            BlockSplitter.connect(bottomSplitterBlock, handlerBlock);
        }
    }
    TryCatchBlockAttr outerTryBlock = tryCatchBlock.getOuterTryBlock();
    if (outerTryBlock != null) {
        connectSplittersAndHandlers(outerTryBlock, topSplitterBlock, bottomSplitterBlock);
    }
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) BlockNode(jadx.core.dex.nodes.BlockNode) TryCatchBlockAttr(jadx.core.dex.trycatch.TryCatchBlockAttr)

Example 12 with TryCatchBlockAttr

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

the class BlockExceptionHandler method sortHandlers.

private static void sortHandlers(MethodNode mth, List<TryCatchBlockAttr> tryBlocks) {
    TypeCompare typeCompare = mth.root().getTypeCompare();
    Comparator<ArgType> comparator = typeCompare.getReversedComparator();
    for (TryCatchBlockAttr tryBlock : tryBlocks) {
        for (ExceptionHandler handler : tryBlock.getHandlers()) {
            handler.getCatchTypes().sort((first, second) -> compareByTypeAndName(comparator, first, second));
        }
        tryBlock.getHandlers().sort((first, second) -> {
            if (first.equals(second)) {
                throw new JadxRuntimeException("Same handlers in try block: " + tryBlock);
            }
            if (first.isCatchAll()) {
                return 1;
            }
            if (second.isCatchAll()) {
                return -1;
            }
            return compareByTypeAndName(comparator, ListUtils.first(first.getCatchTypes()), ListUtils.first(second.getCatchTypes()));
        });
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) TryCatchBlockAttr(jadx.core.dex.trycatch.TryCatchBlockAttr) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

TryCatchBlockAttr (jadx.core.dex.trycatch.TryCatchBlockAttr)12 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)9 BlockNode (jadx.core.dex.nodes.BlockNode)8 ArrayList (java.util.ArrayList)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 ArgType (jadx.core.dex.instructions.args.ArgType)4 TypeCompare (jadx.core.dex.visitors.typeinference.TypeCompare)4 ArrayDeque (java.util.ArrayDeque)4 Utils (jadx.api.plugins.utils.Utils)3 Consts (jadx.core.Consts)3 AFlag (jadx.core.dex.attributes.AFlag)3 AType (jadx.core.dex.attributes.AType)3 TmpEdgeAttr (jadx.core.dex.attributes.nodes.TmpEdgeAttr)3 ClassInfo (jadx.core.dex.info.ClassInfo)3 InsnType (jadx.core.dex.instructions.InsnType)3 InsnArg (jadx.core.dex.instructions.args.InsnArg)3 NamedArg (jadx.core.dex.instructions.args.NamedArg)3 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)3 InsnNode (jadx.core.dex.nodes.InsnNode)3 MethodNode (jadx.core.dex.nodes.MethodNode)3