Esempio n. 1
0
        /// <summary>
        /// Extracts files from an MSI database and rewrites the paths embedded in the source .wixpdb to the output .wixpdb.
        /// </summary>
        private void MeltProduct()
        {
            // print friendly message saying what file is being decompiled
            Console.WriteLine("{0} / {1}", Path.GetFileName(this.inputFile), Path.GetFileName(this.inputPdbFile));

            // extract files from the .msi (unless suppressed) and get the path map of File ids to target paths
            string outputDirectory = this.exportBasePath ?? Environment.GetEnvironmentVariable("WIX_TEMP");
            IDictionary<string, string> paths = null;
            using (InstallPackage package = new InstallPackage(this.inputFile, DatabaseOpenMode.ReadOnly, null, outputDirectory))
            {
                if (!this.suppressExtraction)
                {
                    package.ExtractFiles();
                }

                paths = package.Files.SourcePaths;
            }

            Pdb inputPdb = Pdb.Load(this.inputPdbFile, true, true);
            Table wixFileTable = inputPdb.Output.Tables["WixFile"];
            if (null != wixFileTable)
            {
                foreach (Row row in wixFileTable.Rows)
                {
                    WixFileRow fileRow = row as WixFileRow;
                    if (null != fileRow)
                    {
                        string newPath;
                        if (paths.TryGetValue(fileRow.File, out newPath))
                        {
                            fileRow.Source = Path.Combine(outputDirectory, newPath);
                        }
                    }
                }
            }

            string tempPath = Path.Combine(Environment.GetEnvironmentVariable("WIX_TEMP") ?? Path.GetTempPath(), Path.GetRandomFileName());
            try
            {
                inputPdb.Save(this.outputFile, null, null, tempPath);
            }
            finally
            {
                if (this.tidy)
                {
                    if (!AppCommon.DeleteDirectory(tempPath, this.messageHandler))
                    {
                        Console.WriteLine(MeltStrings.WAR_FailedToDeleteTempDir, tempPath);
                    }
                }
                else
                {
                    Console.WriteLine(MeltStrings.INF_TempDirLocatedAt, tempPath);
                }
            }
        }
Esempio n. 2
0
	public static int Main(string[] args)
	{
		if(!(args.Length == 2 || args.Length == 3))
		{
			Usage(Console.Out);
			return -1;
		}

		string msiFile = args[0];

		string option = args[1].ToLowerInvariant();
		if(option.StartsWith("-", StringComparison.Ordinal)) option = "/" + option.Substring(1);

		string[] fileNames = null;
		if(args.Length == 3)
		{
			fileNames = args[2].Split(',');
		}

		try
		{
			switch(option)
			{
				case "/l":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.ReadOnly))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
						IEnumerable<string> fileKeys = (fileNames != null ? FindFileKeys(pkg, fileNames) : pkg.Files.Keys);

						foreach(string fileKey in fileKeys)
						{
							Console.WriteLine(pkg.Files[fileKey]);
						}
					}
					break;

				case "/x":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.ReadOnly))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
						ICollection<string> fileKeys = FindFileKeys(pkg, fileNames);

						pkg.ExtractFiles(fileKeys);
					}
					break;

				case "/u":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.Transact))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
                        ICollection<string> fileKeys = FindFileKeys(pkg, fileNames);

						pkg.UpdateFiles(fileKeys);
						pkg.Commit();
					}
					break;

				default:
                    Usage(Console.Out);
					return -1;
			}
		}
		catch(InstallerException iex)
		{
			Console.WriteLine("Error: " + iex.Message);
			return iex.ErrorCode != 0 ? iex.ErrorCode : 1;
		}
		catch(FileNotFoundException fnfex)
		{
			Console.WriteLine(fnfex.Message);
			return 2;
		}
		catch(Exception ex)
		{
			Console.WriteLine("Error: " + ex.Message);
			return 1;
		}
		return 0;
	}
Esempio n. 3
0
        /// <summary>
        /// Extracts files from an MSI database and rewrites the paths embedded in the source .wixpdb to the output .wixpdb.
        /// </summary>
        private void MeltProduct()
        {
            // print friendly message saying what file is being decompiled
            Console.WriteLine(Path.GetFileName(this.inputFile), "/", Path.GetFileName(this.inputPdbFile));

            // extract files from the .msi and get the path map of File ids to target paths
            string outputDirectory = this.exportBasePath ?? Environment.GetEnvironmentVariable("WIX_TEMP");
            IDictionary<string, string> paths = null;
            using (InstallPackage package = new InstallPackage(this.inputFile, DatabaseOpenMode.ReadOnly, null, outputDirectory))
            {
                package.ExtractFiles();
                paths = package.Files.SourcePaths;
            }

            Pdb inputPdb = Pdb.Load(this.inputPdbFile, true, true);
            if (null != inputPdb)
            {
                Table wixFileTable = inputPdb.Output.Tables["WixFile"];
                if (null != wixFileTable)
                {
                    foreach (Row row in wixFileTable.Rows)
                    {
                        WixFileRow fileRow = row as WixFileRow;
                        if (null != fileRow)
                        {
                            string newPath;
                            if (paths.TryGetValue(fileRow.File, out newPath))
                            {
                                fileRow.Source = Path.Combine(outputDirectory, newPath);
                            }
                        }
                    }
                }

                inputPdb.Save(this.outputFile, null, null, outputDirectory);
            }
        }