Search in sources :

Example 6 with SSAVar

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

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

the class MethodNode method getNextSVarVersion.

public int getNextSVarVersion(int regNum) {
    int v = -1;
    for (SSAVar sVar : sVars) {
        if (sVar.getRegNum() == regNum) {
            v = Math.max(v, sVar.getVersion());
        }
    }
    v++;
    return v;
}
Also used : SSAVar(jadx.core.dex.instructions.args.SSAVar)

Example 8 with SSAVar

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

the class MethodNode method makeNewSVar.

public SSAVar makeNewSVar(int regNum, int version, @NotNull RegisterArg assignArg) {
    SSAVar var = new SSAVar(regNum, version, assignArg);
    if (sVars.isEmpty()) {
        sVars = new ArrayList<SSAVar>();
    }
    sVars.add(var);
    return var;
}
Also used : SSAVar(jadx.core.dex.instructions.args.SSAVar)

Example 9 with SSAVar

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

the class DebugInfoParser method startVar.

private void startVar(LocalVar var, int addr, int line) {
    int regNum = var.getRegNum();
    LocalVar prev = locals[regNum];
    if (prev != null && !prev.isEnd()) {
        prev.end(addr, line);
        setVar(prev);
    }
    InsnArg activeReg = activeRegisters[var.getRegNum()];
    if (activeReg instanceof RegisterArg) {
        SSAVar ssaVar = ((RegisterArg) activeReg).getSVar();
        if (ssaVar != null && ssaVar.getStartAddr() != -1) {
            InsnNode parentInsn = ssaVar.getAssign().getParentInsn();
            if (parentInsn != null && parentInsn.getOffset() >= 0) {
                addr = parentInsn.getOffset();
            }
        }
    }
    var.start(addr, line);
    locals[regNum] = var;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 10 with SSAVar

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

the class SSATransform method inlinePhiInsn.

private static boolean inlinePhiInsn(MethodNode mth, BlockNode block, PhiInsn phi) {
    SSAVar resVar = phi.getResult().getSVar();
    if (resVar == null) {
        return false;
    }
    RegisterArg arg = phi.getArg(0);
    if (arg.getSVar() == null) {
        return false;
    }
    List<RegisterArg> useList = resVar.getUseList();
    for (RegisterArg useArg : new ArrayList<RegisterArg>(useList)) {
        InsnNode useInsn = useArg.getParentInsn();
        if (useInsn == null || useInsn == phi) {
            return false;
        }
        useArg.getSVar().removeUse(useArg);
        RegisterArg inlArg = arg.duplicate();
        if (!useInsn.replaceArg(useArg, inlArg)) {
            return false;
        }
        inlArg.getSVar().use(inlArg);
        inlArg.setName(useArg.getName());
        inlArg.setType(useArg.getType());
    }
    if (block.contains(AType.EXC_HANDLER)) {
        // don't inline into exception handler
        InsnNode assignInsn = arg.getAssignInsn();
        if (assignInsn != null) {
            assignInsn.add(AFlag.DONT_INLINE);
        }
    }
    InstructionRemover.unbindInsn(mth, phi);
    return true;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) ArrayList(java.util.ArrayList)

Aggregations

SSAVar (jadx.core.dex.instructions.args.SSAVar)28 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)22 InsnNode (jadx.core.dex.nodes.InsnNode)16 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 PhiInsn (jadx.core.dex.instructions.PhiInsn)7 BlockNode (jadx.core.dex.nodes.BlockNode)7 ArgType (jadx.core.dex.instructions.args.ArgType)6 PhiListAttr (jadx.core.dex.attributes.nodes.PhiListAttr)5 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)5 ArrayList (java.util.ArrayList)5 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)4 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 FieldNode (jadx.core.dex.nodes.FieldNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 ForEachLoop (jadx.core.dex.regions.loops.ForEachLoop)2 MethodParameters (jadx.core.dex.attributes.annotations.MethodParameters)1 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)1 AccessInfo (jadx.core.dex.info.AccessInfo)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 MethodInfo (jadx.core.dex.info.MethodInfo)1