mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-20 21:25:43 +00:00
afl_custom_fuzz_send added
This commit is contained in:
@ -314,6 +314,14 @@ struct custom_mutator *load_custom_mutator(afl_state_t *afl, const char *fn) {
|
||||
|
||||
}
|
||||
|
||||
/* "afl_custom_fuzz_send", optional */
|
||||
mutator->afl_custom_fuzz_send = dlsym(dh, "afl_custom_fuzz_send");
|
||||
if (!mutator->afl_custom_fuzz_send) {
|
||||
|
||||
ACTF("optional symbol 'afl_custom_fuzz_send' not found.");
|
||||
|
||||
}
|
||||
|
||||
/* "afl_custom_queue_new_entry", optional */
|
||||
mutator->afl_custom_queue_new_entry = dlsym(dh, "afl_custom_queue_new_entry");
|
||||
if (!mutator->afl_custom_queue_new_entry) {
|
||||
|
@ -246,6 +246,8 @@ static py_mutator_t *init_py_module(afl_state_t *afl, u8 *module_name) {
|
||||
PyObject_GetAttrString(py_module, "havoc_mutation_probability");
|
||||
py_functions[PY_FUNC_QUEUE_GET] =
|
||||
PyObject_GetAttrString(py_module, "queue_get");
|
||||
py_functions[PY_FUNC_FUZZ_SEND] =
|
||||
PyObject_GetAttrString(py_module, "fuzz_send");
|
||||
py_functions[PY_FUNC_QUEUE_NEW_ENTRY] =
|
||||
PyObject_GetAttrString(py_module, "queue_new_entry");
|
||||
py_functions[PY_FUNC_INTROSPECTION] =
|
||||
@ -466,6 +468,12 @@ struct custom_mutator *load_custom_mutator_py(afl_state_t *afl,
|
||||
|
||||
}
|
||||
|
||||
if (py_functions[PY_FUNC_FUZZ_SEND]) {
|
||||
|
||||
mutator->afl_custom_fuzz_send = fuzz_send_py;
|
||||
|
||||
}
|
||||
|
||||
if (py_functions[PY_FUNC_QUEUE_NEW_ENTRY]) {
|
||||
|
||||
mutator->afl_custom_queue_new_entry = queue_new_entry_py;
|
||||
@ -893,6 +901,43 @@ u8 queue_get_py(void *py_mutator, const u8 *filename) {
|
||||
|
||||
}
|
||||
|
||||
void fuzz_send_py(void *py_mutator, const u8 *buf, size_t buf_size) {
|
||||
|
||||
PyObject *py_args, *py_value;
|
||||
|
||||
py_args = PyTuple_New(1);
|
||||
py_value = PyByteArray_FromStringAndSize(buf, buf_size);
|
||||
if (!py_value) {
|
||||
|
||||
Py_DECREF(py_args);
|
||||
FATAL("Failed to convert arguments");
|
||||
|
||||
}
|
||||
|
||||
PyTuple_SetItem(py_args, 0, py_value);
|
||||
|
||||
py_value = PyObject_CallObject(
|
||||
((py_mutator_t *)py_mutator)->py_functions[PY_FUNC_FUZZ_SEND], py_args);
|
||||
Py_DECREF(py_args);
|
||||
|
||||
if (py_value != NULL) {
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
u32 retcnt = (u32)PyLong_AsLong(py_value);
|
||||
#else
|
||||
u32 retcnt = PyInt_AsLong(py_value);
|
||||
#endif
|
||||
Py_DECREF(py_value);
|
||||
|
||||
} else {
|
||||
|
||||
PyErr_Print();
|
||||
FATAL("Call failed");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u8 queue_new_entry_py(void *py_mutator, const u8 *filename_new_queue,
|
||||
const u8 *filename_orig_queue) {
|
||||
|
||||
|
@ -133,9 +133,25 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
|
||||
|
||||
if (new_mem != *mem) { *mem = new_mem; }
|
||||
|
||||
/* everything as planned. use the potentially new data. */
|
||||
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, new_size);
|
||||
len = new_size;
|
||||
if (unlikely(afl->custom_mutators_count)) {
|
||||
|
||||
LIST_FOREACH(&afl->custom_mutator_list, struct custom_mutator, {
|
||||
|
||||
if (el->afl_custom_fuzz_send) {
|
||||
|
||||
el->afl_custom_fuzz_send(el->data, *mem, new_size);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
/* everything as planned. use the potentially new data. */
|
||||
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, new_size);
|
||||
len = new_size;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@ -149,8 +165,24 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
|
||||
|
||||
}
|
||||
|
||||
/* boring uncustom. */
|
||||
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, len);
|
||||
if (unlikely(afl->custom_mutators_count)) {
|
||||
|
||||
LIST_FOREACH(&afl->custom_mutator_list, struct custom_mutator, {
|
||||
|
||||
if (el->afl_custom_fuzz_send) {
|
||||
|
||||
el->afl_custom_fuzz_send(el->data, *mem, len);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
/* boring uncustom. */
|
||||
afl_fsrv_write_to_testcase(&afl->fsrv, *mem, len);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user