MBR表获取与解析
来源:互联网 发布:软件批量卸载 编辑:程序博客网 时间:2024/06/03 15:23
#include<iostream>#include<windows.h>using namespace std;#define BOOTRECORDSIZE 440typedef struct _BOOTRECORD {unsigned char BootRecord[BOOTRECORDSIZE];}BOOTRECORD,*PBOOTRECORD;#define DPTSIZE 64typedef struct _DPT {unsigned char Dpt[DPTSIZE];}DPT,*PDPT;typedef struct _MBR {BOOTRECORD BootRecord; //引导程序unsigned char ulSinged[4]; //Windows 磁盘签名unsigned char sReserve[2]; //保留位DPT Dpt; //分区表unsigned char EndSign[2]; //结束标志}MBR,*PMBR;#define DPTNUMBER 4typedef struct _DP {unsigned char BootSign; //引导标志unsigned char StartHsc[3];unsigned char Partitiontype; //分区类型unsigned char EndHsc[3];unsigned int SectorsPreceding; //本分区之前使用的扇区数unsigned int SectorInPartition;}DP,*PDP;unsigned char FixMbr[16] = { 0x00, 0xFE,0xFF ,0xFF ,0x07 ,0xFE, 0xFF ,0xFF ,0x00, 0xA8 ,0x58 ,0x01 ,0x00, 0x48 ,0x27 ,0x01 };VOID ShowMbr(HANDLE hDevice, PMBR pMbr) {DWORD dwRead = 0;//ReadFile(hDevice, (LPVOID)pMbr, sizeof(MBR), &dwRead, NULL);if (ReadFile(hDevice, (LPVOID)pMbr, sizeof(MBR), &dwRead, NULL)) {printf("ReadFile successful \r\n");}for (int i = 0; i < 512; i++) {printf("%02X ",((BYTE*)pMbr)[i]);if ((i + 1) % 16 == 0) {printf("\r\n");}}}// 解析MBRVOID ParseMbr(MBR Mbr) {printf("引导记录: \r\n");for (int i = 0; i < BOOTRECORDSIZE; i++) {printf("%02X ",Mbr.BootRecord.BootRecord[i]);if ((i + 1) % 16 == 0) {printf("\r\n");}}printf("\r\n");printf("磁盘分区表: \r\n");for (int i = 0; i < DPTSIZE; i++) {printf("%02X ", Mbr.Dpt.Dpt[i]);if ((i + 1) % 16 == 0) {printf("\r\n");}}printf("\r\n");PDP pDp = (PDP)&(Mbr.Dpt.Dpt);for (int i = 0; i < DPTNUMBER; i++) {printf("引导标志: %02X ", pDp[i].BootSign);printf("分区类型: %02X",pDp[i].Partitiontype);printf("\r\n");printf("本分区之前扇区数: %d ",pDp[i].SectorInPartition);printf("本分区的扇区数: %d", pDp[i].SectorInPartition);printf("\r\n");printf("该分区大小: %f \r\n",(double)pDp[i].SectorInPartition /1024*512/1024/1024);printf("\r\n \r\n");}printf("结束标志: \r\n");for (int i = 0; i < 2; i++) {printf("%02X ",Mbr.EndSign[i]);}printf("\r\n");} int writeMBR() {//PDP pDp = (PDP)&(Mbr.Dpt.Dpt);//Mbr.Dpt.Dpt[2] = 0;int flag = 0;PMBR pMbr = { 0 };HANDLE hDevice = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);if (hDevice == INVALID_HANDLE_VALUE) {printf("CreatrFile Error %d \r\n", GetLastError());return -1;}DWORD dwRead = 0;if (ReadFile(hDevice, (LPVOID)pMbr, sizeof(MBR), &dwRead, NULL)) {printf("ReadFile successful \r\n");}DWORD dwBytesReturned;//BYTE lpMbr[512] = { Mbr };//pMbr->Dpt.Dpt[2] = { 0 };DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dwBytesReturned, NULL);//写入磁盘文件 //WriteFile(hDevice, (LPVOID)pMbr, 512, &dwBytesReturned, NULL);if (WriteFile(hDevice, (LPVOID)pMbr, sizeof(MBR), &dwBytesReturned, NULL)) {printf("kill mbr successful!!!");}else { printf("kill mbr error"); }DeviceIoControl(hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &dwBytesReturned, NULL);CloseHandle(hDevice);return flag;}int main() {int a;//打开物理设备HANDLE hDevice = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);if (hDevice == INVALID_HANDLE_VALUE) {printf("CreatrFile Error %d \r\n",GetLastError());return -1;}MBR Mbr = { 0 };ShowMbr(hDevice, &Mbr);ParseMbr(Mbr);CloseHandle(hDevice);//writeMBR();system("pause");return 0;}
0 0
- MBR表获取与解析
- MBR结构解析与fdisk的bash实现
- 主引导记录(MBR)信息分析与获取
- MBR拓展分区解析
- MBR与分区表
- MBR与GTP
- MBR与grub
- 硬盘分区GPT与MBR
- 开机流程与MBR
- MBR与GPT
- 操作系统备份与MBR
- MBR 与 GPT
- MBR与GPT
- GUID与MBR
- UEFI与MBR区别
- Json获取与解析
- MBR分区与GPT分区
- 分区格式--MBR与GPT
- android实现断点续传
- IOS中JSON数据解析
- Linux平台Makefile文件的编写基础篇
- HttpClient的一些用法
- matlib的重要性
- MBR表获取与解析
- 作业下载图片
- Android实现网络多线程断点续传下载
- dev无法调试如何解决
- 生成javadoc帮助文档
- Android第一行代码读书笔记
- 拓扑排序介绍
- poj 1254 Hansel and Grethel 直线求交
- Windows服务器系统入侵简单流程