add AFL autodict capability to Nyx mode

This commit is contained in:
Sergej Schumilo
2022-01-25 19:13:26 +01:00
parent 87f2789e98
commit 026096ccf3
3 changed files with 58 additions and 2 deletions

View File

@ -1 +1 @@
8842549 76100c5

View File

@ -425,6 +425,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
} }
} }
ck_free(x);
if (fsrv->nyx_runner == NULL) { FATAL("Something went wrong ..."); } if (fsrv->nyx_runner == NULL) { FATAL("Something went wrong ..."); }
@ -464,6 +465,61 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
} }
/* autodict in Nyx mode */
if (!ignore_autodict) {
x = alloc_printf("%s/workdir/dump/afl_autodict.txt", fsrv->out_dir_path);
int nyx_autodict_fd = open(x, O_RDONLY);
ck_free(x);
if (nyx_autodict_fd >= 0) {
struct stat st;
if (fstat(nyx_autodict_fd, &st) >= 0) {
u32 f_len = st.st_size;
u8 *dict = ck_alloc(f_len);
if (dict == NULL) {
FATAL("Could not allocate %u bytes of autodictionary memory", f_len);
}
u32 offset = 0, count = 0;
u32 len = f_len;
while (len != 0) {
rlen = read(nyx_autodict_fd, dict + offset, len);
if (rlen > 0) {
len -= rlen;
offset += rlen;
} else {
FATAL(
"Reading autodictionary fail at position %u with %u bytes "
"left.",
offset, len);
}
}
close(nyx_autodict_fd);
offset = 0;
while (offset < (u32)f_len &&
(u8)dict[offset] + offset < (u32)f_len) {
fsrv->add_extra_func(fsrv->afl_ptr, dict + offset + 1,
(u8)dict[offset]);
offset += (1 + dict[offset]);
count++;
}
if (!be_quiet) { ACTF("Loaded %u autodictionary entries", count); }
ck_free(dict);
}
}
}
return; return;
} }