Search in sources :

Example 1 with IgnoreEdgeAttr

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

the class BlockNode method cleanSuccessors.

/**
	 * Return all successor which are not exception handler or followed by loop back edge
	 */
private static List<BlockNode> cleanSuccessors(BlockNode block) {
    List<BlockNode> sucList = block.getSuccessors();
    if (sucList.isEmpty()) {
        return sucList;
    }
    List<BlockNode> toRemove = new LinkedList<BlockNode>();
    for (BlockNode b : sucList) {
        if (BlockUtils.isBlockMustBeCleared(b)) {
            toRemove.add(b);
        }
    }
    if (block.contains(AFlag.LOOP_END)) {
        List<LoopInfo> loops = block.getAll(AType.LOOP);
        for (LoopInfo loop : loops) {
            toRemove.add(loop.getStart());
        }
    }
    IgnoreEdgeAttr ignoreEdgeAttr = block.get(AType.IGNORE_EDGE);
    if (ignoreEdgeAttr != null) {
        toRemove.addAll(ignoreEdgeAttr.getBlocks());
    }
    if (toRemove.isEmpty()) {
        return sucList;
    }
    List<BlockNode> result = new ArrayList<BlockNode>(sucList);
    result.removeAll(toRemove);
    return result;
}
Also used : LoopInfo(jadx.core.dex.attributes.nodes.LoopInfo) ArrayList(java.util.ArrayList) IgnoreEdgeAttr(jadx.core.dex.attributes.nodes.IgnoreEdgeAttr) LinkedList(java.util.LinkedList)

Example 2 with IgnoreEdgeAttr

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

the class BlockUtils method filterPredecessors.

/**
	 * Return predecessors list without blocks contains 'IGNORE_EDGE' attribute.
	 *
	 * @return new list of filtered predecessors
	 */
public static List<BlockNode> filterPredecessors(BlockNode block) {
    List<BlockNode> predecessors = block.getPredecessors();
    List<BlockNode> list = new ArrayList<BlockNode>(predecessors.size());
    for (BlockNode pred : predecessors) {
        IgnoreEdgeAttr edgeAttr = pred.get(AType.IGNORE_EDGE);
        if (edgeAttr == null) {
            list.add(pred);
        } else if (!edgeAttr.contains(block)) {
            list.add(pred);
        }
    }
    return list;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ArrayList(java.util.ArrayList) IgnoreEdgeAttr(jadx.core.dex.attributes.nodes.IgnoreEdgeAttr)

Example 3 with IgnoreEdgeAttr

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

the class BlockFinallyExtract method mergeReturnBlocks.

/**
	 * Merge return block with same predecessor.
	 */
private static void mergeReturnBlocks(MethodNode mth) {
    List<BlockNode> exitBlocks = mth.getExitBlocks();
    BlockNode pred = getFinallyOutBlock(exitBlocks);
    if (pred == null) {
        return;
    }
    IgnoreEdgeAttr edgeAttr = pred.get(AType.IGNORE_EDGE);
    if (edgeAttr == null) {
        return;
    }
    List<BlockNode> merge = new LinkedList<BlockNode>();
    for (BlockNode blockNode : pred.getSuccessors()) {
        if (blockNode.contains(AFlag.RETURN)) {
            merge.add(blockNode);
        }
    }
    if (merge.size() < 2) {
        return;
    }
    // select 'original' return block
    BlockNode origReturnBlock = null;
    for (BlockNode ret : merge) {
        if (ret.contains(AFlag.ORIG_RETURN)) {
            origReturnBlock = ret;
            break;
        }
    }
    if (origReturnBlock == null) {
        return;
    }
    for (BlockNode mb : merge) {
        if (mb == origReturnBlock) {
            continue;
        }
        for (BlockNode remPred : mb.getPredecessors()) {
            connect(remPred, origReturnBlock);
        }
        markForRemove(mth, mb);
        edgeAttr.getBlocks().remove(mb);
    }
    mergeSyntheticPredecessors(mth, origReturnBlock);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IgnoreEdgeAttr(jadx.core.dex.attributes.nodes.IgnoreEdgeAttr) LinkedList(java.util.LinkedList)

Example 4 with IgnoreEdgeAttr

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

the class BlockFinallyExtract method addIgnoredEdge.

private static void addIgnoredEdge(BlockNode from, BlockNode toBlock) {
    IgnoreEdgeAttr edgeAttr = from.get(AType.IGNORE_EDGE);
    if (edgeAttr == null) {
        edgeAttr = new IgnoreEdgeAttr();
        from.addAttr(edgeAttr);
    }
    edgeAttr.getBlocks().add(toBlock);
}
Also used : IgnoreEdgeAttr(jadx.core.dex.attributes.nodes.IgnoreEdgeAttr)

Aggregations

IgnoreEdgeAttr (jadx.core.dex.attributes.nodes.IgnoreEdgeAttr)4 BlockNode (jadx.core.dex.nodes.BlockNode)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)1