Search in sources :

Example 1 with MethodInlineAttr

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

the class MethodInlineVisitor method addInlineAttr.

private static void addInlineAttr(MethodNode mth, InsnNode insn) {
    mth.addAttr(new MethodInlineAttr(insn));
    mth.add(AFlag.DONT_GENERATE);
}
Also used : MethodInlineAttr(jadx.core.dex.attributes.nodes.MethodInlineAttr)

Example 2 with MethodInlineAttr

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

the class InsnGen method inlineMethod.

private boolean inlineMethod(MethodNode callMthNode, InvokeNode insn, CodeWriter code) throws CodegenException {
    MethodInlineAttr mia = callMthNode.get(AType.METHOD_INLINE);
    if (mia == null) {
        return false;
    }
    InsnNode inl = mia.getInsn();
    if (callMthNode.getMethodInfo().getArgumentsTypes().isEmpty()) {
        makeInsn(inl, code, Flags.BODY_ONLY);
    } else {
        // remap args
        InsnArg[] regs = new InsnArg[callMthNode.getRegsCount()];
        List<RegisterArg> callArgs = callMthNode.getArguments(true);
        for (int i = 0; i < callArgs.size(); i++) {
            InsnArg arg = insn.getArg(i);
            RegisterArg callArg = callArgs.get(i);
            regs[callArg.getRegNum()] = arg;
        }
        // replace args
        InsnNode inlCopy = inl.copy();
        List<RegisterArg> inlArgs = new ArrayList<RegisterArg>();
        inlCopy.getRegisterArgs(inlArgs);
        for (RegisterArg r : inlArgs) {
            int regNum = r.getRegNum();
            if (regNum >= regs.length) {
                LOG.warn("Unknown register number {} in method call: {} from {}", r, callMthNode, mth);
            } else {
                InsnArg repl = regs[regNum];
                if (repl == null) {
                    LOG.warn("Not passed register {} in method call: {} from {}", r, callMthNode, mth);
                } else {
                    inlCopy.replaceArg(r, repl);
                }
            }
        }
        makeInsn(inlCopy, code, Flags.BODY_ONLY);
    }
    return true;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) ArrayList(java.util.ArrayList) MethodInlineAttr(jadx.core.dex.attributes.nodes.MethodInlineAttr)

Aggregations

MethodInlineAttr (jadx.core.dex.attributes.nodes.MethodInlineAttr)2 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 ArrayList (java.util.ArrayList)1