Windows驅動匹配詳解

 

在Windows下,幾乎全部的硬件設備都須要安裝驅動後才能正常工做,咱們重裝系統後第一件事就是要爲各設備安裝好驅動,咱們能夠下載官方驅動手動安裝,也可讓我Windows自動掃描安裝,還可使用驅動精靈、電腦管家之類的工具幫咱們安裝,爲了發揮硬件設備最好的性能,咱們還須要及時把驅動升級到最新的版本。那麼,這些工具是如何爲硬件設備匹配到最佳的驅動的呢?此文就這個問題一探究竟。windows

驅動匹配相關信息

設備都是經過hardware ID進行標識,一個設備通常有多個hardware ID和compatible ID,這些ID對設備的標識程度按照順序依次下降,咱們能夠在Windows設備管理器中查看到設備的硬件Id和兼容Id。安全

 

Windows下的驅動必須包含一個信息文件(INF)以進行安裝,INF文本文件包含設備安裝組件(device installation components)安裝驅動所必需的全部信息。從INF文件中能夠提取驅動匹配所需的信息:服務器

(1)驅動提供商ide

(2)驅動類型工具

(3)驅動的日期和版本性能

(4)驅動的特徵值,用來衡量驅動對設備特徵的支持程度ui

(5)驅動支持的操做系統版本和硬件平臺spa

(6)驅動支持的設備的hardware ID和compatible ID操作系統

設備和驅動的標識匹配是指設備的hardware ID或compatible ID與驅動INF文件指定的hardware ID或compatible ID的匹配,匹配程度從高到低有如下4中類型:3d

(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

相關文章
相關標籤/搜索