-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserialize.cpp-1
executable file
·122 lines (100 loc) · 2.47 KB
/
serialize.cpp-1
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
#include <iostream>
#include <fstream>
#include <map>
#include <errno.h>
#include "serialize.h"
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <iostream>
#include <fstream>
using namespace boost::archive;
/*
void save()
{
std::ofstream file{"archive.txt"};
text_oarchive oa{file};
int i = 1;
oa << i;
}
void load()
{
std::ifstream file{"archive.txt"};
text_iarchive ia{file};
int i = 0;
ia >> i;
std::cout << i << '\n';
}
*/
void unserialize( const char * f,
Prog & prog,
CallGraph *& callgraph,
std::map<ADDRINT, Function *> & functions
)
{
std::ifstream file{f};
text_iarchive ia{file};
ia >> prog;
/*
try
{
std::ifstream ifs(f, std::ios::in|std::ios::binary);
if (!ifs.is_open())
{
fprintf(stderr, "Failed to open %s: %s\n", f,
strerror(errno));
exit(1);
}
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(ifs);
boost::archive::binary_iarchive ia(in);
// Unserialize the CFGs
ia >> prog;
}
catch (boost::iostreams::bzip2_error)
{
std::ifstream ifs(f, std::ios::in|std::ios::binary);
if (!ifs.is_open())
{
fprintf(stderr, "Failed to open %s: %s\n", f,
strerror(errno));
exit(1);
}
boost::archive::binary_iarchive ia(ifs);
// Unserialize the CFGs
ia >> prog;
}
*/
callgraph = prog.getCallGraph();
for ( CallGraph::const_func_iterator fit = callgraph->func_begin();
fit != callgraph->func_end();
fit++
)
{
Function *f = *fit;
functions[f->getAddress()] = f;
}
}
void serialize(const char *f, const Prog &prog) {
/*
std::ofstream ofs( f,
std::ios::out|std::ios::binary|std::ios::trunc
);
*/
std::ofstream file{f};
text_oarchive oa{file};
oa << prog;
/*
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::bzip2_compressor());
out.push(ofs);
boost::archive::binary_oarchive oa(out);
oa << prog;
*/
}
// Local Variables:
// c-basic-offset: 4
// compile-command: "dchroot -c typeinfer -d make"
// End: