Exemplo n.º 1
0
        /// <summary>
        /// Creates a message that the decompiler output was too long.
        /// The message contains buttons that allow re-trying (with larger limit) or saving to a file.
        /// </summary>
        void WriteOutputLengthExceededMessage(ISmartTextOutput output, DecompilationContext context, bool wasNormalLimit)
        {
            if (wasNormalLimit)
            {
                output.WriteLine("You have selected too much code for it to be displayed automatically.");
            }
            else
            {
                output.WriteLine("You have selected too much code; it cannot be displayed here.");
            }
            output.WriteLine();
            if (wasNormalLimit)
            {
                output.AddButton(
                    Images.ViewCode, "Display Code",
                    delegate {
                    DoDecompile(context, ExtendedOutputLengthLimit).HandleExceptions();
                });
                output.WriteLine();
            }

            output.AddButton(
                Images.Save, "Save Code",
                delegate {
                SaveToDisk(context.Language, context.TreeNodes, context.Options);
            });
            output.WriteLine();
        }
Exemplo n.º 2
0
 void WriteHighlightedCommentLine(ISmartTextOutput output, string text, int startColumn, int endColumn, bool isSingleLine)
 {
     if (startColumn > text.Length)
     {
         Debug.Fail("startColumn is invalid");
         startColumn = text.Length;
     }
     if (endColumn > text.Length)
     {
         Debug.Fail("endColumn is invalid");
         endColumn = text.Length;
     }
     output.Write("// ");
     output.BeginSpan(gray);
     if (isSingleLine)
     {
         output.Write(text.Substring(0, startColumn).TrimStart());
     }
     else
     {
         output.Write(text.Substring(0, startColumn));
     }
     output.EndSpan();
     output.Write(text.Substring(startColumn, endColumn - startColumn));
     output.BeginSpan(gray);
     output.Write(text.Substring(endColumn));
     output.EndSpan();
     output.WriteLine();
 }
Exemplo n.º 3
0
        // There are several methods available to override; in this sample, we deal with methods only

        public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            if (method.Body != null)
            {
                output.WriteLine("Size of method: {0} bytes", method.Body.CodeSize);

                ISmartTextOutput smartOutput = output as ISmartTextOutput;
                if (smartOutput != null)
                {
                    // when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons:
                    smartOutput.AddButton(null, "Click me!", (sender, e) => (sender as Button).Content = "I was clicked!");
                    smartOutput.WriteLine();
                }

                // ICSharpCode.Decompiler.Ast.AstBuilder can be used to decompile to C#

                /*
                 * AstBuilder b = new AstBuilder(new DecompilerContext(method.Module) {
                 *                              Settings = options.DecompilerSettings,
                 *                              CurrentType = method.DeclaringType
                 *                            });
                 * b.AddMethod(method);
                 * b.RunTransformations();
                 * output.WriteLine("Decompiled AST has {0} nodes", b.SyntaxTree.DescendantsAndSelf.Count());*/
            }
        }
        // There are several methods available to override; in this sample, we deal with methods only

        public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            if (method.Body != null)
            {
                output.WriteLine("Size of method: {0} bytes", method.Body.CodeSize);

                ISmartTextOutput smartOutput = output as ISmartTextOutput;
                if (smartOutput != null)
                {
                    // when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons:
                    smartOutput.AddButton(null, "Click me!", (sender, e) => (sender as Button).Content = "I was clicked!");
                    smartOutput.WriteLine();
                }

                // ICSharpCode.Decompiler.CSharp.CSharpDecompiler can be used to decompile to C#.

                /*
                 *      ModuleDefinition module = LoadModule(assemblyFileName);
                 *      var typeSystem = new DecompilerTypeSystem(module);
                 *      CSharpDecompiler decompiler = new CSharpDecompiler(typeSystem, new DecompilerSettings());
                 *
                 *      decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers());
                 *      SyntaxTree syntaxTree = decompiler.DecompileWholeModuleAsSingleFile();
                 *      var visitor = new CSharpOutputVisitor(output, FormattingOptionsFactory.CreateSharpDevelop());
                 *      syntaxTree.AcceptVisitor(visitor);
                 */
            }
        }
Exemplo n.º 5
0
 public void Write(ISmartTextOutput textOutput)
 {
     textOutput.WriteLine();
     textOutput.Write("This is a test.");
     textOutput.WriteLine();
     textOutput.WriteLine();
     textOutput.BeginSpan(new HighlightingColor {
         Background = new SimpleHighlightingBrush(Colors.Black),
         FontStyle  = FontStyle.Italic,
         Foreground = new SimpleHighlightingBrush(Colors.Aquamarine)
     });
     textOutput.Write("DO NOT PRESS THIS BUTTON --> ");
     textOutput.AddButton(null, "Test!", (sender, args) => MessageBox.Show("Naughty Naughty!", "Naughty!", MessageBoxButton.OK, MessageBoxImage.Exclamation));
     textOutput.Write(" <--");
     textOutput.WriteLine();
     textOutput.EndSpan();
     textOutput.WriteLine();
 }