首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

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

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

热点排行