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学习书推荐 ...
随机推荐
- 浅谈python的对象的三大特性之封装
我们家里都有电视机,从开机,浏览节目,换台到关机,我们不需要知道电视机里面的具体细节,只需要在用的时候按下遥控器就可以完成操作,这就是功能的封装. 在用支付宝进行付款的时候,只需要在用的时候把二唯码给 ...
- centos6.8 安装gitlab记录
sudo yum install -y curl policycoreutils-python openssh-server cronie sudo lokkit -s http -s ssh sud ...
- JavaBean命名规范
———————————————————————————————————————————————————————— 属性名/类型 | ...
- BZOJ 4503: 两个串 [FFT]
4503: 两个串 题意:兔子们在玩两个串的游戏.给定两个只含小写字母的字符串S和T,兔子们想知道T在S中出现了几次, 分别在哪些位置出现.注意T中可能有"?"字符,这个字符可以匹 ...
- 数组的复制及ES6数组的扩展
一.数组的复制 // alert([1,2,3]==[1,2,3]); let cc = [0,1,2]; let dd = cc; alert(dd==cc);//此时改变dd会影响cc ES5 只 ...
- SDN第五次上机作业
作业链接 1.建立拓扑,并连接上ODL控制器. 2.利用ODL下发组表.流表,实现建议负载均衡 查看s2接收的数据包都被drop掉了 在s1中下发组表 在s1中下发流表使组表生效 下发流表覆盖S2中d ...
- 创建hbase-indexer出现 0 running
新建hbase-indexer后通过hbase-indexer list-indexers发现SEP subscription ID: null并且0 running processes,如下: IN ...
- 8、flask之flask-script组件
Flask Script扩展提供向Flask插入外部脚本的功能,包括运行一个开发用的服务器,一个定制的Python shell,设置数据库的脚本,cronjobs,及其他运行在web应用之外的命令行任 ...
- 一致性哈希(附带C++实现)
在分布式集群中,对机器的添加删除,或者机器故障后自动脱离集群这些操作是分布式集群管理最基本的功能.如果采用常用的hash(object)%N算 法,那么在有机器添加或者删除后,就需要大范围的移动原有数 ...
- java 堆和栈
转载自 http://blog.csdn.net/peterwin1987/article/details/7571808 博主讲的相当清楚吼吼吼