This commit is contained in:
vanhauser-thc 2023-01-15 18:17:28 +01:00
parent 35801bed7a
commit 10b82c7277
2 changed files with 30 additions and 12 deletions

View File

@ -1,7 +1,7 @@
all: autotokens.so all: autotokens.so
autotokens.so: autotokens.cpp autotokens.so: autotokens.cpp
$(CXX) -O3 -shared -fPIC -o autotokens.so -I../../include autotokens.cpp ../../src/afl-performance.o $(CXX) -g -O3 $(CFLAGS) -shared -fPIC -o autotokens.so -I../../include autotokens.cpp ../../src/afl-performance.o
clean: clean:
rm -f autotokens.so *~ core rm -f autotokens.so *~ core

View File

@ -14,7 +14,7 @@ extern "C" {
#include <vector> #include <vector>
#include <regex> #include <regex>
#define AUTOTOKENS_DEBUG 1 #define AUTOTOKENS_DEBUG 0
#define AUTOTOKENS_CHANGE_MIN 8 #define AUTOTOKENS_CHANGE_MIN 8
using namespace std; using namespace std;
@ -64,11 +64,13 @@ extern "C" size_t afl_custom_fuzz(my_mutator_t *data, u8 *buf, size_t buf_size,
afl_ptr->havoc_div / 256)); afl_ptr->havoc_div / 256));
// DEBUG(stderr, "structure size: %lu, rounds: %u \n", m.size(), rounds); // DEBUG(stderr, "structure size: %lu, rounds: %u \n", m.size(), rounds);
u32 max_rand = 4;
for (i = 0; i < rounds; ++i) { for (i = 0; i < rounds; ++i) {
u32 item, new_item; u32 item, new_item;
switch (rand_below(afl_ptr, 4)) { switch (rand_below(afl_ptr, max_rand)) {
/* CHANGE */ /* CHANGE */
case 0: /* fall through */ case 0: /* fall through */
@ -90,9 +92,19 @@ extern "C" size_t afl_custom_fuzz(my_mutator_t *data, u8 *buf, size_t buf_size,
break; break;
/* ERASE - only if large enough */ /* ERASE - only if large enough */
case 3: case 3:
if (m_size > 8) { m.erase(m.begin() + rand_below(afl_ptr, m_size)); } if (m_size > 8) {
--m_size;
m.erase(m.begin() + rand_below(afl_ptr, m_size));
--m_size;
} else {
max_rand = 3;
}
break; break;
// TODO: add full line insert splice, replace splace, delete // TODO: add full line insert splice, replace splace, delete
} }
@ -119,9 +131,16 @@ extern "C" size_t afl_custom_fuzz(my_mutator_t *data, u8 *buf, size_t buf_size,
} }
if (unlikely(debug)) {
DEBUG(stderr, "MUTATED to %u bytes:\n", mutated_size);
fwrite(output.data(), 1, mutated_size, stderr);
DEBUG(stderr, "\n---\n");
}
memcpy(mutated_out, output.data(), mutated_size); memcpy(mutated_out, output.data(), mutated_size);
*out_buf = mutated_out; *out_buf = mutated_out;
DEBUG(stderr, "MUTATED to %u bytes:\n%s\n---\n", mutated_size, mutated_out);
return mutated_size; return mutated_size;
} }
@ -292,11 +311,10 @@ extern "C" unsigned char afl_custom_queue_get(void *data,
while (regex_search(cur, ende, match, regex_string)) { while (regex_search(cur, ende, match, regex_string)) {
prev = cur; prev = cur;
found = match[1].first; found = match[0].first;
cur = match[1].second; cur = match[0].second;
DEBUG(stderr, DEBUG(stderr, "string %s found at start %lu offset %lu continue at %lu\n",
"string \"%s\" found at start %lu offset %lu continue at %lu\n", match[0].str().c_str(), prev - input.begin(), match.position(),
match[1].str().c_str(), prev - input.begin(), match.position(),
cur - input.begin()); cur - input.begin());
if (prev < found) { // there are items between search start and find if (prev < found) { // there are items between search start and find
sregex_token_iterator it{prev, found, regex_whitespace, -1}; sregex_token_iterator it{prev, found, regex_whitespace, -1};
@ -361,7 +379,7 @@ extern "C" unsigned char afl_custom_queue_get(void *data,
} }
if (match[1].length() > 0) { tokens.push_back(match[1]); } if (match[0].length() > 0) { tokens.push_back(match[0]); }
} }