Unable to access my driver

I am facing a problem in opening the device handle in user mode. I am a newbie to driver development and right now, I want to dump/visualize the system attributes that the BIOS actually places in RAM at 000F0000h to 000FFFFFh. So, I wrote a simple driver which I am unable to open its handle in user mode application via CreateFile win32 API or WinObj sysInternals tool. Please anyone could help me out as I am stuck in it for last three days.
In driver code, I do not register myself for the PNP dispatch function as I am not handling any device. Also, I created the device object with device type as unknown. I do not know what I have done wrong. Below, is the driver code and driver inf file.

==============
Driver Code

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath )
{
DriverObject->DriverExtension->AddDevice = (PDRIVER_ADD_DEVICE)BiosDump_AddDevice;
DriverObject->DriverUnload = (PDRIVER_UNLOAD)BiosDump_Unload;

DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)BiosDump_Create;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)BiosDump_Close;
DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)BiosDump_Read;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)BiosDump_DeviceIO;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)BiosDump_Cleanup;

return STATUS_SUCCESS;
}

NTSTATUS
BiosDump_AddDevice(
__in struct _DRIVER_OBJECT *DriverObject,
__in struct _DEVICE_OBJECT *PhysicalDeviceObject )
{
NTSTATUS status;
UNICODE_STRING DeviceName;
UNICODE_STRING SymbolicLinkName;
PDEVICE_OBJECT DeviceObject;

RtlInitUnicodeString( &DeviceName, BIOS_DUMP_NT_DEVICE_NAME );

//
// Create Bios Dump device object
//
status = IoCreateDevice( DriverObject, // DriverObject
0, // DeviceExtensionSize
&DeviceName, // DeviceName
FILE_DEVICE_UNKNOWN, // DeviceType
0, // DeviceCharacteristics
FALSE, // Exclusive
&DeviceObject ); // DeviceObject
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create BiosDump device object…%d\n”, status );
return status;
}

//
// Set the device object flags
//
DeviceObject->Flags |= DO_DIRECT_IO;

RtlInitUnicodeString( &SymbolicLinkName, BIOS_DUMP_DOS_DEVICE_NAME );

//
// Create symbolic link to the device
//
status = IoCreateSymbolicLink( &SymbolicLinkName, &DeviceName );
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create symbolic link to BiosDump device object…%d\n”, status );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Attach the device object to the device stack
//
if( IoAttachDeviceToDeviceStack( DeviceObject, PhysicalDeviceObject ) == NULL )
{
DbgPrint( “ERROR : Failed to attach BiosDump device object to device stack\n” );
IoDeleteSymbolicLink( &SymbolicLinkName );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Clear the device initialization flag
//
DeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);

return STATUS_SUCCESS;
}

===========================================
Driver INF

;--------------------------------------------------------------------
; Version section
;--------------------------------------------------------------------
[Version]
Signature = “$WINDOWS NT$”
Class = System
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
Provider = %EMS%
DriverVer = 07/01/2007,1.0.0.1

;--------------------------------------------------------------------
; DestinationDirs section
;--------------------------------------------------------------------
[DestinationDirs]
DefaultDestDir = 12

;--------------------------------------------------------------------
; SourceDisksNames section
;--------------------------------------------------------------------
[SourceDisksNames]
1 = %Disk1%

;--------------------------------------------------------------------
; SourceDisksFiles section
;--------------------------------------------------------------------
[SourceDisksFiles]
BiosDump.sys = 1

;--------------------------------------------------------------------
; Manufacturer section
;--------------------------------------------------------------------
[Manufacturer]
%EMS% = BiosDumpModelSection,NTx86

[BiosDumpModelSection.NTx86]
%BiosDump% = BiosDumpDDInstall, BiosDump

[BiosDumpDDInstall]
CopyFiles = @BiosDump.sys

[BiosDumpDDInstall.Services]
AddService = %BiosDump%,0x00000002,BiosDumpServiceInstallSection

[BiosDumpServiceInstallSection]
DisplayName = %BiosDump%
Description = %BiosDumpDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 1 ; SERVICE_SYSTEM_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\BiosDump.sys

;--------------------------------------------------------------------
; Strings section
;--------------------------------------------------------------------
[Strings]
EMS = “EMS”
Disk1 = “HardDisk 0”
BiosDump = “BiosDump”
BiosDumpDesc = “Bios Dump Utility”

Your driver doesn’t seem to serve any device stack(s), so your AddDevice routine won’t be called, the driver object won’t be created and the symbolic link won’t be set up.

If you want to verify this, add some debug print
(e.g., ‘DbgPrint(“BiosDump_AddDevice - Called.\r\n”);’)
and see if it appears in the debugger.

The solution is as simple as the problem:
You don’t need an AddDevice routine, so move the IoCreateDevice & IoCreateSymbolicLink stuff to your DriverEntry routine.
Do not call IoAttachDeviceToDeviceStack, because there is no stack to attach to.

Have you put some DbgPrint’s in your driver too see what’s going on?
Is the driver actually loaded into memory and started?

I would bet the driver is not loaded into memory, and in any case your
AddDevice is not called (so the I/O device is not even created).

Hope it helps
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Friday, July 27, 2007 11:18 AM
Subject: [ntdev] Unable to access my driver

>I am facing a problem in opening the device handle in user mode. I am a
>newbie to driver development and right now, I want to dump/visualize the
>system attributes that the BIOS actually places in RAM at 000F0000h to
>000FFFFFh. So, I wrote a simple driver which I am unable to open its handle
>in user mode application via CreateFile win32 API or WinObj sysInternals
>tool. Please anyone could help me out as I am stuck in it for last three
>days.
> In driver code, I do not register myself for the PNP dispatch
> function as I am not handling any device. Also, I created the device
> object with device type as unknown. I do not know what I have done wrong.
> Below, is the driver code and driver inf file.
>
> ==============
> Driver Code
> ==============
>
> NTSTATUS
> DriverEntry(
> IN PDRIVER_OBJECT DriverObject,
> IN PUNICODE_STRING RegistryPath )
> {
> DriverObject->DriverExtension->AddDevice =
> (PDRIVER_ADD_DEVICE)BiosDump_AddDevice;
> DriverObject->DriverUnload =
> (PDRIVER_UNLOAD)BiosDump_Unload;
>
> DriverObject->MajorFunction[IRP_MJ_CREATE] =
> (PDRIVER_DISPATCH)BiosDump_Create;
> DriverObject->MajorFunction[IRP_MJ_CLOSE] =
> (PDRIVER_DISPATCH)BiosDump_Close;
> DriverObject->MajorFunction[IRP_MJ_READ] =
> (PDRIVER_DISPATCH)BiosDump_Read;
> DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
> (PDRIVER_DISPATCH)BiosDump_DeviceIO;
> DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
> (PDRIVER_DISPATCH)BiosDump_Cleanup;
>
> return STATUS_SUCCESS;
> }
>
>
>
> NTSTATUS
> BiosDump_AddDevice(
> _in struct DRIVER_OBJECT *DriverObject,
>
in struct _DEVICE_OBJECT *PhysicalDeviceObject )
> {
> NTSTATUS status;
> UNICODE_STRING DeviceName;
> UNICODE_STRING SymbolicLinkName;
> PDEVICE_OBJECT DeviceObject;
>
> RtlInitUnicodeString( &DeviceName, BIOS_DUMP_NT_DEVICE_NAME );
>
>
> //
> // Create Bios Dump device object
> //
> status = IoCreateDevice( DriverObject, // DriverObject
> 0, //
> DeviceExtensionSize
> &DeviceName, // DeviceName
> FILE_DEVICE_UNKNOWN, // DeviceType
> 0, //
> DeviceCharacteristics
> FALSE, // Exclusive
> &DeviceObject ); // DeviceObject
> if( NT_ERROR( status ) )
> {
> DbgPrint( “ERROR : Failed to create BiosDump device
> object…%d\n”, status );
> return status;
> }
>
> //
> // Set the device object flags
> //
> DeviceObject->Flags |= DO_DIRECT_IO;
>
>
> RtlInitUnicodeString( &SymbolicLinkName, BIOS_DUMP_DOS_DEVICE_NAME );
>
>
> //
> // Create symbolic link to the device
> //
> status = IoCreateSymbolicLink( &SymbolicLinkName, &DeviceName );
> if( NT_ERROR( status ) )
> {
> DbgPrint( “ERROR : Failed to create symbolic link to BiosDump
> device object…%d\n”, status );
> IoDeleteDevice( DeviceObject );
> return status;
> }
>
>
> //
> // Attach the device object to the device stack
> //
> if( IoAttachDeviceToDeviceStack( DeviceObject, PhysicalDeviceObject )
> == NULL )
> {
> DbgPrint( “ERROR : Failed to attach BiosDump device object to
> device stack\n” );
> IoDeleteSymbolicLink( &SymbolicLinkName );
> IoDeleteDevice( DeviceObject );
> return status;
> }
>
>
> //
> // Clear the device initialization flag
> //
> DeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);
>
> return STATUS_SUCCESS;
> }
>
>
>
> ===========================================
> Driver INF
> ===========================================
>
> ;--------------------------------------------------------------------
> ; Version section
> ;--------------------------------------------------------------------
> [Version]
> Signature = “$WINDOWS NT$”
> Class = System
> ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
> Provider = %EMS%
> DriverVer = 07/01/2007,1.0.0.1
>
>
>
>
>
> ;--------------------------------------------------------------------
> ; DestinationDirs section
> ;--------------------------------------------------------------------
> [DestinationDirs]
> DefaultDestDir = 12
>
>
>
>
>
> ;--------------------------------------------------------------------
> ; SourceDisksNames section
> ;--------------------------------------------------------------------
> [SourceDisksNames]
> 1 = %Disk1%
>
>
>
>
>
> ;--------------------------------------------------------------------
> ; SourceDisksFiles section
> ;--------------------------------------------------------------------
> [SourceDisksFiles]
> BiosDump.sys = 1
>
>
>
>
>
> ;--------------------------------------------------------------------
> ; Manufacturer section
> ;--------------------------------------------------------------------
> [Manufacturer]
> %EMS% = BiosDumpModelSection,NTx86
>
>
>
> [BiosDumpModelSection.NTx86]
> %BiosDump% = BiosDumpDDInstall, BiosDump
>
>
>
> [BiosDumpDDInstall]
> CopyFiles = @BiosDump.sys
>
>
>
>
>
> [BiosDumpDDInstall.Services]
> AddService = %BiosDump%,0x00000002,BiosDumpServiceInstallSection
>
>
>
> [BiosDumpServiceInstallSection]
> DisplayName = %BiosDump%
> Description = %BiosDumpDesc%
> ServiceType = 1 ; SERVICE_KERNEL_DRIVER
> StartType = 1 ; SERVICE_SYSTEM_START
> ErrorControl = 1 ; SERVICE_ERROR_NORMAL
> ServiceBinary = %12%\BiosDump.sys
>
>
>
>
>
> ;--------------------------------------------------------------------
> ; Strings section
> ;--------------------------------------------------------------------
> [Strings]
> EMS = “EMS”
> Disk1 = “HardDisk 0”
> BiosDump = “BiosDump”
> BiosDumpDesc = “Bios Dump Utility”
>
>
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

What’s the error your getting? Are you seeing any debugger output? If
not, are you running on Vista, and if so have enabled DbgPrint to be
displayed?

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com
Sent: Friday, July 27, 2007 14:19
To: Windows System Software Devs Interest List
Subject: [ntdev] Unable to access my driver

I am facing a problem in opening the device handle in user mode. I am a
newbie to driver development and right now, I want to dump/visualize the
system attributes that the BIOS actually places in RAM at 000F0000h to
000FFFFFh. So, I wrote a simple driver which I am unable to open its
handle in user mode application via CreateFile win32 API or WinObj
sysInternals tool. Please anyone could help me out as I am stuck in it
for last three days.
In driver code, I do not register myself for the PNP dispatch
function as I am not handling any device. Also, I created the device
object with device type as unknown. I do not know what I have done
wrong. Below, is the driver code and driver inf file.

==============
Driver Code

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath )
{
DriverObject->DriverExtension->AddDevice =
(PDRIVER_ADD_DEVICE)BiosDump_AddDevice;
DriverObject->DriverUnload =
(PDRIVER_UNLOAD)BiosDump_Unload;

DriverObject->MajorFunction[IRP_MJ_CREATE] =
(PDRIVER_DISPATCH)BiosDump_Create;
DriverObject->MajorFunction[IRP_MJ_CLOSE] =
(PDRIVER_DISPATCH)BiosDump_Close;
DriverObject->MajorFunction[IRP_MJ_READ] =
(PDRIVER_DISPATCH)BiosDump_Read;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
(PDRIVER_DISPATCH)BiosDump_DeviceIO;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
(PDRIVER_DISPATCH)BiosDump_Cleanup;

return STATUS_SUCCESS;
}

NTSTATUS
BiosDump_AddDevice(
__in struct _DRIVER_OBJECT *DriverObject,
__in struct _DEVICE_OBJECT *PhysicalDeviceObject )
{
NTSTATUS status;
UNICODE_STRING DeviceName;
UNICODE_STRING SymbolicLinkName;
PDEVICE_OBJECT DeviceObject;

RtlInitUnicodeString( &DeviceName, BIOS_DUMP_NT_DEVICE_NAME );

//
// Create Bios Dump device object
//
status = IoCreateDevice( DriverObject, // DriverObject
0, //
DeviceExtensionSize
&DeviceName, // DeviceName
FILE_DEVICE_UNKNOWN, // DeviceType
0, //
DeviceCharacteristics
FALSE, // Exclusive
&DeviceObject ); // DeviceObject
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create BiosDump device
object…%d\n”, status );
return status;
}

//
// Set the device object flags
//
DeviceObject->Flags |= DO_DIRECT_IO;

RtlInitUnicodeString( &SymbolicLinkName, BIOS_DUMP_DOS_DEVICE_NAME
);

//
// Create symbolic link to the device
//
status = IoCreateSymbolicLink( &SymbolicLinkName, &DeviceName );
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create symbolic link to BiosDump
device object…%d\n”, status );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Attach the device object to the device stack
//
if( IoAttachDeviceToDeviceStack( DeviceObject, PhysicalDeviceObject
) == NULL )
{
DbgPrint( “ERROR : Failed to attach BiosDump device object to
device stack\n” );
IoDeleteSymbolicLink( &SymbolicLinkName );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Clear the device initialization flag
//
DeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);

return STATUS_SUCCESS;
}

===========================================
Driver INF

;--------------------------------------------------------------------
; Version section
;--------------------------------------------------------------------
[Version]
Signature = “$WINDOWS NT$”
Class = System
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
Provider = %EMS%
DriverVer = 07/01/2007,1.0.0.1

;--------------------------------------------------------------------
; DestinationDirs section
;--------------------------------------------------------------------
[DestinationDirs]
DefaultDestDir = 12

;--------------------------------------------------------------------
; SourceDisksNames section
;--------------------------------------------------------------------
[SourceDisksNames]
1 = %Disk1%

;--------------------------------------------------------------------
; SourceDisksFiles section
;--------------------------------------------------------------------
[SourceDisksFiles]
BiosDump.sys = 1

;--------------------------------------------------------------------
; Manufacturer section
;--------------------------------------------------------------------
[Manufacturer]
%EMS% = BiosDumpModelSection,NTx86

[BiosDumpModelSection.NTx86]
%BiosDump% = BiosDumpDDInstall, BiosDump

[BiosDumpDDInstall]
CopyFiles = @BiosDump.sys

[BiosDumpDDInstall.Services]
AddService = %BiosDump%,0x00000002,BiosDumpServiceInstallSection

[BiosDumpServiceInstallSection]
DisplayName = %BiosDump%
Description = %BiosDumpDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 1 ; SERVICE_SYSTEM_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\BiosDump.sys

;--------------------------------------------------------------------
; Strings section
;--------------------------------------------------------------------
[Strings]
EMS = “EMS”
Disk1 = “HardDisk 0”
BiosDump = “BiosDump”
BiosDumpDesc = “Bios Dump Utility”


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@yahoo.com wrote:

I am facing a problem in opening the device handle in user mode. I am a newbie to driver development and right now, I want to dump/visualize the system attributes that the BIOS actually places in RAM at 000F0000h to 000FFFFFh.

What “system attributes” do you expect to find here? A much quicker and
easier way to dump this information is to open a cmd shell and do this:

C:\Windows>debug
-d f000:0 l 280
F000:0000 00 13 00 00 01 02 00 E0-03 07 90 9E CB 7F 00 00

F000:0010 00 00 33 50 68 6F 65 6E-69 78 20 54 65 63 68 6E …3Phoenix
Techn
F000:0020 6F 6C 6F 67 69 65 73 2C-20 4C 54 44 00 36 2E 30 ologies,
LTD.6.0
F000:0030 30 20 50 47 00 31 30 2F-32 30 2F 32 30 30 35 00 0
PG.10/20/2005.
F000:0040 00 01 19 01 00 01 02 03-04 FF FF FF FF FF FF FF

F000:0050 FF FF FF FF FF FF FF FF-FF 06 20 00 20 00 20 00 …
. . .
F000:0060 20 00 00 02 08 02 00 01-02 03 04 20 00 6E 46 6F …
.nFo
F000:0070 72 63 65 34 2D 41 39 33-39 00 20 00 20 00 00 03 rce4-A939.
. …
F000:0080 0D 03 00 01 03 02 03 04-02 02 02 02 20 00 20 00
… . .
F000:0090 20 00 20 00 00 04 20 04-00 01 03 83 02 B1 0F 02 . …

F000:00A0 00 FF FB 8B 17 03 8D C9-00 B8 0B DA 07 41 12 0A
…A…
F000:00B0 00 0C 00 FF FF 53 6F 63-6B 65 74 20 39 33 39 00 …Socket
939.
F000:00C0 41 4D 44 00 41 4D 44 20-41 74 68 6C 6F 6E 28 74 AMD.AMD
Athlon(t
F000:00D0 6D 29 20 36 34 20 58 32-20 44 75 61 6C 20 43 6F m) 64 X2
Dual Co
F000:00E0 72 65 20 50 72 6F 63 65-73 73 6F 72 20 33 38 30 re
Processor 380
F000:00F0 30 2B 00 00 05 18 05 00-06 04 03 03 0C 1C 00 04
0+…
F000:0100 01 04 04 06 00 07 00 08-00 09 00 00 00 00 06 0C

F000:0110 06 00 01 FF 05 12 00 7F-7F 00 41 30 00 00 06 0C
…A0…
F000:0120 07 00 01 FF 05 12 00 7F-7F 00 41 31 00 00 06 0C
…A1…
F000:0130 08 00 01 45 05 12 00 89-89 00 41 32 00 00 06 0C
…E…A2…
F000:0140 09 00 01 67 05 12 00 89-89 00 41 33 00 00 07 13
…g…A3…
F000:0150 0A 00 01 80 01 80 00 80-00 20 00 20 00 00 02 02 … .

F000:0160 02 49 6E 74 65 72 6E 61-6C 20 43 61 63 68 65 00 .Internal
Cache.
F000:0170 00 07 13 0B 00 01 80 01-80 00 80 00 20 00 20 00
… . .
F000:0180 00 02 02 02 45 78 74 65-72 6E 61 6C 20 43 61 63
…External Cac
F000:0190 68 65 00 00 08 09 0C 00-01 16 00 00 FF 50 52 49
he…PRI
F000:01A0 4D 41 52 59 20 49 44 45-00 00 08 09 0D 00 01 16 MARY
IDE…
F000:01B0 00 00 FF 53 45 43 4F 4E-44 41 52 59 20 49 44 45
…SECONDARY IDE
F000:01C0 00 00 08 09 0E 00 01 17-00 00 A1 46 44 44 00 00
…FDD…
F000:01D0 08 09 0F 00 01 18 02 08-07 43 4F 4D 31 00 20 00
…COM1. .
F000:01E0 00 08 09 10 00 01 18 02-08 07 43 4F 4D 32 00 20 …COM2.
F000:01F0 00 00 08 09 11 00 01 05-02 05 05 4C 50 54 31 00
…LPT1.
F000:0200 20 00 00 08 09 12 00 01-0F 02 0F 0D 4B 65 79 62
…Keyb
F000:0210 6F 61 72 64 00 20 00 00-08 09 13 00 01 0F 02 0F oard.

F000:0220 0E 50 53 2F 32 20 4D 6F-75 73 65 00 20 00 00 08 .PS/2
Mouse. …
F000:0230 09 14 00 00 00 01 FF 10-55 53 42 30 00 00 09 0D
…USB0…
F000:0240 15 00 01 06 05 03 04 01-00 02 01 50 43 49 30 00
…PCI0.
F000:0250 00 09 0D 16 00 01 06 05-04 04 02 00 02 01 50 43
…PC
F000:0260 49 31 00 00 09 0D 17 00-01 06 05 03 04 03 00 02
I1…
F000:0270 01 50 43 49 32 00 00 09-0D 18 00 01 06 05 03 04
.PCI2…

So, I wrote a simple driver which I am unable to open its handle in user mode application via CreateFile win32 API or WinObj sysInternals tool. Please anyone could help me out as I am stuck in it for last three days.

How do you expect that your driver will be loaded? Who is going to
request it?

You should make this a “legacy” driver, not a PnP driver. Then you can
use the service manager to load and unload it from user-mode. You will
have to move all of the AddDevice processing into DriverEntry


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Salman,

Why would you think your AddDevice would be getting called if there is
no device you are controlling?

Move the code you have in your AddDevice for creating the control device
into your DriverEntry so the code is actually executed. Obviously you
would not perform the IoAttach() call since there is nothing to attach to.

Then make sure your dispatch handlers correctly handle requests and
completes the Irp. There should be no dispatch handlers which pass
things down the ‘stack’ since there is no stack for your device
instance, it is stand alone.

Pete

Kernel Drivers
Windows File System and Device Driver Consulting
www.KernelDrivers.com
(303)546-0300

xxxxx@yahoo.com wrote:

I am facing a problem in opening the device handle in user mode. I am a newbie to driver development and right now, I want to dump/visualize the system attributes that the BIOS actually places in RAM at 000F0000h to 000FFFFFh. So, I wrote a simple driver which I am unable to open its handle in user mode application via CreateFile win32 API or WinObj sysInternals tool. Please anyone could help me out as I am stuck in it for last three days.
In driver code, I do not register myself for the PNP dispatch function as I am not handling any device. Also, I created the device object with device type as unknown. I do not know what I have done wrong. Below, is the driver code and driver inf file.

==============
Driver Code

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath )
{
DriverObject->DriverExtension->AddDevice = (PDRIVER_ADD_DEVICE)BiosDump_AddDevice;
DriverObject->DriverUnload = (PDRIVER_UNLOAD)BiosDump_Unload;

DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)BiosDump_Create;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)BiosDump_Close;
DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)BiosDump_Read;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)BiosDump_DeviceIO;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)BiosDump_Cleanup;

return STATUS_SUCCESS;
}

NTSTATUS
BiosDump_AddDevice(
__in struct _DRIVER_OBJECT *DriverObject,
__in struct _DEVICE_OBJECT *PhysicalDeviceObject )
{
NTSTATUS status;
UNICODE_STRING DeviceName;
UNICODE_STRING SymbolicLinkName;
PDEVICE_OBJECT DeviceObject;

RtlInitUnicodeString( &DeviceName, BIOS_DUMP_NT_DEVICE_NAME );

//
// Create Bios Dump device object
//
status = IoCreateDevice( DriverObject, // DriverObject
0, // DeviceExtensionSize
&DeviceName, // DeviceName
FILE_DEVICE_UNKNOWN, // DeviceType
0, // DeviceCharacteristics
FALSE, // Exclusive
&DeviceObject ); // DeviceObject
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create BiosDump device object…%d\n”, status );
return status;
}

//
// Set the device object flags
//
DeviceObject->Flags |= DO_DIRECT_IO;

RtlInitUnicodeString( &SymbolicLinkName, BIOS_DUMP_DOS_DEVICE_NAME );

//
// Create symbolic link to the device
//
status = IoCreateSymbolicLink( &SymbolicLinkName, &DeviceName );
if( NT_ERROR( status ) )
{
DbgPrint( “ERROR : Failed to create symbolic link to BiosDump device object…%d\n”, status );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Attach the device object to the device stack
//
if( IoAttachDeviceToDeviceStack( DeviceObject, PhysicalDeviceObject ) == NULL )
{
DbgPrint( “ERROR : Failed to attach BiosDump device object to device stack\n” );
IoDeleteSymbolicLink( &SymbolicLinkName );
IoDeleteDevice( DeviceObject );
return status;
}

//
// Clear the device initialization flag
//
DeviceObject->Flags &= ~(DO_DEVICE_INITIALIZING);

return STATUS_SUCCESS;
}

===========================================
Driver INF

;--------------------------------------------------------------------
; Version section
;--------------------------------------------------------------------
[Version]
Signature = “$WINDOWS NT$”
Class = System
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
Provider = %EMS%
DriverVer = 07/01/2007,1.0.0.1

;--------------------------------------------------------------------
; DestinationDirs section
;--------------------------------------------------------------------
[DestinationDirs]
DefaultDestDir = 12

;--------------------------------------------------------------------
; SourceDisksNames section
;--------------------------------------------------------------------
[SourceDisksNames]
1 = %Disk1%

;--------------------------------------------------------------------
; SourceDisksFiles section
;--------------------------------------------------------------------
[SourceDisksFiles]
BiosDump.sys = 1

;--------------------------------------------------------------------
; Manufacturer section
;--------------------------------------------------------------------
[Manufacturer]
%EMS% = BiosDumpModelSection,NTx86

[BiosDumpModelSection.NTx86]
%BiosDump% = BiosDumpDDInstall, BiosDump

[BiosDumpDDInstall]
CopyFiles = @BiosDump.sys

[BiosDumpDDInstall.Services]
AddService = %BiosDump%,0x00000002,BiosDumpServiceInstallSection

[BiosDumpServiceInstallSection]
DisplayName = %BiosDump%
Description = %BiosDumpDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 1 ; SERVICE_SYSTEM_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\BiosDump.sys

;--------------------------------------------------------------------
; Strings section
;--------------------------------------------------------------------
[Strings]
EMS = “EMS”
Disk1 = “HardDisk 0”
BiosDump = “BiosDump”
BiosDumpDesc = “Bios Dump Utility”


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

First of all thanks for your reply and suggestions. Second, I put DbgPrint in AddDevice routine and it is called. Also, I verified from the DeviceTree utility that the device is created and my lower device to which I am attached is \Device\PnPManager. The problem I always get is that I am unable to open the device. Also, When I try to install through ADD New Hardware device wizard. It installs successfully but it says when finishing that unable to start service. I do not know what to do. If you want to send my code in zip format and place it in some file sharing site. I can do that. I will be glad if you kindly look into it.
Thanks