Ejemplo n.º 1
0
        public void SaveSpreadsheet(Stream outputStream, Stream backgroundImage, ushort backgroundImageWidth, ushort backgroundImageHeight)
        {
            CompleteCurrentWorksheet();
            m_worksheet    = null;
            m_worksheetOut = null;
            Stream       stream       = m_createTempStream("Workbook");
            BinaryWriter binaryWriter = new BinaryWriter(stream, Encoding.Unicode);
            List <long>  list         = WriteGlobalStream(binaryWriter);
            bool         isFirstPage  = true;

            for (int i = 0; i < m_worksheets.Count; i++)
            {
                WorksheetInfo worksheetInfo = m_worksheets[i];
                worksheetInfo.ResolveCellReferences(m_bookmarks);
                worksheetInfo.Write(binaryWriter, isFirstPage, m_createTempStream, backgroundImage, backgroundImageWidth, backgroundImageHeight);
                isFirstPage = false;
            }
            for (int j = 0; j < list.Count; j++)
            {
                stream.Seek(list[j] + 4, SeekOrigin.Begin);
                binaryWriter.Write((uint)m_worksheets[j].BOFStartOffset);
            }
            m_worksheets = null;
            stream.Flush();
            stream.Seek(0L, SeekOrigin.Begin);
            StructuredStorage.CreateSingleStreamFile(stream, "Workbook", "00020820-0000-0000-c000-000000000046", outputStream, forceInMemory: false);
            stream.Close();
            stream = null;
            outputStream.Flush();
        }
Ejemplo n.º 2
0
        public override SignatureVerificationResult VerifySignature(string path, string parent)
        {
            // Defer to the base class to check the AuthentiCode signature
            SignatureVerificationResult svr = base.VerifySignature(path, parent);

            if (VerifyRecursive)
            {
                StructuredStorage.OpenAndExtractStorages(path, svr.TempPath);

                foreach (string file in Directory.EnumerateFiles(svr.TempPath))
                {
                    svr.NestedResults.Add(VerifyFile(file, svr.Filename, containerPath: null));
                }

                DeleteDirectory(svr.TempPath);
            }

            return(svr);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Worker thread that actually performs the file generation
        /// </summary>
        void WorkerThread()
        {
            string destFile = m_destinationFile.Text;

            // Set up the necessary delegates we need to invoke methods on the main thread

            WorkerExceptionHandler onException = new WorkerExceptionHandler(WorkerException);
            WorkerFinishedHandler  onFinished  = new WorkerFinishedHandler(WorkerFinished);
            WorkerProgressHandler  onProgress  = new WorkerProgressHandler(WorkerProgress);

            try
            {
                // Attempt to create/replace the main structured storage file.  Notice the
                // completely meaningless pause for dramatic effect

                Invoke(onProgress, new object[] { "Creating the Virtual File System structured storage file" });
                Thread.Sleep(500);

                using (StructuredStorage storage = StructuredStorage.Open(destFile, StorageOpenMode.Create, StorageAccessMode.Exclusive))
                {
                    // If the user did not elect to filter out non-virtualizable ASP.NET stuff,
                    // we can just rip and roar through this without any additional work. Otherwise
                    // use the special case handler for exclusing root items from the VFS

                    if (!m_excludeCommon.Checked)
                    {
                        ProcessStorageFolder(m_sourceFolder.Text, storage, onProgress);
                    }
                    else
                    {
                        ProcessRootStorageFolderSpecial(m_sourceFolder.Text, storage, onProgress);
                    }
                }

                Invoke(onProgress, new object[] { "The Virtual File System was generated successfully" });
                Invoke(onFinished);
            }

            catch (ThreadAbortException)
            {
                // If the thread is aborting, that means the form was closed while the
                // process was still active.  Just nuke the file and exit the thread

                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }
            }

            catch (Exception exception)
            {
                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }

                // Standard exceptions get pumped back into the main thread to be
                // reported. Also invoke the finish handler since I'm not really
                // spending a lot of time making this a top-notch application :)

                Invoke(onException, new object[] { exception });
                Invoke(onProgress, new object[] { "The Virtual File System could not be generated" });
                Invoke(onFinished);
            }
        }
Ejemplo n.º 4
0
        public override SignatureVerificationResult VerifySignature(string path, string parent, string virtualPath)
        {
            SignatureVerificationResult svr = base.VerifySignature(path, parent, virtualPath);

            if (VerifyRecursive)
            {
                CreateDirectory(svr.TempPath);

                // TODO: Fix for MSIs with external CABs that are not present.
                using (var installPackage = new InstallPackage(svr.FullPath, DatabaseOpenMode.Transact, sourceDir: null, workingDir: svr.TempPath))
                {
                    InstallPathMap files         = installPackage.Files;
                    var            originalFiles = new Dictionary <string, string>();

                    // Flatten the files to avoid path too long errors. We use the File column and extension to create a unique file
                    // and record the original, relative MSI path in the result.
                    foreach (string key in installPackage.Files.Keys)
                    {
                        originalFiles[key] = installPackage.Files[key].TargetPath;
                        string name       = key + Path.GetExtension(installPackage.Files[key].TargetName);
                        string targetPath = Path.Combine(svr.TempPath, name);
                        installPackage.Files[key].TargetName = name;
                        installPackage.Files[key].SourceName = name;
                        installPackage.Files[key].SourcePath = targetPath;
                        installPackage.Files[key].TargetPath = targetPath;
                    }

                    try
                    {
                        Log.WriteMessage(LogVerbosity.Diagnostic, SignCheckResources.DiagExtractingFileContents, svr.TempPath);
                        installPackage.ExtractFiles(installPackage.Files.Keys);

                        foreach (string key in installPackage.Files.Keys)
                        {
                            SignatureVerificationResult packageFileResult = VerifyFile(installPackage.Files[key].TargetPath, svr.Filename, Path.Combine(svr.VirtualPath, originalFiles[key]), containerPath: null);
                            packageFileResult.AddDetail(DetailKeys.File, SignCheckResources.DetailFullName, originalFiles[key]);
                            svr.NestedResults.Add(packageFileResult);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.WriteError(e.Message);
                    }
                }

                // Extract files from the Binary table - this is where items such as custom actions are stored.
                try
                {
                    using (var installDatabase = new Database(svr.FullPath, DatabaseOpenMode.ReadOnly))
                        using (View view = installDatabase.OpenView("SELECT `Name`, `Data` FROM `Binary`"))
                        {
                            view.Execute();

                            foreach (Record record in view)
                            {
                                string binaryFile     = (string)record["Name"];
                                string binaryFilePath = Path.Combine(svr.TempPath, binaryFile);
                                StructuredStorage.SaveStream(record, svr.TempPath);
                                SignatureVerificationResult binaryStreamResult = VerifyFile(binaryFilePath, svr.Filename, Path.Combine(svr.VirtualPath, binaryFile), containerPath: null);
                                binaryStreamResult.AddDetail(DetailKeys.Misc, SignCheckResources.FileExtractedFromBinaryTable);
                                svr.NestedResults.Add(binaryStreamResult);
                                record.Close();
                            }
                        }
                }
                catch (Exception e)
                {
                    Log.WriteError(e.Message);
                }

                DeleteDirectory(svr.TempPath);
            }

            return(svr);
        }