|
楼主 |
发表于 2009-10-15 23:02:12
|
显示全部楼层
/*FILE1.H*/
#define maxsize 255
#define commaxsize 4096
#define FS_NotExists 0x01
#define FS_NotDir 0x02
#define FS_Empty 0x03
#define FS_NotReady 0x04
class FS_TIME{
public:
WORD year;
BYTE month;
BYTE day;
BYTE zero;
BYTE hour;
BYTE minute;
BYTE second;
};
typedef class FAT {
public:
WORD ErrorCode;
WORD fs;
BYTE filetype;
WCHAR shortname[13];
WCHAR longname[maxsize];
LARGE_INTEGER filesize;
LARGE_INTEGER base;
LARGE_INTEGER r_base;
DWORD offset;
DWORD clust;
FS_TIME ctime;
FS_TIME mtime;
FAT * head;
FAT * next;
FAT * pre;
}FS_FAT,*pFS_FAT;
typedef class NTFS {
public:
WORD ErrorCode; //错误信息
WORD fs; //FS标记
BYTE filetype;//文件类型--目录、文件
WCHAR shortname[13];//短文件名
WCHAR longname[maxsize];
// BYTE padding1;
LARGE_INTEGER filesize;//文件大小
DWORD mftnum;//MFT记录号
// BYTE padding2;
FILETIME ctime;//创建日期
FILETIME mtime;//修改日期
FILETIME mfttime;//MFT修改日期
NTFS * head;
NTFS * next;
NTFS * pre;
BYTE hardlinkname[commaxsize];
BYTE symboliclinkname[commaxsize];
BYTE streamname[commaxsize];
}FS_NTFS,*pFS_NTFS;
typedef BYTE * (* FSREAD)(LARGE_INTEGER base,DWORD size) ;
typedef bool (* FSWRITE)(LARGE_INTEGER base,DWORD size,BYTE * mem) ;
typedef bool ( * FS_PRE_READ)(FSREAD FSIO_READ);
typedef bool ( * FS_PRE_WRITE)(FSWRITE FSIO_WRITE);
typedef void * (* FS_ENUMFILE)(wchar_t * path,void * node) ;
typedef int (* FS_COPYFILE)(wchar_t * path,wchar_t * Stream);
typedef bool (* FS_REGFIRE)(wchar_t * regcode);
//unit1.cpp---------------------------------------------------------------------------
#include <iostream.h>
#include <vcl.h>
#include "file1.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
HANDLE hDev=NULL,hFile=NULL;
BYTE * buffer=new BYTE[65536];
void * node=NULL;
HINSTANCE DLLInst = NULL;
FS_ENUMFILE enumfile;
FS_COPYFILE copyfile;
FS_PRE_READ read;
FS_PRE_WRITE write;
FS_REGFIRE regfire;
void fun0();
void fun1();
BYTE * Read(LARGE_INTEGER a,DWORD b)
{
if (hDev!=INVALID_HANDLE_VALUE)
{
DWORD dwRet;
SetFilePointer(hDev,a.LowPart,&a.HighPart,FILE_BEGIN);
ReadFile(hDev,buffer,b,&dwRet,0);
}
else
{
}
return buffer;
}
bool Write(LARGE_INTEGER a,DWORD b,Byte * mem)
{
if (hFile!=INVALID_HANDLE_VALUE)
{
DWORD dwRet;
SetFilePointer(hFile,a.LowPart,&a.HighPart,FILE_BEGIN);
WriteFile(hFile,mem,b,&dwRet,0);
}
else
{
}
return 1;
}
int main(int argc, char* argv[])
{
int num=0;
loop:
cout<<endl<<"请选择功能:0-枚举文件;1-复制文件;9-退出。";
cin>>num;
switch(num)
{
case 0:
fun0();
break;
case 1:
fun1();
break;
case 9:
return 0;
}
goto loop;
}
void fun0()
{
String path="";
cout<<"请输入待枚举目录全路径(包括盘符)";
char letter;
cin>>letter;
while(letter!='\n')
{
path=path+letter;
letter=getchar();
}
String temp="\\\\.\\"+path.SubString(1,2);
hDev=CreateFile(temp.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (hDev==INVALID_HANDLE_VALUE){cout<<endl<<"打开磁盘错误。";return;}
temp=path.SubString(1,2);
DWORD fstype;char name[10];
GetVolumeInformation(temp.c_str(),NULL,NULL,0,0,&fstype,name,10);
if( NULL == DLLInst ) DLLInst = LoadLibrary("FS.dll");
if (DLLInst) {regfire=(FS_REGFIRE)GetProcAddress( DLLInst, "FS_REGFIRE" );enumfile=(FS_ENUMFILE)GetProcAddress( DLLInst, "FS_ENUMFILE" );read=(FS_PRE_READ)GetProcAddress( DLLInst, "FS_PRE_READ" );}//write=(FS_PRE_WRITE)GetProcAddress( DLLInst, "FS_PRE_WRITE" );copyfile=(FS_COPYFILE)GetProcAddress( DLLInst, "FS_COPYFILE" );
else{cout<<"DLL加载失败。";return;}
if(!regfire(L"银砾石")){cout<<"注册失败。";return;}
read(Read);
WideString Path=path;
node=enumfile(Path.c_bstr(),node);
temp=name;String a,b;
if(temp=="NTFS")
{
FS_NTFS * fp=(FS_NTFS *)node;
cout<<endl<<"*****************目录清单******************"<<endl;
while(fp!=NULL)
{
if (fp->ErrorCode==0x01){cout<<"指定路径不存在"<<endl;break;}
if (fp->ErrorCode==0x02){cout<<"指定路径不是一个目录"<<endl;break;}
a=fp->longname;
if (fp->filetype==1){b="目录";}else{b="文件";}
cout<<a<<" "+b<<endl;
fp=fp->next;
}
}
if(temp=="FAT16"||temp=="FAT32")
{
FS_FAT * fp=(FS_FAT *)node;
cout<<endl<<"*****************目录清单******************"<<endl;
while(fp!=NULL)
{
if (fp->ErrorCode==0x01){cout<<"指定路径不存在"<<endl;break;}
if (fp->ErrorCode==0x02){cout<<"指定路径不是一个目录"<<endl;break;}
a=fp->longname;
if (fp->filetype==1){b="目录";}else{b="文件";}
if(a!="")
{
cout<<a<<" "+b<<endl;
}
else
{
a=fp->shortname;
cout<<a<<" "+b<<endl;
}
fp=fp->next;
}
}
CloseHandle(hDev);
}
void fun1()
{
String path="";
cout<<"请输入待复制文件全路径(包括盘符)";
char letter;
cin>>letter;
while(letter!='\n')
{
path=path+letter;
letter=getchar();
}
String temp="\\\\.\\"+path.SubString(1,2);
hDev=CreateFile(temp.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (hDev==INVALID_HANDLE_VALUE){cout<<endl<<"打开磁盘错误。";return;}
if( NULL == DLLInst ) DLLInst = LoadLibrary("FS.dll");
if (DLLInst) {regfire=(FS_REGFIRE)GetProcAddress( DLLInst, "FS_REGFIRE" );copyfile=(FS_COPYFILE)GetProcAddress( DLLInst, "FS_COPYFILE" );read=(FS_PRE_READ)GetProcAddress( DLLInst, "FS_PRE_READ" );write=(FS_PRE_WRITE)GetProcAddress( DLLInst, "FS_PRE_WRITE" );}
else{cout<<"DLL加载失败。";return;}
if(!regfire(L"银砾石")){cout<<"注册失败。";return;}
read(Read);
write(Write);
WideString Path=path;
path="";
cout<<"请输入目标全路径(包括盘符)";
cin>>letter;
while(letter!='\n')
{
path=path+letter;
letter=getchar();
}
hFile=CreateFile(path.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_ALWAYS,0,0);
if (hFile==INVALID_HANDLE_VALUE){cout<<endl<<"写入失败。";return;}
int re=copyfile(Path.c_bstr(),L"");
switch(re)
{
case 0:
cout<<"文件成功复制。"<<endl;
break;
case 1:
cout<<"不存在。"<<endl;
break;
case 2:
break;
case 3:
cout<<"文件大小为0。"<<endl;
break;
case 4:
cout<<"未准备好。"<<endl;
break;
}
CloseHandle(hDev);
CloseHandle(hFile);
}
//--------------------------------------------------------------------------- |
评分
-
查看全部评分
|