Search in sources :

Example 6 with IfInfo

use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.

the class IfMakerHelper method mergeTernaryConditions.

private static IfInfo mergeTernaryConditions(IfInfo currentIf, IfInfo nextThen, IfInfo nextElse) {
    IfCondition newCondition = IfCondition.ternary(currentIf.getCondition(), nextThen.getCondition(), nextElse.getCondition());
    IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock());
    result.setIfBlock(currentIf.getIfBlock());
    result.merge(currentIf, nextThen, nextElse);
    confirmMerge(result);
    return result;
}
Also used : IfInfo(jadx.core.dex.regions.conditions.IfInfo) IfCondition(jadx.core.dex.regions.conditions.IfCondition)

Example 7 with IfInfo

use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.

the class IfMakerHelper method mergeIfInfo.

private static IfInfo mergeIfInfo(IfInfo first, IfInfo second, boolean followThenBranch) {
    Mode mergeOperation = followThenBranch ? Mode.AND : Mode.OR;
    IfCondition condition = IfCondition.merge(mergeOperation, first.getCondition(), second.getCondition());
    // skip synthetic successor if both parts leads to same block
    BlockNode thenBlock;
    BlockNode elseBlock;
    if (followThenBranch) {
        thenBlock = second.getThenBlock();
        elseBlock = getCrossBlock(first.getElseBlock(), second.getElseBlock());
    } else {
        thenBlock = getCrossBlock(first.getThenBlock(), second.getThenBlock());
        elseBlock = second.getElseBlock();
    }
    IfInfo result = new IfInfo(condition, thenBlock, elseBlock);
    result.setIfBlock(first.getIfBlock());
    result.merge(first, second);
    BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock();
    skipSimplePath(otherPathBlock, result.getSkipBlocks());
    return result;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) Mode(jadx.core.dex.regions.conditions.IfCondition.Mode) IfInfo(jadx.core.dex.regions.conditions.IfInfo) IfCondition(jadx.core.dex.regions.conditions.IfCondition)

Example 8 with IfInfo

use of jadx.core.dex.regions.conditions.IfInfo in project jadx by skylot.

the class IfMakerHelper method mergeNestedIfNodes.

static IfInfo mergeNestedIfNodes(IfInfo currentIf) {
    BlockNode curThen = currentIf.getThenBlock();
    BlockNode curElse = currentIf.getElseBlock();
    if (curThen == curElse) {
        return null;
    }
    boolean followThenBranch;
    IfInfo nextIf = getNextIf(currentIf, curThen);
    if (nextIf != null) {
        followThenBranch = true;
    } else {
        nextIf = getNextIf(currentIf, curElse);
        if (nextIf != null) {
            followThenBranch = false;
        } else {
            return null;
        }
    }
    if (isInversionNeeded(currentIf, nextIf)) {
        // invert current node for match pattern
        nextIf = IfInfo.invert(nextIf);
    }
    if (!isEqualPaths(curThen, nextIf.getThenBlock()) && !isEqualPaths(curElse, nextIf.getElseBlock())) {
        // complex condition, run additional checks
        if (checkConditionBranches(curThen, curElse) || checkConditionBranches(curElse, curThen)) {
            return null;
        }
        BlockNode otherBranchBlock = followThenBranch ? curElse : curThen;
        otherBranchBlock = BlockUtils.skipSyntheticSuccessor(otherBranchBlock);
        if (!isPathExists(nextIf.getIfBlock(), otherBranchBlock)) {
            return checkForTernaryInCondition(currentIf);
        }
        // this is nested conditions with different mode (i.e (a && b) || c),
        // search next condition for merge, get null if failed
        IfInfo tmpIf = mergeNestedIfNodes(nextIf);
        if (tmpIf != null) {
            nextIf = tmpIf;
            if (isInversionNeeded(currentIf, nextIf)) {
                nextIf = IfInfo.invert(nextIf);
            }
            if (!canMerge(currentIf, nextIf, followThenBranch)) {
                return currentIf;
            }
        } else {
            return currentIf;
        }
    }
    IfInfo result = mergeIfInfo(currentIf, nextIf, followThenBranch);
    // search next nested if block
    return searchNestedIf(result);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IfInfo(jadx.core.dex.regions.conditions.IfInfo)

Aggregations

IfInfo (jadx.core.dex.regions.conditions.IfInfo)8 BlockNode (jadx.core.dex.nodes.BlockNode)5 IfCondition (jadx.core.dex.regions.conditions.IfCondition)3 IRegion (jadx.core.dex.nodes.IRegion)2 Region (jadx.core.dex.regions.Region)2 SwitchRegion (jadx.core.dex.regions.SwitchRegion)2 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)2 IfRegion (jadx.core.dex.regions.conditions.IfRegion)2 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)2 IfMakerHelper.makeIfInfo (jadx.core.dex.visitors.regions.IfMakerHelper.makeIfInfo)2 EdgeInsnAttr (jadx.core.dex.attributes.nodes.EdgeInsnAttr)1 IfNode (jadx.core.dex.instructions.IfNode)1 Edge (jadx.core.dex.nodes.Edge)1 Mode (jadx.core.dex.regions.conditions.IfCondition.Mode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1