1 /* 2 american fuzzy lop++ - common routines header 3 --------------------------------------------- 4 5 Originally written by Michal Zalewski 6 7 Now maintained by Marc Heuse <mh@mh-sec.de>, 8 Heiko Eißfeldt <heiko.eissfeldt@hexco.de>, 9 Andrea Fioraldi <andreafioraldi@gmail.com>, 10 Dominik Maier <mail@dmnk.co> 11 12 Copyright 2016, 2017 Google Inc. All rights reserved. 13 Copyright 2019-2022 AFLplusplus Project. All rights reserved. 14 15 Licensed under the Apache License, Version 2.0 (the "License"); 16 you may not use this file except in compliance with the License. 17 You may obtain a copy of the License at: 18 19 https://www.apache.org/licenses/LICENSE-2.0 20 21 Gather some functions common to multiple executables 22 23 - detect_file_args 24 25 */ 26 27 #ifndef __AFLCOMMON_H 28 #define __AFLCOMMON_H 29 30 #include <stdio.h> 31 #include <string.h> 32 #include <unistd.h> 33 #include <sys/time.h> 34 #include <stdbool.h> 35 #include "types.h" 36 37 /* STRINGIFY_VAL_SIZE_MAX will fit all stringify_ strings. */ 38 39 #define STRINGIFY_VAL_SIZE_MAX (16) 40 41 u32 check_binary_signatures(u8 *fn); 42 void detect_file_args(char **argv, u8 *prog_in, bool *use_stdin); 43 void print_suggested_envs(char *mispelled_env); 44 void check_environment_vars(char **env); 45 46 char **argv_cpy_dup(int argc, char **argv); 47 void argv_cpy_free(char **argv); 48 49 char **get_cs_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv); 50 char **get_qemu_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv); 51 char **get_wine_argv(u8 *own_loc, u8 **target_path_p, int argc, char **argv); 52 char * get_afl_env(char *env); 53 54 /* Extract env vars from input string and set them using setenv() 55 For use with AFL_TARGET_ENV, ... */ 56 bool extract_and_set_env(u8 *env_str); 57 58 extern u8 be_quiet; 59 extern u8 *doc_path; /* path to documentation dir */ 60 61 /* Find binary, used by analyze, showmap, tmin 62 @returns the path, allocating the string */ 63 64 u8 *find_binary(u8 *fname); 65 66 /* find an afl binary */ 67 68 u8 *find_afl_binary(u8 *own_loc, u8 *fname); 69 70 /* Parses the kill signal environment variable, FATALs on error. 71 If the env is not set, sets the env to default_signal for the signal handlers 72 and returns the default_signal. */ 73 int parse_afl_kill_signal_env(u8 *afl_kill_signal_env, int default_signal); 74 75 /* Read a bitmap from file fname to memory 76 This is for the -B option again. */ 77 78 void read_bitmap(u8 *fname, u8 *map, size_t len); 79 80 /* Get unix time in milliseconds */ 81 82 u64 get_cur_time(void); 83 84 /* Get unix time in microseconds */ 85 86 u64 get_cur_time_us(void); 87 88 /* Describe integer. The buf should be 89 at least 6 bytes to fit all ints we randomly see. 90 Will return buf for convenience. */ 91 92 u8 *stringify_int(u8 *buf, size_t len, u64 val); 93 94 /* Describe float. Similar as int. */ 95 96 u8 *stringify_float(u8 *buf, size_t len, double val); 97 98 /* Describe integer as memory size. */ 99 100 u8 *stringify_mem_size(u8 *buf, size_t len, u64 val); 101 102 /* Describe time delta as string. 103 Returns a pointer to buf for convenience. */ 104 105 u8 *stringify_time_diff(u8 *buf, size_t len, u64 cur_ms, u64 event_ms); 106 107 /* Unsafe Describe integer. The buf sizes are not checked. 108 This is unsafe but fast. 109 Will return buf for convenience. */ 110 111 u8 *u_stringify_int(u8 *buf, u64 val); 112 113 /* Unsafe describe float. Similar as unsafe int. */ 114 115 u8 *u_stringify_float(u8 *buf, double val); 116 117 /* Unsafe describe integer as memory size. */ 118 119 u8 *u_stringify_mem_size(u8 *buf, u64 val); 120 121 /* Unsafe describe time delta as string. 122 Returns a pointer to buf for convenience. */ 123 124 u8 *u_stringify_time_diff(u8 *buf, u64 cur_ms, u64 event_ms); 125 126 /* Reads the map size from ENV */ 127 u32 get_map_size(void); 128 129 /* create a stream file */ 130 FILE *create_ffile(u8 *fn); 131 132 /* create a file */ 133 s32 create_file(u8 *fn); 134 135 #endif 136 137