-
Notifications
You must be signed in to change notification settings - Fork 29
/
events.cc
63 lines (53 loc) · 2.1 KB
/
events.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
52
53
54
55
56
57
58
59
60
61
62
63
#include <libvmi/libvmi.h>
#include <libvmi/events.h>
#include <memory>
#include "state.h"
#include "events.h"
#include "error.h"
typedef vmi_event_t *event_ptr;
event_ptr new_memevent(State *s, addr_t paddr,
vmi_memevent_granularity_t granularity,
vmi_mem_access_t access, event_callback_t callback,
bool _register) {
auto event = new vmi_event_t();
event->type = VMI_EVENT_MEMORY;
event->mem_event.physical_address = paddr;
event->mem_event.npages = 1;
event->mem_event.granularity = granularity;
event->mem_event.in_access = access;
event->callback = callback;
s->logger->debug("Registering mem event for address: {}", paddr);
if (_register) {
if (vmi_register_event(s->vmi, event) != VMI_SUCCESS) {
s->logger->debug("Could not register mem event for address: {}",
paddr);
throw VMIException("Failed to register memory event!");
}
}
return event;
}
event_ptr new_page_memevent(State *s, addr_t paddr, vmi_mem_access_t access,
event_callback_t callback) {
return new_memevent(s, paddr, VMI_MEMEVENT_PAGE, access, callback, true);
}
event_ptr new_byte_memevent(State *s, addr_t paddr, vmi_mem_access_t access,
event_callback_t callback) {
return new_memevent(s, paddr, VMI_MEMEVENT_BYTE, access, callback, true);
}
event_ptr new_regevent(State *s, registers_t reg, event_callback_t callback,
bool _register) {
auto event = new vmi_event_t();
event->type = VMI_EVENT_REGISTER;
event->reg_event.reg = reg;
event->reg_event.in_access = VMI_REGACCESS_W;
event->callback = callback;
s->logger->debug("Registering reg write event for register: {}", reg);
if (_register) {
if (vmi_register_event(s->vmi, event) != VMI_SUCCESS) {
s->logger->error(
"Could not register reg write event for register: {}", reg);
throw VMIException("Failed to register memory event!");
}
}
return event;
}