示例#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();
        }
示例#2
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);
                 */
            }
        }
示例#4
0
        public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
        {
            language.WriteCommentLine(output, string.Format("{0} ({1}, {2})", Resource.Name, Resource.ResourceType, Resource.Attributes));

            ISmartTextOutput smartOutput = output as ISmartTextOutput;

            if (smartOutput != null)
            {
                smartOutput.AddButton(Images.Save, Resources.Save, delegate { Save(Docking.DockWorkspace.Instance.ActiveTabPage); });
                output.WriteLine();
            }
        }
        public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
        {
            language.WriteCommentLine(output, string.Format("{0} ({1}, {2})", r.Name, r.ResourceType, r.Attributes));

            ISmartTextOutput smartOutput = output as ISmartTextOutput;

            if (smartOutput != null && r is EmbeddedResource)
            {
                smartOutput.AddButton(Images.Save, "Save", delegate { Save(null); });
                output.WriteLine();
            }
        }
示例#6
0
        public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
        {
            language.WriteCommentLine(output, string.Format("{0} ({1}, {2})", r.Name, r.ResourceType, r.Attributes));

            ISmartTextOutput smartOutput = output as ISmartTextOutput;

            if (smartOutput != null)
            {
                smartOutput.AddButton(Images.Save, Resources.Save, delegate { Save(MainWindow.Instance.TextView); });
                output.WriteLine();
            }
        }
示例#7
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();
 }