Search in sources :

Example 21 with BlockNode

use of jadx.core.dex.nodes.BlockNode in project jadx by skylot.

the class BlockSplitter method insertBlockBetween.

static BlockNode insertBlockBetween(MethodNode mth, BlockNode source, BlockNode target) {
    BlockNode newBlock = startNewBlock(mth, target.getStartOffset());
    newBlock.add(AFlag.SYNTHETIC);
    removeConnection(source, target);
    connect(source, newBlock);
    connect(newBlock, target);
    return newBlock;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode)

Example 22 with BlockNode

use of jadx.core.dex.nodes.BlockNode in project jadx by skylot.

the class DebugInfoVisitor method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    int debugOffset = mth.getDebugInfoOffset();
    if (debugOffset > 0) {
        InsnNode[] insnArr = mth.getInstructions();
        DebugInfoParser debugInfoParser = new DebugInfoParser(mth, debugOffset, insnArr);
        debugInfoParser.process();
        // set method source line from first instruction
        if (insnArr.length != 0) {
            for (InsnNode insn : insnArr) {
                if (insn != null) {
                    int line = insn.getSourceLine();
                    if (line != 0) {
                        mth.setSourceLine(line - 1);
                    }
                    break;
                }
            }
        }
        if (!mth.getReturnType().equals(ArgType.VOID)) {
            // fix debug info for splitter 'return' instructions
            for (BlockNode exit : mth.getExitBlocks()) {
                InsnNode ret = BlockUtils.getLastInsn(exit);
                if (ret == null) {
                    continue;
                }
                InsnNode oldRet = insnArr[ret.getOffset()];
                if (oldRet == ret) {
                    continue;
                }
                RegisterArg oldArg = (RegisterArg) oldRet.getArg(0);
                RegisterArg newArg = (RegisterArg) ret.getArg(0);
                newArg.mergeDebugInfo(oldArg.getType(), oldArg.getName());
                ret.setSourceLine(oldRet.getSourceLine());
            }
        }
    }
    mth.unloadInsnArr();
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) DebugInfoParser(jadx.core.dex.nodes.parser.DebugInfoParser)

Example 23 with BlockNode

use of jadx.core.dex.nodes.BlockNode in project jadx by skylot.

the class DependencyCollector method processMethod.

private static void processMethod(DexNode dex, Set<ClassNode> depList, MethodNode methodNode) {
    addDep(dex, depList, methodNode.getParentClass());
    addDep(dex, depList, methodNode.getReturnType());
    for (ArgType arg : methodNode.getMethodInfo().getArgumentsTypes()) {
        addDep(dex, depList, arg);
    }
    for (BlockNode block : methodNode.getBasicBlocks()) {
        for (InsnNode insnNode : block.getInstructions()) {
            processInsn(dex, depList, insnNode);
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode)

Example 24 with BlockNode

use of jadx.core.dex.nodes.BlockNode in project jadx by skylot.

the class BlockSplitter method connectExceptionHandlers.

private static void connectExceptionHandlers(Map<Integer, BlockNode> blocksMap, BlockNode block, InsnNode insn) {
    CatchAttr catches = insn.get(AType.CATCH_BLOCK);
    SplitterBlockAttr spl = block.get(AType.SPLITTER_BLOCK);
    if (catches == null || spl == null) {
        return;
    }
    BlockNode splitterBlock = spl.getBlock();
    boolean tryEnd = insn.contains(AFlag.TRY_LEAVE);
    for (ExceptionHandler h : catches.getTryBlock().getHandlers()) {
        BlockNode handlerBlock = getBlock(h.getHandleOffset(), blocksMap);
        // skip self loop in handler
        if (splitterBlock != handlerBlock) {
            if (!handlerBlock.contains(AType.SPLITTER_BLOCK)) {
                handlerBlock.addAttr(spl);
            }
            connect(splitterBlock, handlerBlock);
        }
        if (tryEnd) {
            connect(block, handlerBlock);
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) SplitterBlockAttr(jadx.core.dex.trycatch.SplitterBlockAttr) CatchAttr(jadx.core.dex.trycatch.CatchAttr)

Example 25 with BlockNode

use of jadx.core.dex.nodes.BlockNode in project jadx by skylot.

the class RegionMaker method processHandlersOutBlocks.

/**
	 * Search handlers successor blocks not included in any region.
	 */
protected IRegion processHandlersOutBlocks(MethodNode mth, Set<TryCatchBlock> tcs) {
    Set<IBlock> allRegionBlocks = new HashSet<IBlock>();
    RegionUtils.getAllRegionBlocks(mth.getRegion(), allRegionBlocks);
    Set<IBlock> succBlocks = new HashSet<IBlock>();
    for (TryCatchBlock tc : tcs) {
        for (ExceptionHandler handler : tc.getHandlers()) {
            IContainer region = handler.getHandlerRegion();
            if (region != null) {
                IBlock lastBlock = RegionUtils.getLastBlock(region);
                if (lastBlock instanceof BlockNode) {
                    succBlocks.addAll(((BlockNode) lastBlock).getSuccessors());
                }
                RegionUtils.getAllRegionBlocks(region, allRegionBlocks);
            }
        }
    }
    succBlocks.removeAll(allRegionBlocks);
    if (succBlocks.isEmpty()) {
        return null;
    }
    Region excOutRegion = new Region(mth.getRegion());
    for (IBlock block : succBlocks) {
        if (block instanceof BlockNode) {
            excOutRegion.add(makeRegion((BlockNode) block, new RegionStack(mth)));
        }
    }
    return excOutRegion;
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) BlockNode(jadx.core.dex.nodes.BlockNode) IBlock(jadx.core.dex.nodes.IBlock) Region(jadx.core.dex.regions.Region) IRegion(jadx.core.dex.nodes.IRegion) SwitchRegion(jadx.core.dex.regions.SwitchRegion) SynchronizedRegion(jadx.core.dex.regions.SynchronizedRegion) LoopRegion(jadx.core.dex.regions.loops.LoopRegion) IfRegion(jadx.core.dex.regions.conditions.IfRegion) TryCatchBlock(jadx.core.dex.trycatch.TryCatchBlock) IContainer(jadx.core.dex.nodes.IContainer) HashSet(java.util.HashSet)

Aggregations

BlockNode (jadx.core.dex.nodes.BlockNode)220 InsnNode (jadx.core.dex.nodes.InsnNode)91 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)43 ArrayList (java.util.ArrayList)41 BitSet (java.util.BitSet)31 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)29 InsnArg (jadx.core.dex.instructions.args.InsnArg)25 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)21 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)19 PhiInsn (jadx.core.dex.instructions.PhiInsn)14 SSAVar (jadx.core.dex.instructions.args.SSAVar)14 Nullable (org.jetbrains.annotations.Nullable)14 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)13 IRegion (jadx.core.dex.nodes.IRegion)13 HashSet (java.util.HashSet)13 MethodNode (jadx.core.dex.nodes.MethodNode)12 Region (jadx.core.dex.regions.Region)12 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)12 InsnType (jadx.core.dex.instructions.InsnType)11 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)11