Search in sources :

Example 46 with InsnWrapArg

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

the class CodeShrinkVisitor method simplifyMoveInsns.

private static void simplifyMoveInsns(MethodNode mth, BlockNode block) {
    List<InsnNode> insns = block.getInstructions();
    int size = insns.size();
    for (int i = 0; i < size; i++) {
        InsnNode insn = insns.get(i);
        if (insn.getType() == InsnType.MOVE) {
            // replace 'move' with wrapped insn
            InsnArg arg = insn.getArg(0);
            if (arg.isInsnWrap()) {
                InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                InsnRemover.unbindResult(mth, wrapInsn);
                wrapInsn.setResult(insn.getResult().duplicate());
                wrapInsn.inheritMetadata(insn);
                wrapInsn.setOffset(insn.getOffset());
                wrapInsn.remove(AFlag.WRAPPED);
                block.getInstructions().set(i, wrapInsn);
            }
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 47 with InsnWrapArg

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

the class InsnUtils method getConstValueByArg.

/**
 * Search constant assigned to provided arg.
 *
 * @return LiteralArg, String, ArgType or null
 */
public static Object getConstValueByArg(RootNode root, InsnArg arg) {
    if (arg.isLiteral()) {
        return arg;
    }
    if (arg.isRegister()) {
        RegisterArg reg = (RegisterArg) arg;
        InsnNode parInsn = reg.getAssignInsn();
        if (parInsn == null) {
            return null;
        }
        if (parInsn.getType() == InsnType.MOVE) {
            return getConstValueByArg(root, parInsn.getArg(0));
        }
        return getConstValueByInsn(root, parInsn);
    }
    if (arg.isInsnWrap()) {
        InsnNode insn = ((InsnWrapArg) arg).getWrapInsn();
        return getConstValueByInsn(root, insn);
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 48 with InsnWrapArg

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

the class InsnUtils method recursiveInsnCheck.

private static InsnNode recursiveInsnCheck(InsnNode insn, InsnType insnType, Predicate<InsnNode> test) {
    if (insn.getType() == insnType && test.test(insn)) {
        return insn;
    }
    for (InsnArg arg : insn.getArguments()) {
        if (arg.isInsnWrap()) {
            InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
            InsnNode foundInsn = recursiveInsnCheck(wrapInsn, insnType, test);
            if (foundInsn != null) {
                return foundInsn;
            }
        }
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 49 with InsnWrapArg

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

the class InsnRemover method unbindArgUsage.

public static void unbindArgUsage(@Nullable MethodNode mth, InsnArg arg) {
    if (arg instanceof RegisterArg) {
        RegisterArg reg = (RegisterArg) arg;
        SSAVar sVar = reg.getSVar();
        if (sVar != null) {
            sVar.removeUse(reg);
        }
    } else if (arg instanceof InsnWrapArg) {
        InsnWrapArg wrap = (InsnWrapArg) arg;
        unbindInsn(mth, wrap.getWrapInsn());
    }
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 50 with InsnWrapArg

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

the class NameGen method makeNameFromInsn.

private String makeNameFromInsn(InsnNode insn) {
    switch(insn.getType()) {
        case INVOKE:
            InvokeNode inv = (InvokeNode) insn;
            return makeNameFromInvoke(inv.getCallMth());
        case CONSTRUCTOR:
            ConstructorInsn co = (ConstructorInsn) insn;
            return makeNameForObject(co.getClassType().getType());
        case ARRAY_LENGTH:
            return "length";
        case ARITH:
        case TERNARY:
        case CAST:
            for (InsnArg arg : insn.getArguments()) {
                if (arg.isInsnWrap()) {
                    InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                    String wName = makeNameFromInsn(wrapInsn);
                    if (wName != null) {
                        return wName;
                    }
                }
            }
            break;
        default:
            break;
    }
    return null;
}
Also used : 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) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn)

Aggregations

InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)50 InsnNode (jadx.core.dex.nodes.InsnNode)41 InsnArg (jadx.core.dex.instructions.args.InsnArg)38 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)32 FieldNode (jadx.core.dex.nodes.FieldNode)9 InvokeNode (jadx.core.dex.instructions.InvokeNode)8 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)8 FieldInfo (jadx.core.dex.info.FieldInfo)7 ArithNode (jadx.core.dex.instructions.ArithNode)7 ArgType (jadx.core.dex.instructions.args.ArgType)6 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 ClassNode (jadx.core.dex.nodes.ClassNode)5 ArrayList (java.util.ArrayList)5 InsnType (jadx.core.dex.instructions.InsnType)4 SSAVar (jadx.core.dex.instructions.args.SSAVar)4 MethodNode (jadx.core.dex.nodes.MethodNode)4 Nullable (org.jetbrains.annotations.Nullable)4 ArithOp (jadx.core.dex.instructions.ArithOp)3 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)3 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)3