code format

This commit is contained in:
Andrea Fioraldi
2019-09-18 10:23:36 +02:00
parent b55ea6409d
commit 74a984d75f
7 changed files with 45 additions and 36 deletions

View File

@ -27,9 +27,9 @@
#define __AFLCOMMON_H #define __AFLCOMMON_H
#include "types.h" #include "types.h"
extern u8 *target_path; /* Path to target binary */ extern u8* target_path; /* Path to target binary */
void detect_file_args(char **argv, u8 *prog_in); void detect_file_args(char** argv, u8* prog_in);
char** get_qemu_argv(u8* own_loc, char** argv, int argc); char** get_qemu_argv(u8* own_loc, char** argv, int argc);
char** get_wine_argv(u8* own_loc, char** argv, int argc); char** get_wine_argv(u8* own_loc, char** argv, int argc);

View File

@ -1 +1,2 @@

View File

@ -760,7 +760,8 @@ static void usage(u8* argv0) {
" -m megs - memory limit for child process (%d MB)\n" " -m megs - memory limit for child process (%d MB)\n"
" -Q - use binary-only instrumentation (QEMU mode)\n" " -Q - use binary-only instrumentation (QEMU mode)\n"
" -U - use unicorn-based instrumentation (Unicorn mode)\n" " -U - use unicorn-based instrumentation (Unicorn mode)\n"
" -W - use qemu-based instrumentation with Wine (Wine mode)\n\n" " -W - use qemu-based instrumentation with Wine (Wine "
"mode)\n\n"
"Analysis settings:\n\n" "Analysis settings:\n\n"
@ -834,7 +835,8 @@ static void find_binary(u8* fname) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
s32 opt; s32 opt;
u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0, use_wine = 0; u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0,
use_wine = 0;
char** use_argv; char** use_argv;
doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH; doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH;
@ -930,7 +932,7 @@ int main(int argc, char** argv) {
unicorn_mode = 1; unicorn_mode = 1;
break; break;
case 'W': /* Wine+QEMU mode */ case 'W': /* Wine+QEMU mode */
if (use_wine) FATAL("Multiple -W options not supported"); if (use_wine) FATAL("Multiple -W options not supported");
qemu_mode = 1; qemu_mode = 1;
@ -963,13 +965,14 @@ int main(int argc, char** argv) {
detect_file_args(argv + optind, prog_in); detect_file_args(argv + optind, prog_in);
if (qemu_mode) { if (qemu_mode) {
if (use_wine) if (use_wine)
use_argv = get_wine_argv(argv[0], argv + optind, argc - optind); use_argv = get_wine_argv(argv[0], argv + optind, argc - optind);
else else
use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind);
} else } else
use_argv = argv + optind; use_argv = argv + optind;
SAYF("\n"); SAYF("\n");

View File

@ -35,7 +35,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
u8 *target_path; /* Path to target binary */ u8* target_path; /* Path to target binary */
void detect_file_args(char** argv, u8* prog_in) { void detect_file_args(char** argv, u8* prog_in) {
@ -97,7 +97,6 @@ void detect_file_args(char** argv, u8* prog_in) {
} }
/* Rewrite argv for QEMU. */ /* Rewrite argv for QEMU. */
char** get_qemu_argv(u8* own_loc, char** argv, int argc) { char** get_qemu_argv(u8* own_loc, char** argv, int argc) {
@ -193,9 +192,9 @@ char** get_wine_argv(u8* own_loc, char** argv, int argc) {
cp = alloc_printf("%s/afl-qemu-trace", tmp); cp = alloc_printf("%s/afl-qemu-trace", tmp);
if (access(cp, X_OK)) FATAL("Unable to find '%s'", tmp); if (access(cp, X_OK)) FATAL("Unable to find '%s'", tmp);
ck_free(cp); ck_free(cp);
cp = alloc_printf("%s/afl-wine-trace", tmp); cp = alloc_printf("%s/afl-wine-trace", tmp);
if (access(cp, X_OK)) FATAL("Unable to find '%s'", tmp); if (access(cp, X_OK)) FATAL("Unable to find '%s'", tmp);
@ -218,14 +217,14 @@ char** get_wine_argv(u8* own_loc, char** argv, int argc) {
if (!access(cp, X_OK)) { if (!access(cp, X_OK)) {
ck_free(cp); ck_free(cp);
cp = alloc_printf("%s/afl-wine-trace", own_copy); cp = alloc_printf("%s/afl-wine-trace", own_copy);
if (!access(cp, X_OK)) { if (!access(cp, X_OK)) {
target_path = new_argv[0] = cp; target_path = new_argv[0] = cp;
return new_argv; return new_argv;
} }
} }
@ -234,17 +233,17 @@ char** get_wine_argv(u8* own_loc, char** argv, int argc) {
ck_free(own_copy); ck_free(own_copy);
u8 *ncp = BIN_PATH "/afl-qemu-trace"; u8* ncp = BIN_PATH "/afl-qemu-trace";
if (!access(ncp, X_OK)) { if (!access(ncp, X_OK)) {
ncp = BIN_PATH "/afl-wine-trace"; ncp = BIN_PATH "/afl-wine-trace";
if (!access(ncp, X_OK)) { if (!access(ncp, X_OK)) {
target_path = new_argv[0] = ck_strdup(ncp); target_path = new_argv[0] = ck_strdup(ncp);
return new_argv; return new_argv;
} }
} }
@ -263,10 +262,10 @@ char** get_wine_argv(u8* own_loc, char** argv, int argc) {
" instrumented at compile time with afl-gcc. It is also possible to " " instrumented at compile time with afl-gcc. It is also possible to "
"use it as a\n" "use it as a\n"
" traditional \"dumb\" fuzzer by specifying '-n' in the command " " traditional \"dumb\" fuzzer by specifying '-n' in the command "
"line.\n", ncp); "line.\n",
ncp);
FATAL("Failed to locate '%s'.", ncp); FATAL("Failed to locate '%s'.", ncp);
} }

View File

@ -132,8 +132,8 @@ int main(int argc, char** argv) {
gettimeofday(&tv, &tz); gettimeofday(&tv, &tz);
init_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); init_seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
while ((opt = getopt(argc, argv, "+i:o:f:m:t:T:dnCB:S:M:x:QUWe:p:s:V:E:L:h")) > while ((opt = getopt(argc, argv,
0) "+i:o:f:m:t:T:dnCB:S:M:x:QUWe:p:s:V:E:L:h")) > 0)
switch (opt) { switch (opt) {
@ -370,8 +370,8 @@ int main(int argc, char** argv) {
if (!mem_limit_given) mem_limit = MEM_LIMIT_UNICORN; if (!mem_limit_given) mem_limit = MEM_LIMIT_UNICORN;
break; break;
case 'W': /* Wine+QEMU mode */ case 'W': /* Wine+QEMU mode */
if (use_wine) FATAL("Multiple -W options not supported"); if (use_wine) FATAL("Multiple -W options not supported");
qemu_mode = 1; qemu_mode = 1;
@ -721,13 +721,14 @@ int main(int argc, char** argv) {
start_time = get_cur_time(); start_time = get_cur_time();
if (qemu_mode) { if (qemu_mode) {
if (use_wine) if (use_wine)
use_argv = get_wine_argv(argv[0], argv + optind, argc - optind); use_argv = get_wine_argv(argv[0], argv + optind, argc - optind);
else else
use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind);
} else } else
use_argv = argv + optind; use_argv = argv + optind;
perform_dry_run(use_argv); perform_dry_run(use_argv);

View File

@ -498,8 +498,9 @@ static void find_binary(u8* fname) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
s32 opt; s32 opt;
u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0, use_wine = 0; u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0,
u32 tcnt = 0; use_wine = 0;
u32 tcnt = 0;
char** use_argv; char** use_argv;
doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH; doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH;
@ -612,7 +613,7 @@ int main(int argc, char** argv) {
unicorn_mode = 1; unicorn_mode = 1;
break; break;
case 'W': /* Wine+QEMU mode */ case 'W': /* Wine+QEMU mode */
if (use_wine) FATAL("Multiple -W options not supported"); if (use_wine) FATAL("Multiple -W options not supported");
qemu_mode = 1; qemu_mode = 1;
@ -671,13 +672,14 @@ int main(int argc, char** argv) {
detect_file_args(argv + optind, at_file); detect_file_args(argv + optind, at_file);
if (qemu_mode) { if (qemu_mode) {
if (use_wine) if (use_wine)
use_argv = get_wine_argv(argv[0], argv + optind, argc - optind); use_argv = get_wine_argv(argv[0], argv + optind, argc - optind);
else else
use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind);
} else } else
use_argv = argv + optind; use_argv = argv + optind;
run_target(use_argv); run_target(use_argv);

View File

@ -934,7 +934,8 @@ static void usage(u8* argv0) {
" -m megs - memory limit for child process (%d MB)\n" " -m megs - memory limit for child process (%d MB)\n"
" -Q - use binary-only instrumentation (QEMU mode)\n" " -Q - use binary-only instrumentation (QEMU mode)\n"
" -U - use unicorn-based instrumentation (Unicorn mode)\n" " -U - use unicorn-based instrumentation (Unicorn mode)\n"
" -W - use qemu-based instrumentation with Wine (Wine mode)\n\n" " -W - use qemu-based instrumentation with Wine (Wine "
"mode)\n\n"
" (Not necessary, here for consistency with other afl-* " " (Not necessary, here for consistency with other afl-* "
"tools)\n\n" "tools)\n\n"
@ -1025,7 +1026,8 @@ static void read_bitmap(u8* fname) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
s32 opt; s32 opt;
u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0, use_wine = 0; u8 mem_limit_given = 0, timeout_given = 0, qemu_mode = 0, unicorn_mode = 0,
use_wine = 0;
char** use_argv; char** use_argv;
doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH; doc_path = access(DOC_PATH, F_OK) ? "docs" : DOC_PATH;
@ -1133,7 +1135,7 @@ int main(int argc, char** argv) {
unicorn_mode = 1; unicorn_mode = 1;
break; break;
case 'W': /* Wine+QEMU mode */ case 'W': /* Wine+QEMU mode */
if (use_wine) FATAL("Multiple -W options not supported"); if (use_wine) FATAL("Multiple -W options not supported");
qemu_mode = 1; qemu_mode = 1;
@ -1184,13 +1186,14 @@ int main(int argc, char** argv) {
detect_file_args(argv + optind, out_file); detect_file_args(argv + optind, out_file);
if (qemu_mode) { if (qemu_mode) {
if (use_wine) if (use_wine)
use_argv = get_wine_argv(argv[0], argv + optind, argc - optind); use_argv = get_wine_argv(argv[0], argv + optind, argc - optind);
else else
use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind); use_argv = get_qemu_argv(argv[0], argv + optind, argc - optind);
} else } else
use_argv = argv + optind; use_argv = argv + optind;
exact_mode = !!getenv("AFL_TMIN_EXACT"); exact_mode = !!getenv("AFL_TMIN_EXACT");