Search in sources :

Example 81 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class BlockProcessor method computeDominanceFrontier.

static void computeDominanceFrontier(MethodNode mth) {
    mth.getExitBlock().setDomFrontier(EMPTY);
    List<BlockNode> domSortedBlocks = new ArrayList<>(mth.getBasicBlocks().size());
    Deque<BlockNode> stack = new LinkedList<>();
    stack.push(mth.getEnterBlock());
    while (!stack.isEmpty()) {
        BlockNode node = stack.pop();
        for (BlockNode dominated : node.getDominatesOn()) {
            stack.push(dominated);
        }
        domSortedBlocks.add(node);
    }
    Collections.reverse(domSortedBlocks);
    for (BlockNode block : domSortedBlocks) {
        try {
            computeBlockDF(mth, block);
        } catch (Exception e) {
            throw new JadxRuntimeException("Failed compute block dominance frontier", e);
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) LinkedList(java.util.LinkedList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 82 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class ProcessInstructionsVisitor method initJumps.

private static void initJumps(MethodNode mth, InsnNode[] insnByOffset) {
    for (int offset = 0; offset < insnByOffset.length; offset++) {
        InsnNode insn = insnByOffset[offset];
        if (insn == null) {
            continue;
        }
        switch(insn.getType()) {
            case SWITCH:
                SwitchInsn sw = (SwitchInsn) insn;
                if (sw.needData()) {
                    attachSwitchData(insnByOffset, offset, sw);
                }
                int defCaseOffset = sw.getDefaultCaseOffset();
                if (defCaseOffset != -1) {
                    addJump(mth, insnByOffset, offset, defCaseOffset);
                }
                for (int target : sw.getTargets()) {
                    addJump(mth, insnByOffset, offset, target);
                }
                break;
            case IF:
                int next = getNextInsnOffset(insnByOffset, offset);
                if (next != -1) {
                    addJump(mth, insnByOffset, offset, next);
                }
                addJump(mth, insnByOffset, offset, ((IfNode) insn).getTarget());
                break;
            case GOTO:
                addJump(mth, insnByOffset, offset, ((GotoNode) insn).getTarget());
                break;
            case INVOKE:
                if (insn.getResult() == null) {
                    ArgType retType = ((BaseInvokeNode) insn).getCallMth().getReturnType();
                    mergeMoveResult(insnByOffset, offset, insn, retType);
                }
                break;
            case STR_CONCAT:
                // invoke-custom with string concatenation translated directly to STR_CONCAT, merge next move-result
                if (insn.getResult() == null) {
                    mergeMoveResult(insnByOffset, offset, insn, ArgType.STRING);
                }
                break;
            case FILLED_NEW_ARRAY:
                ArgType arrType = ((FilledNewArrayNode) insn).getArrayType();
                mergeMoveResult(insnByOffset, offset, insn, arrType);
                break;
            case FILL_ARRAY:
                FillArrayInsn fillArrayInsn = (FillArrayInsn) insn;
                int target = fillArrayInsn.getTarget();
                InsnNode arrDataInsn = getInsnAtOffset(insnByOffset, target);
                if (arrDataInsn != null && arrDataInsn.getType() == InsnType.FILL_ARRAY_DATA) {
                    fillArrayInsn.setArrayData((FillArrayData) arrDataInsn);
                    removeInsn(insnByOffset, arrDataInsn);
                } else {
                    throw new JadxRuntimeException("Payload for fill-array not found at " + InsnUtils.formatOffset(target));
                }
                break;
            default:
                break;
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) FillArrayInsn(jadx.core.dex.instructions.FillArrayInsn) InsnNode(jadx.core.dex.nodes.InsnNode) FilledNewArrayNode(jadx.core.dex.instructions.FilledNewArrayNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) SwitchInsn(jadx.core.dex.instructions.SwitchInsn)

Example 83 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class OverrideMethodVisitor method processMth.

private void processMth(MethodNode mth, SuperTypesData superData) {
    if (mth.isConstructor() || mth.getAccessFlags().isStatic() || mth.getAccessFlags().isPrivate()) {
        return;
    }
    MethodOverrideAttr attr = processOverrideMethods(mth, superData);
    if (attr != null) {
        if (attr.getBaseMethods().isEmpty()) {
            throw new JadxRuntimeException("No base methods for override attribute: " + attr.getOverrideList());
        }
        mth.addAttr(attr);
        IMethodDetails baseMth = Utils.getOne(attr.getBaseMethods());
        if (baseMth != null) {
            boolean updated = fixMethodReturnType(mth, baseMth, superData);
            updated |= fixMethodArgTypes(mth, baseMth, superData);
            if (updated) {
                // check if new signature cause method collisions
                checkMethodSignatureCollisions(mth, mth.root().getArgs().isRenameValid());
            }
        }
    }
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 84 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class BlockExceptionHandler method searchTopBlock.

private static BlockNode searchTopBlock(MethodNode mth, List<BlockNode> blocks) {
    BlockNode top = BlockUtils.getTopBlock(blocks);
    if (top != null) {
        return adjustTopBlock(top);
    }
    BlockNode topDom = BlockUtils.getCommonDominator(mth, blocks);
    if (topDom != null) {
        return adjustTopBlock(topDom);
    }
    throw new JadxRuntimeException("Failed to find top block for try-catch from: " + blocks);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 85 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException 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

JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)115 BlockNode (jadx.core.dex.nodes.BlockNode)25 ArrayList (java.util.ArrayList)25 InsnNode (jadx.core.dex.nodes.InsnNode)24 ArgType (jadx.core.dex.instructions.args.ArgType)20 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)17 BitSet (java.util.BitSet)11 ClassNode (jadx.core.dex.nodes.ClassNode)10 MethodNode (jadx.core.dex.nodes.MethodNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)8 SSAVar (jadx.core.dex.instructions.args.SSAVar)8 IOException (java.io.IOException)8 List (java.util.List)8 File (java.io.File)7 IRegion (jadx.core.dex.nodes.IRegion)6 Path (java.nio.file.Path)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)5 PhiInsn (jadx.core.dex.instructions.PhiInsn)5 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 FieldNode (jadx.core.dex.nodes.FieldNode)5