



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、分享如下:/ SafeTest.cpp :定义控制台应用程序的入口点。/#includestdafx.h#include#include#includeusingnamespacestd ;int_tmain (intargc , _TCHAR* argv )/ 读取物理磁盘数据HANDLEhFile =:CreateFile( L.PhysicalDrive0, GENERIC_READ,0, NULL, OPEN_EX ISTING, NULL, NULL);BYTE MBR512;DWORD outRead;if( hFile )bool bRet =:ReadFile( hFile ,
2、 MBR,sizeof( MBR),& outRead, NULL); :CloseHandle( hFile );if( bRet)/*从 0x00 - 0x162 :这是 MBR 的主体代码区域从 0x162 - 0x1bd :这是 MBR 用到的数据区域从 0x1be - 0x1fd:这是 MBR 的磁盘分区表区域从 0x1fe - 0x1ff :这是 MBR 的标志 55AA */ 主引导记录 446 个字节/ 在 MBR 里的后 64个字节里是磁盘的分区表结构,可定义分区 16 bytes,从 0x1be 0x1fe共 64 bytes。4个分区,每个/ 最后两位是结束标志位,55A
3、Aintbootindicator=MBR0x1BE;/ 分区的启动标志, 80H可启动分区, 00H不可启动分区/ 分区的起始扇区intheads =MBR0x1BF;/ 起始 headsintsector=MBR0x1C0&0x3F;/ 低6 bits表示起始sector,这里只用该节字的低 6 bits来表示sectorintcylinder=MBR0x1C1|(MBR0x1C0&0xC0)2;/1C0的高2 btis加上1C1 的 8 bits组成10 bits表示起始cylinderintfilesys=MBR0x1C2;/ 文件系统 ,如: 07 表示 ntfs系统/ 分区的结束扇
4、区intheads_end =MBR0x1C3;/ 起始intsector_end =MBR0x1C4&0x3F;用该节字的低 6 bits来表示 sectorheads/ 低 6 bits表示起始sector,这里只intcylinder_end加上 1C1 的 8 bits=( MBR0x1C4&0xC0)2|组成 10 bits表示起始MBR0x1C5; cylinder/1C0的高2 btis/cylinder 最大只能表示 1023 个,超过部分没办法表示,这里就以分区扇数为准intcount_before =MBR0x1C924| MBR0x1C816| MBR0x1C78| MB
5、R0x1C6; / 这 4 bytes 表示此分区前有多少扇区(实际上等于此分区的起始扇区号),以little-endian排列的。intcount =MBR0x1CD24| MBR0x1CC16| MBR0x1CB8| MBR0x1CA;/这 4 bytes用来表示此分区共有多少扇区,同样是以little-endian排列的。/*1 byte的 head 最大可表示: 0xFF 个 heads ,即: 255 个 heads6 bits的 sector最大表示: 0x3F 个 sector即: 63 个 sectors10 bits 的 cylinder 最大表示: 0x3FF 个 cyli
6、nder 即: 1023 个 cylinders每个 cylinder的扇区为: heads * 63 = 255 * 63 = 16065 sectorsL = cylinder * 16065 + heads * 63 + sector - 1disk size = cylinders * 63 * heads * 512*/intL_Start= cylinder* 16065 + heads* 63 + sector- 1;intL_End = cylinder_end* 16065 + heads_end * 63 + sector_end- 1;floattotalspace=co
7、unt *0.5/1024/1024;/ 硬盘的容量 =柱面数磁头数扇区数 512B。printf(Boot Indicator:%XHnn,bootindicator);printf(Heads:%02XHn, heads);printf(Sector:%02XHn,sector );printf(Cylinder:%02XHnn,cylinder);printf(FileSystem:%02XHnn,filesys );printf(End_Heads:%02XHn, heads_end);printf(End_Sector:%02XHn, sector_end );printf(End_Cylinder:%02XHnn,cylinder_end);printf(Count_Before:%08XHn,count_before );printf(Count:%08XHnn, count );printf(L_End(%XH)-L_Start(%XH)=Diff(%XH)nn,L_End, L_Start , L_End-L_Start);printf(Total Space:%fGBnn,totalspace );/*从 0x00 - 0x162 :这是 MBR 的主体代码区域从 0x162 - 0x1bd :这是 MBR 用到的数据区域从 0x1
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论