Search in sources :

Example 1 with InsnType

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

the class ModVisitor method removeAssignChain.

/**
	 * Remove instructions on 'move' chain until instruction with type 'insnType'
	 */
private static InsnNode removeAssignChain(InsnNode insn, InstructionRemover remover, InsnType insnType) {
    if (insn == null) {
        return null;
    }
    remover.add(insn);
    InsnType type = insn.getType();
    if (type == insnType) {
        return insn;
    }
    if (type == InsnType.MOVE) {
        RegisterArg arg = (RegisterArg) insn.getArg(0);
        return removeAssignChain(arg.getAssignInsn(), remover, insnType);
    }
    return null;
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnType(jadx.core.dex.instructions.InsnType)

Example 2 with InsnType

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

the class ConditionGen method isArgWrapNeeded.

private static boolean isArgWrapNeeded(InsnArg arg) {
    if (!arg.isInsnWrap()) {
        return false;
    }
    InsnNode insn = ((InsnWrapArg) arg).getWrapInsn();
    InsnType insnType = insn.getType();
    if (insnType == InsnType.ARITH) {
        switch(((ArithNode) insn).getOp()) {
            case ADD:
            case SUB:
            case MUL:
            case DIV:
            case REM:
                return false;
        }
    } else {
        switch(insnType) {
            case INVOKE:
            case SGET:
            case IGET:
            case AGET:
            case CONST:
            case ARRAY_LENGTH:
                return false;
            default:
                return true;
        }
    }
    return true;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) ArithNode(jadx.core.dex.instructions.ArithNode) InsnType(jadx.core.dex.instructions.InsnType)

Example 3 with InsnType

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

the class IfCondition method simplifyCmpOp.

private static void simplifyCmpOp(Compare c) {
    if (!c.getA().isInsnWrap()) {
        return;
    }
    if (!c.getB().isLiteral() || ((LiteralArg) c.getB()).getLiteral() != 0) {
        return;
    }
    InsnNode wrapInsn = ((InsnWrapArg) c.getA()).getWrapInsn();
    InsnType type = wrapInsn.getType();
    if (type != InsnType.CMP_L && type != InsnType.CMP_G) {
        return;
    }
    IfNode insn = c.getInsn();
    insn.changeCondition(insn.getOp(), wrapInsn.getArg(0), wrapInsn.getArg(1));
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) LiteralArg(jadx.core.dex.instructions.args.LiteralArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IfNode(jadx.core.dex.instructions.IfNode) InsnType(jadx.core.dex.instructions.InsnType)

Example 4 with InsnType

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

the class RegionUtils method hasExitEdge.

public static boolean hasExitEdge(IContainer container) {
    if (container instanceof IBlock) {
        InsnNode lastInsn = BlockUtils.getLastInsn((IBlock) container);
        if (lastInsn == null) {
            return false;
        }
        InsnType type = lastInsn.getType();
        return type == InsnType.RETURN || type == InsnType.CONTINUE || type == InsnType.BREAK || type == InsnType.THROW;
    } else if (container instanceof IBranchRegion) {
        for (IContainer br : ((IBranchRegion) container).getBranches()) {
            if (br == null || !hasExitEdge(br)) {
                return false;
            }
        }
        return true;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        return !blocks.isEmpty() && hasExitEdge(blocks.get(blocks.size() - 1));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) InsnType(jadx.core.dex.instructions.InsnType) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 5 with InsnType

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

the class SimplifyVisitor method convertFieldArith.

/**
	 * Convert field arith operation to arith instruction
	 * (IPUT = ARITH (IGET, lit) -> ARITH (fieldArg <op>= lit))
	 */
private static InsnNode convertFieldArith(MethodNode mth, InsnNode insn) {
    InsnArg arg = insn.getArg(0);
    if (!arg.isInsnWrap()) {
        return null;
    }
    InsnNode wrap = ((InsnWrapArg) arg).getWrapInsn();
    InsnType wrapType = wrap.getType();
    if (wrapType != InsnType.ARITH && wrapType != InsnType.STR_CONCAT || !wrap.getArg(0).isInsnWrap()) {
        return null;
    }
    InsnNode get = ((InsnWrapArg) wrap.getArg(0)).getWrapInsn();
    InsnType getType = get.getType();
    if (getType != InsnType.IGET && getType != InsnType.SGET) {
        return null;
    }
    FieldInfo field = (FieldInfo) ((IndexInsnNode) insn).getIndex();
    FieldInfo innerField = (FieldInfo) ((IndexInsnNode) get).getIndex();
    if (!field.equals(innerField)) {
        return null;
    }
    try {
        InsnArg reg = null;
        if (getType == InsnType.IGET) {
            reg = get.getArg(0);
            InsnArg putReg = insn.getArg(1);
            if (!reg.equals(putReg)) {
                return null;
            }
        }
        FieldArg fArg = new FieldArg(field, reg);
        if (reg != null) {
            fArg.setType(get.getArg(0).getType());
        }
        if (wrapType == InsnType.ARITH) {
            ArithNode ar = (ArithNode) wrap;
            return new ArithNode(ar.getOp(), fArg, ar.getArg(1));
        } else {
            int argsCount = wrap.getArgsCount();
            InsnNode concat = new InsnNode(InsnType.STR_CONCAT, argsCount - 1);
            for (int i = 1; i < argsCount; i++) {
                concat.addArg(wrap.getArg(i));
            }
            return new ArithNode(ArithOp.ADD, fArg, InsnArg.wrapArg(concat));
        }
    } catch (Exception e) {
        LOG.debug("Can't convert field arith insn: {}, mth: {}", insn, mth, e);
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) FieldArg(jadx.core.dex.instructions.args.FieldArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) ArithNode(jadx.core.dex.instructions.ArithNode) InsnType(jadx.core.dex.instructions.InsnType) FieldInfo(jadx.core.dex.info.FieldInfo)

Aggregations

InsnType (jadx.core.dex.instructions.InsnType)6 InsnNode (jadx.core.dex.nodes.InsnNode)5 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)3 ArithNode (jadx.core.dex.instructions.ArithNode)2 FieldInfo (jadx.core.dex.info.FieldInfo)1 IfNode (jadx.core.dex.instructions.IfNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 FieldArg (jadx.core.dex.instructions.args.FieldArg)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 BlockNode (jadx.core.dex.nodes.BlockNode)1 IBlock (jadx.core.dex.nodes.IBlock)1 IBranchRegion (jadx.core.dex.nodes.IBranchRegion)1 IContainer (jadx.core.dex.nodes.IContainer)1 IRegion (jadx.core.dex.nodes.IRegion)1 SplitterBlockAttr (jadx.core.dex.trycatch.SplitterBlockAttr)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 HashMap (java.util.HashMap)1