/// <param name="hardwareID">enumerator-specific-device-id</param>
        public static string DetectExportedDeviceInstanceID(string path, string hardwareID, out string deviceID)
        {
            Console.WriteLine("Searching for '" + hardwareID + "' in " + path);
            deviceID = String.Empty; // sometimes the device presents longer hardware ID than the one specified in the driver

            string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(hardwareID);

            if (enumerator == "*")
            {
                return(String.Empty); // unsupported enumerator;
            }

            string deviceInstanceID     = String.Empty;
            ExportedRegistryKey hiveKey = new ExportedRegistry(path).LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum" + enumerator);

            foreach (string deviceKeyName in hiveKey.GetSubKeyNames())
            {
                ExportedRegistryKey deviceKey = hiveKey.OpenSubKey(deviceKeyName);
                if (deviceKey != null)
                {
                    foreach (string instanceKeyName in deviceKey.GetSubKeyNames())
                    {
                        ExportedRegistryKey instanceKey = deviceKey.OpenSubKey(instanceKeyName);
                        if (instanceKey != null)
                        {
                            object compatibleIDsEntry = instanceKey.GetValue("CompatibleIDs", new string[0]);
                            if (compatibleIDsEntry is string[])
                            {
                                string[] compatibleIDs = (string[])compatibleIDsEntry;

                                foreach (string compatibleID in compatibleIDs)
                                {
                                    if (compatibleID.Equals(hardwareID, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        deviceID         = RegistryKeyUtils.GetShortKeyName(deviceKey.Name);
                                        deviceInstanceID = RegistryKeyUtils.GetShortKeyName(instanceKey.Name);
                                        // Irrelevant Note: if a device is present but not installed in Windows then ConfigFlags entry will not be present
                                        // and it doesn't matter anyway because we don't care about how existing installation configure the device

                                        // there are two reasons not to use DeviceDesc from the local machine:
                                        // 1. on Windows 6.0+ (or just Windows PE?) the format is different and not compatible with Windows 5.x
                                        // 2. If the hadrware is present but not installed, the DeviceDesc will be a generic description (e.g. 'Ethernet Controller')

                                        Console.WriteLine("Found matching device: '" + deviceID + "'");
                                        return(deviceInstanceID);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(deviceInstanceID);
        }
Esempio n. 2
0
        private void ProcessCopyFileDirective(PNPDriverINFFile pnpDriverInf, string sourceFileName, string destinationFileName)
        {
            string     relativeSourcePath = PNPDriverIntegratorUtils.GetRelativeDirectoryPath(pnpDriverInf, sourceFileName, m_architectureIdentifier);
            FileToCopy fileToCopy         = new FileToCopy(relativeSourcePath, sourceFileName, destinationFileName);

            if (!FileSystemUtils.IsFileExist(m_driverDirectory.Path + fileToCopy.RelativeSourceFilePath))
            {
                Console.WriteLine("Error: Missing file: " + m_driverDirectory.Path + fileToCopy.RelativeSourceFilePath);
                Program.Exit();
            }
            // actual copy will be performed later
            m_driverFilesToCopy.Add(fileToCopy);
        }
Esempio n. 3
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.");
        }
Esempio n. 4
0
        public void RegisterPhysicalDevice(PNPDriverINFFile pnpDriverInf)
        {
            if (m_preconfigure && pnpDriverInf.IsNetworkAdapter && (m_useLocalHardwareConfig || m_enumExportPath != String.Empty))
            {
                string deviceID;
                string deviceInstanceID;

                if (m_useLocalHardwareConfig)
                {
                    deviceInstanceID = PNPLocalHardwareDetector.DetectLocalDeviceInstanceID(this.HardwareID, out deviceID);
                    if (deviceInstanceID == String.Empty)
                    {
                        Console.WriteLine("Warning: Could not detect matching device installed locally, configuration will not be applied!");
                    }
                }
                else // m_enumExportPath != String.Empty
                {
                    deviceInstanceID = PNPExportedHardwareDetector.DetectExportedDeviceInstanceID(m_enumExportPath, this.HardwareID, out deviceID);
                    if (deviceInstanceID == String.Empty)
                    {
                        Console.WriteLine("Warning: Could not detect matching device in the exported registry, configuration will not be applied!");
                    }
                }

                if (deviceInstanceID != String.Empty)
                {
                    // m_netDeviceServices is now populated
                    if (this.NetworkDeviceServices.Count > 0)
                    {
                        // unlike other types of hardware (SCSI controllers etc.), it's not enough to add a NIC to the
                        // Criticla Device Database (CDDB) to make it usable during boot, as mentioned in the comments above RegisterNicAsCriticalDevice()
                        // at the very least, a CDDB entry and a "Device" registry value under Enum\Enumerator\DeviceID\DeviceInstanceID is required
                        // (as well as DeviceDesc if not automatically added by the kernel-PNP)
                        // here we manually register the hardware in advance, but it's better to use NICBootConf to do this during boot,
                        // NICBootConf will also work if the NIC has been moved to another PCI slot since creating the installation media.

                        // the first item in m_netDeviceServices should be the actual NIC (CHECKME: what about NIC / bus driver combination like nVIdia)
                        NetworkDeviceService deviceService = this.NetworkDeviceServices[0];
                        string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(this.HardwareID);
                        PreconfigureDeviceInstance(pnpDriverInf, enumerator, deviceID, deviceInstanceID, deviceService);
                    }
                    else
                    {
                        Console.WriteLine("Warning: failed to install '{0}', because the service for this network adapter has not been registered!", this.HardwareID);
                    }
                }
            }
            else
            {
                // if it's a NIC, We assume the user will integrate NICBootConf, which will configure the network adapter during boot.
                // we'll just add the device to the Criticla Device Database (CDDB), and let kernel-PNP and NICBootConf do the rest.
                if (pnpDriverInf.IsNetworkAdapter)
                {
                    // NICBootConf needs the ClassGUID in place for each DeviceInstance Key,
                    // if we put the ClassGUID in the CDDB, the ClassGUID will be applied to each DeviceInstance with matching hardwareID
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                }
                else
                {
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                }
            }
        }
Esempio n. 5
0
        /// <param name="hardwareID">enumerator-specific-device-id</param>
        public static string DetectLocalDeviceInstanceID(string hardwareID, out string deviceID)
        {
            Console.WriteLine("Searching for '" + hardwareID + "' on local machine");
            deviceID = String.Empty; // sometimes the device presents longer hardware ID than the one specified in the driver

            string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(hardwareID);

            if (enumerator == "*")
            {
                return(String.Empty); // unsupported enumerator;
            }

            string      deviceInstanceID = String.Empty;
            RegistryKey hiveKey          = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\" + enumerator);

            foreach (string deviceKeyName in hiveKey.GetSubKeyNames())
            {
                RegistryKey deviceKey = hiveKey.OpenSubKey(deviceKeyName);
                if (deviceKey != null)
                {
                    foreach (string instanceKeyName in deviceKey.GetSubKeyNames())
                    {
                        RegistryKey instanceKey = deviceKey.OpenSubKey(instanceKeyName);
                        if (instanceKey != null)
                        {
                            List <string> hardwareIDs = new List <string>();

                            object hardwareIDEntry = instanceKey.GetValue("HardwareID", new string[0]);
                            if (hardwareIDEntry is string[])
                            {
                                hardwareIDs.AddRange((string[])hardwareIDEntry);
                            }

                            object compatibleIDsEntry = instanceKey.GetValue("CompatibleIDs", new string[0]);
                            if (compatibleIDsEntry is string[])
                            {
                                hardwareIDs.AddRange((string[])compatibleIDsEntry);
                            }

                            if (StringUtils.ContainsCaseInsensitive(hardwareIDs, hardwareID))
                            {
                                deviceID         = RegistryKeyUtils.GetShortKeyName(deviceKey.Name);
                                deviceInstanceID = RegistryKeyUtils.GetShortKeyName(instanceKey.Name);
                                // Irrelevant Note: if a device is present but not installed in Windows then ConfigFlags entry will not be present
                                // and it doesn't matter anyway because we don't care about how existing installation configure the device

                                // there are two reasons not to use DeviceDesc from the local machine:
                                // 1. on Windows 6.0+ (or just Windows PE?) the format is different and not compatible with Windows 5.x
                                // 2. If the hadrware is present but not installed, the DeviceDesc will be a generic description (e.g. 'Ethernet Controller')

                                Console.WriteLine("Found matching device: '" + deviceID + "'");
                                instanceKey.Close();
                                deviceKey.Close();
                                hiveKey.Close();
                                return(deviceInstanceID);
                            }

                            instanceKey.Close();
                        }
                    }
                    deviceKey.Close();
                }
            }

            hiveKey.Close();
            return(deviceInstanceID);
        }