-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
76 lines (62 loc) · 1.44 KB
/
test.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
#include "disasm.h"
#include <iostream>
#include <elfio/elfio.hpp>
#include "cfg.h"
#include "analysis.h"
#include "reg-alloc.h"
#include <iomanip>
#include "countermeasures/eddi.h"
#include "countermeasures/rasm.h"
#include "countermeasures/swift.h"
#include "countermeasures/post-process.h"
int fastrand() {
static int g_seed;
g_seed = (214013*g_seed+2531011);
return (g_seed>>16)&0x7FFF;
}
static void replace_reg(basic_block& bb, std::map<vreg, vreg>& replace_map) {
if (bb.visited)
return;
for (vins& in : bb) {
for (vreg& reg : in.regs) {
auto f = replace_map.find(reg);
if (f != replace_map.end()) {
reg = f->second;
}
}
}
bb.visited = true;
for (basic_block* succ : bb.successors) {
replace_reg(*succ, replace_map);
}
for (basic_block* pred : bb.predecessors) {
replace_reg(*pred, replace_map);
}
}
int main(int argc, char *argv[]) {
lifter lift;
if (!lift.load(argv[1])) {
std::cerr << "Cannot open input file " << argv[1] << '\n';
return 1;
}
if (lift.instructions.empty()) {
try {
lift.save(argv[argc-1]);
return 0;
}
catch (std::runtime_error& e) {
std::cout << e.what() << '\n';
return 1;
}
}
control_flow_graph cfg = get_cfg(lift);
apply_swift(lift, cfg);
allocate_registers(cfg);
mitigate_second_stack_vunerabilities(cfg);
lift.instructions = cfg_dump(cfg);
try { lift.save(argv[argc-1]); }
catch (std::runtime_error& e) {
std::cout << e.what() << '\n';
return 1;
}
}