Search in sources :

Example 41 with RegisterArg

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

Example 42 with RegisterArg

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

the class NameGen method guessName.

private String guessName(RegisterArg arg) {
    SSAVar sVar = arg.getSVar();
    if (sVar != null && sVar.getName() == null) {
        RegisterArg assignArg = sVar.getAssign();
        InsnNode assignInsn = assignArg.getParentInsn();
        if (assignInsn != null) {
            String name = makeNameFromInsn(assignInsn);
            if (name != null && !NameMapper.isReserved(name)) {
                assignArg.setName(name);
                return name;
            }
        }
    }
    return makeNameForType(arg.getType());
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar)

Example 43 with RegisterArg

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

the class RegionGen method declareVars.

private void declareVars(CodeWriter code, IContainer cont) {
    DeclareVariablesAttr declVars = cont.get(AType.DECLARE_VARIABLES);
    if (declVars != null) {
        for (RegisterArg v : declVars.getVars()) {
            code.startLine();
            declareVar(code, v);
            code.add(';');
        }
    }
}
Also used : DeclareVariablesAttr(jadx.core.dex.attributes.nodes.DeclareVariablesAttr) RegisterArg(jadx.core.dex.instructions.args.RegisterArg)

Example 44 with RegisterArg

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

the class RegionGen method makeCatchBlock.

private void makeCatchBlock(CodeWriter code, ExceptionHandler handler) throws CodegenException {
    IContainer region = handler.getHandlerRegion();
    if (region == null) {
        return;
    }
    code.startLine("} catch (");
    InsnArg arg = handler.getArg();
    if (arg instanceof RegisterArg) {
        declareVar(code, (RegisterArg) arg);
    } else if (arg instanceof NamedArg) {
        if (handler.isCatchAll()) {
            code.add("Throwable");
        } else {
            useClass(code, handler.getCatchType());
        }
        code.add(' ');
        code.add(mgen.getNameGen().assignNamedArg((NamedArg) arg));
    }
    code.add(") {");
    makeRegionIndent(code, region);
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) NamedArg(jadx.core.dex.instructions.args.NamedArg) IContainer(jadx.core.dex.nodes.IContainer)

Example 45 with RegisterArg

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

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