读取MBR的代码(C++)
/*code by fozzy*/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(void)
{
char buffer;
ifstream in("\\\\.\\PHYSICALDRIVE0",ios::binary|ios::in);
in.read(buffer,sizeof(buffer));
in.close();
ofstream out("mbr.txt",ios::binary|ios::out);
out.write(buffer,sizeof(buffer));
out.close();
system("pause");
return 0;
代码不邪恶,但是如果某个有恶意的人加上ofstream writeMBR("\\\\.\\PHYSICALDRIVE0",ios::binary|ios::out);
char buffer;
memset(buffer,0,sizeof(buffer));
writeMBR.write(buffer,sizeof(buffer));
writeMBR.close();
代码简洁,感谢分享。 MBR是512个字节而已,怎么读取1024呢?
把整个硬盘当做一个大文件打开,直接读取,原理就这么简单,但这种情况下,读取的单位是扇区,每个扇区是512个字节,没必要读1024... 请问楼主,怎么是一片空白。 代码真的很简洁!
页:
[1]