Search in sources :

Example 16 with RegisterArg

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

the class MethodNode method initArguments.

private void initArguments(List<ArgType> args) {
    int pos;
    if (noCode) {
        pos = 1;
    } else {
        pos = regsCount;
        for (ArgType arg : args) {
            pos -= arg.getRegCount();
        }
    }
    if (accFlags.isStatic()) {
        thisArg = null;
    } else {
        TypeImmutableArg arg = InsnArg.typeImmutableReg(pos - 1, parentClass.getClassInfo().getType());
        arg.markAsThis();
        thisArg = arg;
    }
    if (args.isEmpty()) {
        argsList = Collections.emptyList();
        return;
    }
    argsList = new ArrayList<RegisterArg>(args.size());
    for (ArgType arg : args) {
        argsList.add(InsnArg.typeImmutableReg(pos, arg));
        pos += arg.getRegCount();
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) TypeImmutableArg(jadx.core.dex.instructions.args.TypeImmutableArg)

Example 17 with RegisterArg

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

the class MethodNode method checkInstructions.

public void checkInstructions() {
    List<RegisterArg> list = new ArrayList<RegisterArg>();
    for (InsnNode insnNode : instructions) {
        if (insnNode == null) {
            continue;
        }
        list.clear();
        RegisterArg resultArg = insnNode.getResult();
        if (resultArg != null) {
            list.add(resultArg);
        }
        insnNode.getRegisterArgs(list);
        int argsCount = list.size();
        for (int i = 0; i < argsCount; i++) {
            if (list.get(i).getRegNum() >= regsCount) {
                throw new JadxRuntimeException("Incorrect register number in instruction: " + insnNode + ", expected to be less than " + regsCount);
            }
        }
    }
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 18 with RegisterArg

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

the class DebugInfoParser method addrChange.

private int addrChange(int addr, int addrInc, int line) {
    int newAddr = addr + addrInc;
    int maxAddr = insnByOffset.length - 1;
    newAddr = Math.min(newAddr, maxAddr);
    for (int i = addr + 1; i <= newAddr; i++) {
        InsnNode insn = insnByOffset[i];
        if (insn == null) {
            continue;
        }
        for (InsnArg arg : insn.getArguments()) {
            if (arg.isRegister()) {
                activeRegisters[((RegisterArg) arg).getRegNum()] = arg;
            }
        }
        RegisterArg res = insn.getResult();
        if (res != null) {
            activeRegisters[res.getRegNum()] = res;
        }
    }
    setSourceLines(addr, newAddr, line);
    return newAddr;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 19 with RegisterArg

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

the class DebugInfoParser method process.

public void process() throws DecodeException {
    int addr = 0;
    int line = section.readUleb128();
    int paramsCount = section.readUleb128();
    List<RegisterArg> mthArgs = mth.getArguments(false);
    for (int i = 0; i < paramsCount; i++) {
        int id = section.readUleb128() - 1;
        if (id != DexNode.NO_INDEX) {
            String name = dex.getString(id);
            if (i < mthArgs.size()) {
                mthArgs.get(i).setName(name);
            }
        }
    }
    for (RegisterArg arg : mthArgs) {
        int rn = arg.getRegNum();
        locals[rn] = new LocalVar(arg);
        activeRegisters[rn] = arg;
    }
    // process '0' instruction
    addrChange(-1, 1, line);
    setLine(addr, line);
    int c = section.readByte() & 0xFF;
    while (c != DBG_END_SEQUENCE) {
        switch(c) {
            case DBG_ADVANCE_PC:
                {
                    int addrInc = section.readUleb128();
                    addr = addrChange(addr, addrInc, line);
                    setLine(addr, line);
                    break;
                }
            case DBG_ADVANCE_LINE:
                {
                    line += section.readSleb128();
                    break;
                }
            case DBG_START_LOCAL:
                {
                    int regNum = section.readUleb128();
                    int nameId = section.readUleb128() - 1;
                    int type = section.readUleb128() - 1;
                    LocalVar var = new LocalVar(dex, regNum, nameId, type, DexNode.NO_INDEX);
                    startVar(var, addr, line);
                    break;
                }
            case DBG_START_LOCAL_EXTENDED:
                {
                    int regNum = section.readUleb128();
                    int nameId = section.readUleb128() - 1;
                    int type = section.readUleb128() - 1;
                    int sign = section.readUleb128() - 1;
                    LocalVar var = new LocalVar(dex, regNum, nameId, type, sign);
                    startVar(var, addr, line);
                    break;
                }
            case DBG_RESTART_LOCAL:
                {
                    int regNum = section.readUleb128();
                    LocalVar var = locals[regNum];
                    if (var != null) {
                        if (var.end(addr, line)) {
                            setVar(var);
                        }
                        var.start(addr, line);
                    }
                    break;
                }
            case DBG_END_LOCAL:
                {
                    int regNum = section.readUleb128();
                    LocalVar var = locals[regNum];
                    if (var != null) {
                        var.end(addr, line);
                        setVar(var);
                    }
                    break;
                }
            case DBG_SET_PROLOGUE_END:
            case DBG_SET_EPILOGUE_BEGIN:
                // do nothing
                break;
            case DBG_SET_FILE:
                {
                    int idx = section.readUleb128() - 1;
                    if (idx != DexNode.NO_INDEX) {
                        String sourceFile = dex.getString(idx);
                        mth.addAttr(new SourceFileAttr(sourceFile));
                    }
                    break;
                }
            default:
                {
                    if (c >= DBG_FIRST_SPECIAL) {
                        int adjustedOpcode = c - DBG_FIRST_SPECIAL;
                        int addrInc = adjustedOpcode / DBG_LINE_RANGE;
                        addr = addrChange(addr, addrInc, line);
                        line += DBG_LINE_BASE + adjustedOpcode % DBG_LINE_RANGE;
                        setLine(addr, line);
                    } else {
                        throw new DecodeException("Unknown debug insn code: " + c);
                    }
                    break;
                }
        }
        c = section.readByte() & 0xFF;
    }
    for (LocalVar var : locals) {
        if (var != null && !var.isEnd()) {
            var.end(mth.getCodeSize() - 1, line);
            setVar(var);
        }
    }
    setSourceLines(addr, insnByOffset.length, line);
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SourceFileAttr(jadx.core.dex.attributes.nodes.SourceFileAttr) DecodeException(jadx.core.utils.exceptions.DecodeException)

Example 20 with RegisterArg

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

Aggregations

RegisterArg (jadx.core.dex.instructions.args.RegisterArg)67 InsnNode (jadx.core.dex.nodes.InsnNode)39 InsnArg (jadx.core.dex.instructions.args.InsnArg)24 SSAVar (jadx.core.dex.instructions.args.SSAVar)22 BlockNode (jadx.core.dex.nodes.BlockNode)17 PhiInsn (jadx.core.dex.instructions.PhiInsn)11 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)10 ArgType (jadx.core.dex.instructions.args.ArgType)8 ArrayList (java.util.ArrayList)8 PhiListAttr (jadx.core.dex.attributes.nodes.PhiListAttr)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)6 MethodNode (jadx.core.dex.nodes.MethodNode)4 MethodInfo (jadx.core.dex.info.MethodInfo)3 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 FieldNode (jadx.core.dex.nodes.FieldNode)3 IContainer (jadx.core.dex.nodes.IContainer)3 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)3