tags:

views:

323

answers:

4

I'm trying to use the giveio.sys driver which requires a "file" to be opened before you can access protected memory. I'm looking at a C example from WinAVR/AVRdude that uses the syntax:

 #define DRIVERNAME      "\\\\.\\giveio"
 HANDLE h = CreateFile(DRIVERNAME,
            GENERIC_READ,
            0,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

but this does not seem to work in Python - I just get a "The specified path is invalid" error.

/Edited to hopefully reduce confusion of ideas (thanks Will). I did verify that the device driver is running via the batch files that come with AVRdude.

+1  A: 

You're question is very confusing to say the least.

1> The code you pasted is using a trick to communicate with the driver using its 'DOSNAME' i.e.

\\.\DRIVERNAME

2> Have you created & loaded the 'giveio' driver ?

The reason the driver handles this calls is because of this

http://msdn.microsoft.com/en-us/library/ms806162.aspx

Kapil Kapre
+1  A: 

I'm not sure if that's possible. As an alternative, you could write a C/C++ program that does all that kernel space work for you and interface with it in Python via the subprocess module or Python C/C++ bindings (and another link for that).

wbowers
+3  A: 

I don't know anything about Python, but I do know a bit about drivers. You're not trying to 'open a file in kernel space' at all - you're just trying to open a handle to a device which happens to be made to look a bit like opening a file.

CreateFile is a user-mode function, and everything you're doing here is user-mode, not kernel mode.

As xenon says, your call may be failing because you haven't loaded the driver yet, or because whatever Python call you're using to do the CreateFile is not passing the write parameters in.

I've never used giveio.sys myself, but personally I would establish that it was loaded correctly by using 'C' or C++ (or some pre-written app) before I tried to get it working via Python.

Will Dean
+2  A: 

Solution: in python you have to use win32file.CreateFile() instead of open(). Thanks everyone for telling me what I was trying to do, it helped me find the answer!

apaulsen