A forum for reverse engineering, OS internals and malware analysis 

Ask your beginner questions here.
 #23889  by Carlbyte
 Tue Sep 16, 2014 3:13 am
I'm dealing with a few issues about writing data to file. Some doubts arose about ZwFlushBuffersFile function. Which is the case when to use this? If I use the sequence of functions below is not enough? I read the documentation from microsoft but it was not clear enough.

Openfile (file ... writefile (file ... closefile (file ...

Thanks
 #23894  by EP_X0FF
 Tue Sep 16, 2014 9:56 am
http://msdn.microsoft.com/en-us/library ... s.85).aspx

see Remarks for a detailed description how it works.
Carlbyte wrote:I'm dealing with a few issues about writing data to file. Some doubts arose about ZwFlushBuffersFile function. Which is the case when to use this? If I use the sequence of functions below is not enough? I read the documentation from microsoft but it was not clear enough.

Openfile (file ... writefile (file ... closefile (file ...

Thanks
 #23896  by Carlbyte
 Tue Sep 16, 2014 3:11 pm
Thanks..

I have a question that when I call the function ZwWriteFile and then I need to call the function again this occurring BSOD.

IF NT_SUCCESS (ZwWriteFile ()) THEN
ZwWriteFile ()

CreateFile with flags FILE_WRITE_DATA | FILE_READ_DATA

Access without syncing because I have several threads reading data in this file.

I thought in flushbuffers, but do not know if it is the case. Anyone with any tips?
 #23898  by Carlbyte
 Tue Sep 16, 2014 4:40 pm
if I disable the second ZwWriteFile the bsod does not occur. The error does not occur when I install the driver, the code works normally. But when I restart the computer, so the system loads the driver, BSOD occurs.
 #23899  by Vrtule
 Tue Sep 16, 2014 4:52 pm
Well, I still think it would be more effective to look at your code. For now, we can only have some ideas why you are encountering the BSOD. Personally, I think you are passing an invalid buffer to one of the function parameters. Maybe, the buffer is not strictly invalid but it might be sometimes.
 #23901  by Carlbyte
 Tue Sep 16, 2014 7:43 pm
The error is PAGE_FAULT_IN_NONPAGED_AREA, but I think the error is being caused by some other factor. The input buffer in this case is a local variable of the function that calls ZwWriteFile. Was experiencing the same problem with ZwReadFile function and the problem was only solved when I used WaitForSingleObject, so the question flushbuffer.

The purpose of this post is whether missing something about parameters / calls for writing to file.

Anyway, thanks for the help
 #23902  by Vrtule
 Tue Sep 16, 2014 10:19 pm
Remember that if you are doing an asynchronous read/write (or other operation that uses buffers for input/output) the buffer(s) usually must remain valid until the operation completes (not until the function initiating the asynchronous operation returns, this is usually not sufficient).