有些时候,我们读取磁盘文件,会被hook.我们读到的可能并不是实际的文件。
我们直接读取磁盘扇区获得数据。
实现磁盘数据的读写,不依赖WindowsAPI。
- void CSectorEdit2000Dlg::OnView()
- {
- UpdateData(TRUE);
- if (m_uTo < m_uFrom)
- return;
-
- char cTemp[1];
- memcpy(cTemp, m_DrvListBoxSResult.Left(1), 1);
- UINT uDiskID = cTemp[0] - 64;
-
- DWORD dwSectorNum = m_uTo - m_uFrom + 1;
- if (dwSectorNum > 100)
- return;
-
- unsigned char* bBuf = new unsigned char[dwSectorNum * 512];
-
- if (ReadSectors(uDiskID, m_uFrom, (UINT)dwSectorNum, bBuf) == FALSE)
- {
- MessageBox("所选磁盘分区不存在!", "毛病", MB_OK | MB_ICONERROR);
- return;
- }
-
- char* cBuf = new char[dwSectorNum * 5120];
- memset(cBuf, 0, sizeof(cBuf));
-
- for (DWORD i = 0; i < dwSectorNum * 512; i++)
- {
- sprintf(cBuf, "%s%02X ", cBuf, bBuf[i]);
-
- if ((i % 512) == 511)
- sprintf(cBuf, "%s
第%d扇区
", cBuf, (int)(i / 512) + m_uFrom);
- if ((i % 16) == 15)
- sprintf(cBuf, "%s
", cBuf);
- else if ((i % 16) == 7)
- sprintf(cBuf, "%s- ", cBuf);
- }
- SetDlgItemText(IDC_DATA, cBuf);
- delete[] bBuf;
- delete[] cBuf;
- }
-
- void CSectorEdit2000Dlg::OnCleardata()
- {
- UpdateData(TRUE);
-
- char cTemp[1];
- memcpy(cTemp, m_DrvListBoxSResult.Left(1), 1);
- UINT uDiskID = cTemp[0] - 64;
- if (uDiskID > 2)
- {
- if (MessageBox("要清算的是硬盘分区,请确认是不是继续?", "提示", MB_YESNO | MB_ICONWARNING) != 6)
- return;
- if (uDiskID == 3)
- {
- if (MessageBox("要清算的是系统分区,请再次确认是不是继续?", "提示", MB_YESNO | MB_ICONWARNING) != 6)
- return;
- }
- }
-
- unsigned char bBuf[512];
-
- UINT i = 0;
- BOOL bRet = TRUE;
- while (m_bAllDisk)
- {
- memset(bBuf, 0xFF, sizeof(bBuf));
- bRet = WriteSectors(uDiskID, i, 1, bBuf);
- memset(bBuf, 0, sizeof(bBuf));
- bRet = WriteSectors(uDiskID, i, 1, bBuf);
-
- if (bRet == FALSE)
- {
- if (i == 0)
- MessageBox("所选磁盘分区不存在!", "毛病", MB_OK | MB_ICONERROR);
- else
- MessageBox("磁盘数据擦除终了!", "毛病", MB_OK | MB_ICONERROR);
- return;
- }
- i++;
- }
-
- if (m_bAllDisk == FALSE)
- {
- for (DWORD i = m_uFrom; i <= m_uTo; i++)
- {
- memset(bBuf, 0xFF, sizeof(bBuf));
- bRet = WriteSectors(uDiskID, i, 1, bBuf);
- memset(bBuf, 0, sizeof(bBuf));
- bRet = WriteSectors(uDiskID, i, 1, bBuf);
- if (bRet == FALSE)
- {
- if (i == 0)
- MessageBox("所选磁盘分区不存在!", "毛病", MB_OK | MB_ICONERROR);
- else
- MessageBox("磁盘数据擦除终了!", "提示", MB_OK | MB_ICONINFORMATION);
- return;
- }
- }
- }
- }
-
-
------分隔线----------------------------
------分隔线----------------------------