Search in sources :

Example 36 with InsnWrapArg

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

the class ExtractFieldInit method checkInsn.

private static boolean checkInsn(FieldInitInfo initInfo) {
    if (!initInfo.singlePath) {
        return false;
    }
    IndexInsnNode insn = initInfo.putInsn;
    InsnArg arg = insn.getArg(0);
    if (arg.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
        if (!wrapInsn.canReorderRecursive() && insn.contains(AType.EXC_CATCH)) {
            return false;
        }
    } else {
        return arg.isLiteral() || arg.isThis();
    }
    Set<RegisterArg> regs = new HashSet<>();
    insn.getRegisterArgs(regs);
    if (!regs.isEmpty()) {
        for (RegisterArg reg : regs) {
            if (!reg.isThis()) {
                return false;
            }
        }
    }
    return true;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) HashSet(java.util.HashSet)

Example 37 with InsnWrapArg

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

the class ExtractFieldInit method moveCommonFieldsInit.

private static void moveCommonFieldsInit(ClassNode cls) {
    List<MethodNode> constructors = getConstructorsList(cls);
    if (constructors.isEmpty()) {
        return;
    }
    List<ConstructorInitInfo> infoList = new ArrayList<>(constructors.size());
    for (MethodNode constructorMth : constructors) {
        if (constructorMth.isNoCode()) {
            return;
        }
        List<FieldInitInfo> inits = collectFieldsInit(cls, constructorMth, InsnType.IPUT);
        filterFieldsInit(inits);
        if (inits.isEmpty()) {
            return;
        }
        infoList.add(new ConstructorInitInfo(constructorMth, inits));
    }
    // compare collected instructions
    ConstructorInitInfo common = null;
    for (ConstructorInitInfo info : infoList) {
        if (common == null) {
            common = info;
            continue;
        }
        if (!compareFieldInits(common.fieldInits, info.fieldInits)) {
            return;
        }
    }
    if (common == null) {
        return;
    }
    // all checks passed
    for (ConstructorInitInfo info : infoList) {
        for (FieldInitInfo fieldInit : info.fieldInits) {
            IndexInsnNode putInsn = fieldInit.putInsn;
            InsnArg arg = putInsn.getArg(0);
            if (arg instanceof InsnWrapArg) {
                ((InsnWrapArg) arg).getWrapInsn().add(AFlag.DECLARE_VAR);
            }
            InsnRemover.remove(info.constructorMth, putInsn);
        }
    }
    for (FieldInitInfo fieldInit : common.fieldInits) {
        addFieldInitAttr(common.constructorMth, fieldInit.fieldNode, fieldInit.putInsn);
    }
    fixFieldsOrder(cls, common.fieldInits);
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) ArrayList(java.util.ArrayList) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode)

Example 38 with InsnWrapArg

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

the class InsnNode method visitInsns.

/**
 * Visit this instruction and all inner (wrapped) instructions
 * To terminate visiting return non-null value
 */
@Nullable
public <R> R visitInsns(Function<InsnNode, R> visitor) {
    R result = visitor.apply(this);
    if (result != null) {
        return result;
    }
    for (InsnArg arg : this.getArguments()) {
        if (arg.isInsnWrap()) {
            InsnNode innerInsn = ((InsnWrapArg) arg).getWrapInsn();
            R res = innerInsn.visitInsns(visitor);
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with InsnWrapArg

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

the class InsnNode method rebindArgs.

/**
 * Fix SSAVar info in register arguments.
 * Must be used after altering instructions.
 */
public void rebindArgs() {
    RegisterArg resArg = getResult();
    if (resArg != null) {
        resArg.getSVar().setAssign(resArg);
    }
    for (InsnArg arg : getArguments()) {
        if (arg instanceof RegisterArg) {
            RegisterArg reg = (RegisterArg) arg;
            SSAVar ssaVar = reg.getSVar();
            ssaVar.use(reg);
            ssaVar.updateUsedInPhiList();
        } else if (arg instanceof InsnWrapArg) {
            ((InsnWrapArg) arg).getWrapInsn().rebindArgs();
        }
    }
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 40 with InsnWrapArg

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

the class InsnNode method visitArgs.

/**
 * Visit all args recursively (including inner instructions), but excluding wrapped args.
 * To terminate visiting return non-null value
 */
@Nullable
public <R> R visitArgs(Function<InsnArg, R> visitor) {
    for (InsnArg arg : getArguments()) {
        R result;
        if (arg.isInsnWrap()) {
            InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
            result = wrapInsn.visitArgs(visitor);
        } else {
            result = visitor.apply(arg);
        }
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) Nullable(org.jetbrains.annotations.Nullable)

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 MethodNode (jadx.core.dex.nodes.MethodNode)5 ArrayList (java.util.ArrayList)5 InsnType (jadx.core.dex.instructions.InsnType)4 SSAVar (jadx.core.dex.instructions.args.SSAVar)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