/// <summary> /// Load the text to display /// </summary> protected override string LoadText(ISpyContext settings) { var nl = Environment.NewLine; var sb = new StringBuilder(); sb.AppendFormat("AccessFlags: {0}{1}", AccessFlagsAsString(fieldDef.AccessFlags), nl); sb.AppendFormat("Type: {0}{1}", fieldDef.FieldType.ClassName, nl); sb.AppendFormat("Value: {0}{1}", fieldDef.ConstantValue, nl); sb.AppendFormat("Annotations: {0}{1}", TextNode.LoadAnnotations(fieldDef), nl); return(sb.ToString()); }
protected override string LoadText() { EnsureChildNodesCreated(); var nl = Environment.NewLine; var sb = new StringBuilder(); sb.AppendFormat("FullName:\t\t{0}{1}", classDef.ClassName, nl); sb.AppendFormat("Name:\t\t{0}{1}", classDef.Name, nl); sb.AppendFormat("Package:\t\t{0}{1}", classDef.Package, nl); sb.AppendFormat("DeclaringClass:\t{0}{1}", (classDef.DeclaringClass != null) ? classDef.DeclaringClass.ClassName : "<none>", nl); sb.AppendFormat("SuperClass:\t{0}{1}", (classDef.SuperClass != null) ? classDef.SuperClass.ClassName : "<none>", nl); sb.AppendFormat("Signature:\t{0}{1}", (classDef.Signature != null) ? classDef.Signature.Original : "<none>", nl); foreach (var intf in classDef.Interfaces) { sb.AppendFormat("Implements:\t{0}{1}", intf.ClassName, nl); } sb.AppendFormat("AccessFlags:\t{0}{1}", AccessFlagsAsString(classDef.AccessFlags), nl); sb.AppendFormat("Annotations: {0}{1}", TextNode.LoadAnnotations(classDef), nl); var attr = classDef.InnerClassesAttribute; if (attr != null) { sb.AppendLine(); sb.AppendLine("Inner classes:"); var index = 0; foreach (var innerClass in classDef.InnerClassesAttribute.Classes) { sb.AppendFormat("\t[{0}]{1}", index++, nl); sb.AppendFormat("\tinner:\t\t{0}{1}", innerClass.Inner, nl); sb.AppendFormat("\touter:\t\t{0}{1}", innerClass.Outer, nl); sb.AppendFormat("\tname:\t\t{0}{1}", innerClass.Name, nl); sb.AppendFormat("\taccess flags:\t{0}{1}", AccessFlagsAsString(innerClass.AccessFlags), nl); } } return(sb.ToString()); }
/// <summary> /// Load the text to display /// </summary> protected override string LoadText(ISpyContext settings) { var nl = Environment.NewLine; var sb = new StringBuilder(); sb.AppendFormat("AccessFlags: {0} (0x{1:X4}){2}", AccessFlagsAsString(methodDef.AccessFlags), (int)methodDef.AccessFlags, nl); sb.AppendFormat("Descriptor: {0}{1}", methodDef.Descriptor, nl); sb.AppendFormat("Signature: {0}{1}", (methodDef.Signature != null) ? methodDef.Signature.Original : "<none>", nl); sb.AppendFormat("Annotations: {0}{1}", TextNode.LoadAnnotations(methodDef), nl); var code = methodDef.Attributes.OfType <CodeAttribute>().FirstOrDefault(); if (code != null) { sb.AppendFormat("Max locals: {0}{1}", code.MaxLocals, nl); sb.AppendFormat("Max stack: {0}{1}", code.MaxStack, nl); sb.AppendLine("Code:"); foreach (var i in code.Instructions) { sb.AppendFormat("\t{0:x4} {1} {2} {3} {4}", i.Offset, Format(i.Opcode), FormatOperand(i.Operand), FormatOperand(i.Operand2), nl); } sb.AppendLine(); if (code.ExceptionHandlers.Any()) { sb.AppendLine("Exception handlers:"); foreach (var handler in code.ExceptionHandlers.OrderBy(x => x.StartPc)) { sb.AppendFormat("\t{0:x4}-{1:x4} => {2:x4} ({3}) {4}", handler.StartPc, handler.EndPc, handler.HandlerPc, handler.CatchType, nl); } sb.AppendLine(); } if (code.Attributes.OfType <LocalVariableTableAttribute>().Any()) { var locVarAttr = code.Attributes.OfType <LocalVariableTableAttribute>().First(); sb.AppendLine("Local variables:"); foreach (var locVar in locVarAttr.Variables.OrderBy(x => x.StartPc)) { sb.AppendFormat("\t{0:x4}-{1:x4} => {2} ({3}) {4}", locVar.StartPc, locVar.EndPc, locVar.Name, locVar.Index, nl); } sb.AppendLine(); } #if DEBUG || ENABLE_SHOW_AST if (settings.ShowAst) { sb.AppendLine("\n\nAST:\n"); try { var module = settings.Module; var xMethod = CompilerLib.XModel.Java.XBuilder.AsMethodDefinition(module, methodDef); var astBuilder = new CompilerLib.Java2Ast.AstBuilder(module, methodDef, xMethod.DeclaringType, true); var context = new DecompilerContext(xMethod); var ast = astBuilder.Build(); var writer = new PlainTextOutput(new StringWriter(sb)); ast.WriteTo(writer, FormattingOptions.Default); writer.WriteLine(); // Optimize AST sb.AppendLine("\n\nOptimized AST:\n"); var astOptimizer = new AstOptimizer(context, ast); astOptimizer.Optimize(); ast.WriteTo(writer, FormattingOptions.Default); writer.WriteLine(); } catch (Exception ex) { sb.Append(string.Format("Error: {0}\n\n{1}", ex.Message, ex.StackTrace)); } } #endif } return(sb.ToString()); }