VarProcessor varProc = new VarProcessor(mt, md); DecompilerContext.startMethod(varProc); VarNamesCollector vc = varProc.getVarNamesCollector(); CounterContainer counter = DecompilerContext.getCounterContainer(); varProc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName); paramCount = 1; varProc.setVarName(new VarVersionPair(varIndex, 0), vc.getFreeName(varIndex)); varProc.refreshVarNames(namesCollector); if (attr != null) { varProc.setDebugVarNames(attr.getMapParamNames()); String name = varExprent.getDebugName(mt); if (name != null) { varProc.setVarName(varExprent.getVarVersionPair(), name);
private static boolean isExprentIndependent(Exprent exprent, MethodWrapper method) { List<Exprent> lst = exprent.getAllExprents(true); lst.add(exprent); for (Exprent expr : lst) { switch (expr.type) { case Exprent.EXPRENT_VAR: VarVersionPair varPair = new VarVersionPair((VarExprent)expr); if (!method.varproc.getExternalVars().contains(varPair)) { String varName = method.varproc.getVarName(varPair); if (!varName.equals("this") && !varName.endsWith(".this")) { // FIXME: remove direct comparison with strings return false; } } break; case Exprent.EXPRENT_FIELD: return false; } } return true; } }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buffer = new TextBuffer(); tracer.addMapping(bytecode); if (classDef) { ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(varType.value); new ClassWriter().classToJava(child, buffer, indent, tracer); tracer.incrementCurrentSourceLine(buffer.countLines()); } else { VarVersionPair varVersion = getVarVersionPair(); String name = null; if (processor != null) { name = processor.getVarName(varVersion); } if (definition) { if (processor != null && processor.getVarFinal(varVersion) == VarTypeProcessor.VAR_EXPLICIT_FINAL) { buffer.append("final "); } appendDefinitionType(buffer); buffer.append(" "); } buffer.append(name == null ? ("var" + index + (this.version == 0 ? "" : "_" + this.version)) : name); } return buffer; }
if (mapParamsToNewVars.containsKey(varIndex)) { VarVersionPair newVar = mapParamsToNewVars.get(varIndex); method.varproc.getExternalVars().add(newVar); return new VarExprent(newVar.var, method.varproc.getVarType(newVar), method.varproc); method.varproc.getExternalVars().add(newVar); return new VarExprent(newVar.var, method.varproc.getVarType(newVar), method.varproc);
varName = enclosingMethod.varproc.getVarName(pair); varType = enclosingMethod.varproc.getVarType(pair); enclosingMethod.varproc.setVarFinal(pair, VarTypeProcessor.VAR_EXPLICIT_FINAL); varName = parent.simpleName + ".this"; method.varproc.getThisVars().put(newVar, parent.classStruct.qualifiedName); MethodWrapper enclosing_method = classNode.parent.getWrapper().getMethods().getWithKey(classNode.enclosingMethod); varName = enclosing_method.varproc.getVarName(entry.getValue()); varType = enclosing_method.varproc.getVarType(entry.getValue()); enclosing_method.varproc.setVarFinal(entry.getValue(), VarTypeProcessor.VAR_EXPLICIT_FINAL); varName = classNode.parent.simpleName + ".this"; method.varproc.getThisVars().put(newVar, classNode.parent.classStruct.qualifiedName); setNewOuterNames.removeAll(method.setOuterVarNames); method.varproc.refreshVarNames(new VarNamesCollector(setNewOuterNames)); method.setOuterVarNames.addAll(setNewOuterNames); method.varproc.setVarName(pair, entry.getValue()); if (type != null) { method.varproc.setVarType(pair, type);
method.varproc.getThisVars().put(new VarVersionPair(0, 0), parent_class_name); method.varproc.setVarName(new VarVersionPair(0, 0), parent.simpleName + ".this"); NewExprent new_expr = (NewExprent)expr; VarNamesCollector enclosingCollector = new VarNamesCollector(enclosingMethod.varproc.getVarNames()); mapNewNames.put(varVersion, enclosingMethod.varproc.getVarName(new VarVersionPair((VarExprent)param))); mapNewNames.put(varVersion, enclosingCollector.getFreeName(method.varproc.getVarName(varVersion))); setNewOuterNames.removeAll(method.setOuterVarNames); method.varproc.refreshVarNames(new VarNamesCollector(setNewOuterNames)); method.setOuterVarNames.addAll(setNewOuterNames); method.varproc.setVarName(entry.getKey(), entry.getValue());
if (exsource.getValue().type == Exprent.EXPRENT_VAR) { // qualified this VarExprent var = (VarExprent)exsource.getValue(); String varname = methsource.varproc.getVarName(new VarVersionPair(var)); vnc.addName(varname); methdest.varproc.refreshVarNames(vnc); methdest.setOuterVarNames.add(varname); methdest.varproc.setVarName(new VarVersionPair(index, 0), varname);
VarNamesCollector vc = varproc.getVarNamesCollector(); for (int i = 0; i < paramcount; i++) { implDefVars.add(varindex); varproc.setVarName(new VarVersionPair(varindex, 0), vc.getFreeName(varindex)); StructClass current_class = (StructClass)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS); varproc.getThisVars().put(new VarVersionPair(0, 0), current_class.qualifiedName); varproc.setVarName(new VarVersionPair(0, 0), "this"); vc.addName("this"); for (VarExprent var : lstVars) { implDefVars.add(var.getIndex()); varproc.setVarName(new VarVersionPair(var), vc.getFreeName(var.getIndex())); var.setDefinition(true);
public void setVarDefinitions() { VarNamesCollector vc = varproc.getVarNamesCollector(); varproc.setVarName(new VarVersionPair(index.intValue(), 0), vc.getFreeName(index)); VarExprent var = new VarExprent(index, varproc.getVarType(new VarVersionPair(index.intValue(), 0)), varproc); var.setDefinition(true);
method.varproc.getThisVars().put(new VarVersionPair(0, 0), parent_class_name); method.varproc.setVarName(new VarVersionPair(0, 0), parent.simpleName + ".this"); setNewOuterNames.removeAll(method.setOuterVarNames); method.varproc.refreshVarNames(new VarNamesCollector(setNewOuterNames)); method.setOuterVarNames.addAll(setNewOuterNames); method.varproc.setVarName(entry.getKey(), entry.getValue());
public static boolean isInvocationInitConstructor(InvocationExprent inv, MethodWrapper method, ClassWrapper wrapper, boolean withThis) { if (inv.getFunctype() == InvocationExprent.TYP_INIT && inv.getInstance().type == Exprent.EXPRENT_VAR) { VarExprent instVar = (VarExprent)inv.getInstance(); VarVersionPair varPair = new VarVersionPair(instVar); String className = method.varproc.getThisVars().get(varPair); if (className != null) { // any this instance. TODO: Restrict to current class? return withThis || !wrapper.getClassStruct().qualifiedName.equals(inv.getClassname()); } } return false; } }
NewExprent new_expr = (NewExprent)expr; VarNamesCollector enclosingCollector = new VarNamesCollector(enclosingMethod.varproc.getVarNames()); mapNewNames.put(varVersion, enclosingMethod.varproc.getVarName(new VarVersionPair((VarExprent)param))); mapNewNames.put(varVersion, enclosingCollector.getFreeName(method.varproc.getVarName(varVersion)));
public String getDebugName(StructMethod method) { StructLocalVariableTableAttribute attr = method.getLocalVariableAttr(); if (attr != null && processor != null) { Integer origIndex = processor.getVarOriginalIndex(index); if (origIndex != null) { String name = attr.getName(origIndex, visibleOffset); if (name != null && TextUtil.isValidIdentifier(name, method.getClassStruct().getBytecodeVersion())) { return name; } } } return null; }
String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0)); buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors
for (int i = 0; i < paramcount; i++) { implDefVars.add(varindex); varproc.setVarName(new VarVersionPair(varindex, 0), vc.getFreeName(varindex)); StructClass current_class = (StructClass)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS); varproc.getThisVars().put(new VarVersionPair(0, 0), current_class.qualifiedName); varproc.setVarName(new VarVersionPair(0, 0), "this"); vc.addName("this"); for (VarExprent var : lstVars) { implDefVars.add(var.getIndex()); varproc.setVarName(new VarVersionPair(var), vc.getFreeName(var.getIndex())); var.setDefinition(true);
varproc.setVarName(new VarVersionPair(index.intValue(), 0), vc.getFreeName(index)); VarExprent var = new VarExprent(index.intValue(), varproc.getVarType(new VarVersionPair(index.intValue(), 0)), varproc); var.setDefinition(true);
public VarType getVarType() { VarType vt = null; if (processor != null) { vt = processor.getVarType(getVarVersionPair()); } if (vt == null || (varType != null && varType.type != CodeConstants.TYPE_UNKNOWN)) { vt = varType; } return vt == null ? VarType.VARTYPE_UNKNOWN : vt; }
if (method.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarTypeProcessor.VAR_NON_FINAL) { return null;
varName = enclosingMethod.varproc.getVarName(pair); varType = enclosingMethod.varproc.getVarType(pair); enclosingMethod.varproc.setVarFinal(pair, VarTypeProcessor.VAR_EXPLICIT_FINAL); varName = parent.simpleName + ".this"; method.varproc.getThisVars().put(newVar, parent.classStruct.qualifiedName); MethodWrapper enclosing_method = classNode.parent.getWrapper().getMethods().getWithKey(classNode.enclosingMethod); varName = enclosing_method.varproc.getVarName(entry.getValue()); varType = enclosing_method.varproc.getVarType(entry.getValue()); enclosing_method.varproc.setVarFinal(entry.getValue(), VarTypeProcessor.VAR_EXPLICIT_FINAL); varName = classNode.parent.simpleName + ".this"; method.varproc.getThisVars().put(newVar, classNode.parent.classStruct.qualifiedName); setNewOuterNames.removeAll(method.setOuterVarNames); method.varproc.refreshVarNames(new VarNamesCollector(setNewOuterNames)); method.setOuterVarNames.addAll(setNewOuterNames); method.varproc.setVarName(pair, entry.getValue()); if (type != null) { method.varproc.setVarType(pair, type);
if (exsource.getValue().type == Exprent.EXPRENT_VAR) { // qualified this VarExprent var = (VarExprent)exsource.getValue(); String varname = methsource.varproc.getVarName(new VarVersionPair(var)); vnc.addName(varname); methdest.varproc.refreshVarNames(vnc); methdest.setOuterVarNames.add(varname); methdest.varproc.setVarName(new VarVersionPair(index, 0), varname);