加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技

发布时间:2020-12-13 20:42:58 所属栏目:PHP教程 来源:网络整理
导读:有些时候,我们读取磁盘文件,会被hook.我们读到的可能并不是实际的文件。 我们直接读取磁盘扇区获得数据。 实现磁盘数据的读写,不依赖WindowsAPI。 [cpp] view plaincopy void CSectorEdit2000Dlg::OnView() { UpdateData(TRUE); if (m_uTom_uFrom) return

有些时候,我们读取磁盘文件,会被hook.我们读到的可能并不是实际的文件。

我们直接读取磁盘扇区获得数据。

实现磁盘数据的读写,不依赖WindowsAPI。

 

[cpp] view plaincopy
  1. void CSectorEdit2000Dlg::OnView()   
  2. {  
  3.     UpdateData(TRUE);  
  4.     if (m_uTo < m_uFrom)  
  5.         return;  
  6.       
  7.     char cTemp[1];  
  8.     memcpy(cTemp, m_DrvListBoxSResult.Left(1), 1);  
  9. UINT uDiskID = cTemp[0] - 64;  
  10.   
  11. DWORD dwSectorNum = m_uTo - m_uFrom + 1;  
  12. if (dwSectorNum > 100)  
  13.     unsigned char* bBuf = new unsigned char[dwSectorNum * 512];  
  14.     if (ReadSectors(uDiskID, m_uFrom, (UINT)dwSectorNum, bBuf) == FALSE)  
  15.     {  
  16.         MessageBox("所选磁盘分区不存在!""毛病", MB_OK | MB_ICONERROR);  
  17.         return;  
  18.     }  
  19. char* cBuf = new char[dwSectorNum * 5120];  
  20.     memset(cBuf, 0, sizeof(cBuf));  
  21.   
  22. for (DWORD i = 0; i < dwSectorNum * 512; i++)  
  23.     {  
  24.         sprintf(cBuf, "%s%02X ", cBuf, bBuf[i]);  
  25. if ((i % 512) == 511)  
  26.             sprintf(cBuf, "%s 第%d扇区 ",87); background-color: inherit; font-weight: bold;">int)(i / 512) + m_uFrom);  
  27. if ((i % 16) == 15)  
  28. "%s ", cBuf);  
  29. else if ((i % 16) == 7)  
  30. "%s- ",248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">    }  
  31.     SetDlgItemText(IDC_DATA, cBuf);  
  32. delete[] bBuf;  
  33. delete[] cBuf;  
  34. }  
  35. void CSectorEdit2000Dlg::OnCleardata()   
  36. {  
  37.     UpdateData(TRUE);  
  38.     char cTemp[1];  
  39.     memcpy(cTemp, 1);  
  40. UINT uDiskID = cTemp[0] - 64;  
  41. if (uDiskID > 2)  
  42. if (MessageBox("要清算的是硬盘分区,请确认是不是继续?""提示", MB_YESNO | MB_ICONWARNING) != 6)  
  43.             if (uDiskID == 3)  
  44.         {  
  45.             if (MessageBox("要清算的是系统分区,请再次确认是不是继续?",248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">                        }  
  46.       
  47.     unsigned char bBuf[512];  
  48. UINT i = 0;  
  49. BOOL bRet = TRUE;  
  50. while (m_bAllDisk)        
  51.         memset(bBuf, 0xFF,153); background-color: inherit; font-weight: bold;">sizeof(bBuf));  
  52.         bRet = WriteSectors(uDiskID, i, 1, bBuf);  
  53.           
  54. if (bRet == FALSE)  
  55. if (i == 0)  
  56.                 MessageBox("所选磁盘分区不存在!", MB_OK | MB_ICONERROR);  
  57. else  
  58.                 MessageBox("磁盘数据擦除终了!",248); line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">        }  
  59.         i++;  
  60.     }     
  61. if (m_bAllDisk == FALSE)  
  62. DWORD i = m_uFrom; i <= m_uTo; i++)  
  63.         {  
  64.             memset(bBuf,108); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">            bRet = WriteSectors(uDiskID,153); background-color: inherit; font-weight: bold;">if (bRet == FALSE)  
  65.             {  
  66. if (i == 0)  
  67.                     MessageBox("所选磁盘分区不存在!",153); background-color: inherit; font-weight: bold;">else  
  68.                     MessageBox("磁盘数据擦除终了!", MB_OK | MB_ICONINFORMATION);  
  69.             }  
  70. (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读