Search in sources :

Example 11 with InsnArg

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

the class ConstInlineVisitor method checkInsn.

private static boolean checkInsn(MethodNode mth, InsnNode insn) {
    if (insn.getType() != InsnType.CONST || insn.contains(AFlag.DONT_INLINE)) {
        return false;
    }
    InsnArg arg = insn.getArg(0);
    if (!arg.isLiteral()) {
        return false;
    }
    long lit = ((LiteralArg) arg).getLiteral();
    SSAVar sVar = insn.getResult().getSVar();
    if (lit == 0 && checkObjectInline(sVar)) {
        if (sVar.getUseCount() == 1) {
            InsnNode assignInsn = insn.getResult().getAssignInsn();
            if (assignInsn != null) {
                assignInsn.add(AFlag.DONT_INLINE);
            }
        }
        return false;
    }
    ArgType resType = insn.getResult().getType();
    // make sure arg has correct type
    if (!arg.getType().isTypeKnown()) {
        arg.merge(mth.dex(), resType);
    }
    return replaceConst(mth, insn, lit);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg) LiteralArg(jadx.core.dex.instructions.args.LiteralArg)

Example 12 with InsnArg

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

the class ConstInlineVisitor method fixTypes.

/**
	 * This is method similar to PostTypeInference.process method,
	 * but contains some expensive operations needed only after constant inline
	 */
private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) {
    DexNode dex = mth.dex();
    PostTypeInference.process(mth, insn);
    switch(insn.getType()) {
        case CONST:
            insn.getArg(0).merge(dex, insn.getResult());
            break;
        case MOVE:
            insn.getResult().merge(dex, insn.getArg(0));
            insn.getArg(0).merge(dex, insn.getResult());
            break;
        case IPUT:
        case SPUT:
            IndexInsnNode node = (IndexInsnNode) insn;
            insn.getArg(0).merge(dex, ((FieldInfo) node.getIndex()).getType());
            break;
        case IF:
            {
                InsnArg arg0 = insn.getArg(0);
                InsnArg arg1 = insn.getArg(1);
                if (arg0 == litArg) {
                    arg0.merge(dex, arg1);
                } else {
                    arg1.merge(dex, arg0);
                }
                break;
            }
        case CMP_G:
        case CMP_L:
            InsnArg arg0 = insn.getArg(0);
            InsnArg arg1 = insn.getArg(1);
            if (arg0 == litArg) {
                arg0.merge(dex, arg1);
            } else {
                arg1.merge(dex, arg0);
            }
            break;
        case RETURN:
            if (insn.getArgsCount() != 0) {
                insn.getArg(0).merge(dex, mth.getReturnType());
            }
            break;
        case INVOKE:
            InvokeNode inv = (InvokeNode) insn;
            List<ArgType> types = inv.getCallMth().getArgumentsTypes();
            int count = insn.getArgsCount();
            int k = types.size() == count ? 0 : -1;
            for (int i = 0; i < count; i++) {
                InsnArg arg = insn.getArg(i);
                if (!arg.getType().isTypeKnown()) {
                    ArgType type;
                    if (k >= 0) {
                        type = types.get(k);
                    } else {
                        type = mth.getParentClass().getClassInfo().getType();
                    }
                    arg.merge(dex, type);
                }
                k++;
            }
            break;
        case ARITH:
            litArg.merge(dex, insn.getResult());
            break;
        case APUT:
        case AGET:
            if (litArg == insn.getArg(1)) {
                litArg.merge(dex, ArgType.INT);
            }
            break;
        case NEW_ARRAY:
            if (litArg == insn.getArg(0)) {
                litArg.merge(dex, ArgType.INT);
            }
            break;
        default:
            break;
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) InsnArg(jadx.core.dex.instructions.args.InsnArg) DexNode(jadx.core.dex.nodes.DexNode) InvokeNode(jadx.core.dex.instructions.InvokeNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode)

Example 13 with InsnArg

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

the class DependencyCollector method processInsn.

// TODO: add custom instructions processing
private static void processInsn(DexNode dex, Set<ClassNode> depList, InsnNode insnNode) {
    RegisterArg result = insnNode.getResult();
    if (result != null) {
        addDep(dex, depList, result.getType());
    }
    for (InsnArg arg : insnNode.getArguments()) {
        if (arg.isInsnWrap()) {
            processInsn(dex, depList, ((InsnWrapArg) arg).getWrapInsn());
        } else {
            addDep(dex, depList, arg.getType());
        }
    }
    processCustomInsn(dex, depList, insnNode);
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 14 with InsnArg

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

the class InsnNode method isSame.

/**
	 * 'Soft' equals, don't compare arguments, only instruction specific parameters.
	 */
public boolean isSame(InsnNode other) {
    if (this == other) {
        return true;
    }
    if (insnType != other.insnType || arguments.size() != other.arguments.size()) {
        return false;
    }
    // check wrapped instructions
    int size = arguments.size();
    for (int i = 0; i < size; i++) {
        InsnArg arg = arguments.get(i);
        InsnArg otherArg = other.arguments.get(i);
        if (arg.isInsnWrap()) {
            if (!otherArg.isInsnWrap()) {
                return false;
            }
            InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
            InsnNode otherWrapInsn = ((InsnWrapArg) otherArg).getWrapInsn();
            if (!wrapInsn.isSame(otherWrapInsn)) {
                return false;
            }
        }
    }
    return true;
}
Also used : InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 15 with InsnArg

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

the class DebugInfoParser method addrChange.

private int addrChange(int addr, int addrInc, int line) {
    int newAddr = addr + addrInc;
    int maxAddr = insnByOffset.length - 1;
    newAddr = Math.min(newAddr, maxAddr);
    for (int i = addr + 1; i <= newAddr; i++) {
        InsnNode insn = insnByOffset[i];
        if (insn == null) {
            continue;
        }
        for (InsnArg arg : insn.getArguments()) {
            if (arg.isRegister()) {
                activeRegisters[((RegisterArg) arg).getRegNum()] = arg;
            }
        }
        RegisterArg res = insn.getResult();
        if (res != null) {
            activeRegisters[res.getRegNum()] = res;
        }
    }
    setSourceLines(addr, newAddr, line);
    return newAddr;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) 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