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 "frida-gum.h"
#include "debug.h"
#include "cmplog.h"
#include "util.h"
extern struct cmp_map *__afl_cmp_map;
static GArray *complog_ranges = NULL;
static gboolean complog_range(const GumRangeDetails *details,
gpointer user_data) {
UNUSED_PARAMETER(user_data);
GumMemoryRange range = *details->range;
g_array_append_val(complog_ranges, range);
return TRUE;
}
static gint complog_sort(gconstpointer a, gconstpointer b) {
return ((GumMemoryRange *)b)->base_address -
((GumMemoryRange *)a)->base_address;
}
void complog_init(void) {
if (__afl_cmp_map != NULL) { OKF("CompLog mode enabled"); }
complog_ranges = g_array_sized_new(false, false, sizeof(GumMemoryRange), 100);
gum_process_enumerate_ranges(GUM_PAGE_READ, complog_range, NULL);
g_array_sort(complog_ranges, complog_sort);
for (guint i = 0; i < complog_ranges->len; i++) {
GumMemoryRange *range = &g_array_index(complog_ranges, GumMemoryRange, i);
OKF("CompLog Range - 0x%016" G_GINT64_MODIFIER
"X - 0x%016" G_GINT64_MODIFIER "X",
range->base_address, range->base_address + range->size);
}
}
static gboolean complog_contains(GumAddress inner_base, GumAddress inner_limit,
GumAddress outer_base,
GumAddress outer_limit) {
return (inner_base >= outer_base && inner_limit <= outer_limit);
}
gboolean complog_is_readable(void *addr, size_t size) {
if (complog_ranges == NULL) FATAL("CompLog not initialized");
GumAddress inner_base = GUM_ADDRESS(addr);
GumAddress inner_limit = inner_base + size;
for (guint i = 0; i < complog_ranges->len; i++) {
GumMemoryRange *range = &g_array_index(complog_ranges, GumMemoryRange, i);
GumAddress outer_base = range->base_address;
GumAddress outer_limit = outer_base + range->size;
if (complog_contains(inner_base, inner_limit, outer_base, outer_limit))
return true;
}
return false;
}
|