VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术
有些时候,我们读取磁盘文件,会被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\r\n第%d扇区\r\n", cBuf, (int)(i / 512) + m_uFrom);
- if ((i % 16) == 15)
- sprintf(cBuf, "%s\r\n", 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;
- }
- }
- }
- }
- void CSectorEdit2000Dlg::OnBackup()
- {
- UpdateData(TRUE);
- if (m_uTo < m_uFrom)
- return;
- CFileDialog fileDlg(FALSE, "*.sec", "*.sec", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "磁盘扇区数据(*.sec)|*.sec||", NULL);
- CFile file;
- if (fileDlg.DoModal() != IDOK)
- return;
- file.Open(fileDlg.GetPathName(), CFile::modeCreate | CFile::modeReadWrite);
- char cTemp[1];
- memcpy(cTemp, m_DrvListBoxSResult.Left(1), 1);
- UINT uDiskID = cTemp[0] - 64;
- DWORD dwSectorNum = m_uTo - m_uFrom + 1;
- unsigned char* bBuf = new unsigned char[dwSectorNum * 512];
- if (ReadSectors(uDiskID, m_uFrom, (UINT)dwSectorNum, bBuf) == FALSE)
- {
- MessageBox("所选磁盘分区不存在!", "错误", MB_OK | MB_ICONERROR);
- return;
- }
- file.Write(bBuf, dwSectorNum * 512);
- file.Close();
- delete[] bBuf;
- MessageBox("数据备份完毕!", "提示", MB_OK | MB_ICONINFORMATION);
- }
- void CSectorEdit2000Dlg::OnRestore()
- {
- UpdateData(TRUE);
- char cTemp[1];
- memcpy(cTemp, m_DrvListBoxSResult.Left(1), 1);
- UINT uDiskID = cTemp[0] - 64;
- CFileDialog fileDlg(TRUE, "*.sec", "*.sec", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "磁盘扇区数据(*.sec)|*.sec||", NULL);
- CFile file;
- if (fileDlg.DoModal() != IDOK)
- return;
- file.Open(fileDlg.GetPathName(), CFile::modeReadWrite);
- DWORD dwSectorNum = file.GetLength();
- if (dwSectorNum % 512 != 0)
- return;
- dwSectorNum /= 512;
- unsigned char* bBuf = new unsigned char[dwSectorNum * 512];
- file.Read(bBuf, dwSectorNum * 512);
- if (WriteSectors(uDiskID, m_uFrom, (UINT)dwSectorNum, bBuf) == FALSE)
- {
- MessageBox("所选磁盘分区不存在!", "错误", MB_OK | MB_ICONERROR);
- return;
- }
- file.Close();
- delete[] bBuf;
- MessageBox("数据恢复完毕!", "提示", MB_OK | MB_ICONINFORMATION);
- }
- BOOL CSectorEdit2000Dlg::WriteSectors(BYTE bDrive, DWORD dwStartSector, WORD wSectors, LPBYTE lpSectBuff)
- {
- if (bDrive == 0)
- return 0;
- char devName[] = "\\\\.\\A:";
- devName[4] ='A' + bDrive - 1;
- HANDLE hDev;
- if(m_bPhysicalDisk==false)
- {
- hDev = CreateFile(devName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- }
- else
- hDev = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- if (hDev == INVALID_HANDLE_VALUE)
- return 0;
- SetFilePointer(hDev, 512 * dwStartSector, 0, FILE_BEGIN);
- DWORD dwCB;
- BOOL bRet = WriteFile(hDev, lpSectBuff, 512 * wSectors, &dwCB, NULL);
- CloseHandle(hDev);
- return bRet;
- }
- BOOL CSectorEdit2000Dlg::ReadSectors(BYTE bDrive, DWORD dwStartSector, WORD wSectors, LPBYTE lpSectBuff)
- {
- if (bDrive == 0)
- return 0;
- char devName[] = "\\\\.\\A:";
- devName[4] ='A' + bDrive - 1;
- HANDLE hDev;
- if(m_bPhysicalDisk==false)
- hDev = CreateFile(devName, GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- else
- hDev = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- if (hDev == INVALID_HANDLE_VALUE)
- return 0;
- SetFilePointer(hDev, 512 * dwStartSector, 0, FILE_BEGIN);
- DWORD dwCB;
- BOOL bRet = ReadFile(hDev, lpSectBuff, 512 * wSectors, &dwCB, NULL);
- CloseHandle(hDev);
- return bRet;
- }
- void CSectorEdit2000Dlg::OnSelchangeComboDrive()
- {
- // TODO: Add your control notification handler code here
- int s;
- s = m_DrvListBox.GetCurSel();
- if( s != CB_ERR )
- m_DrvListBoxSResult = ( const char * )m_DrvListBox.GetItemDataPtr( m_DrvListBox.GetCurSel());
- }
- void CSectorEdit2000Dlg::OnCheck()
- {
- // TODO: Add your control notification handler code here
- m_bPhysicalDisk=!m_bPhysicalDisk;
- if(m_bPhysicalDisk==true)
- {
- GetDlgItem( IDC_COMBO_DRIVE)->EnableWindow( false );
- }
- if(m_bPhysicalDisk==false)
- {
- GetDlgItem( IDC_COMBO_DRIVE)->EnableWindow( true );
- }
- }
VC++信息安全编程(13)Windows2000/xp/vista/7磁盘扇区读写技术的更多相关文章
- How To: Samba4 AD PDC + Windows XP, Vista and 7
dnsmasq If you've been struggling with Samba3 domain controllers and NT4 style domains working with ...
- Linux Versus Windows, Ubuntu/Mint V XP/Vista/7
原文:http://petermoulding.com/linux_versus_windows_ubuntu_mint_v_xp_vista_7 Linux Versus Windows, Ubun ...
- 并发编程 13—— 线程池的使用 之 配置ThreadPoolExecutor 和 饱和策略
Java并发编程实践 目录 并发编程 01—— ThreadLocal 并发编程 02—— ConcurrentHashMap 并发编程 03—— 阻塞队列和生产者-消费者模式 并发编程 04—— 闭 ...
- Vc数据库编程基础MySql数据库的表查询功能
Vc数据库编程基础MySql数据库的表查询功能 一丶简介 不管是任何数据库.都会有查询功能.而且是很重要的功能.上一讲知识简单的讲解了表的查询所有. 那么这次我们需要掌握的则是. 1.使用select ...
- Vc数据库编程基础MySql数据库的表增删改查数据
Vc数据库编程基础MySql数据库的表增删改查数据 一丶表操作命令 1.查看表中所有数据 select * from 表名 2.为表中所有的字段添加数据 insert into 表名( 字段1,字段2 ...
- Vc数据库编程基础MySql数据库的常见库命令.跟表操作命令
Vc数据库编程基础MySql数据库的常见操作 一丶数据库常见的库操作 1.1查看全部数据库 命令: show databases 1.2 创建数据库 命令: Create database 数据库名 ...
- Vc数据库编程基础1
Vc数据库编程基础1 一丶数据库 什么是数据库 数据库简单连接就是存储数据的容器. 而库则是一组容器合成的东西. 也就是存储数据的.我们编程中常常会用到数据库. 什么是数据管理系统 数据库管理系统就是 ...
- 重要:VC DLL编程
VC DLL编程 静态链接:每个应用程序使用函数库,必须拥有一份库的备份.多个应用程序运行时,内存中就有多份函数库代码的备份. 动态连接库:多个应用程序可以共享一份函数库的备份. DLL的调用方式:即 ...
- VC/MFC 编程技巧大总结
1 toolbar默认位图左上角那个点的颜色是透明色,不喜欢的话可以自己改. 2 VC++中 WM_QUERYENDSESSION WM_ENDSESSION 为系统关机消息. 3 Java学习书推荐 ...
随机推荐
- javascript中的BOM对象
1.window对象 所有的浏览器都支持window对象 概念上讲,一个html文档对应一个window对象 功能上讲,控制浏览器窗口 使用上讲,window对象不需要创建对象,直接使用 2.wind ...
- Ubuntu14.04 命令行下安装teamviewer
下载teamviewer 链接:https://pan.baidu.com/s/1hs0BppM 密码:sdmk 上传到 /home/[user] cd /home/[user] 移动安装包到 /o ...
- Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]
CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 ...
- SPOJ DIVCNT2 [我也不知道是什么分类了反正是数论]
SPOJ DIVCNT2 - Counting Divisors (square) 题意:求 \[ \sum_{i=1}^n\sigma_0(i^2) \] 好棒啊! 带着平方没法做,考虑用其他函数表 ...
- u-boot核心初始化
异常向量表:异常:因为内部或者外部的一些事件,导致处理器停下正在处理的工作,转而去处理这些发生的事件.ARM Architecture Reference Manual p54页.7种异常的类型:Re ...
- jQuery中animate()方法用法实例
本文实例讲述了jQuery中animate()方法用法.分享给大家供大家参考.具体分析如下: 此方法用于创建自定义动画,并且能够规定动画执行时长.擦除效果.动画完成后还可以地触发一个回调函数. ani ...
- Godep的基本使用
[http://studygolang.com/articles/4385] 关于Godep 发现好多golang项目都使用到godep作为包管理的工具,像比较大型的项目,比如kubernetes这种 ...
- Zabbix Agent active主动模式监控
zabbix_server端当主机数量过多的时候,由Server端去收集数据,Zabbix会出现严重的性能问题,主要表现如下: 1.当被监控端到达一个量级的时候,Web操作很卡,容易出现502 2.图 ...
- MySQL统计函数记录——按月、按季度、按日、时间段统计
按年汇总,统计:select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, ...
- 插入排序实现&&选择排序实现
萌新刚刚开始学习算法,第一步是学习排序,毕竟算法的四大块"排序,查找,图,字符串"里面,排序是第一位的(PS:今天才知道算法提供的只是一个程序编写思路,一直以为是一个函数,难怪传入 ...