Search in sources :

Example 6 with IRegion

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

the class DebugUtils method printRegion.

private static void printRegion(MethodNode mth, IRegion region, String indent, boolean printInsns) {
    LOG.debug("{}{}", indent, region);
    indent += "|  ";
    for (IContainer container : region.getSubBlocks()) {
        if (container instanceof IRegion) {
            printRegion(mth, (IRegion) container, indent, printInsns);
        } else {
            LOG.debug("{}{} {}", indent, container, container.getAttributesString());
            if (printInsns && container instanceof IBlock) {
                IBlock block = (IBlock) container;
                printInsns(mth, indent, block);
            }
        }
    }
}
Also used : IBlock(jadx.core.dex.nodes.IBlock) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 7 with IRegion

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

the class RegionUtils method isBlocksInSameRegion.

/**
 * Check if two blocks in same region on same level
 * TODO: Add 'region' annotation to all blocks to speed up checks
 */
public static boolean isBlocksInSameRegion(MethodNode mth, BlockNode firstBlock, BlockNode secondBlock) {
    Region region = mth.getRegion();
    if (region == null) {
        return false;
    }
    IContainer firstContainer = getBlockContainer(region, firstBlock);
    if (firstContainer instanceof IRegion) {
        if (firstContainer instanceof IBranchRegion) {
            return false;
        }
        List<IContainer> subBlocks = ((IRegion) firstContainer).getSubBlocks();
        return subBlocks.contains(secondBlock);
    }
    return false;
}
Also used : IRegion(jadx.core.dex.nodes.IRegion) Region(jadx.core.dex.regions.Region) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 8 with IRegion

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

the class RegionUtils method hasExitEdge.

public static boolean hasExitEdge(IContainer container) {
    if (container instanceof IBlock) {
        return BlockUtils.containsExitInsn((IBlock) container);
    }
    if (container instanceof IBranchRegion) {
        // all branches must have exit edge
        for (IContainer br : ((IBranchRegion) container).getBranches()) {
            if (br == null || !hasExitEdge(br)) {
                return false;
            }
        }
        return true;
    }
    if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        return !blocks.isEmpty() && hasExitEdge(blocks.get(blocks.size() - 1));
    }
    throw new JadxRuntimeException(unknownContainerType(container));
}
Also used : 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 9 with IRegion

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

the class DebugUtils method printRegion.

private static void printRegion(MethodNode mth, IRegion region, ICodeWriter cw, String indent, boolean printInsns) {
    printWithAttributes(cw, indent, region.toString(), region);
    indent += "|  ";
    printRegionSpecificInfo(cw, indent, mth, region, printInsns);
    for (IContainer container : region.getSubBlocks()) {
        if (container instanceof IRegion) {
            printRegion(mth, (IRegion) container, cw, indent, printInsns);
        } else {
            printWithAttributes(cw, indent, container.toString(), container);
            if (printInsns && container instanceof IBlock) {
                IBlock block = (IBlock) container;
                printInsns(mth, cw, indent, block);
            }
        }
    }
}
Also used : IBlock(jadx.core.dex.nodes.IBlock) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 10 with IRegion

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

the class DebugUtils method printRegionsWithBlock.

public static void printRegionsWithBlock(MethodNode mth, BlockNode block) {
    Set<IRegion> regions = new LinkedHashSet<>();
    DepthRegionTraversal.traverse(mth, new TracedRegionVisitor() {

        @Override
        public void processBlockTraced(MethodNode mth, IBlock container, IRegion currentRegion) {
            if (block.equals(container)) {
                regions.add(currentRegion);
            }
        }
    });
    LOG.debug(" Found block: {} in regions: {}", block, regions);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IBlock(jadx.core.dex.nodes.IBlock) MethodNode(jadx.core.dex.nodes.MethodNode) TracedRegionVisitor(jadx.core.dex.visitors.regions.TracedRegionVisitor) IRegion(jadx.core.dex.nodes.IRegion)

Aggregations

IRegion (jadx.core.dex.nodes.IRegion)26 IContainer (jadx.core.dex.nodes.IContainer)14 Region (jadx.core.dex.regions.Region)12 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)11 BlockNode (jadx.core.dex.nodes.BlockNode)10 IBlock (jadx.core.dex.nodes.IBlock)10 IfRegion (jadx.core.dex.regions.conditions.IfRegion)8 IBranchRegion (jadx.core.dex.nodes.IBranchRegion)7 SwitchRegion (jadx.core.dex.regions.SwitchRegion)7 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)7 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 HashSet (java.util.HashSet)4 InsnNode (jadx.core.dex.nodes.InsnNode)3 MethodNode (jadx.core.dex.nodes.MethodNode)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)2 Edge (jadx.core.dex.nodes.Edge)2 AbstractRegion (jadx.core.dex.regions.AbstractRegion)2 TryCatchRegion (jadx.core.dex.regions.TryCatchRegion)2