📄 scwipe.c
字号:
PGPInt32 buffer[256];
PGPInt32 passes = kPGPNumPatterns;
OSVERSIONINFO osid;
BOOL bIsNT;
HANDLE hDriver;
PGPError err;
int numletters;
DWORD quanta;
osid.dwOSVersionInfoSize = sizeof (osid);
GetVersionEx (&osid);
bIsNT=(osid.dwPlatformId == VER_PLATFORM_WIN32_NT);
CancelOperation=FALSE;
if((dwPasses==0)||(dwPasses>32))
{
PGPPrefRef prefRef;
prefRef=NULL;
passes=1;
err=PGPclPeekClientLibPrefRefs(&prefRef,NULL);
if(IsntPGPError(err))
{
PGPGetPrefNumber (prefRef,
kPGPPrefFileWipePasses,
(PGPUInt32*)&passes);
}
}
else
{
passes=dwPasses;
}
GetSystemInfo(&sysinfo);
dwPageSize = sysinfo.dwPageSize;
if((dwWipeFlags&WIPE_ADS)==WIPE_ADS)
{
ui64Size=dwSizeADS;
}
else
{
staterror=_stati64(FileName, &buf );
ui64Size = buf.st_size; // Get the file's size
if(staterror!=0)
return WIPE_NOTOPEN; // check to make sure still around
}
if(hwnd!=NULL)
{
ms=(MYSTATE *)PGPscProgressGetUserValue(hwnd);
}
if(hwnd!=NULL)
{
PGPscProgressSetNewFilename(ms->hwndWorking,"From '%s'",FileName,TRUE);
}
// Movefile can't handle file names more than MAX_PATH
if(strlen(FileName)>=MAX_PATH-11)
return WIPE_NOTOPEN;
strcpy(NewFileName,FileName);
if((dwWipeFlags&WIPE_ADS)!=WIPE_ADS)
{
name=strrchr(NewFileName,'\\');
if(name==NULL)
name=NewFileName;
else
name++;
// Set the filename to a's as much as MAX_PATH
// will allow to write over old filename entries
letter='a';
ftest=0;
do
{
if(ftest!=0)
fclose(ftest);
numletters=&(NewFileName[MAX_PATH])-name;
memset(name,letter,numletters);
memset(name,'a',8);
NewFileName[MAX_PATH-10]=0;
letter=letter+1;
ftest=fopen(NewFileName,"r");
} while ((letter<='z')&&(ftest!=0));
if(ftest!=0)
{
fclose(ftest);
return WIPE_NOTOPEN;
}
}
// Try to make writable if readonly
dwFileAttributes=GetFileAttributes(FileName);
dwFileAttributes&=~FILE_ATTRIBUTE_READONLY;
retval=SetFileAttributes(FileName,dwFileAttributes);
if((dwWipeFlags&WIPE_ADS)!=WIPE_ADS)
{
bMoveFileSuccess = NotifyShellRename(FileName, NewFileName);
if (!bMoveFileSuccess)
{
DWORD dwLastError;
dwLastError = GetLastError();
switch (dwLastError)
{
case ERROR_SHARING_VIOLATION:
return WIPE_ALREADYOPEN;
case ERROR_WRITE_PROTECT:
return WIPE_WRITEPROTECT;
case ERROR_REQUEST_ABORTED:
return WIPE_USERABORT;
case ERROR_ACCESS_DENIED:
default:
return WIPE_NOTOPEN;
}
}
}
if( ui64Size==0 )
{
if(dwWipeFlags&WIPE_DONOTDELETE)
NotifyShellRename(NewFileName,FileName);
else
{
NotifyShellOperation(NewFileName,PGPNS_DELETE);
// NotifyShellOperation(FileName,PGPNS_FORCEDELNOTIFY); // For brain dead XP NTFS shell
}
return WIPE_OK;
}
/* we want to wipe out to next page boundary */
// Get up to one more page to make fit
ui64NumPages = (ui64Size+(PGPUInt64)dwPageSize-(PGPUInt64)1)/
((PGPUInt64)dwPageSize);
ui64Size = ui64NumPages * (PGPUInt64)dwPageSize;
// Code to blow out 64K lazy write buffer on NTFS
Zap64Size = ((ONETWENTYEIGHT+(PGPUInt64)dwPageSize-1)/(PGPUInt64)dwPageSize)*dwPageSize;
if(Zap64Size<ui64Size)
Zap64Size=ui64Size;
quanta=(MEGABYTE/dwPageSize)*dwPageSize;
// This is their last chance before it goes FUBAR!!!!!
if(hwnd!=NULL)
{
if(PGPscProgressGetCancel(hwnd))
CancelOperation=TRUE;
if(CancelOperation)
{
// Back from deaths door
NotifyShellRename(NewFileName,FileName);
return WIPE_USERABORT;
}
}
// Support for Windows 95 IFSmgr _VolFlush call
if(!bIsNT)
{
hDriver =
CreateFile ( kPGPMemLockDriver95Name,
0,
0,
NULL,
0,
0,
NULL );
}
hFile = CreateFile( NewFileName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,
NULL );
if( hFile == INVALID_HANDLE_VALUE ) // If unable to open, skip it
{
lastError = GetLastError(); // These calls are for debugging
NotifyShellRename(NewFileName,FileName);
return WIPE_NOTOPEN;
}
// Create a file mapping object
/* hMap = CreateFileMapping( hFile, NULL, PAGE_READWRITE,
HILONG(Zap64Size),
LOLONG(Zap64Size),
NULL );
if(hMap!=NULL)
{
// There was enough extra room so go for the bigger size
ui64Size=Zap64Size;
}
else*/
{
// Not enough space--punt and just do the normal size
hMap = CreateFileMapping( hFile, NULL, PAGE_READWRITE,
HILONG(ui64Size),
LOLONG(ui64Size),
NULL );
}
if(hMap==NULL)
{
lastError = GetLastError(); // If it didn't work, next file
CloseHandle( hFile );
NotifyShellRename(NewFileName,FileName);
return WIPE_NOFILEMAP;
}
// we are now using Colin's patterns
error = PGPCreateDiskWiper( context, &wipeRef, passes);
if( IsntPGPError(error) )
{
DWORD reps;
reps=0;
while( IsntPGPError( PGPGetDiskWipeBuffer(wipeRef, buffer) ) )
{
DWORD count;
DWORD numbytes;
PGPUInt64 ui64NumIters;
PGPUInt64 ui64Iter;
PGPUInt64 ui64MapLoc;
ui64NumIters=(ui64Size+((PGPUInt64)quanta-1))/((PGPUInt64)quanta);
for(ui64Iter=0;ui64Iter<ui64NumIters;ui64Iter++)
{
if(hwnd!=NULL)
{
MSG msg;
DWORD percent;
while(PeekMessage(&msg,hwnd,0,0,PM_REMOVE))
{
if(!IsDialogMessage(hwnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
percent=(DWORD)
(((((PGPUInt64)reps*ui64NumIters)+ui64Iter)*(PGPUInt64)100)/
((PGPUInt64)passes*ui64NumIters));
if(IsPGPError(PGPscProgressSetBar(hwnd,percent,FALSE)))
{
CancelOperation=TRUE;
break;
}
}
numbytes=(DWORD)(ui64Size-ui64Iter*((PGPUInt64)quanta));
if(numbytes>quanta)
numbytes=quanta;
ui64MapLoc=ui64Iter*(PGPUInt64)quanta;
lpFile = MapViewOfFile( hMap, FILE_MAP_WRITE,
HILONG(ui64MapLoc),
LOLONG(ui64MapLoc),
numbytes );
if( lpFile == NULL )
{
lastError = GetLastError(); // On error, back way out
CloseHandle( hMap );
CloseHandle( hFile );
NotifyShellRename(NewFileName,FileName);
PGPDestroyDiskWiper(wipeRef);
return WIPE_NOMEMMAP;
}
else
{
char *view;
view=(char *)lpFile;
for( count = 0; count < numbytes; count += 1024)
{
memcpy(lpFile + count, buffer, 1024);
}
if(numbytes%1024!=0)
{
memcpy(lpFile+((numbytes/1024)*1024),
buffer, numbytes%1024);
}
FlushViewOfFile( lpFile, numbytes ); // Flush it to disk
FlushFileBuffers( hFile );
// Windows 95 IFSmgr _VolFlush call
if(!bIsNT)
{
if(hDriver!=NULL)
{
Win95Flush(hDriver,NewFileName);
}
}
}
UnmapViewOfFile( lpFile ); // Kill mapped area
FlushFileBuffers( hFile );
// Windows 95 IFSmgr _VolFlush call
if(!bIsNT)
{
if(hDriver!=NULL)
{
Win95Flush(hDriver,NewFileName);
}
}
}
reps++;
}
error = PGPDestroyDiskWiper(wipeRef);
}
CloseHandle(hMap);
CloseHandle( hFile );
// Windows 95 IFSmgr _VolFlush call
if(!bIsNT)
{
if(hDriver!=NULL)
{
Win95Flush(hDriver,NewFileName);
CloseHandle(hDriver);
}
}
if(dwWipeFlags&WIPE_DONOTDELETE)
NotifyShellRename(NewFileName,FileName);
else
{
NotifyShellOperation(NewFileName,PGPNS_DELETE);
// NotifyShellOperation(FileName,PGPNS_FORCEDELNOTIFY); // For brain dead XP NTFS shell
}
if(CancelOperation)
return WIPE_USERABORT;
if(hwnd!=NULL)
{
PGPscProgressSetBar(hwnd,100,TRUE);
}
return WIPE_OK;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -