Search in sources :

Example 1 with LocalVarsDebugInfoAttr

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

the class DebugInfoApplyVisitor method searchDebugInfoByOffset.

private static void searchDebugInfoByOffset(MethodNode mth, SSAVar ssaVar) {
    LocalVarsDebugInfoAttr debugInfoAttr = mth.get(AType.LOCAL_VARS_DEBUG_INFO);
    if (debugInfoAttr == null) {
        return;
    }
    OptionalInt max = ssaVar.getUseList().stream().mapToInt(DebugInfoApplyVisitor::getInsnOffsetByArg).max();
    if (!max.isPresent()) {
        return;
    }
    int startOffset = getInsnOffsetByArg(ssaVar.getAssign());
    int endOffset = max.getAsInt();
    int regNum = ssaVar.getRegNum();
    for (ILocalVar localVar : debugInfoAttr.getLocalVars()) {
        if (localVar.getRegNum() == regNum) {
            int startAddr = localVar.getStartOffset();
            int endAddr = localVar.getEndOffset();
            if (isInside(startOffset, startAddr, endAddr) || isInside(endOffset, startAddr, endAddr)) {
                if (Consts.DEBUG_TYPE_INFERENCE) {
                    LOG.debug("Apply debug info by offset for: {} to {}", ssaVar, localVar);
                }
                ArgType type = DebugInfoAttachVisitor.getVarType(mth, localVar);
                applyDebugInfo(mth, ssaVar, type, localVar.getName());
                break;
            }
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) LocalVarsDebugInfoAttr(jadx.core.dex.attributes.nodes.LocalVarsDebugInfoAttr) OptionalInt(java.util.OptionalInt) ILocalVar(jadx.api.plugins.input.data.ILocalVar)

Example 2 with LocalVarsDebugInfoAttr

use of jadx.core.dex.attributes.nodes.LocalVarsDebugInfoAttr 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)

Aggregations

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