Search in sources :

Example 21 with InsnWrapArg

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

the class SimplifyVisitor method flattenInsnChain.

private static List<InsnNode> flattenInsnChain(InsnNode insn) {
    List<InsnNode> chain = new ArrayList<InsnNode>();
    InsnArg i = insn.getArg(0);
    while (i.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) i).getWrapInsn();
        chain.add(wrapInsn);
        if (wrapInsn.getArgsCount() == 0) {
            break;
        }
        i = wrapInsn.getArg(0);
    }
    Collections.reverse(chain);
    return chain;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) ArrayList(java.util.ArrayList) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 22 with InsnWrapArg

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

InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)22 InsnNode (jadx.core.dex.nodes.InsnNode)19 InsnArg (jadx.core.dex.instructions.args.InsnArg)15 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)11 ArithNode (jadx.core.dex.instructions.ArithNode)4 InvokeNode (jadx.core.dex.instructions.InvokeNode)4 FieldInfo (jadx.core.dex.info.FieldInfo)3 InsnType (jadx.core.dex.instructions.InsnType)3 FieldNode (jadx.core.dex.nodes.FieldNode)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)2 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 EnumMapAttr (jadx.core.dex.attributes.nodes.EnumMapAttr)1 MethodInfo (jadx.core.dex.info.MethodInfo)1 ArithOp (jadx.core.dex.instructions.ArithOp)1 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)1 IfNode (jadx.core.dex.instructions.IfNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 FieldArg (jadx.core.dex.instructions.args.FieldArg)1