void CreateValue(List <RegChange> rollbackRegistry) { if (rollbackRegistry != null) { RegChange origValue = new RegChange(RegOperations.CreateValue, RegBasekey, SubKey, Is32BitKey, ValueName); try { using (RegistryKey rk = ReturnOpenKey(SubKey)) { //create a rollback to the previous value origValue.RegValueKind = rk.GetValueKind(ValueName); origValue.ValueData = rk.GetValue(ValueName, null, RegistryValueOptions.DoNotExpandEnvironmentNames); } } catch (Exception) { origValue.RegOperation = RegOperations.RemoveValue; } rollbackRegistry.Add(origValue); } //backup any new subtree creations if (rollbackRegistry != null) { BackupCreateKeyTree(rollbackRegistry); } //set the new registry value using (RegistryKey regValue = ReturnCreateKey()) { regValue.SetValue(ValueName, RegValueKind == RegistryValueKind.MultiString ? StringToMultiString(ValueData) : ValueData, RegValueKind); } }
RegChange ParseRegChange(RegChange reg) { if (reg.RegValueKind == RegistryValueKind.MultiString || reg.RegValueKind == RegistryValueKind.String) { reg.ValueData = ParseText((string)reg.ValueData); } return reg; }
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); }
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; }
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); }
void CreateValue(List<RegChange> rollbackRegistry) { if (rollbackRegistry != null) { RegChange origValue = new RegChange(RegOperations.CreateValue, RegBasekey, SubKey, Is32BitKey, ValueName); try { using (RegistryKey rk = ReturnOpenKey(SubKey)) { //create a rollback to the previous value origValue.RegValueKind = rk.GetValueKind(ValueName); origValue.ValueData = rk.GetValue(ValueName, null, RegistryValueOptions.DoNotExpandEnvironmentNames); } } catch (Exception) { origValue.RegOperation = RegOperations.RemoveValue; } rollbackRegistry.Add(origValue); } //backup any new subtree creations if (rollbackRegistry != null) BackupCreateKeyTree(rollbackRegistry); //set the new registry value using (RegistryKey regValue = ReturnCreateKey()) { regValue.SetValue(ValueName, RegValueKind == RegistryValueKind.MultiString ? StringToMultiString(ValueData) : ValueData, RegValueKind); } }