Beispiel #1
0
        // Windows File Protection may restore a newer unsigned driver file to an older in-box signed driver file (sfc.exe is executed at the end of GUI-mode setup).
        // The list of files that is being protected is stored in sfcfiles.sys, and we can prevent a file from being protected by making sure it's not in that list.
        public static void DisableInBoxDeviceDriverFile(string setupDirectory, string fileName)
        {
            fileName = fileName.ToLower(); // sfcfiles.dll stores all file names in lowercase
            string path = setupDirectory + "sfcfiles.dl_";

            byte[] packed   = File.ReadAllBytes(path);
            byte[] unpacked = HiveINIFile.Unpack(packed, "sfcfiles.dll");
            PortableExecutableInfo peInfo = new PortableExecutableInfo(unpacked);
            string oldValue = @"%systemroot%\system32\drivers\" + fileName;
            string newValue = @"%systemroot%\system32\drivers\" + fileName.Substring(0, fileName.Length - 1) + "0"; // e.g. e1000325.sys => e1000325.sy0

            byte[] oldSequence = Encoding.Unicode.GetBytes(oldValue);
            byte[] newSequence = Encoding.Unicode.GetBytes(newValue);

            bool replaced = false;

            for (int index = 0; index < peInfo.Sections.Count; index++)// XP uses the .text section while Windows 2000 uses the .data section
            {
                byte[] section           = peInfo.Sections[index];
                bool   replacedInSection = KernelAndHalIntegrator.ReplaceInBytes(ref section, oldSequence, newSequence);

                if (replacedInSection)
                {
                    peInfo.Sections[index] = section;
                    replaced = true;
                }
            }

            if (replaced)
            {
                Console.WriteLine();
                Console.WriteLine("'{0}' has been removed from Windows File Protection file list.", fileName);

                MemoryStream peStream = new MemoryStream();
                PortableExecutableInfo.WritePortableExecutable(peInfo, peStream);
                unpacked = peStream.ToArray();
                packed   = HiveINIFile.Pack(unpacked, "sfcfiles.dll");

                FileSystemUtils.ClearReadOnlyAttribute(path);
                File.WriteAllBytes(path, packed);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            args = CommandLineParser.GetCommandLineArgsIgnoreEscape();
            WindowsInstallation            installation;
            List <TextModeDriverDirectory> textModeDriverDirectories;
            List <PNPDriverDirectory>      pnpDriverDirectories;
            bool   useLocalHardwareConfig;
            string enumExportPath;
            bool   preconfigure;
            bool   staticIP;
            bool   usbBoot;

            bool parseSuccess = ParseCommandLineSwitches(args, out installation, out textModeDriverDirectories, out pnpDriverDirectories, out useLocalHardwareConfig, out enumExportPath, out preconfigure, out staticIP, out usbBoot);

            if (!parseSuccess)
            {
                // parser was already supposed to print an error meesage;
                return;
            }

            // Make sure Windows temporary folder exist (the user may have deleted it)
            if (!FileSystemUtils.IsDirectoryExist(Path.GetTempPath()))
            {
                FileSystemUtils.CreateDirectory(Path.GetTempPath());
            }
            installation.SetupRegistryHive.LoadHiveFromDirectory(installation.SetupDirectory);
            TextModeDriverIntegrator.IntegrateTextModeDrivers(textModeDriverDirectories, installation);
            List <DeviceService>        deviceServices    = PNPDriverIntegratorUtils.IntegratePNPDrivers(pnpDriverDirectories, installation, useLocalHardwareConfig, enumExportPath, preconfigure);
            List <NetworkDeviceService> netDeviceServices = DeviceServiceUtils.FilterNetworkDeviceServices(deviceServices);

            if (netDeviceServices.Count > 0)
            {
                if (!preconfigure && !DeviceServiceUtils.ContainsService(deviceServices, "nicbtcfg"))
                {
                    Console.WriteLine();
                    Console.Write("********************************************************************************");
                    Console.Write("*You have supplied a device driver for a network adapter, which requires       *");
                    Console.Write("*special registry configuration to support boot start, but you have not        *");
                    Console.Write("*used the /preconf switch. IntegrateDrv will assume you're using NICBootConf   *");
                    Console.Write("*to configure your network adapter during boot. (recommended)                  *");
                    Console.Write("********************************************************************************");
                }
            }

            if (usbBoot && !DeviceServiceUtils.ContainsService(deviceServices, "wait4ufd"))
            {
                Console.WriteLine();
                Console.Write("********************************************************************************");
                Console.Write("*When booting from a USB storage device, most systems will require that you    *");
                Console.Write("*will use a special driver (such as Wait4UFD) that will wait for the UFD boot  *");
                Console.Write("*storage device to be initialized before proceeding with the boot process.     *");
                Console.Write("********************************************************************************");
            }

            if (DeviceServiceUtils.ContainsService(deviceServices, "sanbootconf"))
            {
                Console.WriteLine();
                Console.WriteLine("sanbootconf detected, GUI boot (Windows logo) has been enabled.");

                installation.TextSetupInf.EnableGUIBoot();
            }

            if (netDeviceServices.Count > 0)
            {
                KernelAndHalIntegrator kernelAndHalIntegrator = new KernelAndHalIntegrator(installation);
                kernelAndHalIntegrator.UseUniprocessorKernel();

                Console.WriteLine();
                Console.WriteLine("Network adapter has been added, adding TCP/IP:");
                TCPIPIntegrator integrator = new TCPIPIntegrator(installation, netDeviceServices);
                integrator.SetTCPIPBoot();
                integrator.AssignIPAddressToNetDeviceServices(staticIP);
            }

            if (usbBoot)
            {
                USBBootIntegrator integrator = new USBBootIntegrator(installation);
                Console.WriteLine();
                Console.WriteLine("Integrating USB 2.0 Host Controller and Hub drivers.");
                integrator.IntegrateUSB20HostControllerAndHubDrivers();
                Console.WriteLine("Integrating USB Mass Storage Class Driver.");
                integrator.IntegrateUSBStorageDriver();
            }

            // no need to keep migration information (current drive letter assignments)
            installation.DeleteMigrationInformation();

            Console.WriteLine("Committing changes.");
            installation.SaveModifiedINIFiles();
            installation.SaveRegistryChanges();
            Console.WriteLine("Driver integration completed.");
        }