-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (44 loc) · 1.15 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
if(argc != 2)
{
cout << argc << endl;
cout << "Please give a dump file!" << endl;
return -1;
}
string strFilePath = argv[1];
ifstream ifs;
ifs.open(strFilePath, ios::binary|ios::ate);
if(!ifs.is_open())
{
cout << "Open file faild!" << endl;
return -1;
}
ifs.seekg(0, ios_base::end);
int nFileLength = ifs.tellg();
if(nFileLength != 1024)
{
cout << "File size must be 1024!" << endl;
return -1;
}
char* pBuffers = new char[4096];
memset(pBuffers, 0, 4096);
ifs.seekg (0, ios::beg);
ifs.read(pBuffers, nFileLength);
ifs.close();
cout << "Read file success!" << endl;
strFilePath.replace(strFilePath.find_last_of("."), 1, "_fix.");
ofstream ofs(strFilePath, ios::binary|ios::ate);
if(!ofs.is_open())
{
cout << "Write file faild!" << endl;
}
ofs.write(pBuffers,4096);
ofs.flush();
ofs.close();
cout << "Fix success!" << endl;
return 0;
}