Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open device name using CreateFile

I am working on a simple device driver I want to comunicate with the driver from user-mode using IRP.

I am having trouble opening the device driver. Using DeviceTree I am able to see the device name eg \Device\MyDevice.

But when I try to open it like this :

hand := CreateFile('\Device\MyDevice', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);  

I always get INVALID_HANDLE_VALUE and GetLastError is (The System cannot find the path specified)

What I am doing wrong ? I know the driver works because I can see it running and printing stuff in DebugView. So any tips ?

enter image description here

like image 737
opc0de Avatar asked Feb 11 '14 13:02

opc0de


1 Answers

Here is a good explanation by Tim Robinson, MVP (Windows SDK):

Names of the form \Device\xxx are internal NT object manager names which are inaccessible to Win32. You will only be able to access your device if it creates a symbolic link to \Device\MyDevice from the \??\ directory. Objects in the \??\ kernel directory show up through \\.\ in Win32. Use Winobj in the DDK (or download it from www.sysinternals.com) to check.

NOTE: Nowadays NT namespace root is exposed via GLOBALROOT symbolic link, so any NT path is accessible to Win32 including \Device\xxx: use \\.\GLOBALROOT\Device\xxx. A device symlink is not required in such case.

like image 173
Sergey Podobry Avatar answered Oct 27 '22 07:10

Sergey Podobry