/// <summary>
        /// "Decompiles" the data
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="stream">Stream</param>
        /// <param name="name">Name</param>
        /// <returns></returns>
        public static bool Decompile(IDecompileNodeContext context, Stream stream, string name)
        {
            if (stream == null || stream.Length > 500 * 1024)
            {
                return(false);
            }

            stream.Position = 0;
            FileType type = GuessFileType.DetectFileType(stream);

            if (type == FileType.Binary)
            {
                return(false);
            }

            stream.Position = 0;
            context.Output.Write(new StreamReader(stream, true).ReadToEnd(), BoxedTextColor.Text);
            string ext;

            if (type == FileType.Xml)
            {
                ext = ".xml";
            }
            else
            {
                try {
                    ext = Path.GetExtension(NameUtilities.CleanName(name));
                }
                catch (ArgumentException) {
                    ext = ".txt";
                }
            }
            context.ContentTypeString = ContentTypesHelper.TryGetContentTypeStringByExtension(ext) ?? ContentTypes.PlainText;
            return(true);
        }
Exemple #2
0
        /// <inheritdoc/>
        public virtual void WriteShort(IDecompilerOutput output, IDecompiler decompiler, bool showOffset)
        {
            decompiler.WriteCommentBegin(output, true);
            output.WriteOffsetComment(this, showOffset);
            const string LTR = "\u200E";

            output.Write(NameUtilities.CleanName(Name) + LTR, this, DecompilerReferenceFlags.Local | DecompilerReferenceFlags.Definition, BoxedTextColor.Comment);
            string extra = null;

            switch (Resource.ResourceType)
            {
            case ResourceType.AssemblyLinked:
                extra = ((AssemblyLinkedResource)Resource).Assembly.FullName;
                break;

            case ResourceType.Linked:
                var file = ((LinkedResource)Resource).File;
                extra = string.Format("{0}, {1}, {2}", file.Name, file.ContainsNoMetaData ? "ContainsNoMetaData" : "ContainsMetaData", SimpleTypeConverter.ByteArrayToString(file.HashValue));
                break;

            case ResourceType.Embedded:
                extra = string.Format(dnSpy_Contracts_DnSpy_Resources.NumberOfBytes, ((EmbeddedResource)Resource).Data.Length);
                break;
            }
            output.Write(string.Format(" ({0}{1}, {2})", extra == null ? string.Empty : string.Format("{0}, ", extra), Resource.ResourceType, Resource.Attributes), BoxedTextColor.Comment);
            decompiler.WriteCommentEnd(output, true);
            output.WriteLine();
        }
Exemple #3
0
 void DecompileUnknown(DocumentTreeNodeData node)
 {
     if (node is IDecompileSelf decompileSelf && !(decompileNodeContext is null))
     {
         if (decompileSelf.Decompile(decompileNodeContext))
         {
             return;
         }
     }
     decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ToString(decompiler)));
 }
Exemple #4
0
        /// <inheritdoc/>
        public virtual void WriteShort(IDecompilerOutput output, IDecompiler decompiler, bool showOffset)
        {
            decompiler.WriteCommentBegin(output, true);
            output.WriteOffsetComment(this, showOffset);
            const string LTR = "\u200E";

            output.Write(NameUtilities.CleanName(Name) + LTR, this, DecompilerReferenceFlags.Local | DecompilerReferenceFlags.Definition, BoxedTextColor.Comment);
            output.Write($" = {ValueString}", BoxedTextColor.Comment);
            decompiler.WriteCommentEnd(output, true);
            output.WriteLine();
        }
Exemple #5
0
        void DecompileUnknown(DocumentTreeNodeData node)
        {
            var decompileSelf = node as IDecompileSelf;

            if (decompileSelf != null && decompileNodeContext != null)
            {
                if (decompileSelf.Decompile(decompileNodeContext))
                {
                    return;
                }
            }
            decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ToString(decompiler)));
        }
Exemple #6
0
        /// <summary>
        /// Writes a file
        /// </summary>
        /// <param name="output">Output</param>
        /// <param name="decompiler">Decompiler</param>
        /// <param name="document">Document</param>
        public void Write(ITextColorWriter output, IDecompiler decompiler, IDsDocument document)
        {
            var filename = GetFilename(document);
            var peImage  = document.PEImage;

            if (peImage != null)
            {
                output.Write(IsExe(peImage) ? BoxedTextColor.AssemblyExe : BoxedTextColor.Assembly, NameUtilities.CleanName(filename));
            }
            else
            {
                output.Write(BoxedTextColor.Text, NameUtilities.CleanName(filename));
            }
        }
Exemple #7
0
        /// <summary>
        /// Writes a file
        /// </summary>
        /// <param name="output">Output</param>
        /// <param name="language">Language</param>
        /// <param name="file">File</param>
        public void Write(ITextColorWriter output, ILanguage language, IDnSpyFile file)
        {
            var filename = GetFilename(file);
            var peImage  = file.PEImage;

            if (peImage != null)
            {
                output.Write(IsExe(peImage) ? BoxedTextColor.AssemblyExe : BoxedTextColor.Assembly, NameUtilities.CleanName(filename));
            }
            else
            {
                output.Write(BoxedTextColor.Text, NameUtilities.CleanName(filename));
            }
        }
        public override void WriteShort(IDecompilerOutput output, IDecompiler decompiler, bool showOffset)
        {
            if (output is IDocumentViewerOutput documentViewerOutput)
            {
                decompiler.WriteCommentBegin(output, true);
                output.WriteOffsetComment(this, showOffset);
                documentViewerOutput.AddUIElement(() => {
                    return(new System.Windows.Controls.Image {
                        Source = imageSource,
                    });
                });
                output.Write(" = ", BoxedTextColor.Comment);
                const string LTR = "\u200E";
                output.Write(NameUtilities.CleanName(Name) + LTR, this, DecompilerReferenceFlags.Local | DecompilerReferenceFlags.Definition, BoxedTextColor.Comment);
                decompiler.WriteCommentEnd(output, true);
                output.WriteLine();
                return;
            }

            base.WriteShort(output, decompiler, showOffset);
        }
Exemple #9
0
 void Decompile(ModuleReferenceNode node) => decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.ModuleRef.ToString()));
Exemple #10
0
 void Decompile(DerivedTypeNode node) => decompiler.WriteCommentLine(output, NameUtilities.CleanName(node.TypeDef.ReflectionFullName));
Exemple #11
0
 /// <summary>
 /// Escapes text for <see cref="MenuItem"/> headers
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static string EscapeMenuItemHeader(string s) => NameUtilities.CleanName(s) !.Replace("_", "__");
 /// <remarks>
 /// TODO: Use UIUtilities.EscapeMenuItemHeader, see 0xd4d/dnSpy#1201
 /// </remarks>
 public override string GetHeader(IMenuItemContext context) => NameUtilities
 .CleanName($"{Path.GetFileName(injectionArguments.Path)} {injectionArguments.TypeFull}.{injectionArguments.Method}({Quote(injectionArguments.Argument) ?? "null"})")
 .Replace("_", "__");
Exemple #13
0
 void Decompile(IBaseTypeNode node) => language.WriteCommentLine(output, NameUtilities.CleanName(node.TypeDefOrRef.ReflectionFullName));
Exemple #14
0
 void Decompile(IAssemblyReferenceNode node) => language.WriteCommentLine(output, NameUtilities.CleanName(node.AssemblyRef.ToString()));