-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmega_info_creator.cpp
134 lines (118 loc) · 2.54 KB
/
mega_info_creator.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdlib>
#include <fstream>
#include "types.hpp"
#include "endian.hpp"
#include "dol.hpp"
#include "functions.hpp"
using namespace std;
int main(int argc, char **argv)
{
bool isDol = false;
bool dumpSigs = false;
bool createIDC = false;
bool ordered = false;
std::vector<bool> arguments(argc, false);
if ( argc < 3 )
{
cout << "Usage: " << argv[0] <<
" <mega file> <dump or dol> [options]" << endl;
cout << "options:" << endl;
cout << "\t--dol using a dol" << endl;
cout << "\t--sigs dump sigs" << endl;
cout << "\t--idc create idc file" << endl;
cout << "\t--ordered [not functional yet]" << endl;
return EXIT_FAILURE;
}
if ( argc >= 4 )
{
for(int n = 1; n < argc; n++)
{
if ( !strncmp(argv[n], "--dol", 5) )
{
isDol = true;
arguments[n] = true;
}
if ( !strncmp(argv[n], "--sigs", 6) )
{
dumpSigs = true;
arguments[n] = true;
}
if ( !strncmp(argv[n], "--idc", 5) )
{
createIDC = true;
arguments[n] = true;
}
if ( !strncmp(argv[n], "--ordered", 9) )
{
ordered = true;
arguments[n] = true;
}
}
}
int mega_index = 0;
int dol_index = 0;
for(int ii = 0; ii < argc; ii++)
{
if(arguments[ii] == false)
{
if(!mega_index)
mega_index = ii;
else if(!dol_index)
dol_index = ii;
}
}
ifstream myInputFile(argv[mega_index], ios::in);
if ( !myInputFile )
{
cout << "File ";
cout << argv[mega_index] << "could not be opened"
<< endl;
return EXIT_FAILURE;
}
vector<string> sigs;
string sLine;
while( getline(myInputFile, sLine) )
{
if ( !sLine.empty() )
sigs.push_back( sLine );
}
myInputFile.close();
ifstream memDump(argv[dol_index], ios::in);
if ( !memDump )
{
cout << "File ";
cout << argv[dol_index] << "could not be opened"
<< endl;
return EXIT_FAILURE;
}
memDump.seekg(0, ifstream::end);
u32 memDumpSize = memDump.tellg();
memDump.seekg(0);
char * buffer = new char[memDumpSize];
memDump.read(buffer, memDumpSize);
memDump.close();
if(dumpSigs)
{
for(u32 stri=0; stri<sigs.size(); stri++)
DumpSigInfo(sigs[stri]);
exit(EXIT_SUCCESS);
}
if (createIDC) {
cout << "#include <idc.idc>" << endl;
cout << "static main() {" << endl;
}
// DO SOMETHING COOL //
for(u32 stri = 0; stri < sigs.size(); stri++)
if(createIDC)
CreateIDC(buffer, memDumpSize, sigs[stri], isDol);
else
FindSig(buffer, memDumpSize, sigs[stri], isDol);
if (createIDC)
cout << "}" << endl;
delete [] buffer;
return EXIT_SUCCESS;
}