Beispiel #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();
        }
Beispiel #2
0
        public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
        {
            EnsureLazyChildren();
            base.Decompile(language, output, options);
            var textView = (DecompilerTextView)Docking.DockWorkspace.Instance.ActiveTabPage.Content;

            if (stringTableEntries.Count != 0)
            {
                ISmartTextOutput smartOutput = output as ISmartTextOutput;
                if (null != smartOutput)
                {
                    smartOutput.AddUIElement(
                        delegate {
                        return(new ResourceStringTable(stringTableEntries, textView));
                    }
                        );
                }
                output.WriteLine();
                output.WriteLine();
            }
            if (otherEntries.Count != 0)
            {
                ISmartTextOutput smartOutput = output as ISmartTextOutput;
                if (null != smartOutput)
                {
                    smartOutput.AddUIElement(
                        delegate {
                        return(new ResourceObjectTable(otherEntries, textView));
                    }
                        );
                }
                output.WriteLine();
            }
        }
 public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
 {
     EnsureLazyChildren();
     base.Decompile(language, output, options);
     if (stringTableEntries.Count != 0)
     {
         ISmartTextOutput smartOutput = output as ISmartTextOutput;
         if (null != smartOutput)
         {
             smartOutput.AddUIElement(
                 delegate {
                 return(new ResourceStringTable(stringTableEntries, MainWindow.Instance.mainPane));
             }
                 );
         }
         output.WriteLine();
         output.WriteLine();
     }
     if (otherEntries.Count != 0)
     {
         ISmartTextOutput smartOutput = output as ISmartTextOutput;
         if (null != smartOutput)
         {
             smartOutput.AddUIElement(
                 delegate {
                 return(new ResourceObjectTable(otherEntries, MainWindow.Instance.mainPane));
             }
                 );
         }
         output.WriteLine();
     }
 }
 private 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();
 }
Beispiel #5
0
 /// <summary>
 /// Creates a button.
 /// </summary>
 public static void AddButton(this ISmartTextOutput output, ImageSource icon, string text, RoutedEventHandler click)
 {
     output.AddUIElement(
         delegate {
         Button button   = ThemeManager.Current.CreateButton();
         button.Cursor   = Cursors.Arrow;
         button.Margin   = new Thickness(2);
         button.Padding  = new Thickness(9, 1, 9, 1);
         button.MinWidth = 73;
         if (icon != null)
         {
             button.Content = new StackPanel {
                 Orientation = Orientation.Horizontal,
                 Children    =
                 {
                     new Image     {
                         Width = 16, Height = 16, Source = icon, Margin = new Thickness(0, 0, 4, 0)
                     },
                     new TextBlock {
                         Text = text
                     }
                 }
             };
         }
         else
         {
             button.Content = text;
         }
         button.Click += click;
         return(button);
     });
 }
Beispiel #6
0
        // There are several methods available to override; in this sample, we deal with methods only

        public override void DecompileMethod(MethodDef method, ITextOutput output, DecompilationOptions options)
        {
            if (method.Body != null)
            {
                output.WriteLine(string.Format("Size of method: {0} bytes", method.Body.GetCodeSize()), TextTokenType.Text);

                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
                })
                {
                    DontShowCreateMethodBodyExceptions = options.DontShowCreateMethodBodyExceptions,
                };
                b.AddMethod(method);
                b.RunTransformations();
                output.WriteLine(string.Format("Decompiled AST has {0} nodes", b.SyntaxTree.DescendantsAndSelf.Count()), TextTokenType.Text);
            }
        }
        // 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);
                 */
            }
        }
Beispiel #8
0
 /// <summary>
 /// Creates a button.
 /// </summary>
 public static void AddButton(this ISmartTextOutput output, string text, RoutedEventHandler click)
 {
     output.AddUIElement(() => {
         var button = new Button();
         button.SetResourceReference(FrameworkElement.StyleProperty, "TextEditorButton");
         button.Content = text;
         button.Click  += click;
         return(button);
     });
 }
Beispiel #9
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();
            }
        }
        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();
            }
        }
 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();
 }
        public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
        {
            base.Decompile(language, output, options);
            if (filteredEntries.Count == 0)
            {
                return;
            }
            ISmartTextOutput smartOutput = output as ISmartTextOutput;

            if (null != smartOutput)
            {
                smartOutput.AddUIElement(
                    delegate {
                    return(new ResourceStringTable(filteredEntries));
                }
                    );
            }
            output.WriteLine();
        }
        public CSharpHighlightingTokenWriter(TokenWriter decoratedWriter, ISmartTextOutput textOutput = null, ILocatable locatable = null)
            : base(decoratedWriter)
        {
            var highlighting = HighlightingManager.Instance.GetDefinition("C#");

            this.locatable  = locatable;
            this.textOutput = textOutput;

            this.visibilityKeywordsColor    = highlighting.GetNamedColor("Visibility");
            this.namespaceKeywordsColor     = highlighting.GetNamedColor("NamespaceKeywords");
            this.structureKeywordsColor     = highlighting.GetNamedColor("Keywords");
            this.gotoKeywordsColor          = highlighting.GetNamedColor("GotoKeywords");
            this.queryKeywordsColor         = highlighting.GetNamedColor("QueryKeywords");
            this.exceptionKeywordsColor     = highlighting.GetNamedColor("ExceptionKeywords");
            this.checkedKeywordColor        = highlighting.GetNamedColor("CheckedKeyword");
            this.unsafeKeywordsColor        = highlighting.GetNamedColor("UnsafeKeywords");
            this.valueTypeKeywordsColor     = highlighting.GetNamedColor("ValueTypeKeywords");
            this.referenceTypeKeywordsColor = highlighting.GetNamedColor("ReferenceTypeKeywords");
            this.operatorKeywordsColor      = highlighting.GetNamedColor("OperatorKeywords");
            this.parameterModifierColor     = highlighting.GetNamedColor("ParameterModifiers");
            this.modifiersColor             = highlighting.GetNamedColor("Modifiers");
            this.accessorKeywordsColor      = highlighting.GetNamedColor("GetSetAddRemove");

            this.referenceTypeColor     = highlighting.GetNamedColor("ReferenceTypes");
            this.valueTypeColor         = highlighting.GetNamedColor("ValueTypes");
            this.interfaceTypeColor     = highlighting.GetNamedColor("InterfaceTypes");
            this.enumerationTypeColor   = highlighting.GetNamedColor("EnumTypes");
            this.typeParameterTypeColor = highlighting.GetNamedColor("TypeParameters");
            this.delegateTypeColor      = highlighting.GetNamedColor("DelegateTypes");
            this.methodDeclarationColor = this.methodCallColor = highlighting.GetNamedColor("MethodCall");
            //this.eventDeclarationColor = this.eventAccessColor = defaultTextColor;
            //this.propertyDeclarationColor = this.propertyAccessColor = defaultTextColor;
            this.fieldDeclarationColor = this.fieldAccessColor = highlighting.GetNamedColor("FieldAccess");
            //this.variableDeclarationColor = this.variableAccessColor = defaultTextColor;
            //this.parameterDeclarationColor = this.parameterAccessColor = defaultTextColor;
            this.valueKeywordColor      = highlighting.GetNamedColor("NullOrValueKeywords");
            this.thisKeywordColor       = highlighting.GetNamedColor("ThisOrBaseReference");
            this.trueKeywordColor       = highlighting.GetNamedColor("TrueFalse");
            this.typeKeywordsColor      = highlighting.GetNamedColor("TypeKeywords");
            this.attributeKeywordsColor = highlighting.GetNamedColor("AttributeKeywords");
            //this.externAliasKeywordColor = ...;
        }
Beispiel #15
0
 public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
 {
     EnsureChildrenFiltered();
     base.Decompile(language, output, options);
     if (stringTableEntries.Count != 0)
     {
         ISmartTextOutput smartOutput = output as ISmartTextOutput;
         if (null != smartOutput)
         {
             smartOutput.AddUIElement(
                 delegate {
                 var textView = options.DecompilerTextView;
                 if (textView != null)
                 {
                     return new ResourceStringTable(stringTableEntries, textView)
                     {
                         Cursor = Cursors.Arrow
                     }
                 }
                 ;
                 return(new TextBlock {
                     Text = "no active tab!"
                 });
             }