读书人

C++如何实现阻止指定或任何程序写入MBR

发布时间: 2012-02-28 13:06:36 作者: rapoo

C++怎么实现阻止指定或任何程序写入MBR
现在有一程序,每次启动都会在MBR里面写个flag

怎么样用C++写一程序阻止其写MBR?

用什么实现。怎么实现。请高手指教。。

[解决办法]
备份代码:

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;} 

读书人网 >C++

热点推荐