-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.cc
51 lines (38 loc) · 1.5 KB
/
converter.cc
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
#include <iostream>
#include <fstream>
#include "converter.h"
#include "assemblage.h"
int main(int argc, char const* argv[]) {
if (argc != 4) {
std::cerr << "Wrong number of arguments.\n";
return 1;
}
char const* elf64_file_name = argv[1];
char const* functions_file_name = argv[2];
char const* output_file_name = argv[3];
std::ifstream func_stream;
func_stream.exceptions(std::ifstream::badbit);
func_stream.open(functions_file_name, std::ifstream::in);
try {
converter::func_spec::Functions functions{func_stream};
converter::assembly::rid_gnu_property(elf64_file_name, output_file_name);
std::ifstream elf_istream;
elf_istream.exceptions(std::ifstream::badbit);
elf_istream.open(output_file_name, std::ifstream::in | std::ifstream::binary);
converter::Elf64 elf64{elf_istream};
elf_istream.close();
converter::Elf32 elf32{elf64, functions};
std::ofstream elf_ostream;
elf_ostream.exceptions(std::ifstream::badbit);
elf_ostream.open(output_file_name, std::ifstream::out | std::ifstream::binary);
elf32.write_out(elf_ostream);
} catch (std::ifstream::failure const&) {
std::cerr << "Error when processing file: read error or unexpected EOF.\n";
return 1;
} catch (converter::UnsupportedFileContent const& e) {
std::cerr << "Nonsupported file content was found in the ELF.\n";
std::cerr << e.what();
return 1;
}
return 0;
}