Search in sources :

Example 1 with RegDebugInfoAttr

use of jadx.core.dex.attributes.nodes.RegDebugInfoAttr in project jadx by skylot.

the class MoveInlineVisitor method processMove.

private static boolean processMove(MethodNode mth, InsnNode move) {
    RegisterArg resultArg = move.getResult();
    InsnArg moveArg = move.getArg(0);
    if (resultArg.sameRegAndSVar(moveArg)) {
        return true;
    }
    SSAVar ssaVar = resultArg.getSVar();
    if (ssaVar.isUsedInPhi()) {
        return deleteMove(mth, move);
    }
    RegDebugInfoAttr debugInfo = moveArg.get(AType.REG_DEBUG_INFO);
    for (RegisterArg useArg : ssaVar.getUseList()) {
        InsnNode useInsn = useArg.getParentInsn();
        if (useInsn == null) {
            return false;
        }
        if (debugInfo == null) {
            RegDebugInfoAttr debugInfoAttr = useArg.get(AType.REG_DEBUG_INFO);
            if (debugInfoAttr != null) {
                debugInfo = debugInfoAttr;
            }
        }
    }
    // all checks passed, execute inline
    for (RegisterArg useArg : new ArrayList<>(ssaVar.getUseList())) {
        InsnNode useInsn = useArg.getParentInsn();
        if (useInsn == null) {
            continue;
        }
        InsnArg replaceArg;
        if (moveArg.isRegister()) {
            replaceArg = ((RegisterArg) moveArg).duplicate(useArg.getInitType());
        } else {
            replaceArg = moveArg.duplicate();
        }
        useInsn.inheritMetadata(move);
        replaceArg.copyAttributesFrom(useArg);
        if (debugInfo != null) {
            replaceArg.addAttr(debugInfo);
        }
        if (!useInsn.replaceArg(useArg, replaceArg)) {
            mth.addWarnComment("Failed to replace arg in insn: " + useInsn);
        }
    }
    return true;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) RegDebugInfoAttr(jadx.core.dex.attributes.nodes.RegDebugInfoAttr) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg) ArrayList(java.util.ArrayList)

Example 2 with RegDebugInfoAttr

use of jadx.core.dex.attributes.nodes.RegDebugInfoAttr in project jadx by skylot.

the class DebugInfoAttachVisitor method attachDebugInfo.

private void attachDebugInfo(MethodNode mth, List<ILocalVar> localVars, InsnNode[] insnArr) {
    if (localVars.isEmpty()) {
        return;
    }
    for (ILocalVar var : localVars) {
        int regNum = var.getRegNum();
        int start = var.getStartOffset();
        int end = var.getEndOffset();
        ArgType type = getVarType(mth, var);
        RegDebugInfoAttr debugInfoAttr = new RegDebugInfoAttr(type, var.getName());
        if (start <= 0) {
            // attach to method arguments
            RegisterArg thisArg = mth.getThisArg();
            if (thisArg != null) {
                attachDebugInfo(thisArg, debugInfoAttr, regNum);
            }
            for (RegisterArg arg : mth.getArgRegs()) {
                attachDebugInfo(arg, debugInfoAttr, regNum);
            }
            start = 0;
        }
        for (int i = start; i <= end; i++) {
            InsnNode insn = insnArr[i];
            if (insn == null) {
                continue;
            }
            int count = 0;
            for (InsnArg arg : insn.getArguments()) {
                count += attachDebugInfo(arg, debugInfoAttr, regNum);
            }
            if (count != 0) {
                // don't apply same info for result if applied to args
                continue;
            }
            attachDebugInfo(insn.getResult(), debugInfoAttr, regNum);
        }
    }
    mth.addAttr(new LocalVarsDebugInfoAttr(localVars));
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) InsnNode(jadx.core.dex.nodes.InsnNode) RegDebugInfoAttr(jadx.core.dex.attributes.nodes.RegDebugInfoAttr) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) LocalVarsDebugInfoAttr(jadx.core.dex.attributes.nodes.LocalVarsDebugInfoAttr) InsnArg(jadx.core.dex.instructions.args.InsnArg) ILocalVar(jadx.api.plugins.input.data.ILocalVar)

Example 3 with RegDebugInfoAttr

use of jadx.core.dex.attributes.nodes.RegDebugInfoAttr in project jadx by skylot.

the class SSAVar method getDetailedVarInfo.

public String getDetailedVarInfo(MethodNode mth) {
    Set<ArgType> types = new HashSet<>();
    Set<String> names = Collections.emptySet();
    List<RegisterArg> useArgs = new ArrayList<>(1 + useList.size());
    useArgs.add(assign);
    useArgs.addAll(useList);
    if (mth.contains(AType.LOCAL_VARS_DEBUG_INFO)) {
        names = new HashSet<>();
        for (RegisterArg arg : useArgs) {
            RegDebugInfoAttr debugInfoAttr = arg.get(AType.REG_DEBUG_INFO);
            if (debugInfoAttr != null) {
                names.add(debugInfoAttr.getName());
                types.add(debugInfoAttr.getRegType());
            }
        }
    }
    for (RegisterArg arg : useArgs) {
        ArgType initType = arg.getInitType();
        if (initType.isTypeKnown()) {
            types.add(initType);
        }
        ArgType type = arg.getType();
        if (type.isTypeKnown()) {
            types.add(type);
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append('r').append(regNum).append('v').append(version);
    if (!names.isEmpty()) {
        sb.append(", names: ").append(names);
    }
    if (!types.isEmpty()) {
        sb.append(", types: ").append(types);
    }
    return sb.toString();
}
Also used : RegDebugInfoAttr(jadx.core.dex.attributes.nodes.RegDebugInfoAttr) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

RegDebugInfoAttr (jadx.core.dex.attributes.nodes.RegDebugInfoAttr)3 InsnArg (jadx.core.dex.instructions.args.InsnArg)2 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 InsnNode (jadx.core.dex.nodes.InsnNode)2 ArrayList (java.util.ArrayList)2 ILocalVar (jadx.api.plugins.input.data.ILocalVar)1 LocalVarsDebugInfoAttr (jadx.core.dex.attributes.nodes.LocalVarsDebugInfoAttr)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 HashSet (java.util.HashSet)1