MBR解析

先推广一下QQ群:61618925。欢迎各位爱好编程的朋友加入。

一、程序界面

二、关键部分代码:

1.数据结构定义

#define MBRSIZE 512
#define BOOTRECORDSIZE 440
#define DISKSIGNEDSIZE 4
#define RESERVESIZE 2
#define DPTNUMBER 4
#define DPTSIZE 16
#define ENDSIGNSIZE 2typedef struct tagBOOTRECORD 
{UCHAR szBootRecord[BOOTRECORDSIZE];
}BOOTRECORD, *PBOOTRECORD;typedef struct tagDPT
{UCHAR szBootSign;            //引导标志,0x80表示活动分区,0x00表示非活动分区UCHAR szStartHeadNumber;    //起始磁头号UCHAR szStartSectorNumber;    //起始扇区号,低6位UCHAR szStartCylinderNumber;//起始柱面号,起始扇区号的高2位+起始柱面号UCHAR szPartitionType;        //分区类型,0x00表示该分区未使用(即未指定),0x06表示FAT16基本分区,0x0B表示FAT32基本分区,0x05表示拓展分区,0x07表示NTFS分区,0x0F表示(LBA模式)拓展分区(0x83为Linux分区等)。UCHAR szEndHeadNumber;        //结束磁头号UCHAR szEndSectorNumber;    //结束扇区号,低6位UCHAR szEndCylinderNumber;    //结束柱面号,结束扇区号的高2位+结束柱面号ULONG ulSectorsPreceding;    //本分区之前使用的扇区数ULONG ulSectorsInPartition;    //分区的总扇区数
}DPT, *PDPT;typedef struct tagMBR
{BOOTRECORD BootRecord;//引导程序UCHAR ulSigned[DISKSIGNEDSIZE];        //Windows磁盘签名UCHAR szReserve[RESERVESIZE];        //保留位DPT Dpt[DPTNUMBER];            //分区表UCHAR szEndSign[ENDSIGNSIZE];        //结束标志
}MBR, *PMBR;


2.关键程序实现

void CMBRInfoDlg::InitMBRTree(void)
{HTREEITEM hParentItem = m_ctrlMBRTree.InsertItem(_T("引导程序"));hParentItem = m_ctrlMBRTree.InsertItem(_T("Windows磁盘签名"));hParentItem = m_ctrlMBRTree.InsertItem(_T("保留位"));hParentItem = m_ctrlMBRTree.InsertItem(_T("分区表"));HTREEITEM hChildItem = m_ctrlMBRTree.InsertItem(_T("第一分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第二分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第三分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hChildItem = m_ctrlMBRTree.InsertItem(_T("第四分区表"), hParentItem);m_ctrlMBRTree.InsertItem(_T("引导标志"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("起始柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("分区类型"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束磁头号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束扇区号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("结束柱面号"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区前使用的扇区数"), hChildItem);m_ctrlMBRTree.InsertItem(_T("本分区的总扇区数"), hChildItem);hParentItem = m_ctrlMBRTree.InsertItem(_T("结束标志"));m_ctrlMBRTree.SetBkColor(RGB(150, 100, 100));
}void CMBRInfoDlg::ShowMBR()
{DWORD dwRead = 0;DWORD dwError = 0;CString strError = _T("");UCHAR szMBRInfo[MBRSIZE];ZeroMemory(szMBRInfo, MBRSIZE * sizeof(UCHAR));if (!ReadFile(m_hDevice, (LPVOID)szMBRInfo, MBRSIZE * sizeof(UCHAR), &dwRead, NULL)){dwError = GetLastError();strError.Format(_T("ReadFile Error : %d"), dwError);AfxMessageBox(strError);CloseHandle(m_hDevice);m_hDevice = INVALID_HANDLE_VALUE;return;}memcpy(m_Mbr.BootRecord.szBootRecord, szMBRInfo, BOOTRECORDSIZE * sizeof(UCHAR));memcpy(m_Mbr.ulSigned, &szMBRInfo[BOOTRECORDSIZE], DISKSIGNEDSIZE);memcpy(m_Mbr.szReserve, &szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE], RESERVESIZE);for (int i = 0; i < 4; ++i){m_Mbr.Dpt[i].szBootSign = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE];m_Mbr.Dpt[i].szStartHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 1];m_Mbr.Dpt[i].szStartSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 2];m_Mbr.Dpt[i].szStartCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 3];m_Mbr.Dpt[i].szPartitionType = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 4];m_Mbr.Dpt[i].szEndHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 5];m_Mbr.Dpt[i].szEndSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 6];m_Mbr.Dpt[i].szEndCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 7];m_Mbr.Dpt[i].ulSectorsPreceding = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 8]);m_Mbr.Dpt[i].ulSectorsInPartition = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + 12]);}memcpy(m_Mbr.szEndSign, &szMBRInfo[MBRSIZE - ENDSIGNSIZE], ENDSIGNSIZE);UCHAR szTemp[3];CString strTemp = _T("");for (int i = 0; i < MBRSIZE; i++){ZeroMemory(szTemp, 3 * sizeof(UCHAR));wsprintf((LPTSTR)szTemp, _T("%02X"), szMBRInfo[i]);strTemp = szTemp;m_strMBRInfo += strTemp;if ((i + 1) % 16 == 0){m_strMBRInfo += _T("\r\n");}else{m_strMBRInfo += _T("  ");}}m_ctrlMBREdit.SetWindowText(m_strMBRInfo);
}void CMBRInfoDlg::OnTvnSelchangedTreeMbr(NMHDR *pNMHDR, LRESULT *pResult)
{LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);// TODO: 在此添加控件通知处理程序代码HTREEITEM hItem = m_ctrlMBRTree.GetSelectedItem();CString strItemText = m_ctrlMBRTree.GetItemText(hItem);if (strItemText == _T("引导程序")){m_ctrlMBREdit.SetSel(0, 4 * BOOTRECORDSIZE - 2);m_strTips = _T("引导程序占440字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("Windows磁盘签名")){m_ctrlMBREdit.SetSel(4 * BOOTRECORDSIZE, 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE) - 2);m_strTips = _T("Windows磁盘签名占4个字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("保留位")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE) - 2);m_strTips = _T("保留位占2个字节");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTNUMBER * DPTSIZE) - 2);m_strTips = _T("分区表总占64个字节,系统最多有4个主分区。双击分区表节点可以展开下一级节点查看各个分区的具体信息。");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束标志")){m_ctrlMBREdit.SetSel(4 * (MBRSIZE - ENDSIGNSIZE), 4 * MBRSIZE - 2);m_strTips = _T("结束标志占2个字节。[55 AA]为正常结束标志");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE) - 2);m_strTips = _T("每一个分区表占16个字节,双击第一分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2) - 2);m_strTips = _T("每一个分区表占16个字节,双击第二分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3) - 2);m_strTips = _T("每一个分区表占16个字节,双击第三分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 4) - 2);m_strTips = _T("每一个分区表占16个字节,双击第四分区表节点可以展开查看该分区的具体信息");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("引导标志")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 1) - 2);if (m_Mbr.Dpt[0].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[0].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 1) - 2);if (m_Mbr.Dpt[1].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[1].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 1) - 2);if (m_Mbr.Dpt[2].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[2].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 1) - 2);if (m_Mbr.Dpt[3].szBootSign == 0x80){m_strTips = _T("活动分区");}else if (m_Mbr.Dpt[3].szBootSign == 0x00){m_strTips = _T("非活动分区");}else{m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("起始磁头号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 2) - 2);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 2) - 2);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 2) - 2);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 1), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 2) - 2);}m_strTips = _T("起始磁头号");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("起始扇区号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[0].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[1].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[2].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 2), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 3) - 2);m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[3].szStartSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("起始柱面号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[0].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[0].szStartCylinderNumber);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[1].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[1].szStartCylinderNumber);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[2].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[2].szStartCylinderNumber);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 3), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 4) - 2);m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[3].szStartSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[3].szStartCylinderNumber);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("分区类型")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);int iPartitionType = 0;if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 5) - 2);iPartitionType = m_Mbr.Dpt[0].szPartitionType;}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 5) - 2);iPartitionType = m_Mbr.Dpt[1].szPartitionType;}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 5) - 2);iPartitionType = m_Mbr.Dpt[2].szPartitionType;}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 4), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 5) - 2);iPartitionType = m_Mbr.Dpt[3].szPartitionType;}switch (iPartitionType){case 0x00:m_strTips = _T("该分区未使用");break;case 0x05:m_strTips = _T("拓展分区");break;case 0x06:m_strTips = _T("FAT16基本分区");break;case 0x07:m_strTips = _T("NTFS分区");break;case 0x0B:m_strTips = _T("FAT32基本分区");break;case 0x0F:m_strTips = _T("(LBA模式)拓展分区");break;case 0x83:m_strTips = _T("Linux分区");break;default:m_strTips = _T("未知分区");}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束磁头号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 6) - 2);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 6) - 2);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 6) - 2);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 5), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 6) - 2);}m_strTips = _T("结束磁头号");m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("结束扇区号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[0].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[1].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[2].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 6), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 7) - 2);m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[3].szEndSectorNumber & 0x3F);m_ctrlTips.SetWindowText(m_strTips);}}if (strItemText == _T("结束柱面号")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[0].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[0].szEndCylinderNumber);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[1].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[1].szEndCylinderNumber);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[2].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[2].szEndCylinderNumber);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 7), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 8) - 2);m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[3].szEndSectorNumber & 0xC0) << 2) + m_Mbr.Dpt[3].szEndCylinderNumber);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("本分区前使用的扇区数")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[0].ulSectorsPreceding);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[1].ulSectorsPreceding);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[2].ulSectorsPreceding);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 8), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 12) - 2);m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[3].ulSectorsPreceding);}m_ctrlTips.SetWindowText(m_strTips);}if (strItemText == _T("本分区的总扇区数")){HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);if (strParentText == _T("第一分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[0].ulSectorsInPartition, m_Mbr.Dpt[0].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第二分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[1].ulSectorsInPartition, m_Mbr.Dpt[1].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第三分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 2 + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[2].ulSectorsInPartition, m_Mbr.Dpt[2].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}if (strParentText == _T("第四分区表")){m_ctrlMBREdit.SetSel(4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 12), 4 * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * 3 + 16) - 2);m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[3].ulSectorsInPartition, m_Mbr.Dpt[3].ulSectorsInPartition * 1.0 * 512 / 1024 / 1024 / 1024);}m_ctrlTips.SetWindowText(m_strTips);}*pResult = 0;
}HBRUSH CMBRInfoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO:  在此更改 DC 的任何属性pDC->SetBkMode(TRANSPARENT);if (pWnd == GetDlgItem(IDC_EDIT_MBR)){return CreateSolidBrush(RGB(150, 100, 100));}else{return CreateSolidBrush(RGB(120, 100, 100));}// TODO:  如果默认的不是所需画笔,则返回另一个画笔//return hbr;
}BOOL CMBRInfoDlg::OpenDevice(void)
{DWORD dwError = 0;CString strError = _T("");m_hDevice = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);if (INVALID_HANDLE_VALUE == m_hDevice){dwError = GetLastError();strError.Format(_T("CreateFile Error : %d"), dwError);AfxMessageBox(strError);return FALSE;}return TRUE;
}

三、程序下载地址

http://pan.baidu.com/s/1jGKCa94

转载于:https://www.cnblogs.com/qiyueliuguang/p/3624677.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/291640.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

css sprite讲解与使用实例

转自&#xff1a;http://www.manongjc.com/article/886.html 一、什么是css sprites css sprites直译过来就是CSS精灵。通常被解释为“CSS图像拼合”或“CSS贴图定位”。其实就是通过将多个图片融合到一张图里面&#xff0c;然后通过CSS background背景定位技术技巧布局网页背景…

实验 2 关键字驱动测试(2 学时)实验报告--软件功能测试与性能测试实验

以下是实验要求部分&#xff1a;&#xff08;小伙伴们根据自己需求决定是否下载哈&#xff09; 下载位置链接&#xff1a;https://download.csdn.net/download/qq_44872173/20031354

小手工纸盒机器人_亲子手工 | DIY弹珠迷宫小黑手自制玩具系列

上周用鞋盒做的迷你桌球受到很多男孩子的喜欢今天小黑手又做了一个瓦楞纸手工「弹珠迷宫」也是喜欢的爱不释手呢暑假小黑手系列&#xff0c;希望也能攒出个自己的小游乐场自己动手做自己的玩具&#xff0c;买玩具的钱可以省了快速手工教程Let’s do it我们一起做起来吧&#xf…

Linux screen 常用命令

想必&#xff0c;只要接触过Linux一段时间的人&#xff0c;一定知道screen这个神奇的工具了&#xff0c;它主要有如下些优势&#xff1a; 1. 后台运行&#xff1a;当你在ssh terminal执行shell时&#xff0c;如果网络这时断开&#xff0c;你的程序会怎样&#xff1f;TERMINATED…

实验 3 检查点和参数化实验报告--软件功能测试与性能测试实验

实验报告下载链接&#xff1a; https://download.csdn.net/download/qq_44872173/20031539 实验要求部分&#xff1a;

C#中的语句

寄语接下来几篇文章&#xff0c;将和大家一起简单回顾下C#中常规的语法&#xff0c;也是平常我们在编码过程中都使用的。今天来介绍下C#中的语句。一般科班出身的程序猿们大家第一个学习的语言基本都是C语言&#xff0c;C语言里面在刚开始就介绍了语句。C#中介绍的语句和C中的基…

track文件 什么是git_Git 从入门到放弃命令大全

对于刚学 Git 的朋友来说太痛苦了&#xff0c;一堆命令&#xff0c;于是就有了这篇文章&#xff0c;对于常用的命令进行梳理。Workspace&#xff1a;工作区Index / Stage&#xff1a;暂存区Repository&#xff1a;仓库区(或本地仓库)Remote&#xff1a;远程仓库1. 初始化 在当前…

【51NOD】1201 整数划分

【题意】将n划分成不同正整数的和的方案数。 【算法】动态规划 【题解】 暴力&#xff1a;f[i][j]:只用前1..i的数字&#xff0c;总和为j的方案数 本质上是01背包&#xff0c;前i个物体&#xff0c;总质量为j的方案数 f[i][j]f[i-1][j]f[i-1][j-i] 复杂度O(n^2) 优化&#xff1…

linux c之assert函数使用总结

1、assert函数介绍 assert宏的原型定义在<assert.h>中&#xff0c;其作用是如果它的条件返回错误&#xff0c;则终止程序执行&#xff0c;原型定义&#xff1a;#include <assert.h> void assert( int expression ); assert的作用是现计算表达式 expression &#x…

Activity加载View调用顺序

2019独角兽企业重金招聘Python工程师标准>>> 在Activity的onCreate方法中&#xff0c;可以通过setContentView()方法来设置此Activity要显示的界面。在xml中的布局文件需要先解析成View树才能加载显示&#xff0c;通过View的onMeasure,onLayout,onDraw方法完成View的…

使用 kube-bench 和 kube-hunter 对 Kubernetes 集群风险评估

点击上方蓝字关注 &#x1f446;&#x1f446;↓推荐关注↓随着 Kubernetes 越来越受欢迎&#xff0c;门槛也越来越低。但是安全问题仍然存在&#xff0c;下面介绍两个审计集群安全的开源工具。kube-benchkube-bench[1] 是一个 Go 应用程序&#xff0c;拥有 4.5k star。用于检查…

实验 4 操作、输出值和数据表实验报告--软件功能测试与性能测试实验

下载链接&#xff1a; https://download.csdn.net/download/qq_44872173/20031742

easyui 排序实现

1.对easyui datagrid 返回的数据&#xff0c;进行排序处理&#xff0c;便于搜索到我们的有用的信息。 例如&#xff1a; 2.datagrid 需要设置 sortable : true {field : crtTime,title : 创建时间,width : 100,sortable :true,align : center,formatter : crtTimeFtt}, 3.F12…

hm编码工具使用_H.265视频编码与技术全析(下)

H.265视频编码与技术全析&#xff08;下&#xff09;四&#xff0e;帧内预测模式共35个&#xff08;h264有9个&#xff09;&#xff0c;包括Planar&#xff0c;DC&#xff0c;33个方向模式&#xff1a;除了Intra_Angular预测外&#xff0c;HEVC还和H.264/MPEG-4 AVC一样&#x…

redmine安装指引

为什么80%的码农都做不了架构师&#xff1f;>>> 1 前言 本文记录了在window7下面安装redmine的操作过程&#xff0c;同时也为其他有兴趣安装redmine的同学提供帮助。 2 环境说明 操作系统&#xff1a;window7 64位 数据库&#xff1a;mysql-5.5.36-winx64 Red…

.NET 诞生已20周年,您的 .NET 技能是否还停留在2010 年?

20年来&#xff0c;我们见证了超过上千万.NET 开发员&#xff0c;当前有600万.NET 开发者正在使用.NET技术构建各类解决方案。今天&#xff0c;IT市场对.NET 开发人员的需求达到了前所未有的程度,特别是在中国&#xff0c;各大公司对.NET 程序员的需求用火爆来形容都不为过&…

实验 5 性能测试脚本录制和开发实验报告--软件功能测试与性能测试实验

实验内容&#xff1a; 下载链接&#xff1a; https://download.csdn.net/download/qq_44872173/20031769

MySQL-5.5.33主从复制

搭建主从同步需要在两个电脑上分别安装 MySQL &#xff0c;我这里安装的是 CentOS6.7 64位&#xff0c;MySQL-5.5.33。MySQL 是二进制包安装的&#xff1a;http://aby028.blog.51cto.com/5371905/1892818两台的操作是一样的&#xff0c;要求能够登陆 mysql 数据库即可。主从地址…

C#中的数据字典Dictionary

前言今天上午和往常一样在网上冲浪,看到码甲哥微信群里面在聊一个面试题&#xff0c;比较有意思&#xff0c;这里简单分享下结论中的Dictionary字典。有50w个int类型的数字&#xff0c;现在需要判断一下里面是否存在重复的数字&#xff0c;请简要说明下。假如这个题目让我做&am…