Search in sources :

Example 46 with InsnArg

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

the class SimplifyVisitor method processCast.

private static InsnNode processCast(MethodNode mth, InsnNode insn) {
    InsnArg castArg = insn.getArg(0);
    ArgType argType = castArg.getType();
    // Don't removes CHECK_CAST for wrapped INVOKE if invoked method returns different type
    if (castArg.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) castArg).getWrapInsn();
        if (wrapInsn.getType() == InsnType.INVOKE) {
            argType = ((InvokeNode) wrapInsn).getCallMth().getReturnType();
        }
    }
    ArgType castToType = (ArgType) ((IndexInsnNode) insn).getIndex();
    if (ArgType.isCastNeeded(mth.dex(), argType, castToType)) {
        return null;
    }
    InsnNode insnNode = new InsnNode(InsnType.MOVE, 1);
    insnNode.setOffset(insn.getOffset());
    insnNode.setResult(insn.getResult());
    insnNode.addArg(castArg);
    return insnNode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 47 with InsnArg

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

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

Example 49 with InsnArg

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

the class BlockFinallyExtract method sameInsns.

private static boolean sameInsns(InsnNode remInsn, InsnNode fInsn, BlocksRemoveInfo removeInfo) {
    if (!remInsn.isSame(fInsn)) {
        return false;
    }
    // TODO: compare literals
    for (int i = 0; i < remInsn.getArgsCount(); i++) {
        InsnArg remArg = remInsn.getArg(i);
        InsnArg fArg = fInsn.getArg(i);
        if (remArg.isRegister() != fArg.isRegister()) {
            return false;
        }
        if (removeInfo != null && fArg.isRegister()) {
            RegisterArg remReg = (RegisterArg) remArg;
            RegisterArg fReg = (RegisterArg) fArg;
            if (remReg.getRegNum() != fReg.getRegNum()) {
                RegisterArg mapReg = removeInfo.getRegMap().get(remArg);
                if (mapReg == null) {
                    removeInfo.getRegMap().put(remReg, fReg);
                } else if (!mapReg.equalRegisterAndType(fReg)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 50 with InsnArg

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

the class TypeInference method processPhiNode.

private static void processPhiNode(PhiInsn phi) {
    ArgType type = phi.getResult().getType();
    if (!type.isTypeKnown()) {
        for (InsnArg arg : phi.getArguments()) {
            if (arg.getType().isTypeKnown()) {
                type = arg.getType();
                break;
            }
        }
    }
    phi.getResult().setType(type);
    for (int i = 0; i < phi.getArgsCount(); i++) {
        RegisterArg arg = phi.getArg(i);
        arg.setType(type);
        SSAVar sVar = arg.getSVar();
        if (sVar != null) {
            sVar.setName(phi.getResult().getName());
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Aggregations

InsnArg (jadx.core.dex.instructions.args.InsnArg)52 InsnNode (jadx.core.dex.nodes.InsnNode)32 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)24 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)19 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)15 ArgType (jadx.core.dex.instructions.args.ArgType)9 SSAVar (jadx.core.dex.instructions.args.SSAVar)9 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)8 BlockNode (jadx.core.dex.nodes.BlockNode)8 FieldNode (jadx.core.dex.nodes.FieldNode)7 FieldInfo (jadx.core.dex.info.FieldInfo)6 ArithNode (jadx.core.dex.instructions.ArithNode)5 InvokeNode (jadx.core.dex.instructions.InvokeNode)5 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)4 PhiInsn (jadx.core.dex.instructions.PhiInsn)4 ClassNode (jadx.core.dex.nodes.ClassNode)4 PhiListAttr (jadx.core.dex.attributes.nodes.PhiListAttr)3 MethodInfo (jadx.core.dex.info.MethodInfo)3 SwitchNode (jadx.core.dex.instructions.SwitchNode)3 MethodNode (jadx.core.dex.nodes.MethodNode)3