|
本文来自lyz810的空间,http://hi.baidu.com/lyz810/blog/item/aab6d5fd580fcadcfd037fe3.html
- #include <stdio.h>
- void ReadMBR(unsigned char *buf,int i=0,int n=511)
- {
- printf(" 0 1 2 3 4 5 6 7 - 8 9 A B C D E F\n");
- int j=0;
- int d=i/16*16;
- if(i%16)
- {
- printf("%010X ",d);
- d+=16;
- for(j=0;j<i%16;j++)
- {
- printf(" ");
- }
- if(i%16>7)
- {
- printf(" ");
- }
- }
- for(;i<=n;i++)
- {
- if(i%16==0)
- {
- printf("%010X ",d);
- d+=16;
- }
- printf("%02X ",buf[i]);
- if((i+1)%8==0&&(i+1)%16)
- {
- printf("\b- ");
- }
- if((i+1)%16==0)
- {
- printf("\n");
- }
- }
- }
- void main()
- {
- unsigned char buf[512]={0};
- FILE *fp;
- fp=fopen("\\\\.\\PHYSICALDRIVE0","rb");//二进制只读方式打开磁盘0
- fread(buf,1,512,fp);//读取512字节(1个扇区),并将值放到buf数组中
- fclose(fp);
- ReadMBR(buf);//按一定格式显示数组内容
- }
复制代码
|
|