天天看點

驅動程式在64位簽名

1.inf檔案說明 

微軟說明:https://docs.microsoft.com/zh-cn/windows-hardware/drivers/install/inf-version-section

例子

[Version]
 
Signature="signature-name"
[Class=class-name]
[ClassGuid={nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}]
[Provider=%INF-creator%]
[ExtensionId={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}]
[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)
[CatalogFile.ntarm=unique-filename.cat]  (Windows 8 and later versions of Windows)
[CatalogFile.ntarm64=unique-filename.cat]  (Windows XP and later versions of Windows)

DriverVer=mm/dd/yyyy,w.x.y.z
[PnpLockDown=0|1] (Windows Vista and later versions of Windows)
[DriverPackageDisplayName=%driver-package-description%]
[DriverPackageType=PackageType]


[Version]
Signature="$Windows NT$"
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}
Provider=%INF_Provider%
CatalogFile=aha154_ntx86.cat
DriverVer=01/29/2010

[SourceDisksNames]
;
; diskid = description[, [tagfile] [, <unused>, subdir]]
;
1 = %Floppy_Description%,,,\WinNT

[SourceDisksFiles.x86]
;
; filename_on_source = diskID[, [subdir][, size]]
;
aha154x.sys = 1,\x86

; ...

[Strings]
INF_Provider="Adaptec"
Floppy_Description = "Adaptec Drivers Disk"
; ...
           

看雪網址:https://bbs.pediy.com/thread-190884.htm

 測試簽名擷取: 

假設編譯好的驅動的位置是: E:\WinDDk\my_test\objchk_win7_amd64\amd64

1. 制作一個測試使用的數字證書: 

使用管理者權限打開指令行(我用的是VS自帶的64位指令行或者WDK指令行x64 Checked Build Environment)進入驅動的路徑,然後輸入以下指令:

makecert –r -pe -ss PrivateCertStore -n "CN=Contoso.com(Test)" My_Test.cer

MakeCert -r -pe -ss PrivateCertStore -n "CN=Contoso.com(Test)" testcert.cer

這個時候在目錄下會生成一個My_Test.cer的測試證書;如果不使用管理者權限可能會失敗;如果使用cmd可能會失敗;

2. 修改INF檔案并生成目錄檔案: 

一般INF檔案都會有一個version節

[version]

Signature   = "$Windows NT$"

Class         = xxx

ClassGUID  = xxx

Provider     = xxx

DriverVer    = xxx

在這個節點的最後增加一個CatalogFile.NtAMD64 = My_Test_AMD64.cat

需要注意的是這個CatalogFile隻有CatalogFile.NtAMD64 CatalogFile.Nt CatalogFile三個情況;然後将INF檔案也放到驅動sys檔案的路徑下

使用管理者權限打開WDK自帶的指令行進入到對應的驅動程式路徑,輸入下面的指令

Inf2cat.exe /driver:E:\WinDDk\my_test\objchk_win7_amd64\amd64\ /os:7_x64

這裡有幾個地方會出問題,首先是/driver:後面不能有空格,否則會出錯;其次是os:7_x64指的是win 7的x64平台(這個時候它又不會區分AMD64和IA64了);最後是INF檔案必須也在這個目錄下,格式不能出錯,DriverVer這個節點的值最容易出錯;

3. 對cat檔案簽名:

使用以管理者權限打開WDK帶的指令行,定位到驅動程式路徑下,輸入下面的指令:

Signtool sign /a /v /s zcPrivateCertStore /n zcContoso.com(Test) /t http://timestamp.verisign.com/scripts/timestamp.dll My_Test_AMD64.cat

這裡需要聯網,不聯網會有一個警告,因為它需要去生成時間戳;

4. 注冊測試數字證書:

以管理者權限打開WDK指令行,定位到驅動檔案路徑下,輸入以下指令:

certmgr.exe /add My_Test.cer /s /r localMachine root

5. 對驅動檔案簽名:

以管理者權限打開WDK指令行,定位到驅動檔案路徑下,輸入以下指令:

Signtool sign /a /v /s zcPrivateCertStore /n zcContoso.com(Test) /t http://timestamp.verisign.com/scripts/timestamp.dll xxxx.sys

這裡需要聯網,不聯網會有一個警告,因為它需要去生成時間戳;

6. 安裝測試簽名:

在目标機上,将xxx.sys xxx.inf My_Test.cer My_Test_AMD64.cat,以及certmgr.exe放在一個路徑下,然後以管理者權限打開CMD指令行定位到這個目錄,輸入以下指令來注冊證書以及打開測試模式:

certmgr.exe /add My_Test.cer /s /r localMachine root

certmgr.exe /add My_Test.cer /s /r localMachine trustedpublisher

cd c:\windows\system32\

bcdedit.exe /set TESTSIGNING ON

測試模式打開一次後,即使重新開機電腦也不用再次設定,除非顯式的關閉它;窗體右下角會提示目前是在測試模式,關閉的指令是bcdedit.exe /set TESTSIGNING OFF

需要注意的事項:

1. 如果目标機上沒有certmgr.exe,那麼可以從主機上直接拷貝一個64位的certmgr.exe過去的;

2. 如果重新生成了sys檔案而沒有修改inf檔案的話,那麼隻需要在生成sys檔案後再次執行對驅動檔案的重新簽名即可;測試證書和目錄檔案都不需要重新生成;

3. 最好都使用管理者權限來啟動指令行;不用每次都關閉WDK的指令行,事實上可以一直使用同一個WDK的指令行;如果覺得輸入太麻煩,那麼可以複制粘貼的;在目标機上的注冊證書,可以寫一個bat檔案的;

4. 測試簽名可以使用預安裝來安裝;makecert、Inf2cat、Signtool、certmgr都在WDK中有;