mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-15 03:18:07 +00:00
removed redundent funcs
This commit is contained in:
@ -836,7 +836,6 @@ u32 calculate_score(afl_state_t *, struct queue_entry *);
|
|||||||
|
|
||||||
/* Bitmap */
|
/* Bitmap */
|
||||||
|
|
||||||
void read_bitmap(afl_state_t *, u8 *);
|
|
||||||
void write_bitmap(afl_state_t *);
|
void write_bitmap(afl_state_t *);
|
||||||
u32 count_bits(afl_state_t *, u8 *);
|
u32 count_bits(afl_state_t *, u8 *);
|
||||||
u32 count_bytes(afl_state_t *, u8 *);
|
u32 count_bytes(afl_state_t *, u8 *);
|
||||||
|
@ -51,6 +51,16 @@ char * get_afl_env(char *env);
|
|||||||
extern u8 be_quiet;
|
extern u8 be_quiet;
|
||||||
extern u8 *doc_path; /* path to documentation dir */
|
extern u8 *doc_path; /* path to documentation dir */
|
||||||
|
|
||||||
|
/* Find binary, used by analyze, showmap, tmin
|
||||||
|
@returns the path, allocating the string */
|
||||||
|
|
||||||
|
u8 *find_binary(u8 *fname);
|
||||||
|
|
||||||
|
/* Read a bitmap from file fname to memory
|
||||||
|
This is for the -B option again. */
|
||||||
|
|
||||||
|
void read_bitmap(u8 *fname, u8 *map, size_t len);
|
||||||
|
|
||||||
/* Get unix time in milliseconds */
|
/* Get unix time in milliseconds */
|
||||||
|
|
||||||
u64 get_cur_time(void);
|
u64 get_cur_time(void);
|
||||||
|
@ -805,61 +805,6 @@ static void usage(u8 *argv0) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find binary. */
|
|
||||||
|
|
||||||
static void find_binary(u8 *fname) {
|
|
||||||
|
|
||||||
u8 * env_path = 0;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (strchr(fname, '/') || !(env_path = getenv("PATH"))) {
|
|
||||||
|
|
||||||
target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
if (stat(target_path, &st) || !S_ISREG(st.st_mode) ||
|
|
||||||
!(st.st_mode & 0111) || st.st_size < 4)
|
|
||||||
FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
while (env_path) {
|
|
||||||
|
|
||||||
u8 *cur_elem, *delim = strchr(env_path, ':');
|
|
||||||
|
|
||||||
if (delim) {
|
|
||||||
|
|
||||||
cur_elem = ck_alloc(delim - env_path + 1);
|
|
||||||
memcpy(cur_elem, env_path, delim - env_path);
|
|
||||||
delim++;
|
|
||||||
|
|
||||||
} else
|
|
||||||
|
|
||||||
cur_elem = ck_strdup(env_path);
|
|
||||||
|
|
||||||
env_path = delim;
|
|
||||||
|
|
||||||
if (cur_elem[0])
|
|
||||||
target_path = alloc_printf("%s/%s", cur_elem, fname);
|
|
||||||
else
|
|
||||||
target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
ck_free(cur_elem);
|
|
||||||
|
|
||||||
if (!stat(target_path, &st) && S_ISREG(st.st_mode) &&
|
|
||||||
(st.st_mode & 0111) && st.st_size >= 4)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ck_free(target_path);
|
|
||||||
target_path = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!target_path) FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main entry point */
|
/* Main entry point */
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
int main(int argc, char **argv, char **envp) {
|
||||||
@ -997,7 +942,7 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
set_up_environment();
|
set_up_environment();
|
||||||
|
|
||||||
find_binary(argv[optind]);
|
target_path = find_binary(argv[optind]);
|
||||||
detect_file_args(argv + optind, prog_in, &use_stdin);
|
detect_file_args(argv + optind, prog_in, &use_stdin);
|
||||||
|
|
||||||
if (qemu_mode) {
|
if (qemu_mode) {
|
||||||
|
@ -37,6 +37,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
u8 be_quiet = 0;
|
u8 be_quiet = 0;
|
||||||
u8 *doc_path = "";
|
u8 *doc_path = "";
|
||||||
@ -353,6 +357,68 @@ char **get_wine_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find binary, used by analyze, showmap, tmin
|
||||||
|
@returns the path, allocating the string */
|
||||||
|
|
||||||
|
u8 *find_binary(u8 *fname) {
|
||||||
|
|
||||||
|
// TODO: Merge this function with check_binary of afl-fuzz-init.c
|
||||||
|
|
||||||
|
u8 *env_path = NULL;
|
||||||
|
u8 *target_path = NULL;
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (strchr(fname, '/') || !(env_path = getenv("PATH"))) {
|
||||||
|
|
||||||
|
target_path = ck_strdup(fname);
|
||||||
|
|
||||||
|
if (stat(target_path, &st) || !S_ISREG(st.st_mode) ||
|
||||||
|
!(st.st_mode & 0111) || st.st_size < 4)
|
||||||
|
FATAL("Program '%s' not found or not executable", fname);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
while (env_path) {
|
||||||
|
|
||||||
|
u8 *cur_elem, *delim = strchr(env_path, ':');
|
||||||
|
|
||||||
|
if (delim) {
|
||||||
|
|
||||||
|
cur_elem = ck_alloc(delim - env_path + 1);
|
||||||
|
memcpy(cur_elem, env_path, delim - env_path);
|
||||||
|
delim++;
|
||||||
|
|
||||||
|
} else
|
||||||
|
|
||||||
|
cur_elem = ck_strdup(env_path);
|
||||||
|
|
||||||
|
env_path = delim;
|
||||||
|
|
||||||
|
if (cur_elem[0])
|
||||||
|
target_path = alloc_printf("%s/%s", cur_elem, fname);
|
||||||
|
else
|
||||||
|
target_path = ck_strdup(fname);
|
||||||
|
|
||||||
|
ck_free(cur_elem);
|
||||||
|
|
||||||
|
if (!stat(target_path, &st) && S_ISREG(st.st_mode) &&
|
||||||
|
(st.st_mode & 0111) && st.st_size >= 4)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ck_free(target_path);
|
||||||
|
target_path = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target_path) FATAL("Program '%s' not found or not executable", fname);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return target_path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void check_environment_vars(char **envp) {
|
void check_environment_vars(char **envp) {
|
||||||
|
|
||||||
if (be_quiet) return;
|
if (be_quiet) return;
|
||||||
@ -414,6 +480,20 @@ char *get_afl_env(char *env) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read mask bitmap from file. This is for the -B option. */
|
||||||
|
|
||||||
|
void read_bitmap(u8 *fname, u8 *map, size_t len) {
|
||||||
|
|
||||||
|
s32 fd = open(fname, O_RDONLY);
|
||||||
|
|
||||||
|
if (fd < 0) PFATAL("Unable to open '%s'", fname);
|
||||||
|
|
||||||
|
ck_read(fd, map, len, fname);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
u64 get_cur_time(void) {
|
u64 get_cur_time(void) {
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -49,20 +49,6 @@ void write_bitmap(afl_state_t *afl) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read bitmap from file. This is for the -B option again. */
|
|
||||||
|
|
||||||
void read_bitmap(afl_state_t *afl, u8 *fname) {
|
|
||||||
|
|
||||||
s32 fd = open(fname, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) PFATAL("Unable to open '%s'", fname);
|
|
||||||
|
|
||||||
ck_read(fd, afl->virgin_bits, MAP_SIZE, fname);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if the current execution path brings anything new to the table.
|
/* Check if the current execution path brings anything new to the table.
|
||||||
Update virgin bits to reflect the finds. Returns 1 if the only change is
|
Update virgin bits to reflect the finds. Returns 1 if the only change is
|
||||||
the hit-count for a particular tuple; 2 if there are new tuples seen.
|
the hit-count for a particular tuple; 2 if there are new tuples seen.
|
||||||
|
@ -474,7 +474,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
|||||||
if (afl->in_bitmap) FATAL("Multiple -B options not supported");
|
if (afl->in_bitmap) FATAL("Multiple -B options not supported");
|
||||||
|
|
||||||
afl->in_bitmap = optarg;
|
afl->in_bitmap = optarg;
|
||||||
read_bitmap(afl, afl->in_bitmap);
|
read_bitmap(afl->in_bitmap, afl->virgin_bits, MAP_SIZE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C': /* crash mode */
|
case 'C': /* crash mode */
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_t shm_list = {.element_prealloc_count = 0};
|
static list_t shm_list = {.element_prealloc_count = 0};
|
||||||
|
|
||||||
/* Get rid of shared memory. */
|
/* Get rid of shared memory. */
|
||||||
|
|
||||||
|
@ -526,62 +526,6 @@ static void usage(u8 *argv0) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find binary. */
|
|
||||||
|
|
||||||
static void find_binary(afl_forkserver_t *fsrv, u8 *fname) {
|
|
||||||
|
|
||||||
u8 * env_path = 0;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (strchr(fname, '/') || !(env_path = getenv("PATH"))) {
|
|
||||||
|
|
||||||
fsrv->target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
if (stat(fsrv->target_path, &st) || !S_ISREG(st.st_mode) ||
|
|
||||||
!(st.st_mode & 0111) || st.st_size < 4)
|
|
||||||
FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
while (env_path) {
|
|
||||||
|
|
||||||
u8 *cur_elem, *delim = strchr(env_path, ':');
|
|
||||||
|
|
||||||
if (delim) {
|
|
||||||
|
|
||||||
cur_elem = ck_alloc(delim - env_path + 1);
|
|
||||||
memcpy(cur_elem, env_path, delim - env_path);
|
|
||||||
delim++;
|
|
||||||
|
|
||||||
} else
|
|
||||||
|
|
||||||
cur_elem = ck_strdup(env_path);
|
|
||||||
|
|
||||||
env_path = delim;
|
|
||||||
|
|
||||||
if (cur_elem[0])
|
|
||||||
fsrv->target_path = alloc_printf("%s/%s", cur_elem, fname);
|
|
||||||
else
|
|
||||||
fsrv->target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
ck_free(cur_elem);
|
|
||||||
|
|
||||||
if (!stat(fsrv->target_path, &st) && S_ISREG(st.st_mode) &&
|
|
||||||
(st.st_mode & 0111) && st.st_size >= 4)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ck_free(fsrv->target_path);
|
|
||||||
fsrv->target_path = NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fsrv->target_path)
|
|
||||||
FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main entry point */
|
/* Main entry point */
|
||||||
|
|
||||||
int main(int argc, char **argv_orig, char **envp) {
|
int main(int argc, char **argv_orig, char **envp) {
|
||||||
@ -772,7 +716,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
|||||||
|
|
||||||
set_up_environment(fsrv);
|
set_up_environment(fsrv);
|
||||||
|
|
||||||
find_binary(fsrv, argv[optind]);
|
fsrv->target_path = find_binary(argv[optind]);
|
||||||
|
|
||||||
if (!quiet_mode) {
|
if (!quiet_mode) {
|
||||||
|
|
||||||
|
@ -749,76 +749,6 @@ static void usage(u8 *argv0) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find binary. */
|
|
||||||
|
|
||||||
static void find_binary(afl_forkserver_t *fsrv, u8 *fname) {
|
|
||||||
|
|
||||||
u8 * env_path = 0;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (strchr(fname, '/') || !(env_path = getenv("PATH"))) {
|
|
||||||
|
|
||||||
fsrv->target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
if (stat(fsrv->target_path, &st) || !S_ISREG(st.st_mode) ||
|
|
||||||
!(st.st_mode & 0111) || st.st_size < 4)
|
|
||||||
FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
while (env_path) {
|
|
||||||
|
|
||||||
u8 *cur_elem, *delim = strchr(env_path, ':');
|
|
||||||
|
|
||||||
if (delim) {
|
|
||||||
|
|
||||||
cur_elem = ck_alloc(delim - env_path + 1);
|
|
||||||
memcpy(cur_elem, env_path, delim - env_path);
|
|
||||||
delim++;
|
|
||||||
|
|
||||||
} else
|
|
||||||
|
|
||||||
cur_elem = ck_strdup(env_path);
|
|
||||||
|
|
||||||
env_path = delim;
|
|
||||||
|
|
||||||
if (cur_elem[0])
|
|
||||||
fsrv->target_path = alloc_printf("%s/%s", cur_elem, fname);
|
|
||||||
else
|
|
||||||
fsrv->target_path = ck_strdup(fname);
|
|
||||||
|
|
||||||
ck_free(cur_elem);
|
|
||||||
|
|
||||||
if (!stat(fsrv->target_path, &st) && S_ISREG(st.st_mode) &&
|
|
||||||
(st.st_mode & 0111) && st.st_size >= 4)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ck_free(fsrv->target_path);
|
|
||||||
fsrv->target_path = NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fsrv->target_path)
|
|
||||||
FATAL("Program '%s' not found or not executable", fname);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read mask bitmap from file. This is for the -B option. */
|
|
||||||
|
|
||||||
static void read_bitmap(u8 *fname) {
|
|
||||||
|
|
||||||
s32 fd = open(fname, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) PFATAL("Unable to open '%s'", fname);
|
|
||||||
|
|
||||||
ck_read(fd, mask_bitmap, MAP_SIZE, fname);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main entry point */
|
/* Main entry point */
|
||||||
|
|
||||||
int main(int argc, char **argv_orig, char **envp) {
|
int main(int argc, char **argv_orig, char **envp) {
|
||||||
@ -977,7 +907,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
|||||||
|
|
||||||
if (mask_bitmap) FATAL("Multiple -B options not supported");
|
if (mask_bitmap) FATAL("Multiple -B options not supported");
|
||||||
mask_bitmap = ck_alloc(MAP_SIZE);
|
mask_bitmap = ck_alloc(MAP_SIZE);
|
||||||
read_bitmap(optarg);
|
read_bitmap(optarg, mask_bitmap, MAP_SIZE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -1001,7 +931,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
|||||||
|
|
||||||
set_up_environment(fsrv);
|
set_up_environment(fsrv);
|
||||||
|
|
||||||
find_binary(fsrv, argv[optind]);
|
fsrv->target_path = find_binary(argv[optind]);
|
||||||
detect_file_args(argv + optind, out_file, &fsrv->use_stdin);
|
detect_file_args(argv + optind, out_file, &fsrv->use_stdin);
|
||||||
|
|
||||||
if (fsrv->qemu_mode) {
|
if (fsrv->qemu_mode) {
|
||||||
|
Reference in New Issue
Block a user