Skip to content

Commit fd82e33

Browse files
committed
add model
1 parent 1db82f3 commit fd82e33

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ src/afl-sharedmem.o : $(COMM_HDR) src/afl-sharedmem.c include/sharedmem.h
472472
$(CC) $(CFLAGS) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) -c src/afl-sharedmem.c -o src/afl-sharedmem.o
473473

474474
afl-fuzz: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o src/hashmap.c | test_x86
475-
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) -Wno-shift-count-overflow $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o src/hashmap.c -o $@ $(PYFLAGS) $(LDFLAGS) -lm
475+
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) -Wno-shift-count-overflow $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o src/hashmap.c -o $@ $(PYFLAGS) $(LDFLAGS) -lm -lxgboost
476476

477477
afl-showmap: src/afl-showmap.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o $(COMM_HDR) | test_x86
478478
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) src/$@.c src/afl-fuzz-mutators.c src/afl-fuzz-python.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(PYFLAGS) $(LDFLAGS)

src/afl-fuzz-queue.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <limits.h>
2727
#include <ctype.h>
2828
#include <math.h>
29+
#include <xgboost/c_api.h>
2930

3031
#ifdef _STANDALONE_MODULE
3132
void minimize_bits(afl_state_t *afl, u8 *dst, u8 *src) {
@@ -117,7 +118,7 @@ void create_alias_table(afl_state_t *afl) {
117118

118119
double avg_exec_us = 0.0;
119120
double avg_bitmap_size = 0.0;
120-
double avg_top_size = 0.0;
121+
double avg_len = 0.0;
121122
u32 active = 0;
122123

123124
for (i = 0; i < n; i++) {
@@ -128,8 +129,8 @@ void create_alias_table(afl_state_t *afl) {
128129
if (likely(!q->disabled)) {
129130

130131
avg_exec_us += q->exec_us;
131-
avg_bitmap_size += log(q->bitmap_size);
132-
avg_top_size += q->tc_ref;
132+
avg_bitmap_size += q->bitmap_size;
133+
avg_len += q->len;
133134
++active;
134135

135136
}
@@ -138,37 +139,59 @@ void create_alias_table(afl_state_t *afl) {
138139

139140
avg_exec_us /= active;
140141
avg_bitmap_size /= active;
141-
avg_top_size /= active;
142+
avg_len /= active;
143+
144+
float *table = malloc((active + 1) * 3 * sizeof(float));
145+
float *pentry = table;
142146

143147
for (i = 0; i < n; i++) {
144148

145149
struct queue_entry *q = afl->queue_buf[i];
146150

147151
if (likely(!q->disabled)) {
148152

149-
q->weight =
150-
compute_weight(afl, q, avg_exec_us, avg_bitmap_size, avg_top_size);
153+
*pentry++ = q->len / avg_len;
154+
*pentry++ = q->exec_us / avg_exec_us;
155+
*pentry++ = q->bitmap_size / avg_bitmap_size;
151156
q->perf_score = calculate_score(afl, q);
152-
sum += q->weight;
153157

154158
}
155159

156160
}
157161

158-
if (unlikely(afl->schedule == MMOPT) && afl->queued_discovered) {
162+
DMatrixHandle dtest;
163+
BoosterHandle booster;
159164

160-
u32 cnt = afl->queued_discovered >= 5 ? 5 : afl->queued_discovered;
165+
// Erstellen einer DMatrix aus dem Array
166+
XGDMatrixCreateFromMat((float *)table, 3, active, -1, &dtest);
167+
XGBoosterCreate(&dtest, 1, &booster);
168+
XGBoosterLoadModel(booster, "./model.bin");
169+
170+
bst_ulong out_len;
171+
const float *predictions;
172+
XGBoosterPredict(booster, dtest, 0, 0, 0, &out_len, &predictions);
161173

162-
for (i = n - cnt; i < n; i++) {
174+
// Ausgabe der Vorhersagen
175+
int count = 0;
176+
for (i = 0; i < n; i++) {
163177

164-
struct queue_entry *q = afl->queue_buf[i];
178+
struct queue_entry *q = afl->queue_buf[i];
165179

166-
if (likely(!q->disabled)) { q->weight *= 2.0; }
180+
if (likely(!q->disabled)) {
181+
182+
fprintf(stderr, "Prediction[%u] = %f\n", i, predictions[count]);
183+
afl->queue_buf[i]->weight = predictions[count++];
184+
sum += predictions[count++];
167185

168186
}
169187

170188
}
171189

190+
// Freigeben der Ressourcen
191+
XGBoosterFree(booster);
192+
XGDMatrixFree(dtest);
193+
free(table);
194+
172195
for (i = 0; i < n; i++) {
173196

174197
// weight is always 0 for disabled entries

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy