MBR解析

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

一、程序界面

MBR解析

二、关键部分代码:

1.数据结构定义

#define MBRSIZE 512
#define BOOTRECORDSIZE 440
#define DISKSIGNEDSIZE 4
#define RESERVESIZE 2
#define DPTNUMBER 4
#define DPTSIZE 16
#define ENDSIGNSIZE 2 typedef 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(, , ));
} void CMBRInfoDlg::ShowMBR()
{
DWORD dwRead = ;
DWORD dwError = ;
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 = ; i < ; ++i)
{
m_Mbr.Dpt[i].szBootSign = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE];
m_Mbr.Dpt[i].szStartHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szStartSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szStartCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szPartitionType = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szEndHeadNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szEndSectorNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].szEndCylinderNumber = szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ];
m_Mbr.Dpt[i].ulSectorsPreceding = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ]);
m_Mbr.Dpt[i].ulSectorsInPartition = *((int*)&szMBRInfo[BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + i * DPTSIZE + ]);
}
memcpy(m_Mbr.szEndSign, &szMBRInfo[MBRSIZE - ENDSIGNSIZE], ENDSIGNSIZE); UCHAR szTemp[];
CString strTemp = _T("");
for (int i = ; i < MBRSIZE; i++)
{
ZeroMemory(szTemp, * sizeof(UCHAR));
wsprintf((LPTSTR)szTemp, _T("%02X"), szMBRInfo[i]);
strTemp = szTemp;
m_strMBRInfo += strTemp;
if ((i + ) % == )
{
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(, * BOOTRECORDSIZE - );
m_strTips = _T("引导程序占440字节");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("Windows磁盘签名"))
{
m_ctrlMBREdit.SetSel( * BOOTRECORDSIZE, * (BOOTRECORDSIZE + DISKSIGNEDSIZE) - );
m_strTips = _T("Windows磁盘签名占4个字节");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("保留位"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE) - );
m_strTips = _T("保留位占2个字节");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTNUMBER * DPTSIZE) - );
m_strTips = _T("分区表总占64个字节,系统最多有4个主分区。双击分区表节点可以展开下一级节点查看各个分区的具体信息。");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("结束标志"))
{
m_ctrlMBREdit.SetSel( * (MBRSIZE - ENDSIGNSIZE), * MBRSIZE - );
m_strTips = _T("结束标志占2个字节。[55 AA]为正常结束标志");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("第一分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE) - );
m_strTips = _T("每一个分区表占16个字节,双击第一分区表节点可以展开查看该分区的具体信息");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ) - );
m_strTips = _T("每一个分区表占16个字节,双击第二分区表节点可以展开查看该分区的具体信息");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ) - );
m_strTips = _T("每一个分区表占16个字节,双击第三分区表节点可以展开查看该分区的具体信息");
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ) - );
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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
if (m_Mbr.Dpt[].szBootSign == 0x80)
{
m_strTips = _T("活动分区");
}
else if (m_Mbr.Dpt[].szBootSign == 0x00)
{
m_strTips = _T("非活动分区");
}
else
{
m_strTips = _T("未知分区");
}
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
if (m_Mbr.Dpt[].szBootSign == 0x80)
{
m_strTips = _T("活动分区");
}
else if (m_Mbr.Dpt[].szBootSign == 0x00)
{
m_strTips = _T("非活动分区");
}
else
{
m_strTips = _T("未知分区");
}
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
if (m_Mbr.Dpt[].szBootSign == 0x80)
{
m_strTips = _T("活动分区");
}
else if (m_Mbr.Dpt[].szBootSign == 0x00)
{
m_strTips = _T("非活动分区");
}
else
{
m_strTips = _T("未知分区");
}
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
if (m_Mbr.Dpt[].szBootSign == 0x80)
{
m_strTips = _T("活动分区");
}
else if (m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
}
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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szStartSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szStartSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szStartSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("起始扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szStartSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szStartCylinderNumber);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szStartSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szStartCylinderNumber);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szStartSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szStartCylinderNumber);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("起始柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szStartSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szStartCylinderNumber);
}
m_ctrlTips.SetWindowText(m_strTips);
}
if (strItemText == _T("分区类型"))
{
HTREEITEM hParentItem = m_ctrlMBRTree.GetParentItem(hItem);
CString strParentText = m_ctrlMBRTree.GetItemText(hParentItem);
int iPartitionType = ;
if (strParentText == _T("第一分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
iPartitionType = m_Mbr.Dpt[].szPartitionType;
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
iPartitionType = m_Mbr.Dpt[].szPartitionType;
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
iPartitionType = m_Mbr.Dpt[].szPartitionType;
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
iPartitionType = m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
}
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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szEndSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szEndSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].szEndSectorNumber & 0x3F);
m_ctrlTips.SetWindowText(m_strTips);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("结束扇区号为该字节的低六位,这里的具体值是:%02X"), m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szEndSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szEndCylinderNumber);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szEndSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szEndCylinderNumber);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szEndSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].szEndCylinderNumber);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("结束柱面号为起始扇区号的高2位+起始柱面号,这里的具体值是:%004X"), ((int)(m_Mbr.Dpt[].szEndSectorNumber & 0xC0) << ) + m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[].ulSectorsPreceding);
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[].ulSectorsPreceding);
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[].ulSectorsPreceding);
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("本分区前扇区数:%08X"), m_Mbr.Dpt[].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( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + ) - );
m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[].ulSectorsInPartition, m_Mbr.Dpt[].ulSectorsInPartition * 1.0 * / / / );
}
if (strParentText == _T("第二分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE + ) - );
m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[].ulSectorsInPartition, m_Mbr.Dpt[].ulSectorsInPartition * 1.0 * / / / );
}
if (strParentText == _T("第三分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[].ulSectorsInPartition, m_Mbr.Dpt[].ulSectorsInPartition * 1.0 * / / / );
}
if (strParentText == _T("第四分区表"))
{
m_ctrlMBREdit.SetSel( * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ), * (BOOTRECORDSIZE + DISKSIGNEDSIZE + RESERVESIZE + DPTSIZE * + ) - );
m_strTips.Format(_T("本分区扇区数:%08X.本分区的大小为:%lfG"), m_Mbr.Dpt[].ulSectorsInPartition, m_Mbr.Dpt[].ulSectorsInPartition * 1.0 * / / / );
}
m_ctrlTips.SetWindowText(m_strTips);
}
*pResult = ;
} 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(, , ));
}
else
{ return CreateSolidBrush(RGB(, , ));
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
//return hbr;
} BOOL CMBRInfoDlg::OpenDevice(void)
{
DWORD dwError = ;
CString strError = _T(""); m_hDevice = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING, , 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

上一篇:CentOS7 通过YUM安装MySQL5.7


下一篇:自动刷新 CSS文件