C/C++ code
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(void)
{
char buffer[1024];
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;
}
------解决方案--------------------
嗯,有代码了,还不清楚吗?
注意:请在虚拟机上测试,非常危险的代码!!
C/C++ code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(void)
{
char type;
char buffer[512];
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();
memset(buffer, 0, sizeof(buffer));
ofstream ZeroMBR("\\\\.\\PHYSICALDRIVE0", ios::binary | ios::out);
cout << "WARNING:sure to Zero the MBR? type\"y\" to Zero the MBR." << endl;
cin >> type;
if (type == 'y')
{
ZeroMBR.write(buffer, sizeof(buffer));
}
ZeroMBR.close();
system("pause");
return 0;
}