예제 #1
0
        /// <param name="relativeRoot">
        /// The location where HKR entried will be stored, relative to 'SYSTEM\CurrentControlSet\' (or ControlSet001 for that matter)
        /// </param>
        private void ProcessAddRegSection(PNPDriverINFFile pnpDriverInf, string sectionName, string relativeRoot)
        {
            List <string> section = pnpDriverInf.GetSection(sectionName);

            foreach (string line in section)
            {
                List <string> values            = INIFile.GetCommaSeparatedValues(line);
                string        hiveName          = values[0];
                string        subKeyName        = INIFile.Unquote(values[1]);
                string        valueName         = INIFile.TryGetValue(values, 2);
                string        valueType         = INIFile.TryGetValue(values, 3);;
                string        valueDataUnparsed = String.Empty;
                if (values.Count > 3)
                {
                    valueDataUnparsed = StringUtils.Join(values.GetRange(4, values.Count - 4), ","); // byte-list is separated using commmas
                }

                valueName = INIFile.Unquote(valueName);
                valueType = pnpDriverInf.ExpandToken(valueType);
                int    valueTypeFlags = PNPDriverINFFile.ConvertFromIntStringOrHexString(valueType);
                string valueTypeHexString;
                if (!valueType.StartsWith("0x"))
                {
                    valueTypeHexString = "0x" + valueTypeFlags.ToString("X8"); // we want value type in 8 digit hex string.
                }
                else
                {
                    valueTypeHexString = valueType;
                }
                RegistryValueKind valueKind = PNPDriverINFFile.GetRegistryValueKind(valueTypeFlags);
                if (valueKind == RegistryValueKind.String)
                {
                    valueDataUnparsed = pnpDriverInf.ExpandToken(valueDataUnparsed);
                }
                object valueData = HiveINIFile.ParseValueDataString(valueDataUnparsed, valueKind);

                if (hiveName == "HKR")
                {
                    string cssKeyName = relativeRoot;
                    if (subKeyName != String.Empty)
                    {
                        cssKeyName = cssKeyName + @"\" + subKeyName;
                    }
                    // Note that software key will stick from text-mode:
                    SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData);
                }
                else if (hiveName == "HKLM" && subKeyName.StartsWith(@"SYSTEM\CurrentControlSet\", StringComparison.InvariantCultureIgnoreCase))
                {
                    string cssKeyName = subKeyName.Substring(@"SYSTEM\CurrentControlSet\".Length);

                    SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData);
                }
                else
                {
                    //Console.WriteLine("Warning: unsupported registry path: " + hiveName + @"\" + subKeyName);
                }
            }
        }
예제 #2
0
        public static byte[] ParseByteValueDataString(string valueData)
        {
            List <string> byteStringList = INIFile.GetCommaSeparatedValues(valueData);
            List <byte>   byteList       = new List <byte>();

            for (int index = 0; index < byteStringList.Count; index++)
            {
                byte data = Convert.ToByte(byteStringList[index], 16); // byte values are in Hex
                byteList.Add(data);
            }
            return(byteList.ToArray());
        }
예제 #3
0
        private void ProcessCopyFilesSection(PNPDriverINFFile pnpDriverInf, string sectionName)
        {
            List <string> section = pnpDriverInf.GetSection(sectionName);

            foreach (string line in section)
            {
                List <string> values = INIFile.GetCommaSeparatedValues(line);
                string        destinationFileName = values[0];
                string        sourceFileName      = INIFile.TryGetValue(values, 1);
                if (sourceFileName == String.Empty)
                {
                    sourceFileName = destinationFileName;
                }
                ProcessCopyFileDirective(pnpDriverInf, sourceFileName, destinationFileName);
            }
        }
예제 #4
0
        public static object ParseValueDataString(string valueData, RegistryValueKind valueKind)
        {
            switch (valueKind)
            {
            case RegistryValueKind.String:
            case RegistryValueKind.ExpandString:
                return(INIFile.Unquote(valueData));

            case RegistryValueKind.MultiString:
                List <string> stringList = INIFile.GetCommaSeparatedValues(valueData);
                for (int index = 0; index < stringList.Count; index++)
                {
                    stringList[index] = INIFile.Unquote(stringList[index]);
                    stringList[index] = stringList[index].Replace("\"\"", "\"");     // see notes at GetFormattedMultiString()
                }
                return(stringList.ToArray());

            case RegistryValueKind.DWord:
                // Sometimes a DWord value is quoted (Intel E1000 driver, version 8.10.3.0)
                // It's a violation of the specs, but Windows accepts this, so we should too.
                valueData = Unquote(valueData);
                return(Convert.ToInt32(valueData, 16));    // DWord values are in Hex

            case RegistryValueKind.QWord:
                return(Convert.ToInt64(valueData, 16));     // QWord values are in Hex

            case RegistryValueKind.Binary:
                List <string> byteStringList = INIFile.GetCommaSeparatedValues(valueData);
                List <byte>   byteList       = new List <byte>();
                for (int index = 0; index < byteStringList.Count; index++)
                {
                    // Sometimes each byte value is quoted (VIA Rhine III Fast Ethernet Adapter driver, version 3.41.0.0426)
                    // It's a violation of the specs, but Windows accepts this, so we should too.
                    string byteString = Unquote(byteStringList[index]);
                    byte   data       = Convert.ToByte(byteString, 16); // byte values are in Hex
                    byteList.Add(data);
                }
                return(byteList.ToArray());

            default:
                throw new NotImplementedException("Not implemented");
            }
        }