Search in sources :

Example 56 with InsnNode

use of jadx.core.dex.nodes.InsnNode 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 57 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class DebugInfoVisitor method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    int debugOffset = mth.getDebugInfoOffset();
    if (debugOffset > 0) {
        InsnNode[] insnArr = mth.getInstructions();
        DebugInfoParser debugInfoParser = new DebugInfoParser(mth, debugOffset, insnArr);
        debugInfoParser.process();
        // set method source line from first instruction
        if (insnArr.length != 0) {
            for (InsnNode insn : insnArr) {
                if (insn != null) {
                    int line = insn.getSourceLine();
                    if (line != 0) {
                        mth.setSourceLine(line - 1);
                    }
                    break;
                }
            }
        }
        if (!mth.getReturnType().equals(ArgType.VOID)) {
            // fix debug info for splitter 'return' instructions
            for (BlockNode exit : mth.getExitBlocks()) {
                InsnNode ret = BlockUtils.getLastInsn(exit);
                if (ret == null) {
                    continue;
                }
                InsnNode oldRet = insnArr[ret.getOffset()];
                if (oldRet == ret) {
                    continue;
                }
                RegisterArg oldArg = (RegisterArg) oldRet.getArg(0);
                RegisterArg newArg = (RegisterArg) ret.getArg(0);
                newArg.mergeDebugInfo(oldArg.getType(), oldArg.getName());
                ret.setSourceLine(oldRet.getSourceLine());
            }
        }
    }
    mth.unloadInsnArr();
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) DebugInfoParser(jadx.core.dex.nodes.parser.DebugInfoParser)

Example 58 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class DependencyCollector method processMethod.

private static void processMethod(DexNode dex, Set<ClassNode> depList, MethodNode methodNode) {
    addDep(dex, depList, methodNode.getParentClass());
    addDep(dex, depList, methodNode.getReturnType());
    for (ArgType arg : methodNode.getMethodInfo().getArgumentsTypes()) {
        addDep(dex, depList, arg);
    }
    for (BlockNode block : methodNode.getBasicBlocks()) {
        for (InsnNode insnNode : block.getInstructions()) {
            processInsn(dex, depList, insnNode);
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode)

Example 59 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class EnumVisitor method getConstString.

private String getConstString(DexNode dex, InsnArg arg) {
    if (arg.isInsnWrap()) {
        InsnNode constInsn = ((InsnWrapArg) arg).getWrapInsn();
        Object constValue = InsnUtils.getConstValueByInsn(dex, constInsn);
        if (constValue instanceof String) {
            return (String) constValue;
        }
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 60 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class InstructionRemover method fixUsedInPhiFlag.

public static void fixUsedInPhiFlag(RegisterArg useReg) {
    PhiInsn usedIn = null;
    for (RegisterArg reg : useReg.getSVar().getUseList()) {
        InsnNode parentInsn = reg.getParentInsn();
        if (parentInsn != null && parentInsn.getType() == InsnType.PHI && parentInsn.containsArg(useReg)) {
            usedIn = (PhiInsn) parentInsn;
        }
    }
    useReg.getSVar().setUsedInPhi(usedIn);
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) PhiInsn(jadx.core.dex.instructions.PhiInsn)

Aggregations

InsnNode (jadx.core.dex.nodes.InsnNode)123 BlockNode (jadx.core.dex.nodes.BlockNode)41 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)39 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)35 InsnArg (jadx.core.dex.instructions.args.InsnArg)32 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)19 SSAVar (jadx.core.dex.instructions.args.SSAVar)16 ArrayList (java.util.ArrayList)14 ArgType (jadx.core.dex.instructions.args.ArgType)11 PhiInsn (jadx.core.dex.instructions.PhiInsn)10 FieldNode (jadx.core.dex.nodes.FieldNode)10 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)7 ClassNode (jadx.core.dex.nodes.ClassNode)7 MethodNode (jadx.core.dex.nodes.MethodNode)7 FieldInfo (jadx.core.dex.info.FieldInfo)6 ArithNode (jadx.core.dex.instructions.ArithNode)6 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)6 InsnType (jadx.core.dex.instructions.InsnType)5 IContainer (jadx.core.dex.nodes.IContainer)5