21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cbWrite = (dwFileSize > cbBuffer ? cbBuffer : dwFileSize);<br />

for (cbTotalWritten = 0; cbWrite > 0; cbTotalWritten += cbWritten)<br />

if (!WriteFile(hFile, pbBuffer + cbTotalWritten, cbWrite - cbTotalWritten,<br />

&cbWritten, 0)) return FALSE;<br />

dwFileSize -= cbTotalWritten;<br />

}<br />

return TRUE;<br />

}<br />

BOOL SpcWipeFile(HANDLE hFile) {<br />

BYTE pbBuffer[SPC_WIPE_BUFSIZE];<br />

DWORD dwCount, dwFileSize, dwIndex, dwPass;<br />

HCRYPTPROV hProvider;<br />

static BYTE pbSinglePats[16] = {<br />

0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,<br />

0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff<br />

};<br />

static BYTE pbTriplePats[6][3] = {<br />

{ 0x92, 0x49, 0x24 }, { 0x49, 0x24, 0x92 }, { 0x24, 0x92, 0x49 },<br />

{ 0x6d, 0xb6, 0xdb }, { 0xb6, 0xdb, 0x6d }, { 0xdb, 0x6d, 0xb6 }<br />

};<br />

static DWORD cbPattern = sizeof(pbTriplePats[0]);<br />

if ((dwFileSize = GetFileSize(hFile, 0)) = = INVALID_FILE_SIZE) return FALSE;<br />

if (!dwFileSize) return TRUE;<br />

if (!CryptAcquireContext(&hProvider, 0, 0, 0, CRYPT_VERIFYCONTEXT))<br />

return FALSE;<br />

for (dwPass = 0; dwPass < 4; dwPass++)<br />

if (!RandomPass(hFile, hProvider, dwFileSize)) {<br />

CryptReleaseContext(hProvider, 0);<br />

return FALSE;<br />

}<br />

memset(pbBuffer, pbSinglePats[5], sizeof(pbBuffer));<br />

if (!PatternPass(hFile, pbBuffer, sizeof(pbBuffer), dwFileSize)) {<br />

CryptReleaseContext(hProvider, 0);<br />

return FALSE;<br />

}<br />

memset(pbBuffer, pbSinglePats[10], sizeof(pbBuffer));<br />

if (!PatternPass(hFile, pbBuffer, sizeof(pbBuffer), dwFileSize)) {<br />

CryptReleaseContext(hProvider, 0);<br />

return FALSE;<br />

}<br />

cbPattern = sizeof(pbTriplePats[0]);<br />

for (dwPass = 0; dwPass < 3; dwPass++) {<br />

dwCount = sizeof(pbBuffer) / cbPattern;<br />

for (dwIndex = 0; dwIndex < dwCount; dwIndex++)<br />

CopyMemory(pbBuffer + (dwIndex * cbPattern), pbTriplePats[dwPass],<br />

cbPattern);<br />

if (!PatternPass(hFile, pbBuffer, cbPattern * dwCount, dwFileSize)) {<br />

52 | Chapter 2: Access Control<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!