Search in sources :

Example 1 with EdgeInsnAttr

use of jadx.core.dex.attributes.nodes.EdgeInsnAttr in project jadx by skylot.

the class RegionMaker method processIf.

private BlockNode processIf(IRegion currentRegion, BlockNode block, IfNode ifnode, RegionStack stack) {
    if (block.contains(AFlag.SKIP)) {
        // block already included in other 'if' region
        return ifnode.getThenBlock();
    }
    IfInfo currentIf = makeIfInfo(block);
    IfInfo mergedIf = mergeNestedIfNodes(currentIf);
    if (mergedIf != null) {
        currentIf = mergedIf;
    } else {
        // invert simple condition (compiler often do it)
        currentIf = IfInfo.invert(currentIf);
    }
    IfInfo modifiedIf = IfMakerHelper.restructureIf(mth, block, currentIf);
    if (modifiedIf != null) {
        currentIf = modifiedIf;
    } else {
        if (currentIf.getMergedBlocks().size() <= 1) {
            return null;
        }
        currentIf = makeIfInfo(block);
        currentIf = IfMakerHelper.restructureIf(mth, block, currentIf);
        if (currentIf == null) {
            // all attempts failed
            return null;
        }
    }
    confirmMerge(currentIf);
    IfRegion ifRegion = new IfRegion(currentRegion, block);
    ifRegion.setCondition(currentIf.getCondition());
    currentRegion.getSubBlocks().add(ifRegion);
    BlockNode outBlock = currentIf.getOutBlock();
    stack.push(ifRegion);
    stack.addExit(outBlock);
    ifRegion.setThenRegion(makeRegion(currentIf.getThenBlock(), stack));
    BlockNode elseBlock = currentIf.getElseBlock();
    if (elseBlock == null || stack.containsExit(elseBlock)) {
        ifRegion.setElseRegion(null);
    } else {
        ifRegion.setElseRegion(makeRegion(elseBlock, stack));
    }
    // TODO: make more common algorithm
    if (ifRegion.getElseRegion() == null && outBlock != null) {
        List<EdgeInsnAttr> edgeInsnAttrs = outBlock.getAll(AType.EDGE_INSN);
        if (!edgeInsnAttrs.isEmpty()) {
            Region elseRegion = new Region(ifRegion);
            for (EdgeInsnAttr edgeInsnAttr : edgeInsnAttrs) {
                if (edgeInsnAttr.getEnd().equals(outBlock)) {
                    addEdgeInsn(currentIf, elseRegion, edgeInsnAttr);
                }
            }
            ifRegion.setElseRegion(elseRegion);
        }
    }
    stack.pop();
    return outBlock;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) 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) IfMakerHelper.makeIfInfo(jadx.core.dex.visitors.regions.IfMakerHelper.makeIfInfo) IfInfo(jadx.core.dex.regions.conditions.IfInfo) IfRegion(jadx.core.dex.regions.conditions.IfRegion) EdgeInsnAttr(jadx.core.dex.attributes.nodes.EdgeInsnAttr)

Example 2 with EdgeInsnAttr

use of jadx.core.dex.attributes.nodes.EdgeInsnAttr in project jadx by skylot.

the class RegionMakerVisitor method insertEdgeInsn.

/**
	 * Insert insn block from edge insn attribute.
	 */
private static void insertEdgeInsn(Region region) {
    List<IContainer> subBlocks = region.getSubBlocks();
    if (subBlocks.isEmpty()) {
        return;
    }
    IContainer last = subBlocks.get(subBlocks.size() - 1);
    List<EdgeInsnAttr> edgeInsnAttrs = last.getAll(AType.EDGE_INSN);
    if (edgeInsnAttrs.isEmpty()) {
        return;
    }
    EdgeInsnAttr insnAttr = edgeInsnAttrs.get(0);
    if (!insnAttr.getStart().equals(last)) {
        return;
    }
    List<InsnNode> insns = Collections.singletonList(insnAttr.getInsn());
    region.add(new InsnContainer(insns));
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnContainer(jadx.core.dex.nodes.InsnContainer) IContainer(jadx.core.dex.nodes.IContainer) EdgeInsnAttr(jadx.core.dex.attributes.nodes.EdgeInsnAttr)

Aggregations

EdgeInsnAttr (jadx.core.dex.attributes.nodes.EdgeInsnAttr)2 BlockNode (jadx.core.dex.nodes.BlockNode)1 IContainer (jadx.core.dex.nodes.IContainer)1 IRegion (jadx.core.dex.nodes.IRegion)1 InsnContainer (jadx.core.dex.nodes.InsnContainer)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 Region (jadx.core.dex.regions.Region)1 SwitchRegion (jadx.core.dex.regions.SwitchRegion)1 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)1 IfInfo (jadx.core.dex.regions.conditions.IfInfo)1 IfRegion (jadx.core.dex.regions.conditions.IfRegion)1 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)1 IfMakerHelper.makeIfInfo (jadx.core.dex.visitors.regions.IfMakerHelper.makeIfInfo)1