VC + 정보 보안 프로 그래 밍 (12) FAT 디스크 데이터 파일 안전하게 삭제

상업 비밀 을 보호 하기 위해 서 는 한 번 만 허용 하고 삭제 해 야 하 는 경우 가 많다.
그러나 윈도 의 삭 제 는 불완전한 것 으로 휴지통 을 통 해 되 찾 을 수 있 으 며 윈도 가 완전히 삭제 되 더 라 도 완전히 삭제 되 는 것 은 아니다.데이터 복구 소프트웨어 를 통 해 찾 을 수도 있 고,
우 리 는 어떻게 철저하게 삭제 하고 바 이 너 리 데이터 로 디스크 를 채 워 서 관련 데 이 터 를 철저히 제거 합 니까?
360 자체 의 기능 을 직접 실천 하 겠 습 니 다.
상세 한 소스 코드 는 다음 과 같 습 니 다. 소스 코드 분석 을 보고 FAT 의 클래스 를 안전하게 삭제 하 십시오.
 
 
#include "stdafx.h"
#include "SecureDelFAT.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSecureDelFAT::CSecureDelFAT()
{

}

CSecureDelFAT::~CSecureDelFAT()
{

}



int CSecureDelFAT::NtOr98()
{
	OSVERSIONINFO osvi;
		
	//               
	osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx (&osvi);
	if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
		return 2000;
	else
	{
		if((osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
			( (osvi.dwMajorVersion > 4) ||
			( (osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0) ) ))
			return 98;
		else
			return 0;
	}
}

//*******************    ***************************
//  :        、    、    
//   :      1,    0
BOOL CSecureDelFAT::LockVolume(BYTE bDrive,DWORD dwPermission,BYTE bLevel)
{
	BOOL fResult;
	DWORD cb;
	HANDLE hDev;
	DIOC_REGISTERS reg;
	reg.reg_EAX=0x440d;
	reg.reg_EBX=MAKEWORD(bDrive,bLevel);
	reg.reg_ECX=0x484a;
	reg.reg_EDX=dwPermission;
	
	hDev=::CreateFile("\\\\.\\vwin32",0,0,NULL,0,FILE_FLAG_DELETE_ON_CLOSE,NULL);
	fResult=::DeviceIoControl(hDev,VWIN32_DIOC_DOS_IOCTL,
	                        ®,sizeof(reg),®,sizeof(reg),&cb,0);
	

	fResult=fResult && !(reg.reg_Flags & CARRY_FLAG);
	CloseHandle(hDev);	
	return fResult;

}

//********************    *****************************
//  :         
//   :       1,    0
BOOL CSecureDelFAT::UnlockVolume(BYTE bDrive)
{
	BOOL fResult;
	DWORD cb;
	HANDLE hDev;
	DIOC_REGISTERS reg={0};
	reg.reg_EAX=0x440d;
	reg.reg_EBX=bDrive;
	reg.reg_ECX=0x486a;
	
	hDev=::CreateFile("\\\\.\\vwin32",0,0,NULL,0,FILE_FLAG_DELETE_ON_CLOSE,NULL);
	fResult=::DeviceIoControl(hDev,VWIN32_DIOC_DOS_IOCTL,
	                        ®,sizeof(reg),®,sizeof(reg),&cb,0);

	fResult=fResult && !(reg.reg_Flags & CARRY_FLAG);
	CloseHandle(hDev);	
	return fResult;

}

//*************         ***************
//  :          、    、      、   
//   :        1,    0
BOOL CSecureDelFAT::ReadSectors(BYTE bDrive,
                     DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{
	BOOL	fResult;
	DWORD	cb;
	DISKIO	dio={0};
	DIOC_REGISTERS reg={0};

	HANDLE	hDev;
	hDev=CreateFile("\\\\.\\vwin32",0,0,NULL,0,FILE_FLAG_DELETE_ON_CLOSE,NULL);

	dio.dwStartSector=dwStartSector; //        
	dio.wSectors=wSectors;  //       
	dio.dwBuffer=(DWORD)lpSectBuff; //          

	reg.reg_EAX=0x7305;     
	reg.reg_EBX=(DWORD)&dio;
	reg.reg_ECX=-1;
	reg.reg_EDX=bDrive;
	

	fResult=::DeviceIoControl(hDev,VWIN32_DIOC_DOS_DRIVEINFO,
	                        ®,sizeof(reg),®,sizeof(reg),&cb,0);

	fResult=fResult && !(reg.reg_Flags & CARRY_FLAG);
	
	CloseHandle(hDev);
	return fResult;

}

//*******************      *******************
//  :          、    、      、   
//   :        1,    0

BOOL CSecureDelFAT::WriteSectors(BYTE bDrive,
                     DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{
	BOOL	fResult,IfLock;
	DWORD	cb;
	DISKIO dio={0};
	DIOC_REGISTERS reg={0};
	IfLock=LockVolume(bDrive,0,1);
	HANDLE	hDev;
	hDev=CreateFile("\\\\.\\vwin32",0,0,NULL,0,FILE_FLAG_DELETE_ON_CLOSE,NULL);
	

	dio.dwStartSector=dwStartSector; //        
	dio.wSectors=wSectors;           //       
	dio.dwBuffer=(DWORD)lpSectBuff;  //           

	reg.reg_EAX=0x7305;              
	reg.reg_EBX=(DWORD)&dio;
	reg.reg_ECX=-1;
	reg.reg_EDX=bDrive;
	reg.reg_ESI=0x0001;
	
	fResult=::DeviceIoControl(hDev,VWIN32_DIOC_DOS_DRIVEINFO,
	                        ®,sizeof(reg),®,sizeof(reg),&cb,0);

	fResult=fResult && !(reg.reg_Flags & CARRY_FLAG);
	
	CloseHandle(hDev);
	IfLock=UnlockVolume(bDrive);
	return fResult;

}
//*************         ***************
//  :          、    、      、   
//   :        1,    0
BOOL CSecureDelFAT::ReadSectors2000(BYTE bDrive,
                     DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{
	BOOL	fResult;
	char InfoFileName[20]="";
	ULONGLONG MoveDistanceOfByte;
	LONG LowDistanceOfByte,HighDistanceOfByte;
	PLONG lpDistance;
	DWORD dwBytesToRead;
	HANDLE	hDev;
	DWORD dwFilePointer;

	//                  
	MoveDistanceOfByte=((ULONGLONG)512*(ULONGLONG)dwStartSector);
	LowDistanceOfByte=(LONG)(MoveDistanceOfByte);
	MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
	MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
	HighDistanceOfByte=(LONG)(MoveDistanceOfByte);
	lpDistance=(PLONG)(&HighDistanceOfByte);
	dwBytesToRead=512*wSectors;
	//         
	strcat(InfoFileName,"\\\\.\\");
	InfoFileName[4]=bDrive-1+'A';
	strcat(InfoFileName,":");
	//               
	hDev=CreateFile(InfoFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
	//      ,            
	dwFilePointer=SetFilePointer(hDev,LowDistanceOfByte,lpDistance, FILE_BEGIN);
	//        
	fResult=ReadFile(hDev,lpSectBuff,dwBytesToRead,&dwBytesToRead,NULL);
	CloseHandle(hDev);
	return fResult;

}

//*******************      *******************
//  :          、    、      、   
//   :        1,    0

BOOL CSecureDelFAT::WriteSectors2000(BYTE bDrive,
                     DWORD dwStartSector,WORD wSectors,LPBYTE lpSectBuff)
{
	BOOL	fResult;
	char InfoFileName[20]="";
	ULONGLONG MoveDistanceOfByte;
	LONG LowDistanceOfByte,HighDistanceOfByte;
	PLONG lpDistance;
	DWORD dwBytesToWrite;
	HANDLE	hDev;
	DWORD dwFilePointer;
	//                 
	MoveDistanceOfByte=((ULONGLONG)512*(ULONGLONG)dwStartSector);
	LowDistanceOfByte=(LONG)(MoveDistanceOfByte);
	MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
	MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
	HighDistanceOfByte=(LONG)(MoveDistanceOfByte);
	lpDistance=(PLONG)(&HighDistanceOfByte);
	dwBytesToWrite=512*wSectors;
	//        
	strcat(InfoFileName,"\\\\.\\");
	InfoFileName[4]=bDrive-1+'A';
	strcat(InfoFileName,":");
	//              
	hDev=CreateFile(InfoFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
	//      
	dwFilePointer=SetFilePointer(hDev,LowDistanceOfByte,lpDistance, FILE_BEGIN);
	//      
	fResult=WriteFile(hDev,lpSectBuff,dwBytesToWrite,&dwBytesToWrite,NULL);
	CloseHandle(hDev);	
	return fResult;

}



//***********       FAT    *************
//  :          
//   :     Fat  0,fat12  12;fat16  16;fat32  32
int CSecureDelFAT::IfFatX(BYTE bDrive)
{
	int i;
	int IsNtOr98;
	
	LPBYTE lpSectBuff;
	
	char FileStyle12[10]={0};
	char FileStyle16[10]={0};
	char FileStyle32[10]={0};
	//**************************

	lpSectBuff=(LPBYTE)malloc(1024);
	//          
	IsNtOr98=NtOr98();
	//            
	if(IsNtOr98==2000)
		ReadSectors2000(bDrive,0,1,lpSectBuff);
	else
		ReadSectors(bDrive,0,1,lpSectBuff);
	//                     
	//     
	for(i=0;i<5;i++)
		FileStyle12[i]=*(lpSectBuff+54+i);

	for(i=0;i<5;i++)
		FileStyle16[i]=*(lpSectBuff+54+i);

	for(i=0;i<5;i++)
		FileStyle32[i]=*(lpSectBuff+82+i);

	free(lpSectBuff);
	//       FAT    
	if(strcmp(FileStyle12,"FAT12")==0)
		return 12;
	else if(strcmp(FileStyle16,"FAT16")==0)
		return 16;
	else if(strcmp(FileStyle32,"FAT32")==0)
		return 32;
	else 
		return 0;

}


//*************      **************
//  :        、          
//   :	 
void CSecureDelFAT::fDiskInfo(FILEINFO InfoOfFile,PINFOFDISK pDiskInfo)		
{
	WORD wLow,wHigh;
	LPBYTE lpSectBuff;//   
	INFOFDISK di={0};
	int IsNtOr98;

	lpSectBuff=(LPBYTE)malloc(1024);
	//         
	IsNtOr98=NtOr98();
	if(IsNtOr98==2000)
		ReadSectors2000(InfoOfFile.bDrive,0,1,lpSectBuff);// BPB 
	else
		ReadSectors(InfoOfFile.bDrive,0,1,lpSectBuff);// BPB 
	//**********Fat16  ***************
	if(InfoOfFile.IfFat==16)//fat16
	{
		//      
		di.wNumOfByteEachSec=MAKEWORD(*(lpSectBuff+11),*(lpSectBuff+12));
		//     
		di.wReserveSector=MAKEWORD(*(lpSectBuff+14),*(lpSectBuff+15));
		//FAT   
		di.bNumOfFat=*(lpSectBuff+16);
		//FAT   
		di.dwLenOfFat=(DWORD)(MAKEWORD(*(lpSectBuff+22),*(lpSectBuff+23)));
		//     
		di.bNumOfSectorsEachClu=*(lpSectBuff+13);
		//     
		di.wNumOfIndex=MAKEWORD(*(lpSectBuff+17),*(lpSectBuff+18));
	}

	//*************fat32  *************
	else
	{		
		//      
		di.wNumOfByteEachSec=MAKEWORD(*(lpSectBuff+11),*(lpSectBuff+12));
		//     
		di.wReserveSector=MAKEWORD(*(lpSectBuff+14),*(lpSectBuff+15));
		//FAT   
		di.bNumOfFat=*(lpSectBuff+16);
		
		//FAT   
		wLow=MAKEWORD(*(lpSectBuff+36),*(lpSectBuff+37));
		wHigh=MAKEWORD(*(lpSectBuff+38),*(lpSectBuff+39));
		di.dwLenOfFat=MAKELONG(wLow,wHigh);
		//     
		di.bNumOfSectorsEachClu=*(lpSectBuff+13);
		//      
		wLow=MAKEWORD(*(lpSectBuff+44),*(lpSectBuff+45));
		wHigh=MAKEWORD(*(lpSectBuff+46),*(lpSectBuff+47));
		di.dwFirstCluOfIndex=MAKELONG(wLow,wHigh);
	}
	pDiskInfo->bNumOfFat=di.bNumOfFat;
	pDiskInfo->bNumOfSectorsEachClu=di.bNumOfSectorsEachClu;
	pDiskInfo->dwFirstCluOfIndex=di.dwFirstCluOfIndex;
	pDiskInfo->dwLenOfFat=di.dwLenOfFat;
	pDiskInfo->wNumOfByteEachSec=di.wNumOfByteEachSec;
	pDiskInfo->wNumOfIndex=di.wNumOfIndex;
	pDiskInfo->wReserveSector=di.wReserveSector;

	free(lpSectBuff);
	
	
}
//**********************************************************************************


//*********  fat        ***************
//  :	    、          
//   :  fat       
DWORD CSecureDelFAT::FatStartSec(INFOFDISK DiskInfo)
{

	WORD wReserveSector;//     
	DWORD dwFatSec;
	
	wReserveSector=DiskInfo.wReserveSector;
	dwFatSec=wReserveSector;
	return dwFatSec;
}

//********    FAT      *********
//  :       、          
//   :   FAT      
DWORD CSecureDelFAT::FatBakStartSec(INFOFDISK DiskInfo)
{
	DWORD dwFatBakStaSec;//  FAT      
	DWORD dwLenOfFat;
	WORD wReserveSector;
	
	dwLenOfFat=DiskInfo.dwLenOfFat;
	wReserveSector=DiskInfo.wReserveSector;
	dwFatBakStaSec=wReserveSector+dwLenOfFat;
	return dwFatBakStaSec;

}

//***********            *************
//  :          、      
//   :         
DWORD CSecureDelFAT::DiskIndex(INFOFDISK DiskInfo,FILEINFO InfoOfFile)
{
	BYTE bNumOfFat;//fat   
	BYTE bNumOfSectorsEachClu;//     

	WORD wReserveSector;//     

	DWORD dwLenOfFat;//fat   
	DWORD dwFirstCluOfIndex;//     
	DWORD dwPositonOfIndex;//       

	//    
	wReserveSector=DiskInfo.wReserveSector;
	//FAT   
	bNumOfFat=DiskInfo.bNumOfFat;
	//FAT   
	dwLenOfFat=DiskInfo.dwLenOfFat;
	//     
	bNumOfSectorsEachClu=DiskInfo.bNumOfSectorsEachClu;
	//     
	dwFirstCluOfIndex=DiskInfo.dwFirstCluOfIndex;
	//**********fat12 fat16***************
	if(InfoOfFile.IfFat==16)
	{		
		//fat16         :
		dwPositonOfIndex=wReserveSector+bNumOfFat*dwLenOfFat;
	}
	
	//*************fat32*************
	else
	{		
		//fat32         :
		dwPositonOfIndex=wReserveSector+bNumOfFat*dwLenOfFat+
			                     (dwFirstCluOfIndex-2)*bNumOfSectorsEachClu;
		
	}
	//*************  *************
	return dwPositonOfIndex;
}
//*************************************************************************************




//**********        *********
//  :            、        、      、      
//   :           
DWORD CSecureDelFAT::SectorOfFile(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,FILEINFO InfoOfFile,DWORD dwTheClu)
{
	BYTE bNumOfSectorsEachClu;//     
	DWORD dwPositonOfData;//       
	DWORD dwFirstCluOfRootIndex;//      
	
	DWORD dwSectorFromClu;//           
	
	//     
	bNumOfSectorsEachClu=DiskInfo.bNumOfSectorsEachClu;
	//     
	dwFirstCluOfRootIndex=DiskInfo.dwFirstCluOfIndex;
	
	//       
	dwPositonOfData=PositionInfo.dwDataStartSec;
	
	if(InfoOfFile.IfFat==32)
		dwSectorFromClu=bNumOfSectorsEachClu*(dwTheClu-dwFirstCluOfRootIndex)+dwPositonOfData;
	else
		dwSectorFromClu=bNumOfSectorsEachClu*(dwTheClu-2)+dwPositonOfData;
	return dwSectorFromClu;
}


//***********             、      ************
//  :          、      、        
//   :                
int CSecureDelFAT::SplitPath(const char *pFilePath,char *pDrive,char *pDir)
{
	char path_buffer[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	int i;
	int length;

	_splitpath( pFilePath, drive, dir, fname, ext);
	for(i=0;i<_MAX_DRIVE;i++)
		*(pDrive+i)=drive[i];
	_makepath(path_buffer,drive,dir,NULL,NULL);
	length=strlen(path_buffer);
	for(i=0;i<length-1;i++)
		*(pDir+i)=path_buffer[i];
	return length-1;
	
}

//***************************************************************************************



//************      FAT     ***************
//  :           、        、      、    
//   :            
DWORD CSecureDelFAT::NextCluster(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,FILEINFO InfoOfFile,DWORD dwCluster)
{
	
	DWORD FatSartSector;
	DWORD dwReadStartSec;
	DWORD NextClu;

	WORD wSectors;
	WORD wNumOfBytesEachSec;
	WORD LowClu,HighClu;

	BYTE NextClu0,NextClu1,NextClu2,NextClu3;
	
	LPBYTE lpSectBuff;
	int IsNtOr98;
	//********************************
	wSectors=1;
	lpSectBuff=(LPBYTE)malloc(1536);
	//       
	IsNtOr98=NtOr98();
	//      
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;	
	//  FAT     
	FatSartSector=PositionInfo.dwFatStartSec;

	if(InfoOfFile.IfFat==16)
	{
		//            
		dwReadStartSec=FatSartSector+(dwCluster*2)/wNumOfBytesEachSec;
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive, dwReadStartSec,wSectors,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive, dwReadStartSec,wSectors,lpSectBuff);


		//         FAT    
		NextClu0=*(lpSectBuff+(int)fmod(dwCluster*2,wNumOfBytesEachSec));
		NextClu1=*(lpSectBuff+(int)fmod(dwCluster*2,wNumOfBytesEachSec)+1);
		
		LowClu=MAKEWORD(NextClu0,NextClu1);
		HighClu=0x0000;
		NextClu=MAKELONG(LowClu,HighClu);
	}
	if(InfoOfFile.IfFat==32)
	{
		//            
		dwReadStartSec=FatSartSector+(dwCluster*4)/wNumOfBytesEachSec;
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive, dwReadStartSec,wSectors,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive, dwReadStartSec,wSectors,lpSectBuff);

		//         FAT    
		NextClu0=*(lpSectBuff+(int)fmod(dwCluster*4,wNumOfBytesEachSec));
		NextClu1=*(lpSectBuff+(int)fmod(dwCluster*4,wNumOfBytesEachSec)+1);
		NextClu2=*(lpSectBuff+(int)fmod(dwCluster*4,wNumOfBytesEachSec)+2);
		NextClu3=*(lpSectBuff+(int)fmod(dwCluster*4,wNumOfBytesEachSec)+3);
		LowClu=MAKEWORD(NextClu0,NextClu1);
		HighClu=MAKEWORD(NextClu2,NextClu3);
		NextClu=MAKELONG(LowClu,HighClu);
	}
		free(lpSectBuff);
		return NextClu;
}


//**********        ***************
//  :          、      
//   :   
void CSecureDelFAT::GetCluster2000(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,FILEINFO InfoOfFile,DWORD* FirstCluster)
{
	
	LPBYTE lpSectBuff;//   
	BY_HANDLE_FILE_INFORMATION FileInfo;

	BOOL IfResult;
	
	HANDLE hFile;

	LONG lDistanceToMove,lDistanceToMoveHigh;
    PLONG lpDistanceToMoveHigh;
	ULONGLONG MoveDistanceOfByte;

	char InfoFileName[20]="";
	
	DWORD dwBytesToRead;
	WORD wLow,wHigh;
	DWORD dwFilePointer;
	DWORD dwSectorPosition;
	DWORD dwNumOfClu;
	DWORD dwMod;
	DWORD dwNextCluster;
	DWORD dwSectorPosition1;
	ULONGLONG BytePosition;
	ULONGLONG BytePosition1;

	ULONGLONG OffSet;
	
	
	int nmod;
	int nDirLeng;
	int i,j,k;
	int nNumOfDir;
	char cDrive[_MAX_DRIVE];
	char cDir[_MAX_DIR];
	char pDir[_MAX_DIR]="";
	const char *pFilePath;
	char cFilePath[50][_MAX_PATH]={0};
	DWORD dwFileFirstClu[50];//          ,           
	//*****************************
	pFilePath=InfoOfFile.pFilePath;
	i=0;
	strcpy(pDir,pFilePath);
	//            cFilePath
	do
	{
		strcpy(cFilePath[i],pDir);
		//                 
		nDirLeng=SplitPath(pDir,cDrive,cDir);
		for(k=0;k<_MAX_DIR;k++)
			pDir[k]=0;
		strncpy(pDir,cDir,nDirLeng);
		i+=1;
		if(nDirLeng<=2)
		{
			strcpy(cFilePath[i],pDir);
			break;
		}
	}while(1);
	//         
	nNumOfDir=i;
	//                
	for(i=nNumOfDir;i>=0;i--)
	{
		//      
		if(i==nNumOfDir)
		{
			//          
			dwFileFirstClu[i]=DiskIndex(DiskInfo,InfoOfFile);
		}
		else
		{
			//          
			hFile=CreateFile(cFilePath[i],GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0);
			IfResult=GetFileInformationByHandle(hFile,&FileInfo);
			CloseHandle(hFile);
			if(IfResult==0)
			{
				::MessageBox(NULL,"          !","  ",MB_OK);
				return;
			}
			else
			{
				//            
				MoveDistanceOfByte=(ULONGLONG)(FileInfo.nFileIndexHigh);
				MoveDistanceOfByte=Int64ShllMod32(MoveDistanceOfByte,0x10);
				MoveDistanceOfByte=Int64ShllMod32(MoveDistanceOfByte,0x10);
				MoveDistanceOfByte+=(ULONGLONG)(FileInfo.nFileIndexLow);
				//             
				//            
				//          
				if((i+1)==nNumOfDir)
					dwSectorPosition=dwFileFirstClu[i+1];
				else
					dwSectorPosition=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,dwFileFirstClu[i+1]);
				//           
				BytePosition=(ULONGLONG)dwSectorPosition*(ULONGLONG)(DiskInfo.wNumOfByteEachSec);
				//                       
				OffSet=MoveDistanceOfByte-BytePosition;
				if(InfoOfFile.IfFat==16 && (i+1)==nNumOfDir)
				{	
					MoveDistanceOfByte=MoveDistanceOfByte;
				}
				else
				{
					//                             
					dwNumOfClu=(DWORD)OffSet/(DiskInfo.bNumOfSectorsEachClu*DiskInfo.wNumOfByteEachSec)+1;
					dwMod=(DWORD)(OffSet-OffSet/(DiskInfo.bNumOfSectorsEachClu*DiskInfo.wNumOfByteEachSec)*(DiskInfo.bNumOfSectorsEachClu*DiskInfo.wNumOfByteEachSec));
					//            
					if((i+1)==nNumOfDir)
					{
						dwNextCluster=DiskInfo.dwFirstCluOfIndex;
					}
					else
					{
						dwNextCluster=dwFileFirstClu[i+1];
					}
					for(j=1;j<(int)dwNumOfClu;j++)
					{
						dwNextCluster=NextCluster(DiskInfo,PositionInfo,InfoOfFile,dwNextCluster);
					}
					//               
					dwSectorPosition1=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,dwNextCluster);
					//           
					BytePosition1=(ULONGLONG)dwSectorPosition1*(ULONGLONG)(DiskInfo.wNumOfByteEachSec);
					//                              
					MoveDistanceOfByte=BytePosition1+dwMod;
				}
				//         
				lpSectBuff=(LPBYTE)malloc(1024);
				if(lpSectBuff==NULL)
				{
					::MessageBox( NULL, "      ", "  ", MB_OK );
					return;
				}
				dwBytesToRead=0x200;
				nmod=(int)(MoveDistanceOfByte-MoveDistanceOfByte/512*512);
				MoveDistanceOfByte=MoveDistanceOfByte/512*512;

				lDistanceToMove=(LONG)MoveDistanceOfByte;

				MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
				MoveDistanceOfByte=Int64ShrlMod32(MoveDistanceOfByte,0x10);
				lDistanceToMoveHigh=(LONG)MoveDistanceOfByte;
	
				lpDistanceToMoveHigh=&lDistanceToMoveHigh;
		
				//           512   
				//         
				strcat(InfoFileName,"\\\\.\\");
				InfoFileName[4]=InfoOfFile.bDrive-1+'A';
				strcat(InfoFileName,":");
				//               
				hFile=CreateFile(InfoFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
				// InfoFileName  
				for(k=0;k<20;k++)
					InfoFileName[k]=0;
				//      ,            
				dwFilePointer=SetFilePointer(hFile,lDistanceToMove,lpDistanceToMoveHigh, FILE_BEGIN);
				//        
				IfResult=ReadFile(hFile,lpSectBuff,dwBytesToRead,&dwBytesToRead,NULL);
				CloseHandle(hFile);
				if(IfResult==0)
				{
					::MessageBox(NULL,"    !","  ",MB_OK);
					return;
				}
				else
				{
					wLow=MAKEWORD((*(lpSectBuff+26+nmod)),(*(lpSectBuff+27+nmod)));
					wHigh=MAKEWORD((*(lpSectBuff+20+nmod)),(*(lpSectBuff+21+nmod)));
					*FirstCluster=MAKELONG(wLow,wHigh);
				}
				free(lpSectBuff);
				//               
				dwFileFirstClu[i]=*FirstCluster;
			}
		}
	}

}
//************    (   )        *************
//  :        、      
//   :      1,    0
BOOL CSecureDelFAT::GetFirstCluster(LPCTSTR lpFileName,DWORD* FirstCluster)
{
	BOOL fResult;
	DWORD cb;
	HANDLE hDev;
	DIOC_REGISTERS reg={0};
	reg.reg_EAX=0x440d;
	reg.reg_EBX=0x0000;
	reg.reg_ECX=0x4871;
	reg.reg_EDX=(DWORD)lpFileName;
	
	hDev=::CreateFile("\\\\.\\vwin32",0,0,NULL,0,FILE_FLAG_DELETE_ON_CLOSE,NULL);
	fResult=::DeviceIoControl(hDev,VWIN32_DIOC_DOS_IOCTL,
	                        ®,sizeof(reg),®,sizeof(reg),&cb,0);

	fResult=fResult && !(reg.reg_Flags & CARRY_FLAG);
	if(fResult)
		*FirstCluster=MAKELONG((WORD)reg.reg_EAX,(WORD)reg.reg_EDX);
	CloseHandle(hDev);	
	return fResult;

}

//**********    (   )    ***************
//  :          、      
//   :   
void CSecureDelFAT::GetCluster(FILEINFO InfoOfFile,DWORD* pFirstCluster)
{
	BOOL IfSucForLock,IfSucForGetClu,IfSucForUnlock;
	BYTE Level;
	DWORD Permission;
		
	Level=1;
	Permission=0;
		
	//        
	IfSucForLock=LockVolume(InfoOfFile.bDrive,Permission,Level);
	if(IfSucForLock)
	{
		//                    
		IfSucForGetClu=GetFirstCluster(InfoOfFile.pFilePath,pFirstCluster);
		//        ,     ,       
		if(!IfSucForGetClu)
		{
			
			::MessageBox(NULL,"        ,               ,       ","  !",MB_OK);
			return;
		}
		//  
		IfSucForUnlock=UnlockVolume(InfoOfFile.bDrive);
		if(!IfSucForUnlock)
		{
			
			::MessageBox(NULL,"    !","  !",MB_OK);
			return;
		}
	}
	else
	{
		
		::MessageBox(NULL,"    !","  !",MB_OK);
		return;
	}

}
//*******************************************************************************************





//*************  (   )        (fat32      FAT16     )*********************
//  :              、        、      、          、
//                ms-dos             、       (               ,    0)
//   :        ms-dos             ,  ms-dos      
DWORD CSecureDelFAT::FilePositionFat32(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
						FILEINFO InfoOfFile,FILEINFO InfoOfDir,
						DWORD *dwStartSec,DWORD *pIfCrossCluster)
{
	
	DWORD dwStartSectorOld;
	DWORD dwStartSector;
	DWORD dwStartClu;
	DWORD dwOldCluster;
	DWORD dwFilePosition;//   

	WORD wLowFirstClu,wHighFirstClu,wLow,wHigh;
	WORD wNumOfBytesEachSec;

	BYTE bFileProperty,bFileProperty1;
	BYTE bIfDelete;
	BYTE bNumOfSectorsEachClu;

	LPBYTE lpSectBuff;
	
	BOOL IfSuccessForRead,IfFind;
	
	int i;
	int nIf0f;
	int nIfCrossClu;
	int IsNtOr98;
	//*****************************
	//        
	IsNtOr98=NtOr98();
	//               
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;	
	bNumOfSectorsEachClu=DiskInfo.bNumOfSectorsEachClu;
	//             
	wLowFirstClu=(WORD)(InfoOfFile.dwFileFirstClu);
	wHighFirstClu=(WORD)(InfoOfFile.dwFileFirstClu>>16);

	IfFind=0;
	nIf0f=0;
	nIfCrossClu=0;
	bFileProperty=0;
	//             
	dwStartSector=InfoOfDir.dwFileStartSec;
	dwStartSectorOld=dwStartSector;
	//        
	dwStartClu=InfoOfDir.dwFileFirstClu;
	//    
	lpSectBuff=(LPBYTE)malloc(1024);
	do
	{
		//             
		if(IsNtOr98==2000)
			IfSuccessForRead=ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			IfSuccessForRead=ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		if(IfSuccessForRead)
		{
			for(i=0;i<(wNumOfBytesEachSec/32);i++)
			{
				bFileProperty1=bFileProperty;
				wLow=MAKEWORD((*(lpSectBuff+26+i*32)),(*(lpSectBuff+27+i*32)));
				wHigh=MAKEWORD((*(lpSectBuff+20+i*32)),(*(lpSectBuff+21+i*32)));
				bFileProperty=*(lpSectBuff+11+i*32);
				bIfDelete=*(lpSectBuff+i*32);
				//                      
				if(bFileProperty1==0x0f)
					nIf0f=1;
				else
				{
					nIf0f=0;
					nIfCrossClu=0;
				}
				//**************************
				if((wLow==wLowFirstClu) && (wHigh==wHighFirstClu) && (bFileProperty!=0x0f) && (bIfDelete!=0xe5))
				{
					if(nIf0f==1 && nIfCrossClu==1)
						*pIfCrossCluster=dwOldCluster;//      
					else
						*pIfCrossCluster=0;
					IfFind=1;
					dwFilePosition=(dwStartSector-dwStartSectorOld)*(wNumOfBytesEachSec/32)+i;
					*dwStartSec=dwStartSectorOld;//       
					break;
				}
			}
		}
		else 
		{
			::MessageBox(NULL,"    !","  !",MB_OK);
			return NULL;
		}
		//                  1
		dwStartSector+=1;
		//                
		if((dwStartSector-dwStartSectorOld)>=bNumOfSectorsEachClu)
			nIfCrossClu=1;
		//      ,           
		if((dwStartSector-dwStartSectorOld)>=bNumOfSectorsEachClu && IfFind==0)
		{
			//              
			dwOldCluster=dwStartClu;
			//     
			dwStartClu=NextCluster(DiskInfo,PositionInfo,InfoOfFile,dwStartClu);
			//        
			dwStartSector=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,dwStartClu);
			//                 
			dwStartSectorOld=dwStartSector;
		}
	}while(!IfFind);
	free(lpSectBuff);
	return dwFilePosition;
}

//***********  (   )        (fat16    )*****************
//  :         、      、          、
//                      、     
//   :                  ,  ms-dos      
DWORD CSecureDelFAT::FilePosition(BYTE bDrive,INFOFDISK DiskInfo,DWORD dwStartSector,
				   DWORD dwFirstClu)
{
	
	DWORD dwStartSectorOld;
	DWORD dwFilePosition;

	WORD wLowFirstClu,wHighFirstClu,wLow,wHigh;
	WORD wNumOfBytesEachSec;
	
	LPBYTE lpSectBuff;

	BOOL IfSuccessForRead,IfFind;
	
	BYTE bFileProperty;
	BYTE bIfDelete;
	int i;
	int IsNtOr98;
	//*************************

	//       
	IsNtOr98=NtOr98();
	//      
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;	
	//             
	wLowFirstClu=(WORD)dwFirstClu;
	wHighFirstClu=(WORD)(dwFirstClu>>16);

	IfFind=0;
	
	//                  
	dwStartSectorOld=dwStartSector;
	//    
	lpSectBuff=(LPBYTE)malloc(1024);
	do
	{
		//             
		if(IsNtOr98==2000)
			IfSuccessForRead=ReadSectors2000(bDrive,dwStartSector,1,lpSectBuff);
		else
			IfSuccessForRead=ReadSectors(bDrive,dwStartSector,1,lpSectBuff);
		if(IfSuccessForRead)
		{
			for(i=0;i<(wNumOfBytesEachSec/32);i++)
			{
				wLow=MAKEWORD((*(lpSectBuff+26+i*32)),(*(lpSectBuff+27+i*32)));
				wHigh=MAKEWORD((*(lpSectBuff+20+i*32)),(*(lpSectBuff+21+i*32)));
				bFileProperty=*(lpSectBuff+11+i*32);
				bIfDelete=*(lpSectBuff+i*32);
				if((wLow==wLowFirstClu) && (wHigh==wHighFirstClu) && (bFileProperty!=0x0f) && (bIfDelete!=0xe5))
				{
					IfFind=1;
					dwFilePosition=(dwStartSector-dwStartSectorOld)*16+i;
					break;
				}
			}
		}
		else 
		{
			::MessageBox(NULL,"    !","  !",MB_OK);
			return NULL;
		}
		//                        1
		dwStartSector+=1;
	}while(!IfFind);
	free(lpSectBuff);
	return dwFilePosition;
}


//**************          ****************
//  :          、        、      、
//            ms-dos       、  ms-dos              
//   :             ,  ms-dos   
int CSecureDelFAT::NumOfLongfile(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
				  FILEINFO InfoOfFile,DWORD dwStartSector,
				  int nFilePosOffStartSector)
{
	LPBYTE lpSectBuff;
	
	BYTE bNumOfSectorsEachClu;

	WORD wNumOfBytesEachSec;
	
	DWORD dwStartSector1;

	int i;
	int IsNtOr98;
	//*************************
	
	i=1;
	lpSectBuff=(LPBYTE)malloc(1024);
	//         
	IsNtOr98=NtOr98();
	//      
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;	
	//     
	bNumOfSectorsEachClu=DiskInfo.bNumOfSectorsEachClu;
	
	//         0             2   
	if(dwStartSector>=1)
	{	
		//           
		if(InfoOfFile.dwIfCrossClu==0)
		{
			//                
			if(IsNtOr98==2000)
				ReadSectors2000(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
			else
				ReadSectors(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
			//                  
			nFilePosOffStartSector+=wNumOfBytesEachSec;
			//                
			do
			{
				if(*(lpSectBuff+nFilePosOffStartSector-i*32+11)!=0x0f)
					break;
				else
					i+=1;
			}while(1);
		}
		//    
		else
		{
			//                              
			dwStartSector1=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,InfoOfFile.dwIfCrossClu);
			//                  
			dwStartSector1=dwStartSector1+bNumOfSectorsEachClu-1;
			//           
			if(IsNtOr98==2000)
				ReadSectors2000(InfoOfFile.bDrive,dwStartSector1,1,lpSectBuff);
			else
				ReadSectors(InfoOfFile.bDrive,dwStartSector1,1,lpSectBuff);
			//      ms-dos             
			if(IsNtOr98==2000)
				ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);
			else
				ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);
			//               
			nFilePosOffStartSector+=wNumOfBytesEachSec;
			//               
			do
			{
				if(*(lpSectBuff+nFilePosOffStartSector-i*32+11)!=0x0f)
					break;
				else
					i+=1;
			}while(1);
		}
	}
	//       0  
	else
	{
		//             
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		//               
		do
		{
			if(*(lpSectBuff+nFilePosOffStartSector-i*32+11)!=0x0f)
				break;
			else
				i+=1;
		}while(1);
	}
	free(lpSectBuff);
	return i;
}

//***********                ************
//  :          、        、      、
//            ms-dos       、  ms-dos              
//   :                           
//                    0; 
int CSecureDelFAT::IfCrossSector(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
				  FILEINFO InfoOfFile,DWORD dwStartSector,
				  int nFilePosOffStartSector)
{
	int NumOfFile;//          
	int OffSet;
	
	WORD wNumOfBytesEachSec;
	//************************
	//      
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;	
	//        
	NumOfFile=NumOfLongfile(DiskInfo,PositionInfo,InfoOfFile,dwStartSector,nFilePosOffStartSector);
	
	OffSet=NumOfFile-(nFilePosOffStartSector/32)-1;

	if(OffSet>0)
		return wNumOfBytesEachSec-OffSet*32;
	else
		return 0;
}


//***********         ****************
//  :         、      、          
//                、             
//              ms-dos         、     
//   :     
void CSecureDelFAT::FileIndex(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
				 FILEINFO InfoOfFile,FILEINFO InfoOfDir)
{
	WORD wNumOfBytesEachSec;
	DWORD dwStartSector;
	LPBYTE lpSectBuff;
	int i,j;
	int IfCrossSec;
	int nFilePosOffStartSector;
	int NumOfFile;
	int IsNtOr98;
	char FullPath[_MAX_PATH]={0};
	char DustName[40]="";
	char InfoFileName[40]="";

	//      
	lpSectBuff=(LPBYTE)malloc(1024);

	//        
	IsNtOr98=NtOr98();
	//      
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;
	//          
	dwStartSector=InfoOfDir.dwFileStartSec+(InfoOfFile.dwFileIndexPosition*32)/wNumOfBytesEachSec;
	//  ms-dos               
	nFilePosOffStartSector=(int)fmod(InfoOfFile.dwFileIndexPosition*32,wNumOfBytesEachSec);
	//         
	 NumOfFile=NumOfLongfile(DiskInfo,PositionInfo,InfoOfFile,dwStartSector,
		                     nFilePosOffStartSector);
	 //                
	IfCrossSec=IfCrossSector(DiskInfo,PositionInfo,InfoOfFile,dwStartSector,
		                     nFilePosOffStartSector);

	if(IfCrossSec>0)//      
	{
		//             2   
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);

		//        
		for(i=0;i<NumOfFile;i++)
		{
			for(j=0;j<32;j++)
			{	
				*(lpSectBuff+IfCrossSec+i*32+j)=0x00;
					
			}	
			*(lpSectBuff+IfCrossSec+i*32)=0xe5;
			
		}
		//            
		if(IsNtOr98==2000)
			WriteSectors2000(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
		else
			WriteSectors(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
		
	}
	else
	{
		//            
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		
		//        
		for(i=0;i<NumOfFile;i++)
		{
			for(j=0;j<32;j++)
			{	
				*(lpSectBuff+nFilePosOffStartSector-(NumOfFile-1)*32+i*32+j)=0x00;
				
			}	
			*(lpSectBuff+nFilePosOffStartSector-(NumOfFile-1)*32+i*32)=0xe5;
		
		}
		
		//            
		if(IsNtOr98==2000)
			WriteSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			WriteSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
				
	}
	free(lpSectBuff);
		
	
}


//************         *****************
//  :         、      、          
//                、             
//              ms-dos         、           
//                  
//   :     
void CSecureDelFAT::FileIndex32(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
				 FILEINFO InfoOfFile,FILEINFO InfoOfDir)
{
	char FullPath[_MAX_PATH]={0};
	WORD wNumOfBytesEachSec;
	BYTE bNumOfSectorsEachClu;
	DWORD dwStartSector,dwBefore;
	LPBYTE lpSectBuff;
	int nFilePosOffStartSector;
	int IfCrossSec;
	int NumOfFile;
	int Reserved;
	int IsNtOr98;
	int i,j;

	lpSectBuff=(LPBYTE)malloc(1024);
	Reserved=0;

	//       
	IsNtOr98=NtOr98();
	//         
	wNumOfBytesEachSec=DiskInfo.wNumOfByteEachSec;
	bNumOfSectorsEachClu=DiskInfo.bNumOfSectorsEachClu;
	//          
	dwStartSector=InfoOfFile.dwSecNearFileIndex+(InfoOfFile.dwFileIndexPosition*32)/wNumOfBytesEachSec;
	
	//  ms-dos               
	nFilePosOffStartSector=(int)fmod(InfoOfFile.dwFileIndexPosition*32,wNumOfBytesEachSec);
	//         
	NumOfFile=NumOfLongfile(DiskInfo,PositionInfo,InfoOfFile,dwStartSector,
		                     nFilePosOffStartSector);
	InfoOfFile.nNumOfFileIndex=NumOfFile;
	//                
	IfCrossSec=IfCrossSector(DiskInfo,PositionInfo,InfoOfFile,dwStartSector,
		                     nFilePosOffStartSector);

	if(IfCrossSec>0)//      
	{
		if(InfoOfFile.dwIfCrossClu==0)
		//             2   
		{
			if(IsNtOr98==2000)
				ReadSectors2000(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);		
			else
				ReadSectors(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);		
		}
		else
		{
			dwBefore=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,InfoOfFile.dwIfCrossClu);
			dwBefore=dwBefore+bNumOfSectorsEachClu-1;
			if(IsNtOr98==2000)
			{
				ReadSectors2000(InfoOfFile.bDrive,dwBefore,1,lpSectBuff);		
				ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);		
			}
			else
			{
				ReadSectors(InfoOfFile.bDrive,dwBefore,1,lpSectBuff);		
				ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);		
			}
		}
		
		//        
		for(i=0;i<NumOfFile;i++)
		{
			for(j=0;j<32;j++)
			{	
				*(lpSectBuff+IfCrossSec+i*32+j)=0x00;
					
			}	
			*(lpSectBuff+IfCrossSec+i*32)=0xe5;
			
		}
		if(InfoOfFile.dwIfCrossClu==0)
		{
			//            
			if(IsNtOr98==2000)
				WriteSectors2000(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
			else
				WriteSectors(InfoOfFile.bDrive,dwStartSector-1,2,lpSectBuff);
		}
		else
		{
			if(IsNtOr98==2000)
			{
				WriteSectors2000(InfoOfFile.bDrive,dwBefore,1,lpSectBuff);
				WriteSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);
			}
			else
				WriteSectors(InfoOfFile.bDrive,dwBefore,1,lpSectBuff);
				WriteSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff+512);
		}
	}
	else //       
	{
		//            
		if(IsNtOr98==2000)
			ReadSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			ReadSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
	

		//        
		for(i=0;i<NumOfFile;i++)
		{
			for(j=0;j<32;j++)
			{	
				*(lpSectBuff+nFilePosOffStartSector-(NumOfFile-1)*32+i*32+j)=0x00;
					
			}	
			*(lpSectBuff+nFilePosOffStartSector-(NumOfFile-1)*32+i*32)=0xe5;
			
		}
		
		//            
		if(IsNtOr98==2000)
			WriteSectors2000(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);
		else
			WriteSectors(InfoOfFile.bDrive,dwStartSector,1,lpSectBuff);

	}

	free(lpSectBuff);

}

//************************    ***********************
//  :              ,       ,           
//   :   
void CSecureDelFAT::DeleteFile(INFOFDISK DiskInfo,INFOFPOSITION PositionInfo,
			  FILEINFO InfoOfFile,FILEINFO InfoOfDir)
{
	
	char cDesktop[_MAX_PATH]="";
	char cRecycled[_MAX_PATH]="";
	char HomeFileName[40]="";
	char InfoFileName[40]="";
	char RecycledName[40]="";
	char DriveName[40]="";

	int IsNtOr98;
	char pDir[_MAX_DIR]="";
	__int64  FileLen=0;

	DWORD dwFileFirstCluster;//    
	DWORD dwDirFirstCluster;//    
	DWORD dwFilePosition;//         
	DWORD dwStartSecOfIndx;//       
	DWORD dwStartSec;//                
	DWORD dwFirstCluOfIndex;//      

	DWORD dwIfCrossClu;
	INFOFDISK pDiskInfo={0};

	//       
	IsNtOr98=NtOr98();
	//    
	DriveName[0]=InfoOfFile.bDrive-1+'A';
	strcat(DriveName,":\\");
	
	//        
	if(IsNtOr98==2000)
		GetCluster2000(DiskInfo,PositionInfo,InfoOfFile,&dwFileFirstCluster);
	else
		GetCluster(InfoOfFile,&dwFileFirstCluster);

	InfoOfFile.dwFileFirstClu=dwFileFirstCluster;
	
	InfoOfFile.dwFileStartSec=SectorOfFile(DiskInfo,PositionInfo,InfoOfFile,dwFileFirstCluster);
	
	
	//             
	if(strlen(InfoOfFile.pFileDirPath)>3)
	{
		//            
		if(IsNtOr98==2000)
			GetCluster2000(DiskInfo,PositionInfo,InfoOfDir,&dwDirFirstCluster);
		else
			GetCluster(InfoOfDir,&dwDirFirstCluster);

		InfoOfDir.dwFileFirstClu=dwDirFirstCluster;
		//             
		dwStartSecOfIndx=SectorOfFile(DiskInfo,PositionInfo,
			                            InfoOfDir,dwDirFirstCluster);
		InfoOfDir.dwFileStartSec=dwStartSecOfIndx;

		//************************************************

		//               
		dwFilePosition=FilePositionFat32(DiskInfo,PositionInfo,InfoOfFile,
			                             InfoOfDir,&dwStartSec,&dwIfCrossClu);
		InfoOfFile.dwFileIndexPosition=dwFilePosition;
		InfoOfFile.dwSecNearFileIndex=dwStartSec;
		InfoOfFile.dwIfCrossClu=dwIfCrossClu;

		//      fat 
		FileIndex32(DiskInfo,PositionInfo,InfoOfFile,InfoOfDir);
		
	}
	//            
	else 
	{
		//            
		dwFirstCluOfIndex=DiskInfo.dwFirstCluOfIndex;
		InfoOfDir.dwFileFirstClu=dwFirstCluOfIndex;
		//             
		dwStartSecOfIndx=DiskIndex(DiskInfo,InfoOfFile);
		InfoOfDir.dwFileStartSec=dwStartSecOfIndx;

		//      FAT16、FAT32   ,        
		if(InfoOfFile.IfFat==32)
		{
			//               
			dwFilePosition=FilePositionFat32(DiskInfo,PositionInfo,InfoOfFile,
			                             InfoOfDir,&dwStartSec,&dwIfCrossClu);
			InfoOfFile.dwFileIndexPosition=dwFilePosition;
			InfoOfFile.dwSecNearFileIndex=dwStartSec;
			InfoOfFile.dwIfCrossClu=dwIfCrossClu;

			//      fat 
			FileIndex32(DiskInfo,PositionInfo,InfoOfFile,InfoOfDir);

		}
		else
		{
			//               
			dwFilePosition=FilePosition(InfoOfFile.bDrive,DiskInfo,dwStartSecOfIndx,
				                        dwFileFirstCluster);
			InfoOfFile.dwFileIndexPosition=dwFilePosition;
			InfoOfFile.dwIfCrossClu=0;

			//                、fat         ,        fat 
			FileIndex(DiskInfo,PositionInfo,InfoOfFile,InfoOfDir);

		}
	}
}

BOOL CSecureDelFAT::SecureDelFatFile(CString FileName)
{
	//       
	CString	m_File=FileName;
	FILEINFO InfoOfFile;//         
	INFOFDISK DiskInfo={0};//              
	FILEINFO InfoOfDir;//             
	INFOFPOSITION PositionInfo;//                
	int nDirLeng;//              
	char cDrive[_MAX_DRIVE];
	char cDir[_MAX_DIR];
	char pDir[_MAX_DIR]="";
	char cDesktop[_MAX_PATH]="";
	char cRecycled[_MAX_PATH]="";
	char cFileName1[_MAX_PATH]="";
	char cFileName2[_MAX_PATH]="";
	//                          
	nDirLeng=SplitPath(m_File,cDrive,cDir);
	strncpy(pDir,cDir,nDirLeng);

	InfoOfFile.pFilePath=m_File;
	InfoOfFile.bDrive=(BYTE)cDrive[0]-'A'+1;
	InfoOfFile.pFileDirPath=&pDir[0];
	InfoOfDir.bDrive=(BYTE)cDrive[0]-'A'+1;
	InfoOfDir.pFilePath=&pDir[0];
	//                
	InfoOfFile.IfFat=IfFatX(InfoOfFile.bDrive);
	InfoOfDir.IfFat=IfFatX(InfoOfFile.bDrive);
	if(InfoOfFile.IfFat!=16 && InfoOfFile.IfFat!=32 )
	{
		::MessageBox(NULL,"         FAT16/32    ","  ",MB_OK);
		return false;
	}
	//              
	fDiskInfo(InfoOfFile,&DiskInfo);
	//  FAT 、  FAT   
	PositionInfo.dwFatStartSec=FatStartSec(DiskInfo);
	PositionInfo.dwBakFatStartSec=FatBakStartSec(DiskInfo);
	//    
	DeleteFile(DiskInfo,PositionInfo,InfoOfFile,InfoOfDir);
	return true;
}

/////////////////////////////////////////////////////////////////////////////
//    :  WipeFileContent(LPCTSTR pFilePath)
//     :
//     :                   
/////////////////////////////////////////////////////////////////////////////
BOOL CSecureDelFAT::WipeFileContent(CString strfilename)
{
	char	filename[MAX_PATH];
	sprintf(filename, "%s", strfilename);

	HANDLE hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 
							NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
	if (hFile == INVALID_HANDLE_VALUE) 
		return false;

	DWORD fileSize = GetFileSize(hFile, 0);
	//       ,     
	if (!fileSize)
	{
		CloseHandle(hFile);
		return false;
	}

	DWORD j=0;

	for (int passes = 0; passes < OVERWRITE_PASSES; passes++)
	{
		char newStorage[BUFFER_SIZE];
		srand((unsigned)time(NULL));
		if(passes<(OVERWRITE_PASSES-1))
			FillMemory((void*)newStorage, BUFFER_SIZE, rand() % 255);
		else
			FillMemory((void*)newStorage, BUFFER_SIZE, 0);

		SetFilePointer(hFile, 0, NULL, FILE_BEGIN);

		DWORD left = fileSize;
		int write = BUFFER_SIZE;
		DWORD written = 0;
		
		while (left)
		{
			j=j+1;
			if (left < BUFFER_SIZE) write = left;
			BOOL status = WriteFile(hFile, newStorage, write, &written, NULL);
			if (!status)
			{
				CloseHandle(hFile);
				return false;
			}

			left -= write;
		}
	}
	CloseHandle(hFile);
	return true;
}

 
 
클래스 호출 코드 는 다음 과 같 습 니 다.
void CSDeleteFATDlg::OnButtonSecuredel() 
{
	// TODO: Add your control notification handler code here
	if(m_filename!="")
	{
		//                  
		m_SdelFAT.WipeFileContent(m_filename);
		//           
		FILE *fp=fopen(m_filename,"w");
		fclose(fp);
		//	         	
		m_SdelFAT.SecureDelFatFile(m_filename);	
		AfxMessageBox("      !");
		m_filename="";
	}
	UpdateData(false);
	
}

 

좋은 웹페이지 즐겨찾기