Exemplo n.º 1
0
 public override void Run(List<string> args)
 {
     // args[0]=v, args[1]=filename.msi
     if (args.Count < 2)
         throw new OptionException("You must specify an msi filename.", "v");
     var msiFileName = args[1];
     using (var msidb = new Database(msiFileName, OpenDatabase.ReadOnly))
     {
         const string tableName = "Property";
         var query = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM `{0}`", tableName);
         using (var view = new ViewWrapper(msidb.OpenExecuteView(query)))
         {
             foreach (var row in view.Records)
             {
                 var property = (string)row[view.ColumnIndex("Property")];
                 var value = row[view.ColumnIndex("Value")];
                 if (string.Equals("ProductVersion", property, StringComparison.InvariantCultureIgnoreCase))
                 {
                     Console.WriteLine(value);
                     return;
                 }
             }
             Console.WriteLine("Version not found!");
         }
     }
 }
Exemplo n.º 2
0
        public static TableRow[] GetRowsFromTable(Database msidb, string tableName)
        {
            if (!msidb.TableExists(tableName))
            {
                Trace.WriteLine(string.Format("Table name does {0} not exist Found.", tableName));
                return(new TableRow[0]);
            }

            var query = string.Concat("SELECT * FROM `", tableName, "`");

            using (var view = new ViewWrapper(msidb.OpenExecuteView(query)))
            {
                var /*<TableRow>*/ rows = new ArrayList(view.Records.Count);

                var columns = view.Columns;
                foreach (var values in view.Records)
                {
                    var valueCollection = new HybridDictionary(values.Length);
                    for (var cIndex = 0; cIndex < columns.Length; cIndex++)
                    {
                        valueCollection[columns[cIndex].Name] = values[cIndex];
                    }
                    rows.Add(new TableRow(valueCollection));
                }
                return((TableRow[])rows.ToArray(typeof(TableRow)));
            }
        }
Exemplo n.º 3
0
        public static TableRow[] GetRowsFromTable(Database msidb, string tableName)
        {
            if (!msidb.TableExists(tableName))
            {
                Trace.WriteLine(string.Format("Table name does {0} not exist Found.", tableName));
                return new TableRow[0];
            }

            string query = string.Concat("SELECT * FROM `", tableName, "`");
            using (var view = new ViewWrapper(msidb.OpenExecuteView(query)))
            {
                var /*<TableRow>*/ rows = new ArrayList(view.Records.Count);

                ColumnInfo[] columns = view.Columns;
                foreach (object[] values in view.Records)
                {
                    HybridDictionary valueCollection = new HybridDictionary(values.Length);
                    for (int cIndex = 0; cIndex < columns.Length; cIndex++)
                    {
                        valueCollection[columns[cIndex].Name] = values[cIndex];
                    }
                    rows.Add(new TableRow(valueCollection));
                }
                return (TableRow[]) rows.ToArray(typeof(TableRow));
            }
        }
Exemplo n.º 4
0
        public override void Run(List<string> args)
        {
            /* examples:
             *	lessmsi l -t Component c:\theinstall.msi
             *	lessmsi l -t Property c:\theinstall.msi
            */
            args = args.Skip(1).ToList();
            var tableName = "";
            var options = new OptionSet {
                { "t=", "Specifies the table to list.", t => tableName = t }
            };
            var extra = options.Parse(args);
            if (extra.Count < 1)
                throw new OptionException("You must specify the msi file to list from.", "l");
            if (string.IsNullOrEmpty(tableName))
                throw new OptionException("You must specify the table name to list.", "t");

            var csv = new StringBuilder();
            Debug.Print("Opening msi file '{0}'.", extra[0]);
            using (var msidb = new Database(extra[0], OpenDatabase.ReadOnly))
            {
                Debug.Print("Opening table '{0}'.", tableName);
                var query = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM `{0}`", tableName);
                using (var view = new ViewWrapper(msidb.OpenExecuteView(query)))
                {
                    for (var index = 0; index < view.Columns.Length; index++)
                    {
                        var col = view.Columns[index];
                        if (index > 0)
                            csv.Append(',');
                        csv.Append(col.Name);
                    }
                    csv.AppendLine();
                    foreach (var row in view.Records)
                    {
                        for (var colIndex = 0; colIndex < row.Length; colIndex++)
                        {
                            if (colIndex > 0)
                                csv.Append(',');
                            var val = Convert.ToString(row[colIndex], CultureInfo.InvariantCulture);
                            var newLine = Environment.NewLine;
                            string[] requireEscapeChars = { ",", newLine };
                            Array.ForEach(requireEscapeChars, s => {
                                if (val.Contains(s))
                                    val = "\"" + val + "\"";
                            });
                            csv.Append(val);
                        }
                        csv.AppendLine();
                    }
                }
            }
            Console.Write(csv.ToString());
        }
Exemplo n.º 5
0
        public void Decompile(string decompilePath)
        {
            try {
                var allTableNames = new string[]
                {
                    #region Hard Coded Table Names
                    //FYI: This list is from http://msdn.microsoft.com/en-us/library/2k3te2cs%28VS.100%29.aspx
                    "ActionText",
                    "AdminExecuteSequence ",
                    "AdminUISequence",
                    "AdvtExecuteSequence",
                    "AdvtUISequence",
                    "AppId",
                    "AppSearch",
                    "BBControl",
                    "Billboard",
                    "Binary",
                    "BindImage",
                    "CCPSearch",
                    "CheckBox",
                    "Class",
                    "ComboBox",
                    "CompLocator",
                    "Complus",
                    "Component",
                    "Condition",
                    "Control",
                    "ControlCondition",
                    "ControlEvent",
                    "CreateFolder",
                    "CustomAction",
                    "Dialog",
                    "Directory",
                    "DrLocator",
                    "DuplicateFile",
                    "Environment",
                    "Error",
                    "EventMapping",
                    "Extension",
                    "Feature",
                    "FeatureComponents",
                    "File",
                    "FileSFPCatalog",
                    "Font",
                    "Icon",
                    "IniFile",
                    "IniLocator",
                    "InstallExecuteSequence",
                    "InstallUISequence",
                    "IsolatedComponent",
                    "LaunchCondition",
                    "ListBox",
                    "ListView",
                    "LockPermissions",
                    "Media",
                    "MIME",
                    "MoveFile",
                    "MsiAssembly",
                    "MsiAssemblyName",
                    "MsiDigitalCertificate",
                    "MsiDigitalSignature",
                    "MsiEmbeddedChainer",
                    "MsiEmbeddedUI",
                    "MsiFileHash",
                    "MsiLockPermissionsEx Table",
                    "MsiPackageCertificate",
                    "MsiPatchCertificate",
                    "MsiPatchHeaders",
                    "MsiPatchMetadata",
                    "MsiPatchOldAssemblyName",
                    "MsiPatchOldAssemblyFile",
                    "MsiPatchSequence",
                    "MsiServiceConfig",
                    "MsiServiceConfigFailureActions",
                    "MsiSFCBypass",
                    "ODBCAttribute",
                    "ODBCDataSource",
                    "ODBCDriver",
                    "ODBCSourceAttribute",
                    "ODBCTranslator",
                    "Patch",
                    "PatchPackage",
                    "ProgId",
                    "Property",
                    "PublishComponent",
                    "RadioButton",
                    "Registry",
                    "RegLocator",
                    "RemoveFile",
                    "RemoveIniFile",
                    "RemoveRegistry",
                    "ReserveCost",
                    "SelfReg",
                    "ServiceControl",
                    "ServiceInstall",
                    "SFPCatalog",
                    "Shortcut",
                    "Signature",
                    "TextStyle",
                    "TypeLib",
                    "UIText",
                    "Verb",
                    "_Validation",
                    "_Columns",
                    "_Streams",
                    "_Storages",
                    "_Tables",
                    "_TransformView Table",
                    "Upgrade"
                    #endregion
                };

                var systemTables = new string[]
                {
                    "_Validation",
                    "_Columns",
                    "_Streams",
                    "_Storages",
                    "_Tables",
                    "_TransformView Table"
                };

                IEnumerable <string> msiTableNames = allTableNames;

                using (var msidb = new Database(msiPackage, OpenDatabase.ReadOnly)) {
                    var query = "SELECT * FROM `_Columns`";
                    using (var msiTable = new ViewWrapper(msidb.OpenExecuteView(query))) {
                        var tableNames = from record in msiTable.Records
                                         select record[0] as string;
                        //NOTE: system tables are not usually in the _Tables table.
                        var tempList = tableNames.ToList();
                        //tempList.AddRange(systemTables);
                        msiTableNames = tempList.ToArray();
                    }
                }
            }

            //var decompiler = new Microsoft.Tools.WindowsInstallerXml.Decompiler(d);
            //decompiler.Decompile(msiPackage, decompilePath);

            catch (Exception ex) {
                var stEx = ex.Message;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Shows the table in the list on the view table tab.
        /// </summary>
        /// <param name="msidb">The msi database.</param>
        /// <param name="tableName">The name of the table.</param>
        private void UpdateMSiTableGrid(Database msidb, string tableName)
        {
            if (msidb == null || string.IsNullOrEmpty(tableName))
                return;

            Status(string.Concat("Processing Table \'", tableName, "\'."));

            using (new DisposableCursor(View))
            {   // clear the columns no matter what happens (in the event the table doesn't exist we don't want to show anything).
                View.ClearTableViewGridColumns();
                try
                {
                    // NOTE: Deliberately not calling msidb.TableExists here as some System tables could not be read due to using it.
                    string query = string.Concat("SELECT * FROM `", tableName, "`");

                    using (var view = new ViewWrapper(msidb.OpenExecuteView(query)))
                    {
                        foreach (ColumnInfo col in view.Columns)
                        {
                            View.AddTableViewGridColumn(string.Concat(col.Name, " (", col.TypeID, ")"));
                        }
                        View.SetTableViewGridDataSource(view.Records);
                    }
                    Status("Idle");
                }
                catch (Exception eUnexpected)
                {
                    Error(string.Concat("Cannot view table:", eUnexpected.Message), eUnexpected);
                }
            }
        }
Exemplo n.º 7
0
        public void LoadTables()
        {
            var allTableNames = new string[]
            {
                #region Hard Coded Table Names
                //FYI: This list is from http://msdn.microsoft.com/en-us/library/2k3te2cs%28VS.100%29.aspx
                "ActionText",
                "AdminExecuteSequence ",
                "AdminUISequence",
                "AdvtExecuteSequence",
                "AdvtUISequence",
                "AppId",
                "AppSearch",
                "BBControl",
                "Billboard",
                "Binary",
                "BindImage",
                "CCPSearch",
                "CheckBox",
                "Class",
                "ComboBox",
                "CompLocator",
                "Complus",
                "Component",
                "Condition",
                "Control",
                "ControlCondition",
                "ControlEvent",
                "CreateFolder",
                "CustomAction",
                "Dialog",
                "Directory",
                "DrLocator",
                "DuplicateFile",
                "Environment",
                "Error",
                "EventMapping",
                "Extension",
                "Feature",
                "FeatureComponents",
                "File",
                "FileSFPCatalog",
                "Font",
                "Icon",
                "IniFile",
                "IniLocator",
                "InstallExecuteSequence",
                "InstallUISequence",
                "IsolatedComponent",
                "LaunchCondition",
                "ListBox",
                "ListView",
                "LockPermissions",
                "Media",
                "MIME",
                "MoveFile",
                "MsiAssembly",
                "MsiAssemblyName",
                "MsiDigitalCertificate",
                "MsiDigitalSignature",
                "MsiEmbeddedChainer",
                "MsiEmbeddedUI",
                "MsiFileHash",
                "MsiLockPermissionsEx Table",
                "MsiPackageCertificate",
                "MsiPatchCertificate",
                "MsiPatchHeaders",
                "MsiPatchMetadata",
                "MsiPatchOldAssemblyName",
                "MsiPatchOldAssemblyFile",
                "MsiPatchSequence",
                "MsiServiceConfig",
                "MsiServiceConfigFailureActions",
                "MsiSFCBypass",
                "ODBCAttribute",
                "ODBCDataSource",
                "ODBCDriver",
                "ODBCSourceAttribute",
                "ODBCTranslator",
                "Patch",
                "PatchPackage",
                "ProgId",
                "Property",
                "PublishComponent",
                "RadioButton",
                "Registry",
                "RegLocator",
                "RemoveFile",
                "RemoveIniFile",
                "RemoveRegistry",
                "ReserveCost",
                "SelfReg",
                "ServiceControl",
                "ServiceInstall",
                "SFPCatalog",
                "Shortcut",
                "Signature",
                "TextStyle",
                "TypeLib",
                "UIText",
                "Verb",
                "_Validation",
                "_Columns",
                "_Streams",
                "_Storages",
                "_Tables",
                "_TransformView Table",
                "Upgrade"
                #endregion
            };

            var systemTables = new string[]
            {
                "_Validation",
                "_Columns",
                "_Streams",
                "_Storages",
                "_Tables",
                "_TransformView Table"
            };

            IEnumerable<string> msiTableNames = allTableNames;

            using (var msidb = new Database(View.SelectedMsiFile.FullName, OpenDatabase.ReadOnly))
            {
                using (new DisposableCursor(View))
                {
                    try
                    {
                        Status("Loading list of tables...");
                        var query = "SELECT * FROM `_Tables`";
                        using (var msiTable = new ViewWrapper(msidb.OpenExecuteView(query)))
                        {
                            var tableNames = from record in msiTable.Records
                                select record[0] as string;
                            //NOTE: system tables are not usually in the _Tables table.
                            var tempList = tableNames.ToList();
                            tempList.AddRange(systemTables);
                            msiTableNames = tempList.ToArray();
                        }

                        Status("");
                    }
                    catch (Exception e)
                    {
                        Status(e.Message);
                    }

                    View.cboTable.Items.Clear();
                    View.cboTable.Items.AddRange(msiTableNames.ToArray());
                    View.cboTable.SelectedIndex = 0;
                }
            }
        }