Search in sources :

Example 1 with FieldArg

use of jadx.core.dex.instructions.args.FieldArg in project jadx by skylot.

the class InsnGen method addArg.

public void addArg(CodeWriter code, InsnArg arg, boolean wrap) throws CodegenException {
    if (arg.isRegister()) {
        code.add(mgen.getNameGen().useArg((RegisterArg) arg));
    } else if (arg.isLiteral()) {
        code.add(lit((LiteralArg) arg));
    } else if (arg.isInsnWrap()) {
        Flags flag = wrap ? Flags.BODY_ONLY : Flags.BODY_ONLY_NOWRAP;
        makeInsn(((InsnWrapArg) arg).getWrapInsn(), code, flag);
    } else if (arg.isNamed()) {
        code.add(((Named) arg).getName());
    } else if (arg.isField()) {
        FieldArg f = (FieldArg) arg;
        if (f.isStatic()) {
            staticField(code, f.getField());
        } else {
            instanceField(code, f.getField(), f.getInstanceArg());
        }
    } else {
        throw new CodegenException("Unknown arg type " + arg);
    }
}
Also used : Named(jadx.core.dex.instructions.args.Named) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) CodegenException(jadx.core.utils.exceptions.CodegenException) FieldArg(jadx.core.dex.instructions.args.FieldArg)

Example 2 with FieldArg

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

FieldArg (jadx.core.dex.instructions.args.FieldArg)2 FieldInfo (jadx.core.dex.info.FieldInfo)1 ArithNode (jadx.core.dex.instructions.ArithNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 InsnType (jadx.core.dex.instructions.InsnType)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)1 Named (jadx.core.dex.instructions.args.Named)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 CodegenException (jadx.core.utils.exceptions.CodegenException)1