示例#1
0
        private static XmlDocument GetXmlDocument(string path)
        {
            using (Stream s = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                byte[] buffer = new byte[2];
                s.Read(buffer, 0, 2);
                s.Position = 0;
                XmlDocument       document   = new XmlDocument();
                XmlReaderSettings xrSettings = new XmlReaderSettings();
                xrSettings.DtdProcessing = DtdProcessing.Ignore;
                // if first two bytes are "MZ" then we're looking at an .exe or a .dll not a .manifest
                if ((buffer[0] == 0x4D) && (buffer[1] == 0x5A))
                {
                    Stream m = EmbeddedManifestReader.Read(path);
                    if (m == null)
                    {
                        throw new BadImageFormatException(null, path);
                    }

                    using (XmlReader xr = XmlReader.Create(m, xrSettings))
                    {
                        document.Load(xr);
                    }
                }
                else
                {
                    using (XmlReader xr = XmlReader.Create(s, xrSettings))
                    {
                        document.Load(xr);
                    }
                }

                return(document);
            }
        }
示例#2
0
 public static bool IsNativeAssembly(string path)
 {
     if (String.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path));
     }
     if (String.Equals(Path.GetExtension(path), ".manifest", StringComparison.Ordinal))
     {
         return(true);
     }
     return(EmbeddedManifestReader.Read(path) != null);
 }
示例#3
0
        private static Manifest ReadEmbeddedManifest(string path)
        {
            Stream s = EmbeddedManifestReader.Read(path);

            if (s == null)
            {
                return(null);
            }
            Util.WriteLogFile(Path.GetFileNameWithoutExtension(path) + ".embedded.xml", s);
            Manifest manifest = ReadManifest(s, false);

            manifest.SourcePath = path;
            return(manifest);
        }
 public static Stream Read(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal))
     {
         return null;
     }
     int tickCount = Environment.TickCount;
     EmbeddedManifestReader reader = new EmbeddedManifestReader(path);
     Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", new object[] { Environment.TickCount - tickCount }));
     return reader.manifest;
 }
        public static Stream Read(string path)
        {
            if (path == null) throw new ArgumentNullException("path");

            if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal))
            {
                // Everything that does not end with .dll or .manifest is not a valid native assembly (this includes
                //    EXEs with ID1 manifest)
                return null;
            }

            int t1 = Environment.TickCount;
            EmbeddedManifestReader r = new EmbeddedManifestReader(path);
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", Environment.TickCount - t1));
            return r._manifest;
        }
        public static Stream Read(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal))
            {
                return(null);
            }
            int tickCount = Environment.TickCount;
            EmbeddedManifestReader reader = new EmbeddedManifestReader(path);

            Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", new object[] { Environment.TickCount - tickCount }));
            return(reader.manifest);
        }
示例#7
0
        /// <summary>
        /// Obtains identity of the specified native assembly.
        /// File must be either a PE with an embedded xml manifest, or a stand-alone xml manifest file.
        /// Returns null if identity could not be obtained.
        /// </summary>
        /// <param name="path">The name of the file from which the identity is to be obtained.</param>
        /// <returns>The assembly identity of the specified file.</returns>
        public static AssemblyIdentity FromNativeAssembly(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            if (PathUtil.IsPEFile(path))
            {
                Stream m = EmbeddedManifestReader.Read(path);
                if (m == null)
                {
                    return(null);
                }
                return(FromManifest(m));
            }
            return(FromManifest(path));
        }
        public static Stream Read(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal))
            {
                // Everything that does not end with .dll or .manifest is not a valid native assembly (this includes
                //    EXEs with ID1 manifest)
                return(null);
            }

            int t1 = Environment.TickCount;
            EmbeddedManifestReader r = new EmbeddedManifestReader(path);

            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", Environment.TickCount - t1));
            return(r._manifest);
        }
示例#9
0
 private static XmlDocument GetXmlDocument(string path)
 {
     using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         byte[] buffer = new byte[2];
         stream.Read(buffer, 0, 2);
         stream.Position = 0L;
         if ((buffer[0] == 0x4d) && (buffer[1] == 90))
         {
             Stream inStream = EmbeddedManifestReader.Read(path);
             if (inStream == null)
             {
                 throw new BadImageFormatException(null, path);
             }
             XmlDocument document = new XmlDocument();
             document.Load(inStream);
             return(document);
         }
         XmlDocument document2 = new XmlDocument();
         document2.Load(stream);
         return(document2);
     }
 }