-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (46 loc) · 1.45 KB
/
main.cpp
File metadata and controls
53 lines (46 loc) · 1.45 KB
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
#include <ElfParser.h>
#include <InstructionFabric.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>
ElfParser* parseFile(std::ifstream& input, const char* path) {
input.open(path, std::ios_base::binary);
if (!input.is_open()) {
throw std::ios_base::failure("Can`t open input file");
}
const auto parser = new ElfParser(input);
parser->parse();
return parser;
};
void openOutFile(std::ofstream& output, const char* path) {
output.open(path, std::ios_base::binary);
if (!output.is_open()) {
throw std::ios_base::failure("Can`t open output file");
}
}
int main(const int argc, char const* argv[]) {
if (argc < 3) {
std::cout << "2 arguments expected, " + std::to_string(argc - 1) + " found\n";
return 0;
}
try {
std::ifstream input;
ElfParser* parser = parseFile(input, argv[1]);
try {
std::ofstream output;
openOutFile(output, argv[2]);
parser->printDotText(output);
output << "\n";
parser->printSymtab(output);
} catch (const std::ios_base::failure& e) {
std::cout << e.what() << std::endl;
}
delete parser;
} catch (std::ios_base::failure& e) {
std::cout << e.what() << std::endl;
} catch (std::runtime_error& e) {
std::cout << e.what() << std::endl;
}
return 0;
}