zoukankan      html  css  js  c++  java
  • Windows驱动匹配详解

     

    在Windows下,几乎所有的硬件设备都需要安装驱动后才能正常工作,我们重装系统后第一件事就是要为各设备安装好驱动,我们可以下载官方驱动手动安装,也可以让我Windows自动扫描安装,还可以使用驱动精灵、电脑管家之类的工具帮我们安装,为了发挥硬件设备最好的性能,我们还需要及时把驱动升级到最新的版本。那么,这些工具是如何为硬件设备匹配到最佳的驱动的呢?此文就这个问题一探究竟。

    驱动匹配相关信息

    设备都是通过hardware ID进行标识,一个设备一般有多个hardware ID和compatible ID,这些ID对设备的标识程度按照顺序依次降低,我们可以在Windows设备管理器中查看到设备的硬件Id和兼容Id。

     

    Windows下的驱动必须包含一个信息文件(INF)以进行安装,INF文本文件包含设备安装组件(device installation components)安装驱动所必需的所有信息。从INF文件中可以提取驱动匹配所需的信息:

    (1)驱动提供商

    (2)驱动类型

    (3)驱动的日期和版本

    (4)驱动的特征值,用来衡量驱动对设备特征的支持程度

    (5)驱动支持的操作系统版本和硬件平台

    (6)驱动支持的设备的hardware ID和compatible ID

    设备和驱动的标识匹配是指设备的hardware ID或compatible ID与驱动INF文件指定的hardware ID或compatible ID的匹配,匹配程度从高到低有以下4中类型:

    (1)设备的hardware ID和INF的hardware ID匹配,匹配程度由设备的hardware ID的位置确定。

    (2)设备的hardware ID和INF的compatible ID匹配,匹配程度由设备的hardware ID的位置确定。

    (3)设备的compatible ID和INF的hardware ID匹配,匹配程度由设备的compatible ID的位置确定。

    (4)设备的compatible ID和INF的compatible ID匹配,匹配程度由设备的compatible ID的位置和INF的compatible ID的位置确定,前者的优先级高。

    驱动签名在驱动的匹配中也起着很关键的作用,签名的排序优先级如下:

    (1)有微软签名的,包括:

            * 优先级别 (Premium) 和标准级别 (Standrd) 的 WHQL 签名;

            * Inbox 驱动签名 ( Signatures for inbox drivers ) ;

            * 可靠驱动签名 (DRS, Driver Reliability Signature);

            * SE 签名 (Windows Sustained Engineering);

            * 老版本 Windows 的 WHQL 签名;

    (2)有效代码签名,系统管理员可以设定安全策略来指定受信任的根证书颁发的微软代码签名证书的签名等同于微软签名;

    (3)没有签名的驱动,但 INF DDInstall 中有 .nt后缀;

    (4)没有签名的驱动,但 INF DDInstall 中没有 .nt后缀;

    (5)没有签名或签名有问题而无法确认是否有签名的驱动。

    驱动匹配规则

    驱动安装工具在服务器端存储了大量的驱动,对于同一个设备可能有多个驱动都合适,那么哪个驱动再是最佳的呢?驱动匹配时就是按照如下匹配规则来选择最佳的驱动:

    (1)客户端上报设备ID(hardware ID和compatible ID)的有序列表,操作系统版本,硬件平台。

    (2)结合设备ID,操作系统版本,硬件平台与驱动库进行匹配,得到所有可用的驱动,若无可用的驱动,则匹配失败。

    (3)选择签名最佳的驱动。

    (4)选择特征最佳的驱动。

    (5)选择匹配类型最佳的驱动。

    (6)选择日期最新的驱动。

    (7)选择版本最高的驱动。

    (8)选择任一驱动。

     

    驱动信息提取方法

    前面提到驱动所支持的硬件等信息都是保存在INF文件中,为了能快速匹配驱动,就需要把这些信息先从INF文件中提取出来,下面就详细说明驱动信息的提取方法

     

    1.基本信息的提取

    Version section出现在INF文件最开始的位置,每一个INF文件都必须包含这个section。

    [Version]

    Signature="signature-name"

    [Class=class-name]

    [ClassGuid={nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}]

    [Provider=%INF-creator%]

    [LayoutFile=filename.inf [,filename.inf]... ]  (Windows 2000 and Windows XP)

    [CatalogFile=filename.cat]

    [CatalogFile.nt=unique-filename.cat]

    [CatalogFile.ntx86=unique-filename.cat]

    [CatalogFile.ntia64=unique-filename.cat]  (Windows XP and later versions of Windows)

    [CatalogFile.ntamd64=unique-filename.cat]  (Windows XP and later versions of Windows)

    DriverVer=mm/dd/yyyy[,w.x.y.z]

    [DontReflectOffline=1] (Windows Vista and later versions of Windows)

    [PnpLockDown=0|1] (Windows Vista and later versions of Windows)

    [DriverPackageDisplayName=%driver-package-description%]

    [DriverPackageType=PackageType]

    (1)Signature必须是$Windows NT$或$Chicago$,表明在所有Windows系统下是可用的。

    (2)Class指定使用该INF文件安装驱动的设备类型,关于类型的详细信息参考http://msdn.microsoft.com/en-us/library/windows/hardware/ff553426(v=vs.85).aspx

    (3)Provider指定驱动的提供商,%INF-creator%在Strings section中定义。

    (4)DriverVer指定驱动的日期和版本。日期是所有文件的最新日期,日期的格式为mm/dd/yyyy或mm-dd-yyyy,年必须包含4个数字,月和日必须包含2个数字;版本w.x.y.z是可选的,如果指定了版本,则w是必需的,x、y、z是可选的,w、x、y、z都是大于等于0小于65535的整数。从Windows 2000开始,INF文件在Version section中必须包含DriverVer,为整个INF指定版本信息,DDInstall sections也可以包含DriverVer,且比前者更明确,优先级更高。

    (5)DriverPackageDisplayName指定驱动显示的名称,%driver-package-description%在Strings section中定义。

    (6)DriverPackageType指定驱动的类型。

     

    2.设备ID、操作系统、硬件平台、驱动特征的提取

    (1)从Manufacturer section中提取所有的Models section name。

    [Manufacturer]

     

    manufacturer-identifier

    [manufacturer-identifier]

    [manufacturer-identifier]

    ...

    manufacturer-identifier格式如下:

    manufacturer-name |

    %strkey%=models-section-name |

    %strkey%=models-section-name [,TargetOSVersion] [,TargetOSVersion] ...  (Windows XP and later versions of Windows)

    提取manufacturer-name或models-section-name作为Models section name。

    (2)TargetOSVersion提取规则

    nt[Architecture][.[OSMajorVersion][.[OSMinorVersion][.[ProductType][.SuiteMask]]]]

    nt 指定操作系统是基于NT的,Windows 2000及以后的版本都是基于NT的。

    Architecture 指定硬件平台,若指定,必须为x86, ia64, or amd64。Windows Server 2003 SP1以前的版本,若Architecture未指定,Model section可用于任何硬件平台;Windows Server 2003 SP1及以后的版本,非x86的操作系统必须指定Architecture,x86的操作系统是可选的。

    OSMinorVersion 操作系统的主版本号。

    Windows version

    Major version

    Windows 8

    6

    Windows Server 2008 R2

    6

    Windows 7

    6

    Windows Server 2008

    6

    Windows Vista

    6

    Windows Server 2003 R2

    5

    Windows Server 2003

    5

    Windows XP

    5

    Windows 2000

    5

     

    OSMinorVersion 操作系统的子版本号。

    Windows version

    Minor version

    Windows 8

    2

    Windows Server 2008 R2

    1

    Windows 7

    1

    Windows Server 2008

    0

    Windows Vista

    0

    Windows Server 2003 R2

    2

    Windows Server 2003

    2

    Windows XP

    1

    Windows 2000

    0

     

    ProductType 在Winnt.h文件中定义的VER_NT_xxxx,若指定,操作系统的ProductType必须与之匹配。

    SuiteMask 在Winnt.h文件中定义的VER_SUITE_xxxx,若指定,操作系统的SuiteMask必须与之匹配。

    TargetOSVersion的提取规则如下:

    1)TargetOSVersion若指定,必须以nt开头

    2)TargetOSVersion的Architecture若指定,则为指定的硬件平台;若未指定,对于Windows Server 2003 SP1以前的版本的操作系统,为任何硬件平台,对于Windows Server 2003 SP1及以后版本的操作系统,为x86硬件平台。

    3)TargetOSVersion的OSMajorVersion[.OSMinorVersion]指定该section适用的操作系统的最低版本;若OSMajorVersion指定而OSMinorVersion未指定,则OSMinorVersion为0;若OSMajorVersion和OSMinorVersion都未指定,则为Windows 2000及以后所有版本。

     

    (3)从Model section中提取操作系统版本,硬件平台,设备ID,设备描述,DDInstall section name

    [models-section-name] |

    [models-section-name.TargetOSVersion]  (Windows XP and later versions of Windows)

     

    device-description=install-section-name[,hw-id][,compatible-id...]

    [device-description=install-section-name[,hw-id][,compatible-id]...] ...

    一个models-section-name可能有多个Models section,带有不同的TargetOSVersion,每一个Models section的操作系统版本和硬件平台需要结合所有同名(名称为models-section-name. [TargetOSVersion])section确定,规则如下:

    1)按TargetOSVersion的提取规则获取每个section的操作系统版本区间和硬件平台。

    2)对于任何一个section,在同一个硬件平台下,如果任何两个同名section的版本区间存在交集,则以起始版本高的区间为准,从起始版本低的区间中移去交集。

    从Model section的每一行提取一个指定的设备,device-description为设备描述,hw-id为hardware ID, compatible-id为compatible ID,install-section-name为该设备对应的DDInstall section name。

    (3)从DDInstall section name提取对应某一设备的驱动特征和驱动版本。

    [install-section-name] |

    [install-section-name.nt] |

    [install-section-name.ntx86] |

    [install-section-name.ntia64] |  (Windows XP and later versions of Windows)

    [install-section-name.ntamd64]  (Windows XP and later versions of Windows)

     

    [DriverVer=mm/dd/yyyy[,x.y.v.z] ]

    [FeatureScore=featurescore]...  (Windows Vista and later versions of Windows)

    install-section-name和install-section-name.nt适用于所有的硬件平台,其它的为指定的硬件平台。

    从DriverVer中提取驱动对应某一设备在指定的硬件平台下的版本,规则同从Version section中提取DriverVer。

    从FeatureScore中提取驱动对应某一设备在指定的硬件平台下的特征值,值越小表明支持的特征越佳。

    3.多个INF文件

    以每个INF为单位进行提取信息,提取所有INF文件。

    参考文献

    http://msdn.microsoft.com/en-us/library/windows/hardware/ff546228(v=vs.85).aspx

  • 相关阅读:
    c:forTokens标签循环输出
    jsp转long类型为date,并且格式化
    spring中@Param和mybatis中@Param使用区别(暂时还没接触)
    734. Sentence Similarity 有字典数组的相似句子
    246. Strobogrammatic Number 上下对称的数字
    720. Longest Word in Dictionary 能连续拼接出来的最长单词
    599. Minimum Index Sum of Two Lists两个餐厅列表的索引和最小
    594. Longest Harmonious Subsequence强制差距为1的最长连续
    645. Set Mismatch挑出不匹配的元素和应该真正存在的元素
    409. Longest Palindrome 最长对称串
  • 原文地址:https://www.cnblogs.com/glacierh/p/5738232.html
Copyright © 2011-2022 走看看