Beispiel #1
0
 private void CheckArchiveCrc()
 {
     if (IgnoreCrc == false)
     {
         CreateDirectory(_archivePath);
         string descriptionFile = _name + XMLEXTENSION;
         _cabInfo.ExtractAll(_archivePath, true, null, null);
         _xmlDoc.Load(Path.Combine(_archivePath, descriptionFile));
         string      storedCrc   = _xmlDoc.DocumentElement.Attributes[CRC].Value;
         XmlNodeList entryList   = _xmlDoc.SelectNodes("*/" + ENTRY);
         XmlNodeList archiveList = _xmlDoc.SelectNodes("*/" + ARCHIVE);
         string[]    files       = new string[entryList.Count + archiveList.Count];
         int         index       = 0;
         for (index = 0; index < entryList.Count; index++)
         {
             files[index] = Path.Combine(_archivePath, entryList[index].Attributes[NAME].Value);
         }
         for (int t = 0; t < archiveList.Count; t++)
         {
             files[index + t] = Path.Combine(_archivePath, archiveList[t].Attributes[NAME].Value);
         }
         string actualCrc = CompFileCrc(files);
         if (storedCrc != actualCrc)
         {
             throw new CryptographicException("CRC does not match, file has been tampered with !");
         }
     }
 }
Beispiel #2
0
        public static string ExtractMediaStream(Database msiDb)
        {
            string tempFileName = Path.GetTempFileName();
            string tempFolder   = GetTempFolder(tempFileName);
            string filePath     = Path.ChangeExtension(tempFileName, ".cab");
            string str4         = (string)msiDb.ExecuteScalar("SELECT `Cabinet` FROM `Media` WHERE `DiskId` = {0}", new object[] { 1 });

            using (View view = msiDb.OpenView("SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = '{0}'", new object[] { str4.Substring(1) }))
            {
                view.Execute();
                Record record = view.Fetch();
                if (record == null)
                {
                    throw new InstallerException("Stream not found: " + str4);
                }
                using (record)
                {
                    record.GetStream("Data", filePath);
                }
            }
            CabinetInfo info = new CabinetInfo(filePath);

            info.ExtractAll(tempFolder);
            info.Delete();
            return(tempFolder);
        }