3

デバッグに「HelloWorld」のみを出力する単純なドライバーを作成しました。空のドライバープロジェクトを作成するために、Visual Studio 2012RCとWDK8を使用して、次のコードを記述しました。

#include <NTDDK.h>

extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath) 
{
    pRegistryPath = pRegistryPath; //unused
    DbgPrint("Hello World!");
    pDriverObject->DriverUnload = NULL;
    return STATUS_SUCCESS;
}

私はそれをwin7x64にコンパイルしました。このドライバーをインストールして実行するには、.infファイルを作成する必要があることを読みましたが、それを管理できないようです。WDK 8からサンプルの.infファイルを取得し、.sysファイルと一致するように変更しましたが、仮想ボックスwin7x64が台無しになりました:-)。そこで、VS2012でフィルタードライバープロジェクトを作成し、.infファイルを取得して.sysファイルと一致するように変更しましたが、インストールしても何も起こりませんでした。作成した新しいサービスを実行してみました

net start MyDriver

しかし、デバッグには何も出力されず、[コンピューター]->[管理]->[サービス]にMyDriverが表示されません。DebugViewを使用して、デバッグに出力される内容を確認しています(http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx)。

もちろん、時間の経過とともに、実際に何かを実行するドライバーを作成したいと思いますが、その間、それを実行する方法を知りたいだけです。

VS2012から取得して変更した.infファイルは次のとおりです。

;;;
;;; MyDriver2
;;;

[Version]
Signature   = "$Windows NT$"
; TODO - Change the Class and ClassGuid to match the Load Order Group value, see http://msdn.microsoft.com/en-us/windows/hardware/gg462963
; Class       = "ActivityMonitor"                         ;This is determined by the work this filter driver does
; ClassGuid   = {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}    ;This value is determined by the Load Order Group value
Class = "ActivityMonitor" 
ClassGuid = {b86dff51-a31e-4bac-b3cf-e8cfe75c9fc2}
Provider    = %ManufacturerName%
DriverVer   = 08/13/2012,1.0.0.0
;CatalogFile = MyDriver2.cat

[DestinationDirs]
DefaultDestDir          = 12
MiniFilter.DriverFiles  = 12            ;%windir%\system32\drivers

;;
;; Default install sections
;;

[DefaultInstall]
OptionDesc          = %ServiceDescription%
CopyFiles           = MiniFilter.DriverFiles

[DefaultInstall.Services]
AddService          = %ServiceName%,,MiniFilter.Service

;;
;; Default uninstall sections
;;

[DefaultUninstall]
DelFiles   = MiniFilter.DriverFiles

[DefaultUninstall.Services]
DelService = %ServiceName%,0x200      ;Ensure service is stopped before deleting

;
; Services Section
;

[MiniFilter.Service]
DisplayName      = %ServiceName%
Description      = %ServiceDescription%
ServiceBinary    = %12%\%DriverName%.sys        ;%windir%\system32\drivers\
Dependencies     = "FltMgr"
ServiceType      = 2                            ;SERVICE_FILE_SYSTEM_DRIVER
StartType        = 3                            ;SERVICE_DEMAND_START
ErrorControl     = 1                            ;SERVICE_ERROR_NORMAL
; TODO - Change the Load Order Group value, see http://connect.microsoft.com/site221/content/content.aspx?ContentID=2512
; LoadOrderGroup = "FSFilter Activity Monitor"
LoadOrderGroup   = "filter"
AddReg           = MiniFilter.AddRegistry

;
; Registry Modifications
;

[MiniFilter.AddRegistry]
HKR,,"DebugFlags",0x00010001 ,0x0
HKR,,"SupportedFeatures",0x00010001,0x3
HKR,"Instances","DefaultInstance",0x00000000,%DefaultInstance%
HKR,"Instances\"%Instance1.Name%,"Altitude",0x00000000,%Instance1.Altitude%
HKR,"Instances\"%Instance1.Name%,"Flags",0x00010001,%Instance1.Flags%

;
; Copy Files
;

[MiniFilter.DriverFiles]
%DriverName%.sys

[SourceDisksFiles]
MyDriver2.sys = 1,,

[SourceDisksNames]
1 = %DiskId1%,,,

;;
;; String Section
;;

[Strings]
; TODO - Add your manufacturer
ManufacturerName        = "Template"
ServiceDescription      = "MyDriver2 Mini-Filter Driver"
ServiceName             = "MyDriver2"
DriverName              = "MyDriver2"
DiskId1                 = "MyDriver2 Device Installation Disk"

;Instances specific information.
DefaultInstance         = "MyDriver2 Instance"
Instance1.Name          = "MyDriver2 Instance"
; TODO - Change the altitude value, see http://connect.microsoft.com/site221/content/content.aspx?ContentID=2512
;Instance1.Altitude      = "370030"
Instance.Altitude       = "370030"
Instance1.Flags         = 0x0              ; Allow all attachments

wdreg.exeを使用してドライバをインストールして実行しようとすると、「INFファイルの製造元セクションが見つかりませんでした」と表示されました。(http://www.jungo.com/st/support/documentation/windriver/10.3.0/wdpci_manual.mhtml/dyn_windows.htmlから).infファイルについてたくさん読んだ(いくつかのマイクロソフトブックとたくさんのグーグルから) )そして私はまだ私の.infファイルを修正する方法を知りません。

私のドライバーを実行するためのより簡単な方法があれば、私はそれについて聞いてみたいです。実行方法がわかれば、実際の製品のデバッグは簡単になります。

ありがとう!

編集:テストモード(http://www.ngohq.com/home.php?page=dseo)でDriver SignatureEnforcementOverriderを使用して.sysファイルも歌います。

4

2 に答える 2

4

ローハンが正しかったことがわかった。win7(Rohanリンクはビスタ用)でデバッグ印刷を表示する方法を見つけることができなかったので、ファイルを作成しました。

#include <wdm.h>
#include <Ntstrsafe.h>

extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath) 
{
    UNICODE_STRING     uniName;
    OBJECT_ATTRIBUTES  objAttr;

    RtlInitUnicodeString(&uniName, L"\\SystemRoot\\example12345.txt");
    InitializeObjectAttributes(&objAttr, &uniName,
                               OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                               NULL, NULL);

    HANDLE   handle;
    NTSTATUS ntstatus;
    IO_STATUS_BLOCK    ioStatusBlock;

    // Do not try to perform any file operations at higher IRQL levels.
    // Instead, you may use a work item or a system worker thread to perform file operations.

    if(KeGetCurrentIrql() != PASSIVE_LEVEL){
        return STATUS_INVALID_DEVICE_STATE; 
    }

    ntstatus = ZwCreateFile(&handle,
                            GENERIC_WRITE,
                            &objAttr, &ioStatusBlock, NULL,
                            FILE_ATTRIBUTE_NORMAL,
                            0,
                            FILE_OVERWRITE_IF, 
                            FILE_SYNCHRONOUS_IO_NONALERT,
                            NULL, 0);


    CHAR     buffer[30];
    size_t  cb;

    if(NT_SUCCESS(ntstatus)) {
        ntstatus = RtlStringCbPrintfA(buffer, sizeof(buffer), "This is a test\r\n");
        if(NT_SUCCESS(ntstatus)) {
            ntstatus = RtlStringCbLengthA(buffer, sizeof(buffer), &cb);
            if(NT_SUCCESS(ntstatus)) {
                ntstatus = ZwWriteFile(handle, NULL, NULL, NULL, &ioStatusBlock, buffer, (ULONG)cb, NULL, NULL);
            }
        }
        ZwClose(handle);
    }


    pRegistryPath = pRegistryPath;
    pDriverObject = pDriverObject;

    return STATUS_SUCCESS;
}

質問で書いたものと同じ.infを使用して、cmdと入力しました

net start MyDriver2

そして、ファイルexample12345.txtはC:/Windowsで作成されました。

于 2012-08-21T11:36:57.653 に答える
2

ドライバをロード/起動すると、そのドライバはカーネルにロードされて機能するため、ほとんどの場合、ドライバがロードされます。ただし、DbgPrint表示されない可能性のあるメッセージは、Vista以降、ログに記録されたデバッグメッセージDbgPrintがフィルタリングされ、出力に表示されないためです。

これを参照して、DbgPrintメッセージの表示を有効にすることができます。Vista以降でDbgPrint出力を表示する

別の方法はDbgPrintEx、適切なコンポーネントとレベルで使用することです。

于 2012-08-15T07:21:06.813 に答える