23 Nisan 2020 Perşembe

WriteFile metodu

Giriş
İmzası şöyle.
 WriteFile(HANDLE hFile,
           LPCVOID lpBuffer,
           DWORD nNumberOfBytesToWrite,
           LPDWORD lpNumberOfBytesWritten,
           LPOVERLAPPED lpOverlapped
          );
Açıklaması şöyle
Don't use the WIN API WriteFile to try and securely delete. Instead use a secure delete tool like SysInternals sdelete.

If you just use WriteFile the operating system/file system has the option of writing the new data (e.g., a bunch of null bytes or whatever) to a new block on the disk and then updating the master file table to point to the new block not the old block. You will not be assured that you have overwritten the original file data (unless you use WriteFile to, say, write a file as large as the entire disk).
Örnek
Elimizde şöyle bir kod olsun.
typedef struct
{
    int len;
    char data[1];
}Message;
Şöyle yaparız.
OVERLAPPED osWriteS = { 0 };
osWriteS.Offset = 0;
osWriteS.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

DWORD bytesSent;

if (WriteFile(serialPortHandle,message.data,message.len,&bytesSent, &osWriteS) == false)
{
  _cprintf("bytes sent before overlap: %x\n", bytesSent);
  ...
}


Hiç yorum yok:

Yorum Gönder