Search in sources :

Example 6 with ArithNode

use of jadx.core.dex.instructions.ArithNode 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

ArithNode (jadx.core.dex.instructions.ArithNode)6 InsnNode (jadx.core.dex.nodes.InsnNode)6 InsnArg (jadx.core.dex.instructions.args.InsnArg)5 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)4 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 InsnType (jadx.core.dex.instructions.InsnType)2 FieldInfo (jadx.core.dex.info.FieldInfo)1 ArithOp (jadx.core.dex.instructions.ArithOp)1 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)1 FillArrayNode (jadx.core.dex.instructions.FillArrayNode)1 FilledNewArrayNode (jadx.core.dex.instructions.FilledNewArrayNode)1 NewArrayNode (jadx.core.dex.instructions.NewArrayNode)1 SwitchNode (jadx.core.dex.instructions.SwitchNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 FieldArg (jadx.core.dex.instructions.args.FieldArg)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 BlockNode (jadx.core.dex.nodes.BlockNode)1 ClassNode (jadx.core.dex.nodes.ClassNode)1