use of jadx.core.dex.instructions.args.CodeVar in project jadx by skylot.
the class InitCodeVariables method initCodeVar.
public static void initCodeVar(SSAVar ssaVar) {
if (ssaVar.isCodeVarSet()) {
return;
}
CodeVar codeVar = new CodeVar();
RegisterArg assignArg = ssaVar.getAssign();
if (assignArg.contains(AFlag.THIS)) {
codeVar.setName(RegisterArg.THIS_ARG_NAME);
codeVar.setThis(true);
}
if (assignArg.contains(AFlag.METHOD_ARGUMENT) || assignArg.contains(AFlag.CUSTOM_DECLARE)) {
codeVar.setDeclared(true);
}
setCodeVar(ssaVar, codeVar);
}
use of jadx.core.dex.instructions.args.CodeVar in project jadx by skylot.
the class VarRef method get.
@Nullable
public static VarRef get(MethodNode mth, RegisterArg reg) {
SSAVar ssaVar = reg.getSVar();
if (ssaVar == null) {
return null;
}
CodeVar codeVar = ssaVar.getCodeVar();
VarRef cachedVarRef = codeVar.getCachedVarRef();
if (cachedVarRef != null) {
if (cachedVarRef.getName() == null) {
cachedVarRef.setName(codeVar.getName());
}
return cachedVarRef;
}
VarRef newVarRef = new VarRef(mth, ssaVar);
codeVar.setCachedVarRef(newVarRef);
return newVarRef;
}
use of jadx.core.dex.instructions.args.CodeVar in project jadx by skylot.
the class ProcessVariables method collectCodeVars.
private List<CodeVar> collectCodeVars(MethodNode mth) {
Map<CodeVar, List<SSAVar>> codeVars = new LinkedHashMap<>();
for (SSAVar ssaVar : mth.getSVars()) {
if (ssaVar.getCodeVar().isThis()) {
continue;
}
CodeVar codeVar = ssaVar.getCodeVar();
List<SSAVar> list = codeVars.computeIfAbsent(codeVar, k -> new ArrayList<>());
list.add(ssaVar);
}
for (Entry<CodeVar, List<SSAVar>> entry : codeVars.entrySet()) {
CodeVar codeVar = entry.getKey();
List<SSAVar> list = entry.getValue();
for (SSAVar ssaVar : list) {
CodeVar localCodeVar = ssaVar.getCodeVar();
codeVar.mergeFlagsFrom(localCodeVar);
}
if (list.size() > 1) {
for (SSAVar ssaVar : list) {
ssaVar.setCodeVar(codeVar);
}
}
codeVar.setSsaVars(list);
}
return new ArrayList<>(codeVars.keySet());
}
use of jadx.core.dex.instructions.args.CodeVar in project jadx by skylot.
the class MethodGen method addMethodArguments.
private void addMethodArguments(ICodeWriter code, List<RegisterArg> args) {
AnnotationMethodParamsAttr paramsAnnotation = mth.get(JadxAttrType.ANNOTATION_MTH_PARAMETERS);
int i = 0;
Iterator<RegisterArg> it = args.iterator();
while (it.hasNext()) {
RegisterArg mthArg = it.next();
SSAVar ssaVar = mthArg.getSVar();
CodeVar var;
if (ssaVar == null) {
// abstract or interface methods
var = CodeVar.fromMthArg(mthArg, classGen.isFallbackMode());
} else {
var = ssaVar.getCodeVar();
}
// add argument annotation
if (paramsAnnotation != null) {
annotationGen.addForParameter(code, paramsAnnotation, i);
}
if (var.isFinal()) {
code.add("final ");
}
ArgType argType;
ArgType varType = var.getType();
if (varType == null || varType == ArgType.UNKNOWN) {
// occur on decompilation errors
argType = mthArg.getInitType();
} else {
argType = varType;
}
if (!it.hasNext() && mth.getAccessFlags().isVarArgs()) {
// change last array argument to varargs
if (argType.isArray()) {
ArgType elType = argType.getArrayElement();
classGen.useType(code, elType);
code.add("...");
} else {
mth.addWarnComment("Last argument in varargs method is not array: " + var);
classGen.useType(code, argType);
}
} else {
classGen.useType(code, argType);
}
code.add(' ');
String varName = nameGen.assignArg(var);
if (code.isMetadataSupported() && ssaVar != null) /* for fallback mode */
{
code.attachDefinition(VarDeclareRef.get(mth, var));
}
code.add(varName);
i++;
if (it.hasNext()) {
code.add(", ");
}
}
}
use of jadx.core.dex.instructions.args.CodeVar in project jadx by skylot.
the class RegionGen method makeCatchBlock.
private void makeCatchBlock(ICodeWriter code, ExceptionHandler handler) throws CodegenException {
IContainer region = handler.getHandlerRegion();
if (region == null) {
return;
}
code.startLine("} catch (");
if (handler.isCatchAll()) {
useClass(code, ArgType.THROWABLE);
} else {
Iterator<ClassInfo> it = handler.getCatchTypes().iterator();
if (it.hasNext()) {
useClass(code, it.next());
}
while (it.hasNext()) {
code.add(" | ");
useClass(code, it.next());
}
}
code.add(' ');
InsnArg arg = handler.getArg();
if (arg == null) {
// throwing exception is too late at this point
code.add("unknown");
} else if (arg instanceof RegisterArg) {
CodeVar codeVar = ((RegisterArg) arg).getSVar().getCodeVar();
if (code.isMetadataSupported()) {
code.attachDefinition(VarDeclareRef.get(mth, codeVar));
}
code.add(mgen.getNameGen().assignArg(codeVar));
} else if (arg instanceof NamedArg) {
code.add(mgen.getNameGen().assignNamedArg((NamedArg) arg));
} else {
throw new JadxRuntimeException("Unexpected arg type in catch block: " + arg + ", class: " + arg.getClass().getSimpleName());
}
code.add(") {");
InsnCodeOffset.attach(code, handler.getHandlerOffset());
CodeGenUtils.addCodeComments(code, mth, handler.getHandlerBlock());
makeRegionIndent(code, region);
}
Aggregations