2012-08-14 3 views
1

"Hello World"만 디버그에 인쇄하는 간단한 드라이버를 작성했습니다. 나는 빈 드라이버 프로젝트를 생성하기 위해 WDK 8 비주얼 스튜디오 2012 RC를 사용하고 follwing을 코드 작성 :드라이버 설치 및 실행 방법

#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; 
} 

내가 WIN7 64에 컴파일 된 적이 있습니다. 이 드라이버를 설치하고 실행하기 위해서는 .inf 파일을 작성해야하지만, 나는 그것을 조정할 수는 없다고 읽었습니다. WDK 8에서 예제 .inf 파일을 가져 와서 .sys 파일과 일치하도록 변경했지만 내 가상 박스 win7 x64 :-)가 망가졌습니다. 그래서 VS2012에서 필터 드라이버 프로젝트를 만들고 .inf 파일을 가져 와서 내 .sys 파일과 일치하도록 변경했습니다. 설치 한 후에는 아무 것도하지 않았습니다. 나는

net start MyDriver 

로 만든 새 서비스를 실행하는 시도했지만 아무것도 디버그에 인쇄되지 않았으며 또한 나는 컴퓨터 -에 MyDriver> Manage-> 서비스를 볼 수 없습니다. 디버그 (http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx)로 인쇄되는 내용을 보려면 DebugView를 사용하고 있습니다.

당연히 나는 acctualy가 뭔가를하는 드라이버를 쓰고 싶지만 그 동안 운전 방법을 알고 싶다.

내가 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 

I 설치하고 내 드라이버를 실행하는 wdreg.exe를 사용하여 시도가 말했다 "INF 파일에서 제조업체 섹션을 찾기 실패". (from http://www.jungo.com/st/support/documentation/windriver/10.3.0/wdpci_manual.mhtml/dyn_windows.html) .inf 파일 (일부 Microsoft 책과 많은 Google)에 대해 많은 내용을 읽었으며 .inf 파일을 수정하는 방법을 아직 모릅니다.

내 드라이버를 실행하는 간단한 방법이 있다면 그것에 대해 듣고 싶습니다. 실행 방법을 알게되면 실제 제품을 디버깅하는 것이 쉬울 것입니다.

감사합니다.

EDIT : 테스트 모드 (http://www.ngohq.com/home.php?page=dseo)에서 Driver Signature Enforcement Overrider를 사용하여 .sys 파일을 또한 처리합니다.

답변

1

드라이버를로드/시작할 때 커널에서로드되고 작동 할 때 드라이버가로드 될 가능성이 큽니다. 그러나 DbgPrint 메시지는으로 기록 된 디버그 메시지가 필터링되고 출력에 표시되지 않기 때문에 표시되지 않을 수 있습니다.

DbgPrint 메시지를 표시하려면이 옵션을 참조하십시오. Getting DbgPrint Output To Appear In Vista and Later

또 다른 방법은 DbgPrintEx을 적절한 구성 요소와 수준으로 사용하는 것입니다.

+0

감사합니다. 나는 그것을 시도 할 것이다. – assafmo

2

로한이 옳았다. win7에서 디버그 인쇄를 볼 방법을 찾지 못했습니다. (Rohan 링크는 Vista 용입니다.) 그래서 방금 파일을 만들었습니다.

#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에서 만든 :/윈도우.

관련 문제