WriteLong() public static method

public static WriteLong ( Stream fs, byte flag, long val ) : void
fs Stream
flag byte
val long
return void
Ejemplo n.º 1
0
        public void WriteToStream(Stream fs, bool embedBinaryData)
        {
            fs.WriteByte(142);
            WriteFiles.WriteInt(fs, 1, (int)RegOperation);
            WriteFiles.WriteInt(fs, 2, (int)RegBasekey);
            WriteFiles.WriteInt(fs, 3, (int)RegValueKind);
            WriteFiles.WriteDeprecatedString(fs, 4, SubKey);
            if (!string.IsNullOrEmpty(ValueName))
            {
                WriteFiles.WriteDeprecatedString(fs, 5, ValueName);
            }
            bool flag = !embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string;

            if (flag)
            {
                fs.WriteByte(128);
            }
            if (RegOperation == RegOperations.CreateValue)
            {
                switch (RegValueKind)
                {
                case RegistryValueKind.Binary:
                    if (flag)
                    {
                        WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData);
                    }
                    else if (embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string)
                    {
                        WriteOutFile(fs, 7, (string)ValueData);
                    }
                    else
                    {
                        WriteFiles.WriteByteArray(fs, 7, (byte[])ValueData);
                    }
                    break;

                case RegistryValueKind.DWord:
                    WriteFiles.WriteInt(fs, 7, (int)ValueData);
                    break;

                case RegistryValueKind.QWord:
                    WriteFiles.WriteLong(fs, 7, (long)ValueData);
                    break;

                case RegistryValueKind.MultiString:
                    WriteFiles.WriteDeprecatedString(fs, 7, MultiStringToString(ValueData));
                    break;

                case RegistryValueKind.String:
                case RegistryValueKind.ExpandString:
                    WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData);
                    break;
                }
            }
            if (Is32BitKey)
            {
                fs.WriteByte(129);
            }
            fs.WriteByte(158);
        }
Ejemplo n.º 2
0
        public Stream Save()
        {
            MemoryStream ms = new MemoryStream();

            try
            {
                // Write any file-identification data you want to here
                WriteFiles.WriteHeader(ms, "IUUDFV2");

                //number of registry changes
                WriteFiles.WriteInt(ms, 0x20, RegistryModifications.Count);

                for (int i = 0; i < RegistryModifications.Count; i++)
                {
                    RegistryModifications[i].WriteToStream(ms, true);
                }

                //Shortcut information
                foreach (ShortcutInfo si in ShortcutInfos)
                {
                    si.SaveToStream(ms, true);
                }


                //Previous shortcuts that needs to be installed in order to install new shortcuts
                foreach (string shortcut in PreviousCommonDesktopShortcuts)
                {
                    WriteFiles.WriteDeprecatedString(ms, 0x30, shortcut);
                }

                foreach (string shortcut in PreviousCommonSMenuShortcuts)
                {
                    WriteFiles.WriteDeprecatedString(ms, 0x31, shortcut);
                }

                foreach (string shortcut in PreviousCUserDesktopShortcuts)
                {
                    WriteFiles.WriteString(ms, 0x36, shortcut);
                }

                foreach (string shortcut in PreviousCUserSMenuShortcuts)
                {
                    WriteFiles.WriteString(ms, 0x37, shortcut);
                }

                //number of file infos
                WriteFiles.WriteInt(ms, 0x21, CountFileInfos());

                // write file info for ngening .NET, execution of files, etc.
                foreach (UpdateFile file in UpdateFiles)
                {
                    if (file.Execute || file.IsNETAssembly || file.DeleteFile || file.DeltaPatchRelativePath != null || file.RegisterCOMDll != COMRegistration.None)
                    {
                        ms.WriteByte(0x8B);//Beginning of the file information

                        //relative path to file
                        WriteFiles.WriteDeprecatedString(ms, 0x40, file.RelativePath);

                        //execution of files
                        if (file.Execute)
                        {
                            // execute?
                            WriteFiles.WriteBool(ms, 0x41, true);

                            // execute before update?
                            WriteFiles.WriteBool(ms, 0x42, file.ExBeforeUpdate);

                            if (file.WaitForExecution)
                            {
                                WriteFiles.WriteBool(ms, 0x45, file.WaitForExecution);

                                if (file.RollbackOnNonZeroRet)
                                {
                                    // we are rolling back on non-zero return code
                                    ms.WriteByte(0x8F);

                                    // write all the exceptions we're making for rollback codes
                                    if (file.RetExceptions != null)
                                    {
                                        foreach (int except in file.RetExceptions)
                                        {
                                            WriteFiles.WriteInt(ms, 0x4D, except);
                                        }
                                    }
                                }
                            }

                            //commandline arguments
                            if (!string.IsNullOrEmpty(file.CommandLineArgs))
                            {
                                WriteFiles.WriteDeprecatedString(ms, 0x43, file.CommandLineArgs);
                            }

                            if (file.ProcessWindowStyle != System.Diagnostics.ProcessWindowStyle.Normal)
                            {
                                WriteFiles.WriteInt(ms, 0x4A, (int)file.ProcessWindowStyle);
                            }

                            if (file.ElevationType != ElevationType.SameAswyUpdate)
                            {
                                WriteFiles.WriteInt(ms, 0x4E, (int)file.ElevationType);
                            }
                        }

                        //is it a .NET assembly?
                        if (file.IsNETAssembly)
                        {
                            WriteFiles.WriteBool(ms, 0x44, true);

                            // save whether the files is AnyCPU, x86, or x64
                            WriteFiles.WriteInt(ms, 0x49, (int)file.CPUVersion);

                            // .NET framework is by default 2.0 - only save the framework version if it's .NET 4.0 or unknown
                            if (file.FrameworkVersion != FrameworkVersion.Net2_0)
                            {
                                WriteFiles.WriteInt(ms, 0x4B, (int)file.FrameworkVersion);
                            }
                        }

                        if (file.RegisterCOMDll != COMRegistration.None)
                        {
                            WriteFiles.WriteInt(ms, 0x4C, (int)file.RegisterCOMDll);
                        }

                        //Delta update particulars:

                        if (file.DeleteFile)
                        {
                            WriteFiles.WriteBool(ms, 0x46, true);
                        }
                        else if (file.DeltaPatchRelativePath != null)
                        {
                            WriteFiles.WriteDeprecatedString(ms, 0x47, file.DeltaPatchRelativePath);

                            if (file.NewFileAdler32 != 0)
                            {
                                WriteFiles.WriteLong(ms, 0x48, file.NewFileAdler32);
                            }
                        }

                        ms.WriteByte(0x9B);//End of the file information
                    }
                }

                foreach (string folder in FoldersToDelete)
                {
                    WriteFiles.WriteDeprecatedString(ms, 0x60, folder);
                }

                foreach (string service in ServicesToStop)
                {
                    WriteFiles.WriteString(ms, 0x32, service);
                }

                foreach (StartService service in ServicesToStart)
                {
                    WriteFiles.WriteString(ms, 0x33, service.Name);

                    if (service.Arguments != null)
                    {
                        WriteFiles.WriteInt(ms, 0x34, service.Arguments.Length);

                        foreach (string arg in service.Arguments)
                        {
                            WriteFiles.WriteString(ms, 0x35, arg);
                        }
                    }
                }

                // end of file
                ms.WriteByte(0xFF);

                // set the pointer to the top of the file
                ms.Position = 0;
            }
            catch (Exception)
            {
                ms.Dispose();
                throw;
            }

            return(ms);
        }
Ejemplo n.º 3
0
        public void WriteToStream(Stream fs, bool embedBinaryData)
        {
            // beginning of RegChange
            fs.WriteByte(0x8E);

            // save the operation
            WriteFiles.WriteInt(fs, 0x01, (int)RegOperation);

            // save BaseKey
            WriteFiles.WriteInt(fs, 0x02, (int)RegBasekey);

            // Save the valueKind
            WriteFiles.WriteInt(fs, 0x03, (int)RegValueKind);

            // Save SubKey
            WriteFiles.WriteDeprecatedString(fs, 0x04, SubKey);

            // Value Name
            if (!string.IsNullOrEmpty(ValueName))
            {
                WriteFiles.WriteDeprecatedString(fs, 0x05, ValueName);
            }

            bool isBinaryString = !embedBinaryData &&
                                  RegValueKind == RegistryValueKind.Binary &&
                                  ValueData is string;

            if (isBinaryString)
            {
                fs.WriteByte(0x80);
            }

            if (RegOperation == RegOperations.CreateValue)
            {
                // Value Data
                switch (RegValueKind)
                {
                case RegistryValueKind.Binary:

                    if (isBinaryString)
                    {
                        //just saving the string pointing to a file on the disk
                        WriteFiles.WriteDeprecatedString(fs, 0x07, (string)ValueData);
                    }
                    else if (embedBinaryData &&
                             RegValueKind == RegistryValueKind.Binary &&
                             ValueData is string)
                    {
                        //load the file and immediately write it out to fs
                        WriteOutFile(fs, 0x07, (string)ValueData);
                    }
                    else
                    {
                        //the byte array is already in memory, just write it out
                        WriteFiles.WriteByteArray(fs, 0x07, (byte[])ValueData);
                    }

                    break;

                case RegistryValueKind.DWord:
                    WriteFiles.WriteInt(fs, 0x07, (int)ValueData);
                    break;

                case RegistryValueKind.QWord:
                    WriteFiles.WriteLong(fs, 0x07, (long)ValueData);
                    break;

                case RegistryValueKind.MultiString:
                    WriteFiles.WriteDeprecatedString(fs, 0x07, MultiStringToString(ValueData));
                    break;

                case RegistryValueKind.ExpandString:
                case RegistryValueKind.String:
                    WriteFiles.WriteDeprecatedString(fs, 0x07, (string)ValueData);
                    break;
                }
            }

            // should treat as x86 under x64 systems
            if (Is32BitKey)
            {
                fs.WriteByte(0x81);
            }

            //end of RegChange
            fs.WriteByte(0x9E);
        }