-
Notifications
You must be signed in to change notification settings - Fork 9
/
bpt_inst_counter.cpp
52 lines (45 loc) · 1.46 KB
/
bpt_inst_counter.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
#include <iostream>
#include <fstream>
#include <map>
#include <boost/range.hpp>
#include <boost/foreach.hpp>
#include "bpt_events.hpp"
#include "bpt_inst_counter.hpp"
namespace bpt {
typedef std::map<OPCODE, std::size_t> map_type;
struct inst_counter::impl {
impl(const std::string& f) : file(f) {}
std::string file;
map_type map;
};
inst_counter::inst_counter(const std::string& file)
: pimpl(new impl(file)) {}
void inst_counter::visit(const event&) {};
void inst_counter::visit(const modload_event&) {};
void inst_counter::visit(const syscall_event&) {};
void inst_counter::visit(const read_event&) {};
void inst_counter::visit(const read_flags_event&) {};
void inst_counter::visit(const write_event&) {};
void inst_counter::visit(const write_flags_event&) {};
void inst_counter::visit(const load_event&) {};
void inst_counter::visit(const store_event&) {};
void inst_counter::visit(const operation_event& e) {
typedef map_type::iterator iterator;
iterator i(pimpl->map.find(e.opcode()));
if (i == boost::end(pimpl->map)) {
pimpl->map[e.opcode()] = 1;
} else {
i->second += 1;
}
}
inst_counter::~inst_counter() {
std::ofstream out(pimpl->file.c_str(), std::ofstream::out);
BOOST_FOREACH(const map_type::value_type& e, pimpl->map) {
out << OPCODE_StringShort(e.first)
<< " = "
<< e.second
<< std::endl;
}
out << "Total = " << pimpl->map.size() << std::endl;
}
} //namespace bpt