Search in sources :

Example 1 with IfNode

use of jadx.core.dex.instructions.IfNode in project jadx by skylot.

the class IfMakerHelper method makeIfInfo.

static IfInfo makeIfInfo(BlockNode ifBlock) {
    IfNode ifNode = (IfNode) ifBlock.getInstructions().get(0);
    IfCondition condition = IfCondition.fromIfNode(ifNode);
    IfInfo info = new IfInfo(condition, ifNode.getThenBlock(), ifNode.getElseBlock());
    info.setIfBlock(ifBlock);
    info.getMergedBlocks().add(ifBlock);
    return info;
}
Also used : IfInfo(jadx.core.dex.regions.conditions.IfInfo) IfNode(jadx.core.dex.instructions.IfNode) IfCondition(jadx.core.dex.regions.conditions.IfCondition)

Example 2 with IfNode

use of jadx.core.dex.instructions.IfNode in project jadx by skylot.

the class BlockSplitter method isDoWhile.

private static boolean isDoWhile(Map<Integer, BlockNode> blocksMap, BlockNode curBlock, InsnNode insn) {
    // split 'do-while' block (last instruction: 'if', target this block)
    if (insn.getType() != InsnType.IF) {
        return false;
    }
    IfNode ifs = (IfNode) insn;
    BlockNode targetBlock = blocksMap.get(ifs.getTarget());
    return targetBlock == curBlock;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IfNode(jadx.core.dex.instructions.IfNode)

Example 3 with IfNode

use of jadx.core.dex.instructions.IfNode in project jadx by skylot.

the class ModVisitor method makeBooleanConvertInsn.

public static TernaryInsn makeBooleanConvertInsn(RegisterArg result, InsnArg castArg, ArgType type) {
    InsnArg zero = LiteralArg.make(0, type);
    long litVal = 1;
    if (type == ArgType.DOUBLE) {
        litVal = DOUBLE_TO_BITS;
    } else if (type == ArgType.FLOAT) {
        litVal = FLOAT_TO_BITS;
    }
    InsnArg one = LiteralArg.make(litVal, type);
    IfNode ifNode = new IfNode(IfOp.EQ, -1, castArg, LiteralArg.litTrue());
    IfCondition condition = IfCondition.fromIfNode(ifNode);
    return new TernaryInsn(condition, result, one, zero);
}
Also used : TernaryInsn(jadx.core.dex.instructions.mods.TernaryInsn) InsnArg(jadx.core.dex.instructions.args.InsnArg) IfNode(jadx.core.dex.instructions.IfNode) IfCondition(jadx.core.dex.regions.conditions.IfCondition)

Example 4 with IfNode

use of jadx.core.dex.instructions.IfNode in project jadx by skylot.

the class IfMakerHelper method makeIfInfo.

@Nullable
static IfInfo makeIfInfo(MethodNode mth, BlockNode ifBlock) {
    InsnNode lastInsn = BlockUtils.getLastInsn(ifBlock);
    if (lastInsn == null || lastInsn.getType() != InsnType.IF) {
        return null;
    }
    IfNode ifNode = (IfNode) lastInsn;
    IfCondition condition = IfCondition.fromIfNode(ifNode);
    IfInfo info = new IfInfo(mth, condition, ifNode.getThenBlock(), ifNode.getElseBlock());
    info.getMergedBlocks().add(ifBlock);
    return info;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IfInfo(jadx.core.dex.regions.conditions.IfInfo) IfNode(jadx.core.dex.instructions.IfNode) IfCondition(jadx.core.dex.regions.conditions.IfCondition) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with IfNode

use of jadx.core.dex.instructions.IfNode in project jadx by skylot.

the class IfCondition method simplifyCmpOp.

private static IfCondition simplifyCmpOp(Compare c) {
    if (!c.getA().isInsnWrap()) {
        return null;
    }
    if (!c.getB().isLiteral()) {
        return null;
    }
    long lit = ((LiteralArg) c.getB()).getLiteral();
    if (lit != 0 && lit != 1) {
        return null;
    }
    InsnNode wrapInsn = ((InsnWrapArg) c.getA()).getWrapInsn();
    switch(wrapInsn.getType()) {
        case CMP_L:
        case CMP_G:
            if (lit == 0) {
                IfNode insn = c.getInsn();
                insn.changeCondition(insn.getOp(), wrapInsn.getArg(0), wrapInsn.getArg(1));
            }
            break;
        case ARITH:
            if (c.getB().getType() == ArgType.BOOLEAN) {
                ArithOp arithOp = ((ArithNode) wrapInsn).getOp();
                if (arithOp == ArithOp.OR || arithOp == ArithOp.AND) {
                    IfOp ifOp = c.getInsn().getOp();
                    boolean isTrue = ifOp == IfOp.NE && lit == 0 || ifOp == IfOp.EQ && lit == 1;
                    IfOp op = isTrue ? IfOp.NE : IfOp.EQ;
                    Mode mode = isTrue && arithOp == ArithOp.OR || !isTrue && arithOp == ArithOp.AND ? Mode.OR : Mode.AND;
                    IfNode if1 = new IfNode(op, -1, wrapInsn.getArg(0), LiteralArg.litFalse());
                    IfNode if2 = new IfNode(op, -1, wrapInsn.getArg(1), LiteralArg.litFalse());
                    return new IfCondition(mode, Arrays.asList(new IfCondition(new Compare(if1)), new IfCondition(new Compare(if2))));
                }
            }
            break;
        default:
            break;
    }
    return null;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) ArithOp(jadx.core.dex.instructions.ArithOp) LiteralArg(jadx.core.dex.instructions.args.LiteralArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IfNode(jadx.core.dex.instructions.IfNode) ArithNode(jadx.core.dex.instructions.ArithNode) IfOp(jadx.core.dex.instructions.IfOp)

Aggregations

IfNode (jadx.core.dex.instructions.IfNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 BlockNode (jadx.core.dex.nodes.BlockNode)3 InsnNode (jadx.core.dex.nodes.InsnNode)3 IfCondition (jadx.core.dex.regions.conditions.IfCondition)3 LoopLabelAttr (jadx.core.dex.attributes.nodes.LoopLabelAttr)2 FieldInfo (jadx.core.dex.info.FieldInfo)2 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)2 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)2 GotoNode (jadx.core.dex.instructions.GotoNode)2 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)2 SwitchInsn (jadx.core.dex.instructions.SwitchInsn)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 IfInfo (jadx.core.dex.regions.conditions.IfInfo)2 CodegenException (jadx.core.utils.exceptions.CodegenException)2 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)1 ArithNode (jadx.core.dex.instructions.ArithNode)1 ArithOp (jadx.core.dex.instructions.ArithOp)1 FillArrayInsn (jadx.core.dex.instructions.FillArrayInsn)1