Search in sources :

Example 11 with Region

use of jadx.core.dex.regions.Region 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)

Example 12 with Region

use of jadx.core.dex.regions.Region in project jadx by skylot.

the class IfRegionVisitor method markElseIfChains.

/**
	 * Mark if-else-if chains
	 */
private static void markElseIfChains(IfRegion ifRegion) {
    if (hasSimpleReturnBlock(ifRegion.getThenRegion())) {
        return;
    }
    IContainer elsRegion = ifRegion.getElseRegion();
    if (elsRegion instanceof Region) {
        List<IContainer> subBlocks = ((Region) elsRegion).getSubBlocks();
        if (subBlocks.size() == 1 && subBlocks.get(0) instanceof IfRegion) {
            subBlocks.get(0).add(AFlag.ELSE_IF_CHAIN);
            elsRegion.add(AFlag.ELSE_IF_CHAIN);
        }
    }
}
Also used : IRegion(jadx.core.dex.nodes.IRegion) IfRegion(jadx.core.dex.regions.conditions.IfRegion) Region(jadx.core.dex.regions.Region) IContainer(jadx.core.dex.nodes.IContainer) IfRegion(jadx.core.dex.regions.conditions.IfRegion)

Aggregations

IRegion (jadx.core.dex.nodes.IRegion)12 Region (jadx.core.dex.regions.Region)12 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)9 BlockNode (jadx.core.dex.nodes.BlockNode)8 SwitchRegion (jadx.core.dex.regions.SwitchRegion)8 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)8 IfRegion (jadx.core.dex.regions.conditions.IfRegion)8 IContainer (jadx.core.dex.nodes.IContainer)6 Edge (jadx.core.dex.nodes.Edge)2 IBlock (jadx.core.dex.nodes.IBlock)2 IfInfo (jadx.core.dex.regions.conditions.IfInfo)2 IfMakerHelper.makeIfInfo (jadx.core.dex.visitors.regions.IfMakerHelper.makeIfInfo)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EdgeInsnAttr (jadx.core.dex.attributes.nodes.EdgeInsnAttr)1 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)1 IBranchRegion (jadx.core.dex.nodes.IBranchRegion)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 AbstractRegion (jadx.core.dex.regions.AbstractRegion)1