Hi.
Is there a way to write to a file from a vxd? something like CreateFile and WriteFile?
Is there a way to write to a file from a vxd? something like CreateFile and WriteFile?
Well... AFAIK you can't, because files are an OS thing, and if you're a VxD you ARE the OS... maybe you can do something like write directly to a disk anyway...
Let me guess: you're trying to debug a VxD and looking for some way to output errors, ne?
Let me guess: you're trying to debug a VxD and looking for some way to output errors, ne?
Hi,
Check out the IFSMgr_Ring0_FileIO series of calls in the Win98DDK. I can post more code if you want it, but as an example this is how you might create the file:
You'll use these other flags as well.
R0_GETFILESIZE
R0_WRITEFILE
R0_CLOSEFILE
Kayaker
Check out the IFSMgr_Ring0_FileIO series of calls in the Win98DDK. I can post more code if you want it, but as an example this is how you might create the file:
;-----------------------------
; Create the file
;-----------------------------
mov eax,R0_OPENCREAT_IN_CONTEXT
mov ebx,02011h ; read/write|share:read/write|no INT24
mov ecx,020h ; archive
mov edx,11h ; create if does not exist / open if exists
mov esi,[edi].pFileName
VxDCall IFSMgr_Ring0_FileIO
jc Exhandler
You'll use these other flags as well.
R0_GETFILESIZE
R0_WRITEFILE
R0_CLOSEFILE
Kayaker
thanks for your replies so far.
i'll try this IFSMgr_Ring0_FileIO
i'll try this IFSMgr_Ring0_FileIO
Maybe TrueDPMI functions wiil work from the VXDs? As far as I know they are implemented in all the Win32 versions when you use DPMI from the command line subsystem. But I don't know if interrupt calls are avaiable to VXDs.
well, with Kayakers code, i can successfully open/create the file:
LogFileName DB "C:\Windows\xyzzyx.bin", 0
...
mov eax, R0_OPENCREATFILE
mov ebx, 02011h
mov ecx, 020h
mov edx, 011
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO
jc _exit
mov ebx, eax ; ebx = file handle
but when i try to write to the file, it doesn't work (i don't know why, but the file is empty):
mov eax, R0_WRITEFILE
mov ecx, 015h ; length of LogFileName
mov edx, 00h ; start to write at pos. 0
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO
with this code, nothing happens...why is this? what am i doing wrong?
LogFileName DB "C:\Windows\xyzzyx.bin", 0
...
mov eax, R0_OPENCREATFILE
mov ebx, 02011h
mov ecx, 020h
mov edx, 011
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO
jc _exit
mov ebx, eax ; ebx = file handle
but when i try to write to the file, it doesn't work (i don't know why, but the file is empty):
mov eax, R0_WRITEFILE
mov ecx, 015h ; length of LogFileName
mov edx, 00h ; start to write at pos. 0
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO
with this code, nothing happens...why is this? what am i doing wrong?
The high word of ebx should be set to zero.
if i use the same code as above and change the code where i save the file handle to ebx to the following:
VxDCall IFSMgr_Ring0_FileIO ; open/create file
jc _exit ; error
xor ebx, ebx ;
mov bx, ax ; new save file handle code
i replaced
mov ebx, eax
by
xor ebx, ebx
mov bx, ax
this causes a bluescreen.
any other suggestions?
VxDCall IFSMgr_Ring0_FileIO ; open/create file
jc _exit ; error
xor ebx, ebx ;
mov bx, ax ; new save file handle code
i replaced
mov ebx, eax
by
xor ebx, ebx
mov bx, ax
this causes a bluescreen.
any other suggestions?
try using TrueDPMI functions:
xor cx,cx
mov edx,offset _file_name
mov ah,3Ch
int 21h
mov ebx,eax
mov edx,offset _data
mov ecx,_data_size
mov ah,40h
int 21h
Privalov,
you cant use int 21h directly in ring 0 in win9x, this works in ring 3 only and not for system vm because there it is trapped by windows to prevent win32 apps using it.
But I wonder why not using the standard functions "BeginNestExec", "ExecInt" and "EndNestExec" for int 21h file functions, at least at appy time. Are there any disadvantages?
you cant use int 21h directly in ring 0 in win9x, this works in ring 3 only and not for system vm because there it is trapped by windows to prevent win32 apps using it.
But I wonder why not using the standard functions "BeginNestExec", "ExecInt" and "EndNestExec" for int 21h file functions, at least at appy time. Are there any disadvantages?
Oh, I thought I had seen some DPMI calls in the disassembly of one of Win95 built-in VxDs one day, when I was viewing it with HIEW to see the LE executable structure. But I might be wrong.
One caveat with using IFSMgr_Ring0_FileIO is I don't think they can be used from within an interrupt service routine, there seems to be a whole host of reentrancy / asynchronous operation issues with writing to disk from within an ISR. The write operation is apparently queued by the system, but the actual disk i/o occurs later at some undetermined time, giving all sorts of timing problems. Just something to be aware of depending on what you're using this for.
Just out of curiosity, can you use R0_GETFILESIZE or R0_DELETEFILE for example on the opened file, indicating the handle is OK and it's definitely a R0_WRITEFILE problem? Your original code appears to be OK the way you've written it...
Just out of curiosity, can you use R0_GETFILESIZE or R0_DELETEFILE for example on the opened file, indicating the handle is OK and it's definitely a R0_WRITEFILE problem? Your original code appears to be OK the way you've written it...