-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxxplug_hide_linked_symbols.cpp
74 lines (64 loc) · 1.69 KB
/
cxxplug_hide_linked_symbols.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
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "cxxplug_hide_linked_symbols/args.hpp"
#include "cxxplug_hide_linked_symbols/hide_symbols.hpp"
#include "cxxplug_hide_linked_symbols/get_symbols.hpp"
using namespace std;
int main (int argc, char **argv) {
bool is_verbose = false;
const char *symbols_lib_path = nullptr;
const char *source_lib_path = nullptr;
const char *destination_lib_path = nullptr;
const char *command_nm = "nm";
const char *command_objcopy = "objcopy";
if (
Args::is_argv_wrong(
argc,
argv,
&symbols_lib_path,
&source_lib_path,
&destination_lib_path,
&command_nm,
&command_objcopy,
&is_verbose
)
) {
cout << Args::get_help();
return -1;
};
if (!destination_lib_path) {
destination_lib_path = source_lib_path;
}
Args args(
symbols_lib_path,
source_lib_path,
destination_lib_path,
command_nm,
command_objcopy,
is_verbose
);
if (args.verbose) {
args.print();
}
try {
list<string> symbols = get_all_symbols(
args.command_nm, args.symbols_lib_static_path
);
if (args.verbose) {
print_all_symbols(symbols);
}
hide_symbols(
args.command_objcopy,
args.source_lib_static_path,
args.destination_lib_static_path,
symbols
);
}
catch (const exception &e) {
cerr << "Failed: " << e.what() << "\n";
return -1;
}
cout << "\n";
return 0;
}