1
Vote

DriverStore enumeration fails if bad drivers are present

description

For example, I have a driver on my system that does not list a package provider. Enumeration crashes with an out of bounds exception in PNPUtil.EnumeratePackages(). If this tertiary crash is fixed, all remaining package information will be misaligned because linenum will be incorrect.

I solved this issue by changing EnumeratePackages to the following:
public List<DriverStoreEntry> EnumeratePackages()
{
    List<DriverStoreEntry> ldse = new List<DriverStoreEntry>();
    string output = ""; 

    bool result = PnpUtilHelper(PnpUtilOptions.Enumerate, "",  ref output);
    if (result == true)
    {                
        // Trace.TraceInformation("O/P of Enumeration : " + Environment.NewLine + output + Environment.NewLine);

        // Parse the output
        // [jenda_] Didn't work on non-english Windows - changed from string recognition to counting lines
        using (StringReader sr = new StringReader(output))                
        {
            string currentLine = "";
            string[] currentLineDivided = { };
            DriverStoreEntry dse = new DriverStoreEntry();
            while ((currentLine = sr.ReadLine()) != null)
            {
                currentLineDivided = currentLine.Split(new char[] { ':' });
                if (currentLineDivided.Length == 2)
                {
                    var item = currentLineDivided[0].Trim();
                    currentLineDivided[1] = currentLineDivided[1].Trim();
                    switch (item)
                    {
                        case "Published name":     // [jenda_] Published name :
                            dse = new DriverStoreEntry();
                            dse.driverPublishedName = currentLineDivided[1];
                            break;
                        case "Driver package provider":     //Driver package provider :
                            dse.driverPkgProvider = currentLine.Split(new char[] { ':' })[1].Trim();
                            break;
                        case "Class":     // [jenda_] Class :
                            dse.driverClass = currentLine.Split(new char[] { ':' })[1].Trim();
                            break;
                        case "Driver date and version":     // [jenda_] Driver date and version :
                            string DateAndVersion = currentLine.Split(new char[] { ':' })[1].Trim();
                            var split = DateAndVersion.Split(new char[] {' '});
                            dse.driverDate = split[0].Trim();
                            dse.driverVersion = split[1].Trim();
                            break;
                        case "Signer name":     // [jenda_] Signer name :
                            dse.driverSignerName = currentLine.Split(new char[] { ':' })[1].Trim();

                            ldse.Add(dse);
                            break;
                        default:
                            continue;
                    }

                }
            }
        }

    }
    return ldse;
}
It looks like this may revert a previous effort to make the application work with non-English versions of Windows. If this project used a git repo, I'd have a try at writing an acceptable implementation, but I don't SVN, sorry.

comments