|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <WINDOWS.H>
#include <STDIO.H>
/************************************************************************/
/* 功能描述: 读取硬盘扇区 并输出文件 */
/************************************************************************/
bool readSector(unsigned long sectorstart,unsigned long sectorcount,char *p);
int main(int argc, char* argv[]){
unsigned long start = 0; //从哪里开始读
unsigned long sectorcount = 0; //读取扇区的数量
char sectorsize[512];
if(readSector(start,sectorcount,sectorsize)){
//遍历
for(int i= 0;i<512;i++){
printf("%02X",sectorsize[i]);
}
}else{
printf("ERROR");
}
getchar();
return 0;
}
bool readSector(unsigned long sectorstart,unsigned long sectorcount,char *p){
bool resuslt =false;
unsigned long PerSector =512; //每个扇区大小
unsigned long bytesIndex; //指向实际读取字节数
char Driver[] ="\\.\PhysicalDrive0"; //指定打开扇区位置
HANDLE hOpen = CreateFile(Driver,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,0);
if(hOpen){
//long pl ; //存放低位
//long ph ; //存放高位
//pl = sectorstart*PerSector;
//ph =pl>>32;
SetFilePointer(hOpen,512,0,FILE_BEGIN); //指定读取的位置
//读取文件
ReadFile(hOpen,p,512,&bytesIndex,NULL);
CloseHandle(hOpen); //关闭句柄
resuslt =true;
return resuslt;
}
return resuslt;
}
输出 的是 FFFFFFCC 就一只循环去了 不知道那个函数 里面的值写错了 求教 |
|