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());
}
}
}
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('}');
}
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);
}
}
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);
}
}
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;
}
Aggregations