Search in sources :

Example 6 with CodeVar

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

the class RegionGen method declareVars.

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

Example 7 with CodeVar

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

the class InsnGen method makeInlinedLambdaMethod.

private void makeInlinedLambdaMethod(ICodeWriter code, InvokeCustomNode customNode, MethodNode callMth) throws CodegenException {
    MethodGen callMthGen = new MethodGen(mgen.getClassGen(), callMth);
    NameGen nameGen = callMthGen.getNameGen();
    nameGen.inheritUsedNames(this.mgen.getNameGen());
    List<ArgType> implArgs = customNode.getImplMthInfo().getArgumentsTypes();
    List<RegisterArg> callArgs = callMth.getArgRegs();
    if (implArgs.isEmpty()) {
        code.add("()");
    } else {
        int callArgsCount = callArgs.size();
        int startArg = callArgsCount - implArgs.size();
        for (int i = startArg; i < callArgsCount; i++) {
            if (i != startArg) {
                code.add(", ");
            }
            CodeVar argCodeVar = callArgs.get(i).getSVar().getCodeVar();
            code.add(nameGen.assignArg(argCodeVar));
        }
    }
    // force set external arg names into call method args
    int extArgsCount = customNode.getArgsCount();
    // skip 'this' arg
    int startArg = customNode.getHandleType() == MethodHandleType.INVOKE_STATIC ? 0 : 1;
    for (int i = startArg; i < extArgsCount; i++) {
        RegisterArg extArg = (RegisterArg) customNode.getArg(i);
        callArgs.get(i).setName(extArg.getName());
    }
    code.add(" -> {");
    code.incIndent();
    callMthGen.addInstructions(code);
    code.decIndent();
    code.startLine('}');
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) CodeVar(jadx.core.dex.instructions.args.CodeVar) RegisterArg(jadx.core.dex.instructions.args.RegisterArg)

Example 8 with CodeVar

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

the class DebugInfoApplyVisitor method processMethodParametersAttribute.

private void processMethodParametersAttribute(MethodNode mth) {
    MethodParametersAttr parametersAttr = mth.get(JadxAttrType.METHOD_PARAMETERS);
    if (parametersAttr == null) {
        return;
    }
    try {
        List<MethodParametersAttr.Info> params = parametersAttr.getList();
        if (params.size() != mth.getMethodInfo().getArgsCount()) {
            return;
        }
        int i = 0;
        for (RegisterArg mthArg : mth.getArgRegs()) {
            MethodParametersAttr.Info paramInfo = params.get(i++);
            String name = paramInfo.getName();
            if (NameMapper.isValidAndPrintable(name)) {
                CodeVar codeVar = mthArg.getSVar().getCodeVar();
                codeVar.setName(name);
                if (AccessFlags.hasFlag(paramInfo.getAccFlags(), AccessFlags.FINAL)) {
                    codeVar.setFinal(true);
                }
            }
        }
    } catch (Exception e) {
        mth.addWarnComment("Failed to process method parameters attribute: " + parametersAttr.getList(), e);
    }
}
Also used : CodeVar(jadx.core.dex.instructions.args.CodeVar) MethodParametersAttr(jadx.api.plugins.input.data.attributes.types.MethodParametersAttr) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) JadxException(jadx.core.utils.exceptions.JadxException)

Example 9 with CodeVar

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

the class ProcessVariables method checkCodeVars.

private void checkCodeVars(MethodNode mth, List<CodeVar> codeVars) {
    int unknownTypesCount = 0;
    for (CodeVar codeVar : codeVars) {
        ArgType codeVarType = codeVar.getType();
        if (codeVarType == null) {
            codeVar.setType(ArgType.UNKNOWN);
            unknownTypesCount++;
        } else {
            codeVar.getSsaVars().forEach(ssaVar -> {
                ArgType ssaType = ssaVar.getImmutableType();
                if (ssaType != null && ssaType.isTypeKnown()) {
                    TypeCompare comparator = mth.root().getTypeUpdate().getTypeCompare();
                    TypeCompareEnum result = comparator.compareTypes(ssaType, codeVarType);
                    if (result == TypeCompareEnum.CONFLICT || result.isNarrow()) {
                        mth.addWarn("Incorrect type for immutable var: ssa=" + ssaType + ", code=" + codeVarType + ", for " + ssaVar.getDetailedVarInfo(mth));
                    }
                }
            });
        }
    }
    if (unknownTypesCount != 0) {
        mth.addWarn("Unknown variable types count: " + unknownTypesCount);
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) CodeVar(jadx.core.dex.instructions.args.CodeVar) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) TypeCompareEnum(jadx.core.dex.visitors.typeinference.TypeCompareEnum)

Example 10 with CodeVar

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

the class ProcessVariables method mergeUsageMaps.

private Map<CodeVar, List<VarUsage>> mergeUsageMaps(List<CodeVar> codeVars, Map<SSAVar, VarUsage> ssaUsageMap) {
    Map<CodeVar, List<VarUsage>> codeVarUsage = new LinkedHashMap<>(codeVars.size());
    for (CodeVar codeVar : codeVars) {
        List<VarUsage> list = new ArrayList<>();
        for (SSAVar ssaVar : codeVar.getSsaVars()) {
            VarUsage usage = ssaUsageMap.get(ssaVar);
            if (usage != null) {
                list.add(usage);
            }
        }
        codeVarUsage.put(codeVar, Utils.lockList(list));
    }
    return codeVarUsage;
}
Also used : CodeVar(jadx.core.dex.instructions.args.CodeVar) SSAVar(jadx.core.dex.instructions.args.SSAVar) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CodeVar (jadx.core.dex.instructions.args.CodeVar)10 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)5 SSAVar (jadx.core.dex.instructions.args.SSAVar)4 ArgType (jadx.core.dex.instructions.args.ArgType)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AnnotationMethodParamsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr)1 MethodParametersAttr (jadx.api.plugins.input.data.attributes.types.MethodParametersAttr)1 DeclareVariablesAttr (jadx.core.dex.attributes.nodes.DeclareVariablesAttr)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 NamedArg (jadx.core.dex.instructions.args.NamedArg)1 IContainer (jadx.core.dex.nodes.IContainer)1 TypeCompare (jadx.core.dex.visitors.typeinference.TypeCompare)1 TypeCompareEnum (jadx.core.dex.visitors.typeinference.TypeCompareEnum)1 JadxException (jadx.core.utils.exceptions.JadxException)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 Nullable (org.jetbrains.annotations.Nullable)1