Ejemplo n.º 1
0
        public static RegChange ReadFromStream(Stream fs)
        {
            RegChange tempReg = new RegChange();

            bool isBinaryString = false;

            byte bType = (byte)fs.ReadByte();

            //read until the end byte is detected
            while (!ReadFiles.ReachedEndByte(fs, bType, 0x9E))
            {
                switch (bType)
                {
                case 0x01:    //RegOperation
                    tempReg.RegOperation = (RegOperations)ReadFiles.ReadInt(fs);
                    break;

                case 0x02:    //load basekey
                    tempReg.RegBasekey = (RegBasekeys)ReadFiles.ReadInt(fs);
                    break;

                case 0x03:    //load valuekind
                    tempReg.RegValueKind = (RegistryValueKind)ReadFiles.ReadInt(fs);
                    break;

                case 0x04:    //subkey
                    tempReg.SubKey = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x05:    //value name
                    tempReg.ValueName = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x06:     //Depreciated: Use 0x07. All 0x06 will be converted to a string "ValueKind"
                    if (tempReg.RegValueKind != RegistryValueKind.ExpandString &&
                        tempReg.RegValueKind != RegistryValueKind.String)
                    {
                        //Read in the entry,if it's
                        tempReg.RegValueKind = RegistryValueKind.String;
                    }

                    tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs);
                    break;

                case 0x80:
                    isBinaryString = true;
                    break;

                case 0x81:
                    tempReg.Is32BitKey = true;
                    break;

                case 0x07:     //Value data
                    switch (tempReg.RegValueKind)
                    {
                    case RegistryValueKind.Binary:

                        if (isBinaryString)
                        {
                            tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs);
                        }
                        else
                        {
                            tempReg.ValueData = ReadFiles.ReadByteArray(fs);
                        }

                        break;

                    case RegistryValueKind.DWord:
                        tempReg.ValueData = ReadFiles.ReadInt(fs);
                        break;

                    case RegistryValueKind.QWord:
                        tempReg.ValueData = ReadFiles.ReadLong(fs);
                        break;

                    case RegistryValueKind.ExpandString:
                    case RegistryValueKind.MultiString:
                    case RegistryValueKind.String:
                        tempReg.ValueData = ReadFiles.ReadDeprecatedString(fs);
                        break;
                    }
                    break;

                default:
                    ReadFiles.SkipField(fs, bType);
                    break;
                }

                bType = (byte)fs.ReadByte();
            }

            return(tempReg);
        }
Ejemplo n.º 2
0
        public static UpdateDetails Load(string fileName)
        {
            UpdateDetails updtDetails = new UpdateDetails();

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    // Read back the file identification data, if any
                    if (!ReadFiles.IsHeaderValid(fs, "IUUDFV2"))
                    {
                        throw new ArgumentException("Incorrect file identifier.");
                    }

                    UpdateFile tempUpdateFile        = new UpdateFile();
                    int        lastStartServiceArgOn = 0;

                    byte bType = (byte)fs.ReadByte();
                    while (!ReadFiles.ReachedEndByte(fs, bType, 0xFF))
                    {
                        switch (bType)
                        {
                        case 0x20:    //num reg changes
                            updtDetails.RegistryModifications = new List <RegChange>(ReadFiles.ReadInt(fs));
                            break;

                        case 0x21:    //num file infos
                            updtDetails.UpdateFiles = new List <UpdateFile>(ReadFiles.ReadInt(fs));
                            break;

                        case 0x8E:
                            updtDetails.RegistryModifications.Add(RegChange.ReadFromStream(fs));
                            break;

                        case 0x30:
                            updtDetails.PreviousCommonDesktopShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

                        case 0x31:
                            updtDetails.PreviousCommonSMenuShortcuts.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

                        case 0x36:
                            updtDetails.PreviousCUserDesktopShortcuts.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x37:
                            updtDetails.PreviousCUserSMenuShortcuts.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x32:     //service to stop
                            updtDetails.ServicesToStop.Add(ReadFiles.ReadString(fs));
                            break;

                        case 0x33:     //service to start
                            updtDetails.ServicesToStart.Add(new StartService(ReadFiles.ReadString(fs)));
                            break;

                        case 0x34:     // number of start arguments for the last service
                            updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments =
                                new string[ReadFiles.ReadInt(fs)];
                            lastStartServiceArgOn = 0;
                            break;

                        case 0x35:
                            updtDetails.ServicesToStart[updtDetails.ServicesToStart.Count - 1].Arguments[
                                lastStartServiceArgOn] = ReadFiles.ReadString(fs);
                            lastStartServiceArgOn++;
                            break;

                        case 0x40:
                            tempUpdateFile.RelativePath = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x41:
                            tempUpdateFile.Execute = ReadFiles.ReadBool(fs);
                            break;

                        case 0x42:
                            tempUpdateFile.ExBeforeUpdate = ReadFiles.ReadBool(fs);
                            break;

                        case 0x43:
                            tempUpdateFile.CommandLineArgs = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x44:
                            tempUpdateFile.IsNETAssembly = ReadFiles.ReadBool(fs);
                            break;

                        case 0x45:
                            tempUpdateFile.WaitForExecution = ReadFiles.ReadBool(fs);
                            break;

                        case 0x8F:
                            tempUpdateFile.RollbackOnNonZeroRet = true;
                            break;

                        case 0x4D:
                            if (tempUpdateFile.RetExceptions == null)
                            {
                                tempUpdateFile.RetExceptions = new List <int>();
                            }

                            tempUpdateFile.RetExceptions.Add(ReadFiles.ReadInt(fs));
                            break;

                        case 0x46:
                            tempUpdateFile.DeleteFile = ReadFiles.ReadBool(fs);
                            break;

                        case 0x47:
                            tempUpdateFile.DeltaPatchRelativePath = ReadFiles.ReadDeprecatedString(fs);
                            break;

                        case 0x48:
                            tempUpdateFile.NewFileAdler32 = ReadFiles.ReadLong(fs);
                            break;

                        case 0x49:
                            tempUpdateFile.CPUVersion = (CPUVersion)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4A:
                            tempUpdateFile.ProcessWindowStyle = (System.Diagnostics.ProcessWindowStyle)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4E:
                            tempUpdateFile.ElevationType = (ElevationType)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4B:
                            tempUpdateFile.FrameworkVersion = (FrameworkVersion)ReadFiles.ReadInt(fs);
                            break;

                        case 0x4C:
                            tempUpdateFile.RegisterCOMDll = (COMRegistration)ReadFiles.ReadInt(fs);
                            break;

                        case 0x9B:    //end of file
                            updtDetails.UpdateFiles.Add(tempUpdateFile);
                            tempUpdateFile = new UpdateFile();
                            break;

                        case 0x8D:
                            updtDetails.ShortcutInfos.Add(ShortcutInfo.LoadFromStream(fs));
                            break;

                        case 0x60:
                            updtDetails.FoldersToDelete.Add(ReadFiles.ReadDeprecatedString(fs));
                            break;

                        default:
                            ReadFiles.SkipField(fs, bType);
                            break;
                        }

                        bType = (byte)fs.ReadByte();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("The update details file failed to open.\n\nFull details: " + ex.Message);
            }

            return(updtDetails);
        }
Ejemplo n.º 3
0
        public static UpdateHelperData FromByteArray(byte[] data)
        {
            UpdateHelperData uhData = new UpdateHelperData();

            using (MemoryStream ms = new MemoryStream(data))
            {
                byte bType = (byte)ms.ReadByte();

                //read until the end byte is detected
                while (!ReadFiles.ReachedEndByte(ms, bType, 0xFF))
                {
                    switch (bType)
                    {
                    case 0x01:
                        uhData.Action = (UpdateAction)ReadFiles.ReadInt(ms);
                        break;

                    case 0x02:     // update step we're on
                        uhData.UpdateStep = (UpdateStep)ReadFiles.ReadInt(ms);
                        break;

                    case 0x80:
                        uhData.ExtraDataIsRTF.Add(true);
                        break;

                    case 0x03:     // extra data

                        uhData.ExtraData.Add(ReadFiles.ReadString(ms));

                        // keep the 'ExtraDataIsRTF' same length as ExtraData
                        if (uhData.ExtraDataIsRTF.Count != uhData.ExtraData.Count)
                        {
                            uhData.ExtraDataIsRTF.Add(false);
                        }

                        break;

                    case 0x04:
                        uhData.ProcessID = ReadFiles.ReadInt(ms);
                        break;

                    case 0x05:
                        uhData.Progress = ReadFiles.ReadInt(ms);
                        break;

                    case 0x06:
                        uhData.ResponseType = (Response)ReadFiles.ReadInt(ms);
                        break;

                    // 0x07, 0x08, and 0x09 used to be links data - obsolete

                    default:
                        ReadFiles.SkipField(ms, bType);
                        break;
                    }

                    bType = (byte)ms.ReadByte();
                }
            }

            return(uhData);
        }