Search in sources :

Example 6 with IBlock

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

the class RegionUtils method getLastInsn.

public static InsnNode getLastInsn(IContainer container) {
    if (container instanceof IBlock) {
        IBlock block = (IBlock) container;
        List<InsnNode> insnList = block.getInstructions();
        if (insnList.isEmpty()) {
            return null;
        }
        return insnList.get(insnList.size() - 1);
    } else if (container instanceof IBranchRegion) {
        return null;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        if (blocks.isEmpty()) {
            return null;
        }
        return getLastInsn(blocks.get(blocks.size() - 1));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 7 with IBlock

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

the class RegionMakerVisitor method processSwitch.

private static void processSwitch(MethodNode mth, SwitchRegion sw) {
    for (IContainer c : sw.getBranches()) {
        if (!(c instanceof Region)) {
            continue;
        }
        Set<IBlock> blocks = new HashSet<IBlock>();
        RegionUtils.getAllRegionBlocks(c, blocks);
        if (blocks.isEmpty()) {
            addBreakToContainer((Region) c);
            continue;
        }
        for (IBlock block : blocks) {
            if (!(block instanceof BlockNode)) {
                continue;
            }
            BlockNode bn = (BlockNode) block;
            for (BlockNode s : bn.getCleanSuccessors()) {
                if (!blocks.contains(s) && !bn.contains(AFlag.SKIP) && !s.contains(AFlag.FALL_THROUGH)) {
                    addBreak(mth, c, bn);
                    break;
                }
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IBlock(jadx.core.dex.nodes.IBlock) 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) Region(jadx.core.dex.regions.Region) IContainer(jadx.core.dex.nodes.IContainer) HashSet(java.util.HashSet)

Aggregations

IBlock (jadx.core.dex.nodes.IBlock)7 IRegion (jadx.core.dex.nodes.IRegion)7 IContainer (jadx.core.dex.nodes.IContainer)5 BlockNode (jadx.core.dex.nodes.BlockNode)3 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)3 HashSet (java.util.HashSet)3 IBranchRegion (jadx.core.dex.nodes.IBranchRegion)2 InsnNode (jadx.core.dex.nodes.InsnNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 Region (jadx.core.dex.regions.Region)2 SwitchRegion (jadx.core.dex.regions.SwitchRegion)2 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 InsnType (jadx.core.dex.instructions.InsnType)1 IfRegion (jadx.core.dex.regions.conditions.IfRegion)1 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)1 TryCatchBlock (jadx.core.dex.trycatch.TryCatchBlock)1 TracedRegionVisitor (jadx.core.dex.visitors.regions.TracedRegionVisitor)1 LinkedHashSet (java.util.LinkedHashSet)1