diff --git a/AFL/afl-fuzz.c b/AFL/afl-fuzz.c old mode 100755 new mode 100644 index f56f1537caf71c2f1bf1e24710c8bfea5761984e..ab2a8e7e384c4f35dff77f2e7e43c802d5e6a0bc --- a/AFL/afl-fuzz.c +++ b/AFL/afl-fuzz.c @@ -70,6 +70,7 @@ #include #include #include +#include #include "../include/ast.h" #include "../include/mutate.h" @@ -119,6 +120,8 @@ using namespace std; const char* file = "/home/wx/openGauss-server/inst_build/bin/gs_ctl"; char* const options[] = { "/home/wx/openGauss-server/inst_build/bin/gs_ctl", "start", "-D", "/home/omm/data", "-Z", "single_node", "-l", "/home/omm/log/opengauss.log", NULL }; +#define MAX_FACTOR 32 + static long seed_count = 0; char* g_current_sql = nullptr; @@ -149,6 +152,15 @@ EXP_ST u64 mem_limit = MEM_LIMIT; /* Memory cap for child (MB) */ static u32 stats_update_freq = 1; /* Stats update frequency (execs) */ +static u8 cooling_schedule = 0; /* Cooling schedule for directed fuzzing */ + +enum { + /* 00 */ SAN_EXP, /* Exponential schedule */ + /* 01 */ SAN_LOG, /* Logarithmical schedule */ + /* 02 */ SAN_LIN, /* Linear schedule */ + /* 03 */ SAN_QUAD /* Quadratic schedule */ +}; + EXP_ST u8 skip_deterministic, /* Skip deterministic stages? */ force_deterministic, /* Force deterministic stages? */ use_splicing, /* Recombine input files? */ @@ -169,6 +181,7 @@ EXP_ST u8 skip_deterministic, /* Skip deterministic stages? */ shuffle_queue, /* Shuffle input queue? */ bitmap_changed = 1, /* Time to update bitmap? */ qemu_mode, /* Running in QEMU mode? */ + direct_mode=0, skip_requested, /* Skip request, via SIGUSR1 */ run_over10m, /* Run time over 10 minutes? */ persistent_mode, /* Running in persistent mode? */ @@ -298,6 +311,7 @@ struct queue_entry { handicap, /* Number of queue cycles behind */ depth; /* Path depth */ + double distance; u8* trace_mini; /* Trace bytes, if kept */ u32 tc_ref; /* Trace bytes ref count */ @@ -327,6 +341,11 @@ static u32 extras_cnt; /* Total number of tokens read */ static struct extra_data* a_extras; /* Automatically selected extras */ static u32 a_extras_cnt; /* Total number of tokens available */ +static double cur_distance = -1.0; /* Distance of executed input */ +static double max_distance = -1.0; /* Maximal distance for any input */ +static double min_distance = -1.0; /* Minimal distance for any input */ +static u32 t_x = 10; + static u8* (*post_handler)(u8* buf, u32* len); /* Interesting values, as per config.h */ @@ -835,6 +854,21 @@ static void add_to_queue(u8* fname, u32 len, u8 passed_det) { q->depth = cur_depth + 1; q->passed_det = passed_det; + if(direct_mode){ + q->distance = cur_distance; + + if (cur_distance > 0) { + + if (max_distance <= 0) { + max_distance = cur_distance; + min_distance = cur_distance; + } + if (cur_distance > max_distance) max_distance = cur_distance; + if (cur_distance < min_distance) min_distance = cur_distance; + + } + } + if (q->depth > max_depth) max_depth = q->depth; if (queue_top) { @@ -937,6 +971,16 @@ static inline u8 has_new_bits(u8* virgin_map) { u32 i = (MAP_SIZE >> 3); + if(direct_mode){ + u64* total_distance = (u64*) (trace_bits + MAP_SIZE); + u64* total_count = (u64*) (trace_bits + MAP_SIZE + 8); + + if (*total_count > 0) + cur_distance = (double) (*total_distance) / (double) (*total_count); + else + cur_distance = -1.0; + } + #else u32* current = (u32*)trace_bits; @@ -944,6 +988,17 @@ static inline u8 has_new_bits(u8* virgin_map) { u32 i = (MAP_SIZE >> 2); + + if(direct_mode){ + u32* total_distance = (u32*)(trace_bits + MAP_SIZE); + u32* total_count = (u32*)(trace_bits + MAP_SIZE + 4); + + if (*total_count > 0) { + cur_distance = (double) (*total_distance) / (double) (*total_count); + else + cur_distance = -1.0; + } + #endif /* ^__x86_64__ */ u8 ret = 0; @@ -1398,7 +1453,14 @@ EXP_ST void setup_shm(void) { memset(virgin_tmout, 255, MAP_SIZE); memset(virgin_crash, 255, MAP_SIZE); - shm_id = shmget(IPC_PRIVATE, MAP_SIZE, IPC_CREAT | IPC_EXCL | 0600); + if(direct_mode){ + /* Allocate 16 byte more for distance info */ + shm_id = shmget(IPC_PRIVATE, MAP_SIZE + 16, IPC_CREAT | IPC_EXCL | 0600); + } + else{ + shm_id = shmget(IPC_PRIVATE, MAP_SIZE, IPC_CREAT | IPC_EXCL | 0600); + } + if (shm_id < 0) PFATAL("shmget() failed"); @@ -2142,7 +2204,7 @@ EXP_ST void init_forkserver(char** argv) { "--pid-file=lrs-dwu01.pid", "--socket=/tmp/mysql.sock", NULL}; - execv(tmp_target_path, tmp_argv); //改参数把,别改这里了,我再去看看那个启动参数 + execv(tmp_target_path, tmp_argv); //改参数把,别改这里了,我再去看看那个启动参�? */ /* Use a distinctive bitmap signature to tell the parent about execv() falling through. */ @@ -2331,8 +2393,12 @@ static u8 run_target(char** argv, u32 timeout) { /* After this memset, trace_bits[] are effectively volatile, so we must prevent any earlier operations from venturing into that territory. */ - - memset(trace_bits, 0, MAP_SIZE); + if(direct_mode){ + memset(trace_bits, 0, MAP_SIZE + 16); + } + else{ + memset(trace_bits, 0, MAP_SIZE); + } MEM_BARRIER(); //********************************** @@ -2502,6 +2568,27 @@ static u8 calibrate_case(char** argv, struct queue_entry* q, u8* use_mem, cksum = hash32(trace_bits, MAP_SIZE, HASH_CONST); + if(direct_mode){ + if (q->distance <= 0) { + + /* This calculates cur_distance */ + has_new_bits(virgin_bits); + + q->distance = cur_distance; + if (cur_distance > 0) { + + if (max_distance <= 0) { + max_distance = cur_distance; + min_distance = cur_distance; + } + if (cur_distance > max_distance) max_distance = cur_distance; + if (cur_distance < min_distance) min_distance = cur_distance; + + } + + } + } + if (q->exec_cksum != cksum) { u8 hnb = has_new_bits(virgin_bits); @@ -2625,9 +2712,8 @@ static void perform_dry_run(char** argv) { u8* fn = strrchr((char *)q->fname, '/') + 1; ACTF("Attempting dry run with '%s'...", fn); - fd = open(q->fname, O_RDONLY); - + if (fd < 0) PFATAL("Unable to open '%s'", q->fname); use_mem = (u8*)malloc(q->len + 1); @@ -2643,7 +2729,7 @@ static void perform_dry_run(char** argv) { IR* root = g_mutator.IR_parser(use_mem); free(use_mem); - + if (root == nullptr) { q = q->next; continue; @@ -2653,7 +2739,7 @@ static void perform_dry_run(char** argv) { char* tmp_str = ir_str.c_str(); int siz = ir_str.size(); - + q->len = siz; res = calibrate_case(argv, q, tmp_str, 0, 1); @@ -3077,9 +3163,15 @@ static u8 save_if_interesting(char** argv, void* mem, u32 len, u8 fault) { } #ifndef SIMPLE_FILES - - fn = alloc_printf("%s/queue/id:%06u,%s", out_dir, queued_paths, + if(direct_mode){ + fn = alloc_printf("%s/queue/id:%06u,%llu,%s", out_dir, queued_paths, + get_cur_time() - start_time, describe_op(hnb)); + } + else{ + fn = alloc_printf("%s/queue/id:%06u,%s", out_dir, queued_paths, + describe_op(hnb)); + } #else @@ -3161,9 +3253,15 @@ error_check: } #ifndef SIMPLE_FILES - - fn = alloc_printf("%s/hangs/id:%06llu,%s", out_dir, + if(direct_mode){ + fn = alloc_printf("%s/hangs/id:%06llu,%llu,%s", out_dir, + unique_hangs, get_cur_time() - start_time, + describe_op(0)); + } + else{ + fn = alloc_printf("%s/hangs/id:%06llu,%s", out_dir, unique_hangs, describe_op(0)); + } #else @@ -3205,9 +3303,15 @@ keep_as_crash: if (!unique_crashes) write_crash_readme(); #ifndef SIMPLE_FILES - - fn = alloc_printf("%s/crashes/id:%06llu,sig:%02u,%s", out_dir, + if(direct_mode){ + fn = alloc_printf("%s/crashes/id:%06llu,%llu,sig:%02u,%s", out_dir, + unique_crashes, get_cur_time() - start_time, + kill_signal, describe_op(0)); + } + else{ + fn = alloc_printf("%s/crashes/id:%06llu,sig:%02u,%s", out_dir, unique_crashes, kill_signal, describe_op(0)); + } #else @@ -4731,6 +4835,62 @@ static u32 calculate_score(struct queue_entry* q) { } /* Make sure that we don't go over limit. */ + if(direct_mode){ + u64 cur_ms = get_cur_time(); + u64 t = (cur_ms - start_time) / 1000; + double progress_to_tx = ((double) t) / ((double) t_x * 60.0); + + double T; + + //TODO Substitute functions of exp and log with faster bitwise operations on integers + switch (cooling_schedule) { + case SAN_EXP: + + T = 1.0 / pow(20.0, progress_to_tx); + + break; + + case SAN_LOG: + + // alpha = 2 and exp(19/2) - 1 = 13358.7268297 + T = 1.0 / (1.0 + 2.0 * log(1.0 + progress_to_tx * 13358.7268297)); + + break; + + case SAN_LIN: + + T = 1.0 / (1.0 + 19.0 * progress_to_tx); + + break; + + case SAN_QUAD: + + T = 1.0 / (1.0 + 19.0 * pow(progress_to_tx, 2)); + + break; + + default: + PFATAL ("Unkown Power Schedule for Directed Fuzzing"); + } + + double power_factor = 1.0; + if (q->distance > 0) { + + double normalized_d = 0; // when "max_distance == min_distance", we set the normalized_d to 0 so that we can sufficiently explore those testcases whose distance >= 0. + if (max_distance != min_distance) + normalized_d = (q->distance - min_distance) / (max_distance - min_distance); + + if (normalized_d >= 0) { + + double p = (1.0 - normalized_d) * (1.0 - T) + 0.5 * T; + power_factor = pow(2.0, 2.0 * (double) log2(MAX_FACTOR) * (p - 0.5)); + + }// else WARNF ("Normalized distance negative: %f", normalized_d); + + } + + perf_score *= power_factor; + } if (perf_score > HAVOC_MAX_MULT * 100) perf_score = HAVOC_MAX_MULT * 100; @@ -5556,6 +5716,14 @@ static void usage(u8* argv0) { " -d - quick & dirty mode (skips deterministic steps)\n" " -n - fuzz without instrumentation (dumb mode)\n" " -x dir - optional fuzzer dictionary (see README)\n\n" + + "Directed fuzzing specific settings:\n\n" + + " -D - Directed fuzzing\n" + " -z schedule - temperature-based power schedules\n" + " {exp, log, lin, quad} (Default: exp)\n" + " -c min - time from start when SA enters exploitation\n" + " in secs (s), mins (m), hrs (h), or days (d)\n\n" "Other stuff:\n\n" @@ -6191,6 +6359,15 @@ static void save_cmdline(u32 argc, char** argv) { } +int stricmp(char const *a, char const *b) { + int d; + for (;; a++, b++) { + d = tolower(*a) - tolower(*b); + if (d != 0 || !*a) + return d; + } +} + #ifndef AFL_LIB char* g_server_path; @@ -6215,8 +6392,8 @@ int main(int argc, char** argv) { gettimeofday(&tv, &tz); srandom(tv.tv_sec ^ tv.tv_usec ^ getpid()); - while ((opt = getopt(argc, argv, "+i:o:f:m:t:T:dnCB:S:M:x:Q:s:c:")) > 0) - + + while ((opt = getopt(argc, argv, "+i:o:f:m:t:T:dnCB:S:M:x:Qs:z:c:D")) > 0) switch (opt) { case 'i': /* input dir */ @@ -6386,6 +6563,52 @@ int main(int argc, char** argv) { if (!mem_limit_given) mem_limit = MEM_LIMIT_QEMU; break; + + case 'D': /* QEMU mode */ + + if (direct_mode) FATAL("Multiple -D options not supported"); + direct_mode = 1; + + break; + + case 'z': /* Cooling schedule for Directed Fuzzing */ + + if (!stricmp(optarg, "exp")) + cooling_schedule = SAN_EXP; + else if (!stricmp(optarg, "log")) + cooling_schedule = SAN_LOG; + else if (!stricmp(optarg, "lin")) + cooling_schedule = SAN_LIN; + else if (!stricmp(optarg, "quad")) + cooling_schedule = SAN_QUAD; + else + PFATAL ("Unknown value for option -z"); + + break; + + case 'c': /* cut-off time for cooling schedule */ + + { + + u8 suffix = 'm'; + + if (sscanf(optarg, "%u%c", &t_x, &suffix) < 1 || + optarg[0] == '-') FATAL("Bad syntax used for -c"); + + switch (suffix) { + + case 's': t_x /= 60; break; + case 'm': break; + case 'h': t_x *= 60; break; + case 'd': t_x *= 60 * 24; break; + + default: FATAL("Unsupported suffix or bad syntax for -c"); + + } + + } + + break; default: @@ -6484,6 +6707,7 @@ int main(int argc, char** argv) { //char* tmp_argv[] = {g_server_path, NULL}; //init_forkserver(tmp_argv); // to do + perform_dry_run(use_argv); cull_queue(); @@ -6524,7 +6748,6 @@ int main(int argc, char** argv) { seek_to--; queue_cur = queue_cur->next; } - show_stats(); if (not_on_tty) { @@ -6547,7 +6770,7 @@ int main(int argc, char** argv) { sync_fuzzers(use_argv); } - + skipped_fuzz = fuzz_one(use_argv); if (!stop_soon && sync_id && !skipped_fuzz) { diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 366f011d319680e0b2822ba27e7fb6224b09677b..81d1327bed0e61dd41db43defd3e7a797ea5dc98 --- a/README.md +++ b/README.md @@ -84,4 +84,105 @@ start\_db函数。afl-fuzz会创建共享内存,并通过环境变量传递shm 最后的"OpenGaussDB"参数没有实际意义。在AFL中,最后需要输入待测程序的路径。在本工具中,不需要这个参数,但是也没有修改AFL命令行参数解析部分。因此为了确保命令完整性,需要加上这个参数。 **Unique Crash** -该工具沿袭了AFL原有的排除重复crash的方法,该方法在DBMS测试中是无效的,因此工具界面中的Unique Crash部分其实包含了重复的crash。建议在得到触发crash的语句后,手动或编写脚本去除重复的crash。 \ No newline at end of file +该工具沿袭了AFL原有的排除重复crash的方法,该方法在DBMS测试中是无效的,因此工具界面中的Unique Crash部分其实包含了重复的crash。建议在得到触发crash的语句后,手动或编写脚本去除重复的crash。 + +**定向模糊测试** + +该功能用于对用户在项目中重点关注的文件,相关函数,指令进行更为集中的测试,该功能基于AFLGO构建,以下为该功能使用方法: + +1.编写BBtargets.txt。该文件用于指定用户想要集中测试的文件和函数,本工具所支持的指定测试目标的指令如下所示: + + + 对某一文件进行测试: + src:文件名称 例如:src:driver_error.cpp + 文件名称 例如:mc_poller_epoll.cpp + + 对某一函数进行测试: + fun:函数名称 例如:fun:make_empty_conn_4cl + + 对某一文件特定行指令相关的基本块进行测试: + line:文件名称:指令对应行数 例如:line:comm_sock.cpp:221 + 文件名称:指令对应行数 例如:comm_sock.cpp:221 + +2.编译距离计算文件(编译相关的工具以及环境如:Cmake,Ninja等请自行构建),进入主文件夹下的 instrument/distance_calculator/ 文件夹,执行以下命令: + + cmake -G Ninja ./ + cmake --build ./ + +3.下载OpenGauss数据库源码以及所下载版本和分支对应的编译好的三方库,请自行按照openGauss官网指导安装所需的软件依赖: + + git clone https://gitee.com/opengauss/openGauss-server.git &&\ + cd openGauss-server &&\ + git checkout master + + cd openGauss-server &&\ + wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz &&\ + tar -zxf openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz + +4.设置OpenGauss编译所需的环境变量: + + export CODE_BASE=________ # openGauss-server的路径 + export BINARYLIBS=________ # binarylibs的路径 + export GAUSSHOME=$CODE_BASE/dest/ #输出文件夹 + export GCC_PATH=$BINARYLIBS/buildtools/________ # gcc的版本,根据三方包中对应的gcc版本进行填写即可,一般有gcc7.3或gcc10.3两种 + export CC=$GCC_PATH/gcc/bin/gcc + export CXX=$GCC_PATH/gcc/bin/g++ + export LD_LIBRARY_PATH=$GAUSSHOME/lib:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$LD_LIBRARY_PATH + export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH + +5.进入 instrument/gcc_mode/ 文件,编译相关工具: + + make clean + make + +编译成功后instrument目录下会出现gcc-fast和g++-fast两个可执行文件。 + +6.回到OpenGauss源代码所在位置,按照OpenGauss官方编译步骤选择相应的 ./configure 命令并执行,命令执行完后修改编译源代码所使用的Makefile ,主要为/src/Makefile.global文件以及位于src/bin/pg_dump/Makefile位置的文件: + + + 修改 gcc 为 gcc-fast 所在位置, g++为 g++-fast 所在位置, CFLAGS和CXXFLAGS 添加 -lsupc++ -lstdc++ -targets=BBtargets.txt所在位置 -outdir=BBtargets.txt所在目录 -flto -fuse-ld=gold -Wno-unused-parameter + +设置环境变量: + + export AFLGO=本工具源码所在目录/instrument + export TMP_DIR=BBtargets.txt所在目录 + + export CC=$AFLGO/gcc-fast + export CXX=$AFLGO/g++-fast + + export COPY_CFLAGS=$CFLAGS + export COPY_CXXFLAGS=$CXXFLAGS + export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -lsupc++ -lstdc++" + export CFLAGS="$CFLAGS $ADDITIONAL" + export CXXFLAGS="$CXXFLAGS $ADDITIONAL" + + +7.第一次编译OpenGauss源代码,在代码所在位置执行 make 命令: + + + make + + +8.编译完成后,可以通过检查$TMP_DIR目录下的Ftargets.txt文件确认PASS是否成功运行(若为空则运行失败)。之后进入instrument/gcc_scripts/文件夹执行以下命令: + + + $AFLGO/gcc_scripts/gen_distance_fast.py $AFLGO/gcc_scripts $TMP_DIR + +这个过程会持续较长时间,请耐心等待。计算过程会在$TMP_DIR目录下生成文件distance.cfg.txt。 + +9.设置新的环境变量,更改Makefile相应的内容,对源代码进行第二次编译: + + + export CFLAGS="$COPY_CFLAGS -distance=$TMP_DIR/distance.cfg.txt -flto -fuse-ld=gold -Wno-unused-parameter -lsupc++ -lstdc++" + export CXXFLAGS="$COPY_CXXFLAGS -distance=$TMP_DIR/distance.cfg.txt -flto -fuse-ld=gold -Wno-unused-parameter -lsupc++ -lstdc++" + + make clean + make + make install + + +10.之后按照本工具之前的教程连接数据库开始fuzz,连接时如果提示找不到"__afl_area_ptr",可以先用正常编译的文件暂时替换相应文件,当使用定向模糊测试功能时,在执行 afl-fuzz 命令时需添加 -D 选项来指定定向测试功能。 + + + /工具路径/AFL/afl-fuzz -i /工具路径/corpus/input -o /自定义输出目录 -D -z exp -c 45m OpenGaussDB + \ No newline at end of file diff --git a/instrument/alloc-inl.h b/instrument/alloc-inl.h new file mode 100644 index 0000000000000000000000000000000000000000..cf9eb3dfba3447f129d16cc958dff3587af18bc0 --- /dev/null +++ b/instrument/alloc-inl.h @@ -0,0 +1,570 @@ +/* + american fuzzy lop - error-checking, memory-zeroing alloc routines + ------------------------------------------------------------------ + + Written and maintained by Michal Zalewski + + Copyright 2013, 2014, 2015 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + This allocator is not designed to resist malicious attackers (the canaries + are small and predictable), but provides a robust and portable way to detect + use-after-free, off-by-one writes, stale pointers, and so on. + + */ + +#ifndef _HAVE_ALLOC_INL_H +#define _HAVE_ALLOC_INL_H + +#include +#include +#include + +#include "config.h" +#include "types.h" +#include "debug.h" + +/* User-facing macro to sprintf() to a dynamically allocated buffer. */ + +#define alloc_printf(_str...) ({ \ + u8* _tmp; \ + s32 _len = snprintf(NULL, 0, _str); \ + if (_len < 0) FATAL("Whoa, snprintf() fails?!"); \ + _tmp = ck_alloc(_len + 1); \ + snprintf((char*)_tmp, _len + 1, _str); \ + _tmp; \ + }) + +/* Macro to enforce allocation limits as a last-resort defense against + integer overflows. */ + +#define ALLOC_CHECK_SIZE(_s) do { \ + if ((_s) > MAX_ALLOC) \ + ABORT("Bad alloc request: %u bytes", (_s)); \ + } while (0) + +/* Macro to check malloc() failures and the like. */ + +#define ALLOC_CHECK_RESULT(_r, _s) do { \ + if (!(_r)) \ + ABORT("Out of memory: can't allocate %u bytes", (_s)); \ + } while (0) + +/* Magic tokens used to mark used / freed chunks. */ + +#define ALLOC_MAGIC_C1 0xFF00FF00 /* Used head (dword) */ +#define ALLOC_MAGIC_F 0xFE00FE00 /* Freed head (dword) */ +#define ALLOC_MAGIC_C2 0xF0 /* Used tail (byte) */ + +/* Positions of guard tokens in relation to the user-visible pointer. */ + +#define ALLOC_C1(_ptr) (((u32*)(_ptr))[-2]) +#define ALLOC_S(_ptr) (((u32*)(_ptr))[-1]) +#define ALLOC_C2(_ptr) (((u8*)(_ptr))[ALLOC_S(_ptr)]) + +#define ALLOC_OFF_HEAD 8 +#define ALLOC_OFF_TOTAL (ALLOC_OFF_HEAD + 1) + +/* Allocator increments for ck_realloc_block(). */ + +#define ALLOC_BLK_INC 256 + +/* Sanity-checking macros for pointers. */ + +#define CHECK_PTR(_p) do { \ + if (_p) { \ + if (ALLOC_C1(_p) ^ ALLOC_MAGIC_C1) {\ + if (ALLOC_C1(_p) == ALLOC_MAGIC_F) \ + ABORT("Use after free."); \ + else ABORT("Corrupted head alloc canary."); \ + } \ + if (ALLOC_C2(_p) ^ ALLOC_MAGIC_C2) \ + ABORT("Corrupted tail alloc canary."); \ + } \ + } while (0) + +#define CHECK_PTR_EXPR(_p) ({ \ + typeof (_p) _tmp = (_p); \ + CHECK_PTR(_tmp); \ + _tmp; \ + }) + + +/* Allocate a buffer, explicitly not zeroing it. Returns NULL for zero-sized + requests. */ + +static inline void* DFL_ck_alloc_nozero(u32 size) { + + void* ret; + + if (!size) return NULL; + + ALLOC_CHECK_SIZE(size); + ret = malloc(size + ALLOC_OFF_TOTAL); + ALLOC_CHECK_RESULT(ret, size); + + ret += ALLOC_OFF_HEAD; + + ALLOC_C1(ret) = ALLOC_MAGIC_C1; + ALLOC_S(ret) = size; + ALLOC_C2(ret) = ALLOC_MAGIC_C2; + + return ret; + +} + + +/* Allocate a buffer, returning zeroed memory. */ + +static inline void* DFL_ck_alloc(u32 size) { + + void* mem; + + if (!size) return NULL; + mem = DFL_ck_alloc_nozero(size); + + return memset(mem, 0, size); + +} + + +/* Free memory, checking for double free and corrupted heap. When DEBUG_BUILD + is set, the old memory will be also clobbered with 0xFF. */ + +static inline void DFL_ck_free(void* mem) { + + if (!mem) return; + + CHECK_PTR(mem); + +#ifdef DEBUG_BUILD + + /* Catch pointer issues sooner. */ + memset(mem, 0xFF, ALLOC_S(mem)); + +#endif /* DEBUG_BUILD */ + + ALLOC_C1(mem) = ALLOC_MAGIC_F; + + free(mem - ALLOC_OFF_HEAD); + +} + + +/* Re-allocate a buffer, checking for issues and zeroing any newly-added tail. + With DEBUG_BUILD, the buffer is always reallocated to a new addresses and the + old memory is clobbered with 0xFF. */ + +static inline void* DFL_ck_realloc(void* orig, u32 size) { + + void* ret; + u32 old_size = 0; + + if (!size) { + + DFL_ck_free(orig); + return NULL; + + } + + if (orig) { + + CHECK_PTR(orig); + +#ifndef DEBUG_BUILD + ALLOC_C1(orig) = ALLOC_MAGIC_F; +#endif /* !DEBUG_BUILD */ + + old_size = ALLOC_S(orig); + orig -= ALLOC_OFF_HEAD; + + ALLOC_CHECK_SIZE(old_size); + + } + + ALLOC_CHECK_SIZE(size); + +#ifndef DEBUG_BUILD + + ret = realloc(orig, size + ALLOC_OFF_TOTAL); + ALLOC_CHECK_RESULT(ret, size); + +#else + + /* Catch pointer issues sooner: force relocation and make sure that the + original buffer is wiped. */ + + ret = malloc(size + ALLOC_OFF_TOTAL); + ALLOC_CHECK_RESULT(ret, size); + + if (orig) { + + memcpy(ret + ALLOC_OFF_HEAD, orig + ALLOC_OFF_HEAD, MIN(size, old_size)); + memset(orig + ALLOC_OFF_HEAD, 0xFF, old_size); + + ALLOC_C1(orig + ALLOC_OFF_HEAD) = ALLOC_MAGIC_F; + + free(orig); + + } + +#endif /* ^!DEBUG_BUILD */ + + ret += ALLOC_OFF_HEAD; + + ALLOC_C1(ret) = ALLOC_MAGIC_C1; + ALLOC_S(ret) = size; + ALLOC_C2(ret) = ALLOC_MAGIC_C2; + + if (size > old_size) + memset(ret + old_size, 0, size - old_size); + + return ret; + +} + + +/* Re-allocate a buffer with ALLOC_BLK_INC increments (used to speed up + repeated small reallocs without complicating the user code). */ + +static inline void* DFL_ck_realloc_block(void* orig, u32 size) { + +#ifndef DEBUG_BUILD + + if (orig) { + + CHECK_PTR(orig); + + if (ALLOC_S(orig) >= size) return orig; + + size += ALLOC_BLK_INC; + + } + +#endif /* !DEBUG_BUILD */ + + return DFL_ck_realloc(orig, size); + +} + + +/* Create a buffer with a copy of a string. Returns NULL for NULL inputs. */ + +static inline u8* DFL_ck_strdup(u8* str) { + + void* ret; + u32 size; + + if (!str) return NULL; + + size = strlen((char*)str) + 1; + + ALLOC_CHECK_SIZE(size); + ret = malloc(size + ALLOC_OFF_TOTAL); + ALLOC_CHECK_RESULT(ret, size); + + ret += ALLOC_OFF_HEAD; + + ALLOC_C1(ret) = ALLOC_MAGIC_C1; + ALLOC_S(ret) = size; + ALLOC_C2(ret) = ALLOC_MAGIC_C2; + + return memcpy(ret, str, size); + +} + + +/* Create a buffer with a copy of a memory block. Returns NULL for zero-sized + or NULL inputs. */ + +static inline void* DFL_ck_memdup(void* mem, u32 size) { + + void* ret; + + if (!mem || !size) return NULL; + + ALLOC_CHECK_SIZE(size); + ret = malloc(size + ALLOC_OFF_TOTAL); + ALLOC_CHECK_RESULT(ret, size); + + ret += ALLOC_OFF_HEAD; + + ALLOC_C1(ret) = ALLOC_MAGIC_C1; + ALLOC_S(ret) = size; + ALLOC_C2(ret) = ALLOC_MAGIC_C2; + + return memcpy(ret, mem, size); + +} + + +/* Create a buffer with a block of text, appending a NUL terminator at the end. + Returns NULL for zero-sized or NULL inputs. */ + +static inline u8* DFL_ck_memdup_str(u8* mem, u32 size) { + + u8* ret; + + if (!mem || !size) return NULL; + + ALLOC_CHECK_SIZE(size); + ret = malloc(size + ALLOC_OFF_TOTAL + 1); + ALLOC_CHECK_RESULT(ret, size); + + ret += ALLOC_OFF_HEAD; + + ALLOC_C1(ret) = ALLOC_MAGIC_C1; + ALLOC_S(ret) = size; + ALLOC_C2(ret) = ALLOC_MAGIC_C2; + + memcpy(ret, mem, size); + ret[size] = 0; + + return ret; + +} + + +#ifndef DEBUG_BUILD + +/* In non-debug mode, we just do straightforward aliasing of the above functions + to user-visible names such as ck_alloc(). */ + +#define ck_alloc DFL_ck_alloc +#define ck_alloc_nozero DFL_ck_alloc_nozero +#define ck_realloc DFL_ck_realloc +#define ck_realloc_block DFL_ck_realloc_block +#define ck_strdup DFL_ck_strdup +#define ck_memdup DFL_ck_memdup +#define ck_memdup_str DFL_ck_memdup_str +#define ck_free DFL_ck_free + +#define alloc_report() + +#else + +/* In debugging mode, we also track allocations to detect memory leaks, and the + flow goes through one more layer of indirection. */ + +/* Alloc tracking data structures: */ + +#define ALLOC_BUCKETS 4096 + +struct TRK_obj { + void *ptr; + char *file, *func; + u32 line; +}; + +#ifdef AFL_MAIN + +struct TRK_obj* TRK[ALLOC_BUCKETS]; +u32 TRK_cnt[ALLOC_BUCKETS]; + +# define alloc_report() TRK_report() + +#else + +extern struct TRK_obj* TRK[ALLOC_BUCKETS]; +extern u32 TRK_cnt[ALLOC_BUCKETS]; + +# define alloc_report() + +#endif /* ^AFL_MAIN */ + +/* Bucket-assigning function for a given pointer: */ + +#define TRKH(_ptr) (((((u32)(_ptr)) >> 16) ^ ((u32)(_ptr))) % ALLOC_BUCKETS) + + +/* Add a new entry to the list of allocated objects. */ + +static inline void TRK_alloc_buf(void* ptr, const char* file, const char* func, + u32 line) { + + u32 i, bucket; + + if (!ptr) return; + + bucket = TRKH(ptr); + + /* Find a free slot in the list of entries for that bucket. */ + + for (i = 0; i < TRK_cnt[bucket]; i++) + + if (!TRK[bucket][i].ptr) { + + TRK[bucket][i].ptr = ptr; + TRK[bucket][i].file = (char*)file; + TRK[bucket][i].func = (char*)func; + TRK[bucket][i].line = line; + return; + + } + + /* No space available - allocate more. */ + + TRK[bucket] = DFL_ck_realloc_block(TRK[bucket], + (TRK_cnt[bucket] + 1) * sizeof(struct TRK_obj)); + + TRK[bucket][i].ptr = ptr; + TRK[bucket][i].file = (char*)file; + TRK[bucket][i].func = (char*)func; + TRK[bucket][i].line = line; + + TRK_cnt[bucket]++; + +} + + +/* Remove entry from the list of allocated objects. */ + +static inline void TRK_free_buf(void* ptr, const char* file, const char* func, + u32 line) { + + u32 i, bucket; + + if (!ptr) return; + + bucket = TRKH(ptr); + + /* Find the element on the list... */ + + for (i = 0; i < TRK_cnt[bucket]; i++) + + if (TRK[bucket][i].ptr == ptr) { + + TRK[bucket][i].ptr = 0; + return; + + } + + WARNF("ALLOC: Attempt to free non-allocated memory in %s (%s:%u)", + func, file, line); + +} + + +/* Do a final report on all non-deallocated objects. */ + +static inline void TRK_report(void) { + + u32 i, bucket; + + fflush(0); + + for (bucket = 0; bucket < ALLOC_BUCKETS; bucket++) + for (i = 0; i < TRK_cnt[bucket]; i++) + if (TRK[bucket][i].ptr) + WARNF("ALLOC: Memory never freed, created in %s (%s:%u)", + TRK[bucket][i].func, TRK[bucket][i].file, TRK[bucket][i].line); + +} + + +/* Simple wrappers for non-debugging functions: */ + +static inline void* TRK_ck_alloc(u32 size, const char* file, const char* func, + u32 line) { + + void* ret = DFL_ck_alloc(size); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void* TRK_ck_realloc(void* orig, u32 size, const char* file, + const char* func, u32 line) { + + void* ret = DFL_ck_realloc(orig, size); + TRK_free_buf(orig, file, func, line); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void* TRK_ck_realloc_block(void* orig, u32 size, const char* file, + const char* func, u32 line) { + + void* ret = DFL_ck_realloc_block(orig, size); + TRK_free_buf(orig, file, func, line); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void* TRK_ck_strdup(u8* str, const char* file, const char* func, + u32 line) { + + void* ret = DFL_ck_strdup(str); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void* TRK_ck_memdup(void* mem, u32 size, const char* file, + const char* func, u32 line) { + + void* ret = DFL_ck_memdup(mem, size); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void* TRK_ck_memdup_str(void* mem, u32 size, const char* file, + const char* func, u32 line) { + + void* ret = DFL_ck_memdup_str(mem, size); + TRK_alloc_buf(ret, file, func, line); + return ret; + +} + + +static inline void TRK_ck_free(void* ptr, const char* file, + const char* func, u32 line) { + + TRK_free_buf(ptr, file, func, line); + DFL_ck_free(ptr); + +} + +/* Aliasing user-facing names to tracking functions: */ + +#define ck_alloc(_p1) \ + TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__) + +#define ck_alloc_nozero(_p1) \ + TRK_ck_alloc(_p1, __FILE__, __FUNCTION__, __LINE__) + +#define ck_realloc(_p1, _p2) \ + TRK_ck_realloc(_p1, _p2, __FILE__, __FUNCTION__, __LINE__) + +#define ck_realloc_block(_p1, _p2) \ + TRK_ck_realloc_block(_p1, _p2, __FILE__, __FUNCTION__, __LINE__) + +#define ck_strdup(_p1) \ + TRK_ck_strdup(_p1, __FILE__, __FUNCTION__, __LINE__) + +#define ck_memdup(_p1, _p2) \ + TRK_ck_memdup(_p1, _p2, __FILE__, __FUNCTION__, __LINE__) + +#define ck_memdup_str(_p1, _p2) \ + TRK_ck_memdup_str(_p1, _p2, __FILE__, __FUNCTION__, __LINE__) + +#define ck_free(_p1) \ + TRK_ck_free(_p1, __FILE__, __FUNCTION__, __LINE__) + +#endif /* ^!DEBUG_BUILD */ + +#endif /* ! _HAVE_ALLOC_INL_H */ diff --git a/instrument/config.h b/instrument/config.h new file mode 100644 index 0000000000000000000000000000000000000000..7e28e21692b746ceebca411860f96d069e612319 --- /dev/null +++ b/instrument/config.h @@ -0,0 +1,361 @@ +/* + american fuzzy lop - vaguely configurable bits + ---------------------------------------------- + + Written and maintained by Michal Zalewski + + Copyright 2013, 2014, 2015, 2016 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + */ + +#ifndef _HAVE_CONFIG_H +#define _HAVE_CONFIG_H + +#include "types.h" + +/* Version string: */ + +#define VERSION "2.52b" + +/****************************************************** + * * + * Settings that may be of interest to power users: * + * * + ******************************************************/ + +/* Comment out to disable terminal colors (note that this makes afl-analyze + a lot less nice): */ + +#define USE_COLOR + +/* Comment out to disable fancy ANSI boxes and use poor man's 7-bit UI: */ + +#define FANCY_BOXES + +/* Default timeout for fuzzed code (milliseconds). This is the upper bound, + also used for detecting hangs; the actual value is auto-scaled: */ + +#define EXEC_TIMEOUT 1000 + +/* Timeout rounding factor when auto-scaling (milliseconds): */ + +#define EXEC_TM_ROUND 20 + +/* Default memory limit for child process (MB): */ + +#ifndef __x86_64__ +# define MEM_LIMIT 25 +#else +# define MEM_LIMIT 50 +#endif /* ^!__x86_64__ */ + +/* Default memory limit when running in QEMU mode (MB): */ + +#define MEM_LIMIT_QEMU 200 + +/* Number of calibration cycles per every new test case (and for test + cases that show variable behavior): */ + +#define CAL_CYCLES 8 +#define CAL_CYCLES_LONG 40 + +/* Number of subsequent timeouts before abandoning an input file: */ + +#define TMOUT_LIMIT 250 + +/* Maximum number of unique hangs or crashes to record: */ + +#define KEEP_UNIQUE_HANG 500 +#define KEEP_UNIQUE_CRASH 5000 + +/* Baseline number of random tweaks during a single 'havoc' stage: */ + +#define HAVOC_CYCLES 256 +#define HAVOC_CYCLES_INIT 1024 + +/* Maximum multiplier for the above (should be a power of two, beware + of 32-bit int overflows): */ + +#define HAVOC_MAX_MULT 16 + +/* Absolute minimum number of havoc cycles (after all adjustments): */ + +#define HAVOC_MIN 16 + +/* Maximum stacking for havoc-stage tweaks. The actual value is calculated + like this: + + n = random between 1 and HAVOC_STACK_POW2 + stacking = 2^n + + In other words, the default (n = 7) produces 2, 4, 8, 16, 32, 64, or + 128 stacked tweaks: */ + +#define HAVOC_STACK_POW2 7 + +/* Caps on block sizes for cloning and deletion operations. Each of these + ranges has a 33% probability of getting picked, except for the first + two cycles where smaller blocks are favored: */ + +#define HAVOC_BLK_SMALL 32 +#define HAVOC_BLK_MEDIUM 128 +#define HAVOC_BLK_LARGE 1500 + +/* Extra-large blocks, selected very rarely (<5% of the time): */ + +#define HAVOC_BLK_XL 32768 + +/* Probabilities of skipping non-favored entries in the queue, expressed as + percentages: */ + +#define SKIP_TO_NEW_PROB 99 /* ...when there are new, pending favorites */ +#define SKIP_NFAV_OLD_PROB 95 /* ...no new favs, cur entry already fuzzed */ +#define SKIP_NFAV_NEW_PROB 75 /* ...no new favs, cur entry not fuzzed yet */ + +/* Splicing cycle count: */ + +#define SPLICE_CYCLES 15 + +/* Nominal per-splice havoc cycle length: */ + +#define SPLICE_HAVOC 32 + +/* Maximum offset for integer addition / subtraction stages: */ + +#define ARITH_MAX 35 + +/* Limits for the test case trimmer. The absolute minimum chunk size; and + the starting and ending divisors for chopping up the input file: */ + +#define TRIM_MIN_BYTES 4 +#define TRIM_START_STEPS 16 +#define TRIM_END_STEPS 1024 + +/* Maximum size of input file, in bytes (keep under 100MB): */ + +#define MAX_FILE (1 * 1024 * 1024) + +/* The same, for the test case minimizer: */ + +#define TMIN_MAX_FILE (10 * 1024 * 1024) + +/* Block normalization steps for afl-tmin: */ + +#define TMIN_SET_MIN_SIZE 4 +#define TMIN_SET_STEPS 128 + +/* Maximum dictionary token size (-x), in bytes: */ + +#define MAX_DICT_FILE 128 + +/* Length limits for auto-detected dictionary tokens: */ + +#define MIN_AUTO_EXTRA 3 +#define MAX_AUTO_EXTRA 32 + +/* Maximum number of user-specified dictionary tokens to use in deterministic + steps; past this point, the "extras/user" step will be still carried out, + but with proportionally lower odds: */ + +#define MAX_DET_EXTRAS 200 + +/* Maximum number of auto-extracted dictionary tokens to actually use in fuzzing + (first value), and to keep in memory as candidates. The latter should be much + higher than the former. */ + +#define USE_AUTO_EXTRAS 50 +#define MAX_AUTO_EXTRAS (USE_AUTO_EXTRAS * 10) + +/* Scaling factor for the effector map used to skip some of the more + expensive deterministic steps. The actual divisor is set to + 2^EFF_MAP_SCALE2 bytes: */ + +#define EFF_MAP_SCALE2 3 + +/* Minimum input file length at which the effector logic kicks in: */ + +#define EFF_MIN_LEN 128 + +/* Maximum effector density past which everything is just fuzzed + unconditionally (%): */ + +#define EFF_MAX_PERC 90 + +/* UI refresh frequency (Hz): */ + +#define UI_TARGET_HZ 5 + +/* Fuzzer stats file and plot update intervals (sec): */ + +#define STATS_UPDATE_SEC 60 +#define PLOT_UPDATE_SEC 5 + +/* Smoothing divisor for CPU load and exec speed stats (1 - no smoothing). */ + +#define AVG_SMOOTHING 16 + +/* Sync interval (every n havoc cycles): */ + +#define SYNC_INTERVAL 5 + +/* Output directory reuse grace period (minutes): */ + +#define OUTPUT_GRACE 25 + +/* Uncomment to use simple file names (id_NNNNNN): */ + +// #define SIMPLE_FILES + +/* List of interesting values to use in fuzzing. */ + +#define INTERESTING_8 \ + -128, /* Overflow signed 8-bit when decremented */ \ + -1, /* */ \ + 0, /* */ \ + 1, /* */ \ + 16, /* One-off with common buffer size */ \ + 32, /* One-off with common buffer size */ \ + 64, /* One-off with common buffer size */ \ + 100, /* One-off with common buffer size */ \ + 127 /* Overflow signed 8-bit when incremented */ + +#define INTERESTING_16 \ + -32768, /* Overflow signed 16-bit when decremented */ \ + -129, /* Overflow signed 8-bit */ \ + 128, /* Overflow signed 8-bit */ \ + 255, /* Overflow unsig 8-bit when incremented */ \ + 256, /* Overflow unsig 8-bit */ \ + 512, /* One-off with common buffer size */ \ + 1000, /* One-off with common buffer size */ \ + 1024, /* One-off with common buffer size */ \ + 4096, /* One-off with common buffer size */ \ + 32767 /* Overflow signed 16-bit when incremented */ + +#define INTERESTING_32 \ + -2147483648LL, /* Overflow signed 32-bit when decremented */ \ + -100663046, /* Large negative number (endian-agnostic) */ \ + -32769, /* Overflow signed 16-bit */ \ + 32768, /* Overflow signed 16-bit */ \ + 65535, /* Overflow unsig 16-bit when incremented */ \ + 65536, /* Overflow unsig 16 bit */ \ + 100663045, /* Large positive number (endian-agnostic) */ \ + 2147483647 /* Overflow signed 32-bit when incremented */ + +/*********************************************************** + * * + * Really exotic stuff you probably don't want to touch: * + * * + ***********************************************************/ + +/* Call count interval between reseeding the libc PRNG from /dev/urandom: */ + +#define RESEED_RNG 10000 + +/* Maximum line length passed from GCC to 'as' and used for parsing + configuration files: */ + +#define MAX_LINE 8192 + +/* Environment variable used to pass SHM ID to the called program. */ + +#define SHM_ENV_VAR "__AFL_SHM_ID" + +/* Other less interesting, internal-only variables. */ + +#define CLANG_ENV_VAR "__AFL_CLANG_MODE" +#define AS_LOOP_ENV_VAR "__AFL_AS_LOOPCHECK" +#define PERSIST_ENV_VAR "__AFL_PERSISTENT" +#define DEFER_ENV_VAR "__AFL_DEFER_FORKSRV" + +/* In-code signatures for deferred and persistent mode. */ + +#define PERSIST_SIG "##SIG_AFL_PERSISTENT##" +#define DEFER_SIG "##SIG_AFL_DEFER_FORKSRV##" + +/* Distinctive bitmap signature used to indicate failed execution: */ + +#define EXEC_FAIL_SIG 0xfee1dead + +/* Distinctive exit code used to indicate MSAN trip condition: */ + +#define MSAN_ERROR 86 + +/* Designated file descriptors for forkserver commands (the application will + use FORKSRV_FD and FORKSRV_FD + 1): */ + +#define FORKSRV_FD 198 + +/* Fork server init timeout multiplier: we'll wait the user-selected + timeout plus this much for the fork server to spin up. */ + +#define FORK_WAIT_MULT 10 + +/* Calibration timeout adjustments, to be a bit more generous when resuming + fuzzing sessions or trying to calibrate already-added internal finds. + The first value is a percentage, the other is in milliseconds: */ + +#define CAL_TMOUT_PERC 125 +#define CAL_TMOUT_ADD 50 + +/* Number of chances to calibrate a case before giving up: */ + +#define CAL_CHANCES 3 + +/* Map size for the traced binary (2^MAP_SIZE_POW2). Must be greater than + 2; you probably want to keep it under 18 or so for performance reasons + (adjusting AFL_INST_RATIO when compiling is probably a better way to solve + problems with complex programs). You need to recompile the target binary + after changing this - otherwise, SEGVs may ensue. */ + +#define MAP_SIZE_POW2 16 +#define MAP_SIZE (1 << MAP_SIZE_POW2) + +/* Maximum allocator request size (keep well under INT_MAX): */ + +#define MAX_ALLOC 0x40000000 + +/* A made-up hashing seed: */ + +#define HASH_CONST 0xa5b35705 + +/* Constants for afl-gotcpu to control busy loop timing: */ + +#define CTEST_TARGET_MS 5000 +#define CTEST_CORE_TRG_MS 1000 +#define CTEST_BUSY_CYCLES (10 * 1000 * 1000) + +/* Uncomment this to use inferior block-coverage-based instrumentation. Note + that you need to recompile the target binary for this to have any effect: */ + +// #define COVERAGE_ONLY + +/* Uncomment this to ignore hit counts and output just one bit per tuple. + As with the previous setting, you will need to recompile the target + binary: */ + +// #define SKIP_COUNTS + +/* Uncomment this to use instrumentation data to record newly discovered paths, + but do not use them as seeds for fuzzing. This is useful for conveniently + measuring coverage that could be attained by a "dumb" fuzzing algorithm: */ + +// #define IGNORE_FINDS + +#define MAX_FACTOR 32 + +/* This enables tracing of the executed CG and CFG edges. In some cases, + the CG and CFGs are that LLVM produces are incomplete due to register- + indirect jumps or calls. To add edges use script/add_edges.py. Don't + forget to set environment variable AFLGO_PROFILER_FILE. + + $ export AFLGO_PROFILER_FILE= */ + +//#define AFLGO_TRACING + +#endif /* ! _HAVE_CONFIG_H */ diff --git a/instrument/debug.h b/instrument/debug.h new file mode 100644 index 0000000000000000000000000000000000000000..83173ca609b2f24ad7c3e0e366998f6e729a9931 --- /dev/null +++ b/instrument/debug.h @@ -0,0 +1,251 @@ +/* + american fuzzy lop - debug / error handling macros + -------------------------------------------------- + + Written and maintained by Michal Zalewski + + Copyright 2013, 2014, 2015, 2016 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + */ + +#ifndef _HAVE_DEBUG_H +#define _HAVE_DEBUG_H + +#include + +#include "types.h" +#include "config.h" + +/******************* + * Terminal colors * + *******************/ + +#ifdef USE_COLOR + +# define cBLK "\x1b[0;30m" +# define cRED "\x1b[0;31m" +# define cGRN "\x1b[0;32m" +# define cBRN "\x1b[0;33m" +# define cBLU "\x1b[0;34m" +# define cMGN "\x1b[0;35m" +# define cCYA "\x1b[0;36m" +# define cLGR "\x1b[0;37m" +# define cGRA "\x1b[1;90m" +# define cLRD "\x1b[1;91m" +# define cLGN "\x1b[1;92m" +# define cYEL "\x1b[1;93m" +# define cLBL "\x1b[1;94m" +# define cPIN "\x1b[1;95m" +# define cLCY "\x1b[1;96m" +# define cBRI "\x1b[1;97m" +# define cRST "\x1b[0m" + +# define bgBLK "\x1b[40m" +# define bgRED "\x1b[41m" +# define bgGRN "\x1b[42m" +# define bgBRN "\x1b[43m" +# define bgBLU "\x1b[44m" +# define bgMGN "\x1b[45m" +# define bgCYA "\x1b[46m" +# define bgLGR "\x1b[47m" +# define bgGRA "\x1b[100m" +# define bgLRD "\x1b[101m" +# define bgLGN "\x1b[102m" +# define bgYEL "\x1b[103m" +# define bgLBL "\x1b[104m" +# define bgPIN "\x1b[105m" +# define bgLCY "\x1b[106m" +# define bgBRI "\x1b[107m" + +#else + +# define cBLK "" +# define cRED "" +# define cGRN "" +# define cBRN "" +# define cBLU "" +# define cMGN "" +# define cCYA "" +# define cLGR "" +# define cGRA "" +# define cLRD "" +# define cLGN "" +# define cYEL "" +# define cLBL "" +# define cPIN "" +# define cLCY "" +# define cBRI "" +# define cRST "" + +# define bgBLK "" +# define bgRED "" +# define bgGRN "" +# define bgBRN "" +# define bgBLU "" +# define bgMGN "" +# define bgCYA "" +# define bgLGR "" +# define bgGRA "" +# define bgLRD "" +# define bgLGN "" +# define bgYEL "" +# define bgLBL "" +# define bgPIN "" +# define bgLCY "" +# define bgBRI "" + +#endif /* ^USE_COLOR */ + +/************************* + * Box drawing sequences * + *************************/ + +#ifdef FANCY_BOXES + +# define SET_G1 "\x1b)0" /* Set G1 for box drawing */ +# define RESET_G1 "\x1b)B" /* Reset G1 to ASCII */ +# define bSTART "\x0e" /* Enter G1 drawing mode */ +# define bSTOP "\x0f" /* Leave G1 drawing mode */ +# define bH "q" /* Horizontal line */ +# define bV "x" /* Vertical line */ +# define bLT "l" /* Left top corner */ +# define bRT "k" /* Right top corner */ +# define bLB "m" /* Left bottom corner */ +# define bRB "j" /* Right bottom corner */ +# define bX "n" /* Cross */ +# define bVR "t" /* Vertical, branch right */ +# define bVL "u" /* Vertical, branch left */ +# define bHT "v" /* Horizontal, branch top */ +# define bHB "w" /* Horizontal, branch bottom */ + +#else + +# define SET_G1 "" +# define RESET_G1 "" +# define bSTART "" +# define bSTOP "" +# define bH "-" +# define bV "|" +# define bLT "+" +# define bRT "+" +# define bLB "+" +# define bRB "+" +# define bX "+" +# define bVR "+" +# define bVL "+" +# define bHT "+" +# define bHB "+" + +#endif /* ^FANCY_BOXES */ + +/*********************** + * Misc terminal codes * + ***********************/ + +#define TERM_HOME "\x1b[H" +#define TERM_CLEAR TERM_HOME "\x1b[2J" +#define cEOL "\x1b[0K" +#define CURSOR_HIDE "\x1b[?25l" +#define CURSOR_SHOW "\x1b[?25h" + +/************************ + * Debug & error macros * + ************************/ + +/* Just print stuff to the appropriate stream. */ + +#ifdef MESSAGES_TO_STDOUT +# define SAYF(x...) printf(x) +#else +# define SAYF(x...) fprintf(stderr, x) +#endif /* ^MESSAGES_TO_STDOUT */ + +/* Show a prefixed warning. */ + +#define WARNF(x...) do { \ + SAYF(cYEL "[!] " cBRI "WARNING: " cRST x); \ + SAYF(cRST "\n"); \ + } while (0) + +/* Show a prefixed "doing something" message. */ + +#define ACTF(x...) do { \ + SAYF(cLBL "[*] " cRST x); \ + SAYF(cRST "\n"); \ + } while (0) + +/* Show a prefixed "success" message. */ + +#define OKF(x...) do { \ + SAYF(cLGN "[+] " cRST x); \ + SAYF(cRST "\n"); \ + } while (0) + +/* Show a prefixed fatal error message (not used in afl). */ + +#define BADF(x...) do { \ + SAYF(cLRD "\n[-] " cRST x); \ + SAYF(cRST "\n"); \ + } while (0) + +/* Die with a verbose non-OS fatal error message. */ + +#define FATAL(x...) do { \ + SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ + cBRI x); \ + SAYF(cLRD "\n Location : " cRST "%s(), %s:%u\n\n", \ + __FUNCTION__, __FILE__, __LINE__); \ + exit(1); \ + } while (0) + +/* Die by calling abort() to provide a core dump. */ + +#define ABORT(x...) do { \ + SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \ + cBRI x); \ + SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n\n", \ + __FUNCTION__, __FILE__, __LINE__); \ + abort(); \ + } while (0) + +/* Die while also including the output of perror(). */ + +#define PFATAL(x...) do { \ + fflush(stdout); \ + SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] SYSTEM ERROR : " \ + cBRI x); \ + SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n", \ + __FUNCTION__, __FILE__, __LINE__); \ + SAYF(cLRD " OS message : " cRST "%s\n", strerror(errno)); \ + exit(1); \ + } while (0) + +/* Die with FAULT() or PFAULT() depending on the value of res (used to + interpret different failure modes for read(), write(), etc). */ + +#define RPFATAL(res, x...) do { \ + if (res < 0) PFATAL(x); else FATAL(x); \ + } while (0) + +/* Error-checking versions of read() and write() that call RPFATAL() as + appropriate. */ + +#define ck_write(fd, buf, len, fn) do { \ + u32 _len = (len); \ + s32 _res = write(fd, buf, _len); \ + if (_res != _len) RPFATAL(_res, "Short write to %s", fn); \ + } while (0) + +#define ck_read(fd, buf, len, fn) do { \ + u32 _len = (len); \ + s32 _res = read(fd, buf, _len); \ + if (_res != _len) RPFATAL(_res, "Short read from %s", fn); \ + } while (0) + +#endif /* ! _HAVE_DEBUG_H */ diff --git a/instrument/distance_calculator/.clang-format b/instrument/distance_calculator/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..76a21c02743a97782c6b844dfedf05c3193aecd6 --- /dev/null +++ b/instrument/distance_calculator/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: Google +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignOperands: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 100 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/instrument/distance_calculator/CMakeLists.txt b/instrument/distance_calculator/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..320492fab080bfe5eec0d96c9d81631215eca576 --- /dev/null +++ b/instrument/distance_calculator/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.10) +project(distance_calculator) + +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE "Release" CACHE + STRING "Choose the type of build." FORCE) +endif() +set(CMAKE_CXX_FLAGS "-Wall -Wextra") +set(CMAKE_CXX_FLAGS_DEBUG "-g") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -march=native") + + +find_package(Boost + REQUIRED + COMPONENTS program_options graph regex + ) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(distance_calculator main.cpp) +target_link_libraries(distance_calculator ${Boost_LIBRARIES}) diff --git a/instrument/distance_calculator/CMakeSettings.json b/instrument/distance_calculator/CMakeSettings.json new file mode 100644 index 0000000000000000000000000000000000000000..cf1cb96900dcfd195a87c6c02bee1f9b8c0bb1ae --- /dev/null +++ b/instrument/distance_calculator/CMakeSettings.json @@ -0,0 +1,16 @@ +{ + // 请参阅 https://go.microsoft.com//fwlink//?linkid=834763 了解有关此文件的详细信息。 + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v", + "ctestCommandArgs": "" + } + ] +} \ No newline at end of file diff --git a/instrument/distance_calculator/main.cpp b/instrument/distance_calculator/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10b5c5c40eeb286330365eb96b1ae35d861dd441 --- /dev/null +++ b/instrument/distance_calculator/main.cpp @@ -0,0 +1,328 @@ +/** + * This is a C++ port of distance.py from + * https://github.com/aflgo/aflgo/blob/master/scripts/distance.py + * + * Loris Reiff + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace po = boost::program_options; +namespace bo = boost; +using std::cout; +using std::cerr; +using std::exception; +using std::unordered_map; + +struct Vertex {//�� + std::string name, label, shape; +}; + +struct Edge {//�� + std::string label; +}; +typedef bo::property graph_p; +typedef bo::adjacency_list graph_t;//���ڱ߻�� +typedef bo::graph_traits::vertex_descriptor vertex_desc; + +static bool is_cg; + +static inline std::string node_name(const std::string &name) { + if (is_cg) { + return "{" + name + "}"; + } else { + return "{" + name + ":"; + } +} + +std::vector find_nodes(const graph_t &G, const std::string &name){ + std::string n_name = node_name(name); + // memoization + static unordered_map> mem; + auto ver_itr = mem.find(n_name); + if (ver_itr != mem.end()) return ver_itr->second; + + std::vector ret; + bo::graph_traits::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi) { + if(G[*vi].label.find(n_name) != std::string::npos) { + ret.push_back(*vi); + } + } + mem[n_name] = ret; + return ret; +} + +// for testing +vertex_desc _get_ver(const graph_t &G, const std::string &name){ + bo::graph_traits::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi) { + if(G[*vi].name.find(name) != std::string::npos) { + return *vi; + } + } + return -1; +} + +inline void init_distances_from(const graph_t &G, vertex_desc from, std::vector &dists) { + auto dist_pmap = bo::make_iterator_property_map(dists.begin(), get(bo::vertex_index, G)); + auto vis = bo::make_bfs_visitor(bo::record_distances(dist_pmap, bo::on_tree_edge())); + bo::breadth_first_search(G, from, bo::visitor(vis)); +} + +void distance( + const graph_t &G, + const std::string &name, + const std::vector &targets, + std::ofstream &out, + unordered_map &bb_distance +) { + if (not is_cg and bb_distance.find(name) != bb_distance.end()) { + out << name << "," << bo::lexical_cast(10 * bb_distance[name]) << "\n"; + return; + } + + double distance = -1; + for (vertex_desc n : find_nodes(G, name)) { + std::vector distances(bo::num_vertices(G), 0); + init_distances_from(G, n, distances); + + double d = 0.0; + unsigned i = 0; + if (is_cg) { + for (vertex_desc t : targets) { + auto shortest = distances[t]; // shortest distance from n to t + if (shortest == 0 and n != t) continue; // not reachable + d += 1.0 / (1.0 + static_cast(shortest)); + ++i; + } + } else { + for (auto &bb_d_entry : bb_distance) { + double di = 0.0; + unsigned ii = 0; + for (auto t : find_nodes(G, bb_d_entry.first)) { + auto shortest = distances[t]; // shortest distance from n to t + if (shortest == 0 and n != t) continue; // not reachable + di += 1.0 / (1.0 + 10 * bb_d_entry.second + static_cast(shortest)); + ++ii; + } + if (ii != 0) { + d += di / static_cast(ii); + ++i; + } + } + } + double tmp = static_cast(i) / d; + if (d != 0 and (distance == -1 or distance > tmp)) { + distance = tmp; + } + } + + if (distance != -1) { + out << name << "," << bo::lexical_cast(distance) << "\n"; + } +} + +std::vector cg_calculation( + graph_t &G, + std::ifstream &target_stream +) { + cout << "Loading targets..\n"; + std::vector targets; + for (std::string line; getline(target_stream, line); ) { + bo::trim(line); + for (auto t : find_nodes(G, line)) { + targets.push_back(t); + } + } + if (targets.empty()) { + cout << "No targets available\n"; + exit(0); + } + return targets; +} + +std::vector cfg_calculation( + graph_t &G, + std::ifstream &targets_stream, + std::ifstream &cg_distance_stream, + std::ifstream &cg_callsites_stream, + unordered_map &cg_distance, + unordered_map &bb_distance +) { + std::vector targets; + + for (std::string line; getline(cg_distance_stream, line); ) { + bo::trim(line); + std::vector splits; + std::vector split; + bo::algorithm::split(split, line, bo::is_any_of(","));; + std::string st1; + for(int i=0;i=1){ + st1+=','; + } + st1+=split[i]; + } + splits.push_back(st1); + splits.push_back(split[split.size()-1]); + assert(splits.size() == 2); + cg_distance[splits[0]] = std::stod(splits[1]); + } + if (cg_distance.empty()) { + cerr << "Call graph distance file is empty.\n"; + exit(0); + } + + + for (std::string line; getline(cg_callsites_stream, line); ) { + bo::trim(line); + std::vector splits; + std::vector split; + bo::algorithm::split(split, line, bo::is_any_of(","));; + std::string st1; + for(int i=1;i cg_distance[splits[1]]) { + bb_distance[splits[0]] = cg_distance[splits[1]]; + } + } else { + bb_distance[splits[0]] = cg_distance[splits[1]]; + } + } + } + } + + cout << "Adding target BBs (if any)..\n"; + for (std::string line; getline(targets_stream, line); ) { + bo::trim(line); + std::vector splits; + bo::algorithm::split(splits, line, bo::is_any_of("/"));; + size_t found = line.find_last_of('/'); + if (found != std::string::npos) + line = line.substr(found+1); + if (not find_nodes(G, splits[0]).empty()) { + bb_distance[line] = 0.0; + cout << "Added target BB " << line << "!\n"; + } + } + return targets; +} + +std::ifstream open_file(const std::string &filename) { + std::ifstream filestream(filename); + if (not filestream) { + cerr << "Error: " << strerror(errno) << ": " << filename << "\n"; + exit(1); + } + return filestream; +} + +int main(int argc, char *argv[]) { + po::variables_map vm; + try { + po::options_description desc("AFLGo distance calculator Port"); + desc.add_options() + ("help,h", "produce help message") + ("dot,d", po::value()->required(), "Path to dot-file representing the " + "graph.") + ("targets,t", po::value()->required(), "Path to file specifying Target" + " nodes.") + ("out,o", po::value()->required(), "Path to output file containing " + "distance for each node.") + ("names,n", po::value()->required(), "Path to file containing name for" + " each node.") + ("cg_distance,c", po::value(), "Path to file containing call graph " + "distance.") + ("cg_callsites,s", po::value(), "Path to file containing mapping " + "between basic blocks and called " + "functions.") + ; + + po::store(po::parse_command_line(argc, argv, desc), vm); + if (vm.count("help")) { + cout << desc << "\n"; + return 0; + } + po::notify(vm); + } + catch(exception& e) { + cerr << "error: " << e.what() << "\n"; + return 1; + } + catch(...) { + cerr << "Exception of unknown type!\n"; + } + + std::ifstream dot = open_file(vm["dot"].as()); + cout << "Parsing " << vm["dot"].as() << " ..\n"; + graph_t graph(0); + bo::dynamic_properties dp(bo::ignore_other_properties); + dp.property("node_id", get(&Vertex::name, graph)); + dp.property("label", get(&Vertex::label, graph)); + dp.property("shape", get(&Vertex::shape, graph)); + dp.property("label", get(&Edge::label, graph)); + boost::ref_property_map gname(get_property(graph, bo::graph_name)); + dp.property("label", gname); + + if (!read_graphviz(dot, graph, dp)) { + cerr << "Error while parsing " << vm["dot"].as() << std::endl; + return 1; + } + is_cg = get_property(graph, bo::graph_name).find("Call graph") != std::string::npos; + cout << "Working on " << (is_cg ? "callgraph" : "control flow graph") << "\n"; + + std::ifstream targets_stream = open_file(vm["targets"].as()); + std::ifstream names = open_file(vm["names"].as()); + std::vector targets; + unordered_map cg_distance; + unordered_map bb_distance; + + if (is_cg) { + targets = cg_calculation(graph, targets_stream); + } else { + if (not vm.count("cg_distance")) { + cerr << "error: the required argument for option '--cg_distance' is missing\n"; + exit(1); + } + if (not vm.count("cg_callsites")) { + cerr << "error: the required argument for option '--cg_callsites' is missing\n"; + exit(1); + } + std::ifstream cg_distance_stream = open_file(vm["cg_distance"].as()); + std::ifstream cg_callsites_stream = open_file(vm["cg_callsites"].as()); + + std::vector splits; + bo::algorithm::split(splits, vm["dot"].as(), bo::is_any_of("."));; + std::string &caller = splits.end()[-2]; + cout << "Loading cg_distance for function '" << caller << "'..\n"; + targets = cfg_calculation(graph, targets_stream, cg_distance_stream, + cg_callsites_stream, cg_distance, bb_distance); + } + + cout << "Calculating distance..\n"; + std::ofstream outstream(vm["out"].as()); + for (std::string line; getline(names, line); ) { + bo::trim(line); + distance(graph, line, targets, outstream, bb_distance); + } + + return 0; +} diff --git a/instrument/distance_calculator/out/build/x64-Debug/.cmake/api/v1/query/client-MicrosoftVS/query.json b/instrument/distance_calculator/out/build/x64-Debug/.cmake/api/v1/query/client-MicrosoftVS/query.json new file mode 100644 index 0000000000000000000000000000000000000000..308f68dd8c5fa3963de18ea6db6d9b5c0842f16b --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/.cmake/api/v1/query/client-MicrosoftVS/query.json @@ -0,0 +1 @@ +{"requests":[{"kind":"cache","version":2},{"kind":"cmakeFiles","version":1},{"kind":"codemodel","version":2}]} \ No newline at end of file diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeCache.txt b/instrument/distance_calculator/out/build/x64-Debug/CMakeCache.txt new file mode 100644 index 0000000000000000000000000000000000000000..71c910bbf2ea4648f4e77fa1dbda36aed301eafa --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeCache.txt @@ -0,0 +1,370 @@ +# This is the CMakeCache file. +# For build in directory: f:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug +# It was generated by CMake: E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//The directory containing a CMake configuration file for Boost. +Boost_DIR:PATH=Boost_DIR-NOTFOUND + +//Boost graph library (debug) +Boost_GRAPH_LIBRARY_DEBUG:FILEPATH=Boost_GRAPH_LIBRARY_DEBUG-NOTFOUND + +//Boost graph library (release) +Boost_GRAPH_LIBRARY_RELEASE:FILEPATH=Boost_GRAPH_LIBRARY_RELEASE-NOTFOUND + +//Path to a file. +Boost_INCLUDE_DIR:PATH=Boost_INCLUDE_DIR-NOTFOUND + +//Boost program_options library (debug) +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG:FILEPATH=Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG-NOTFOUND + +//Boost program_options library (release) +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:FILEPATH=Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE-NOTFOUND + +//Boost regex library (debug) +Boost_REGEX_LIBRARY_DEBUG:FILEPATH=Boost_REGEX_LIBRARY_DEBUG-NOTFOUND + +//Boost regex library (release) +Boost_REGEX_LIBRARY_RELEASE:FILEPATH=Boost_REGEX_LIBRARY_RELEASE-NOTFOUND + +//Choose the type of build, options are: None Debug Release RelWithDebInfo +// MinSizeRel ... +CMAKE_BUILD_TYPE:STRING=Debug + +//No help, variable specified on the command line. +CMAKE_CXX_COMPILER:FILEPATH=E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe + +//Flags used by the CXX compiler during all build types. +CMAKE_CXX_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3 /GR /EHsc + +//Flags used by the CXX compiler during DEBUG builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=/MDd /Zi /Ob0 /Od /RTC1 + +//Flags used by the CXX compiler during MINSIZEREL builds. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=/MD /O1 /Ob1 /DNDEBUG + +//Flags used by the CXX compiler during RELEASE builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG + +//Flags used by the CXX compiler during RELWITHDEBINFO builds. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=/MD /Zi /O2 /Ob1 /DNDEBUG + +//Libraries linked by default with all C++ applications. +CMAKE_CXX_STANDARD_LIBRARIES:STRING=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib + +//No help, variable specified on the command line. +CMAKE_C_COMPILER:FILEPATH=E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3 + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=/MDd /Zi /Ob0 /Od /RTC1 + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=/MD /O1 /Ob1 /DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=/MD /Zi /O2 /Ob1 /DNDEBUG + +//Libraries linked by default with all C applications. +CMAKE_C_STANDARD_LIBRARIES:STRING=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib + +//Flags used by the linker during all build types. +CMAKE_EXE_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during DEBUG builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during MINSIZEREL builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during RELEASE builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during RELWITHDEBINFO builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//No help, variable specified on the command line. +CMAKE_INSTALL_PREFIX:PATH=F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/install/x64-Debug + +//Path to a program. +CMAKE_LINKER:FILEPATH=E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/link.exe + +//make program +CMAKE_MAKE_PROGRAM:FILEPATH=E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe + +//Flags used by the linker during the creation of modules during +// all build types. +CMAKE_MODULE_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of modules during +// DEBUG builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during the creation of modules during +// MINSIZEREL builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of modules during +// RELEASE builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of modules during +// RELWITHDEBINFO builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//Path to a program. +CMAKE_MT:FILEPATH=E:/Windows Kits/10/bin/10.0.18362.0/x64/mt.exe + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=distance_calculator + +//RC compiler +CMAKE_RC_COMPILER:FILEPATH=E:/Windows Kits/10/bin/10.0.18362.0/x64/rc.exe + +//Flags for Windows Resource Compiler during all build types. +CMAKE_RC_FLAGS:STRING=-DWIN32 + +//Flags for Windows Resource Compiler during DEBUG builds. +CMAKE_RC_FLAGS_DEBUG:STRING=-D_DEBUG + +//Flags for Windows Resource Compiler during MINSIZEREL builds. +CMAKE_RC_FLAGS_MINSIZEREL:STRING= + +//Flags for Windows Resource Compiler during RELEASE builds. +CMAKE_RC_FLAGS_RELEASE:STRING= + +//Flags for Windows Resource Compiler during RELWITHDEBINFO builds. +CMAKE_RC_FLAGS_RELWITHDEBINFO:STRING= + +//Flags used by the linker during the creation of shared libraries +// during all build types. +CMAKE_SHARED_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of shared libraries +// during DEBUG builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during the creation of shared libraries +// during MINSIZEREL builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of shared libraries +// during RELEASE builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of shared libraries +// during RELWITHDEBINFO builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries +// during all build types. +CMAKE_STATIC_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of static libraries +// during DEBUG builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of static libraries +// during MINSIZEREL builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELEASE builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELWITHDEBINFO builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Value Computed by CMake +distance_calculator_BINARY_DIR:STATIC=F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug + +//Value Computed by CMake +distance_calculator_SOURCE_DIR:STATIC=F:/大四上/毕设/代码阅读/aflgo/distance_calculator + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: Boost_DIR +Boost_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_GRAPH_LIBRARY_DEBUG +Boost_GRAPH_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_GRAPH_LIBRARY_RELEASE +Boost_GRAPH_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG +Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_REGEX_LIBRARY_DEBUG +Boost_REGEX_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: Boost_REGEX_LIBRARY_RELEASE +Boost_REGEX_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=f:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=19112601 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cpack.exe +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/ctest.exe +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_STANDARD_LIBRARIES +CMAKE_CXX_STANDARD_LIBRARIES-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_STANDARD_LIBRARIES +CMAKE_C_STANDARD_LIBRARIES-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=Unknown +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Ninja +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=F:/大四上/毕设/代码阅读/aflgo/distance_calculator +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MT +CMAKE_MT-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_COMPILER +CMAKE_RC_COMPILER-ADVANCED:INTERNAL=1 +CMAKE_RC_COMPILER_WORKS:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS +CMAKE_RC_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_DEBUG +CMAKE_RC_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_MINSIZEREL +CMAKE_RC_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_RELEASE +CMAKE_RC_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_RELWITHDEBINFO +CMAKE_RC_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.16 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 + diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCCompiler.cmake b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCCompiler.cmake new file mode 100644 index 0000000000000000000000000000000000000000..4b59b8df48576ae1596a9960dfdf50c41f138973 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCCompiler.cmake @@ -0,0 +1,76 @@ +set(CMAKE_C_COMPILER "E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe") +set(CMAKE_C_COMPILER_ARG1 "") +set(CMAKE_C_COMPILER_ID "MSVC") +set(CMAKE_C_COMPILER_VERSION "19.25.28612.0") +set(CMAKE_C_COMPILER_VERSION_INTERNAL "") +set(CMAKE_C_COMPILER_WRAPPER "") +set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "90") +set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_std_99;c_std_11;c_function_prototypes;c_variadic_macros") +set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") +set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_variadic_macros") +set(CMAKE_C11_COMPILE_FEATURES "c_std_11") + +set(CMAKE_C_PLATFORM_ID "Windows") +set(CMAKE_C_SIMULATE_ID "") +set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") +set(CMAKE_C_SIMULATE_VERSION "") +set(CMAKE_C_COMPILER_ARCHITECTURE_ID x64) +set(MSVC_C_ARCHITECTURE_ID x64) + +set(CMAKE_AR "") +set(CMAKE_C_COMPILER_AR "") +set(CMAKE_RANLIB "") +set(CMAKE_C_COMPILER_RANLIB "") +set(CMAKE_LINKER "E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/link.exe") +set(CMAKE_MT "E:/Windows Kits/10/bin/10.0.18362.0/x64/mt.exe") +set(CMAKE_COMPILER_IS_GNUCC ) +set(CMAKE_C_COMPILER_LOADED 1) +set(CMAKE_C_COMPILER_WORKS TRUE) +set(CMAKE_C_ABI_COMPILED TRUE) +set(CMAKE_COMPILER_IS_MINGW ) +set(CMAKE_COMPILER_IS_CYGWIN ) +if(CMAKE_COMPILER_IS_CYGWIN) + set(CYGWIN 1) + set(UNIX 1) +endif() + +set(CMAKE_C_COMPILER_ENV_VAR "CC") + +if(CMAKE_COMPILER_IS_MINGW) + set(MINGW 1) +endif() +set(CMAKE_C_COMPILER_ID_RUN 1) +set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) +set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_C_LINKER_PREFERENCE 10) + +# Save compiler ABI information. +set(CMAKE_C_SIZEOF_DATA_PTR "8") +set(CMAKE_C_COMPILER_ABI "") +set(CMAKE_C_LIBRARY_ARCHITECTURE "") + +if(CMAKE_C_SIZEOF_DATA_PTR) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_C_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") +endif() + +if(CMAKE_C_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "") +endif() + +set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "注意: 包含文件: ") +if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) + set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") +endif() + + + + + +set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "") +set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") +set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "") +set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCXXCompiler.cmake b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCXXCompiler.cmake new file mode 100644 index 0000000000000000000000000000000000000000..01a92c58255e643aa62ebcd897ed080fba6992ae --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeCXXCompiler.cmake @@ -0,0 +1,88 @@ +set(CMAKE_CXX_COMPILER "E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe") +set(CMAKE_CXX_COMPILER_ARG1 "") +set(CMAKE_CXX_COMPILER_ID "MSVC") +set(CMAKE_CXX_COMPILER_VERSION "19.25.28612.0") +set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") +set(CMAKE_CXX_COMPILER_WRAPPER "") +set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14") +set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") +set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") +set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") +set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") +set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") +set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") + +set(CMAKE_CXX_PLATFORM_ID "Windows") +set(CMAKE_CXX_SIMULATE_ID "") +set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") +set(CMAKE_CXX_SIMULATE_VERSION "") +set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID x64) +set(MSVC_CXX_ARCHITECTURE_ID x64) + +set(CMAKE_AR "") +set(CMAKE_CXX_COMPILER_AR "") +set(CMAKE_RANLIB "") +set(CMAKE_CXX_COMPILER_RANLIB "") +set(CMAKE_LINKER "E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/link.exe") +set(CMAKE_MT "E:/Windows Kits/10/bin/10.0.18362.0/x64/mt.exe") +set(CMAKE_COMPILER_IS_GNUCXX ) +set(CMAKE_CXX_COMPILER_LOADED 1) +set(CMAKE_CXX_COMPILER_WORKS TRUE) +set(CMAKE_CXX_ABI_COMPILED TRUE) +set(CMAKE_COMPILER_IS_MINGW ) +set(CMAKE_COMPILER_IS_CYGWIN ) +if(CMAKE_COMPILER_IS_CYGWIN) + set(CYGWIN 1) + set(UNIX 1) +endif() + +set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") + +if(CMAKE_COMPILER_IS_MINGW) + set(MINGW 1) +endif() +set(CMAKE_CXX_COMPILER_ID_RUN 1) +set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP) +set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) + +foreach (lang C OBJC OBJCXX) + if (CMAKE_${lang}_COMPILER_ID_RUN) + foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) + list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) + endforeach() + endif() +endforeach() + +set(CMAKE_CXX_LINKER_PREFERENCE 30) +set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) + +# Save compiler ABI information. +set(CMAKE_CXX_SIZEOF_DATA_PTR "8") +set(CMAKE_CXX_COMPILER_ABI "") +set(CMAKE_CXX_LIBRARY_ARCHITECTURE "") + +if(CMAKE_CXX_SIZEOF_DATA_PTR) + set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") +endif() + +if(CMAKE_CXX_COMPILER_ABI) + set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") +endif() + +if(CMAKE_CXX_LIBRARY_ARCHITECTURE) + set(CMAKE_LIBRARY_ARCHITECTURE "") +endif() + +set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "注意: 包含文件: ") +if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) + set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") +endif() + + + + + +set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "") +set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") +set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "") +set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_C.bin b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_C.bin new file mode 100644 index 0000000000000000000000000000000000000000..e56cd29b4fa964708c4f0dda1ccb989bc3c37da3 Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_C.bin differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_CXX.bin b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_CXX.bin new file mode 100644 index 0000000000000000000000000000000000000000..5dd5c4a1964f98345d800bcd65369ac87a53334b Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeDetermineCompilerABI_CXX.bin differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeRCCompiler.cmake b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeRCCompiler.cmake new file mode 100644 index 0000000000000000000000000000000000000000..888bf682d91f02fab65147a7114cc0cec01bca8d --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeRCCompiler.cmake @@ -0,0 +1,6 @@ +set(CMAKE_RC_COMPILER "E:/Windows Kits/10/bin/10.0.18362.0/x64/rc.exe") +set(CMAKE_RC_COMPILER_ARG1 "") +set(CMAKE_RC_COMPILER_LOADED 1) +set(CMAKE_RC_SOURCE_FILE_EXTENSIONS rc;RC) +set(CMAKE_RC_OUTPUT_EXTENSION .res) +set(CMAKE_RC_COMPILER_ENV_VAR "RC") diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeSystem.cmake b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeSystem.cmake new file mode 100644 index 0000000000000000000000000000000000000000..aed83cab045ffb8c1bf432ea60a72aeead211e07 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CMakeSystem.cmake @@ -0,0 +1,15 @@ +set(CMAKE_HOST_SYSTEM "Windows-10.0.18363") +set(CMAKE_HOST_SYSTEM_NAME "Windows") +set(CMAKE_HOST_SYSTEM_VERSION "10.0.18363") +set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64") + + + +set(CMAKE_SYSTEM "Windows-10.0.18363") +set(CMAKE_SYSTEM_NAME "Windows") +set(CMAKE_SYSTEM_VERSION "10.0.18363") +set(CMAKE_SYSTEM_PROCESSOR "AMD64") + +set(CMAKE_CROSSCOMPILING "FALSE") + +set(CMAKE_SYSTEM_LOADED 1) diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.c b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.c new file mode 100644 index 0000000000000000000000000000000000000000..2d12d8f814e4024a6a39ff0d6d2c8bc03aa1ba56 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.c @@ -0,0 +1,671 @@ +#ifdef __cplusplus +# error "A C++ compiler has been selected for C." +#endif + +#if defined(__18CXX) +# define ID_VOID_MAIN +#endif +#if defined(__CLASSIC_C__) +/* cv-qualifiers did not exist in K&R C */ +# define const +# define volatile +#endif + + +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + +#if defined(__INTEL_COMPILER) || defined(__ICC) +# define COMPILER_ID "Intel" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# if defined(__GNUC__) +# define SIMULATE_ID "GNU" +# endif + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# if defined(__INTEL_COMPILER_UPDATE) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# else +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# endif +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# if defined(__GNUC__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUC__) +# elif defined(__GNUG__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(__PATHCC__) +# define COMPILER_ID "PathScale" +# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# if defined(__PATHCC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# endif + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) + +#elif defined(__BORLANDC__) +# define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) + +#elif defined(__WATCOMC__) && __WATCOMC__ < 1200 +# define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__WATCOMC__) +# define COMPILER_ID "OpenWatcom" + /* __WATCOMC__ = VVRP + 1100 */ +# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__SUNPRO_C) +# define COMPILER_ID "SunPro" +# if __SUNPRO_C >= 0x5100 + /* __SUNPRO_C = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# endif + +#elif defined(__HP_cc) +# define COMPILER_ID "HP" + /* __HP_cc = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) + +#elif defined(__DECC) +# define COMPILER_ID "Compaq" + /* __DECC_VER = VVRRTPPPP */ +# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) +# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) +# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) + +#elif defined(__IBMC__) && defined(__COMPILER_VER__) +# define COMPILER_ID "zOS" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__ibmxl__) && defined(__clang__) +# define COMPILER_ID "XLClang" +# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) +# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) +# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) +# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) + + +#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800 +# define COMPILER_ID "XL" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800 +# define COMPILER_ID "VisualAge" + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) + +#elif defined(__PGI) +# define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif + +#elif defined(_CRAYC) +# define COMPILER_ID "Cray" +# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) +# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) + +#elif defined(__TI_COMPILER_VERSION__) +# define COMPILER_ID "TI" + /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ +# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) + +#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) +# define COMPILER_ID "Fujitsu" + +#elif defined(__ghs__) +# define COMPILER_ID "GHS" +/* __GHS_VERSION_NUMBER = VVVVRP */ +# ifdef __GHS_VERSION_NUMBER +# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) +# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) +# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) +# endif + +#elif defined(__TINYC__) +# define COMPILER_ID "TinyCC" + +#elif defined(__BCC__) +# define COMPILER_ID "Bruce" + +#elif defined(__SCO_VERSION__) +# define COMPILER_ID "SCO" + +#elif defined(__ARMCC_VERSION) && !defined(__clang__) +# define COMPILER_ID "ARMCC" +#if __ARMCC_VERSION >= 1000000 + /* __ARMCC_VERSION = VRRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#else + /* __ARMCC_VERSION = VRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#endif + + +#elif defined(__clang__) && defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) + +#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) +# define COMPILER_ID "ARMClang" + # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) +# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) + +#elif defined(__clang__) +# define COMPILER_ID "Clang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif + +#elif defined(__GNUC__) +# define COMPILER_ID "GNU" +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# if defined(__GNUC_MINOR__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(_MSC_VER) +# define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif + +#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) +# define COMPILER_ID "ADSP" +#if defined(__VISUALDSPVERSION__) + /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ +# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +#endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# define COMPILER_ID "IAR" +# if defined(__VER__) && defined(__ICCARM__) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) +# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) +# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) +# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) +# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# endif + +#elif defined(__SDCC_VERSION_MAJOR) || defined(SDCC) +# define COMPILER_ID "SDCC" +# if defined(__SDCC_VERSION_MAJOR) +# define COMPILER_VERSION_MAJOR DEC(__SDCC_VERSION_MAJOR) +# define COMPILER_VERSION_MINOR DEC(__SDCC_VERSION_MINOR) +# define COMPILER_VERSION_PATCH DEC(__SDCC_VERSION_PATCH) +# else + /* SDCC = VRP */ +# define COMPILER_VERSION_MAJOR DEC(SDCC/100) +# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) +# define COMPILER_VERSION_PATCH DEC(SDCC % 10) +# endif + + +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID "HP" + +#else /* unknown compiler */ +# define COMPILER_ID "" +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; +#ifdef SIMULATE_ID +char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; +#endif + +#ifdef __QNXNTO__ +char const* qnxnto = "INFO" ":" "qnxnto[]"; +#endif + +#if defined(__CRAYXE) || defined(__CRAYXC) +char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; +#endif + +#define STRINGIFY_HELPER(X) #X +#define STRINGIFY(X) STRINGIFY_HELPER(X) + +/* Identify known platforms by name. */ +#if defined(__linux) || defined(__linux__) || defined(linux) +# define PLATFORM_ID "Linux" + +#elif defined(__CYGWIN__) +# define PLATFORM_ID "Cygwin" + +#elif defined(__MINGW32__) +# define PLATFORM_ID "MinGW" + +#elif defined(__APPLE__) +# define PLATFORM_ID "Darwin" + +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +# define PLATFORM_ID "Windows" + +#elif defined(__FreeBSD__) || defined(__FreeBSD) +# define PLATFORM_ID "FreeBSD" + +#elif defined(__NetBSD__) || defined(__NetBSD) +# define PLATFORM_ID "NetBSD" + +#elif defined(__OpenBSD__) || defined(__OPENBSD) +# define PLATFORM_ID "OpenBSD" + +#elif defined(__sun) || defined(sun) +# define PLATFORM_ID "SunOS" + +#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) +# define PLATFORM_ID "AIX" + +#elif defined(__hpux) || defined(__hpux__) +# define PLATFORM_ID "HP-UX" + +#elif defined(__HAIKU__) +# define PLATFORM_ID "Haiku" + +#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) +# define PLATFORM_ID "BeOS" + +#elif defined(__QNX__) || defined(__QNXNTO__) +# define PLATFORM_ID "QNX" + +#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) +# define PLATFORM_ID "Tru64" + +#elif defined(__riscos) || defined(__riscos__) +# define PLATFORM_ID "RISCos" + +#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) +# define PLATFORM_ID "SINIX" + +#elif defined(__UNIX_SV__) +# define PLATFORM_ID "UNIX_SV" + +#elif defined(__bsdos__) +# define PLATFORM_ID "BSDOS" + +#elif defined(_MPRAS) || defined(MPRAS) +# define PLATFORM_ID "MP-RAS" + +#elif defined(__osf) || defined(__osf__) +# define PLATFORM_ID "OSF1" + +#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) +# define PLATFORM_ID "SCO_SV" + +#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) +# define PLATFORM_ID "ULTRIX" + +#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) +# define PLATFORM_ID "Xenix" + +#elif defined(__WATCOMC__) +# if defined(__LINUX__) +# define PLATFORM_ID "Linux" + +# elif defined(__DOS__) +# define PLATFORM_ID "DOS" + +# elif defined(__OS2__) +# define PLATFORM_ID "OS2" + +# elif defined(__WINDOWS__) +# define PLATFORM_ID "Windows3x" + +# else /* unknown platform */ +# define PLATFORM_ID +# endif + +#elif defined(__INTEGRITY) +# if defined(INT_178B) +# define PLATFORM_ID "Integrity178" + +# else /* regular Integrity */ +# define PLATFORM_ID "Integrity" +# endif + +#else /* unknown platform */ +# define PLATFORM_ID + +#endif + +/* For windows compilers MSVC and Intel we can determine + the architecture of the compiler being used. This is because + the compilers do not have flags that can change the architecture, + but rather depend on which compiler is being used +*/ +#if defined(_WIN32) && defined(_MSC_VER) +# if defined(_M_IA64) +# define ARCHITECTURE_ID "IA64" + +# elif defined(_M_X64) || defined(_M_AMD64) +# define ARCHITECTURE_ID "x64" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# elif defined(_M_ARM64) +# define ARCHITECTURE_ID "ARM64" + +# elif defined(_M_ARM) +# if _M_ARM == 4 +# define ARCHITECTURE_ID "ARMV4I" +# elif _M_ARM == 5 +# define ARCHITECTURE_ID "ARMV5I" +# else +# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) +# endif + +# elif defined(_M_MIPS) +# define ARCHITECTURE_ID "MIPS" + +# elif defined(_M_SH) +# define ARCHITECTURE_ID "SHx" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__WATCOMC__) +# if defined(_M_I86) +# define ARCHITECTURE_ID "I86" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# if defined(__ICCARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__ICCRX__) +# define ARCHITECTURE_ID "RX" + +# elif defined(__ICCRH850__) +# define ARCHITECTURE_ID "RH850" + +# elif defined(__ICCRL78__) +# define ARCHITECTURE_ID "RL78" + +# elif defined(__ICCRISCV__) +# define ARCHITECTURE_ID "RISCV" + +# elif defined(__ICCAVR__) +# define ARCHITECTURE_ID "AVR" + +# elif defined(__ICC430__) +# define ARCHITECTURE_ID "MSP430" + +# elif defined(__ICCV850__) +# define ARCHITECTURE_ID "V850" + +# elif defined(__ICC8051__) +# define ARCHITECTURE_ID "8051" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__ghs__) +# if defined(__PPC64__) +# define ARCHITECTURE_ID "PPC64" + +# elif defined(__ppc__) +# define ARCHITECTURE_ID "PPC" + +# elif defined(__ARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__x86_64__) +# define ARCHITECTURE_ID "x64" + +# elif defined(__i386__) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif +#else +# define ARCHITECTURE_ID +#endif + +/* Convert integer to decimal digit literals. */ +#define DEC(n) \ + ('0' + (((n) / 10000000)%10)), \ + ('0' + (((n) / 1000000)%10)), \ + ('0' + (((n) / 100000)%10)), \ + ('0' + (((n) / 10000)%10)), \ + ('0' + (((n) / 1000)%10)), \ + ('0' + (((n) / 100)%10)), \ + ('0' + (((n) / 10)%10)), \ + ('0' + ((n) % 10)) + +/* Convert integer to hex digit literals. */ +#define HEX(n) \ + ('0' + ((n)>>28 & 0xF)), \ + ('0' + ((n)>>24 & 0xF)), \ + ('0' + ((n)>>20 & 0xF)), \ + ('0' + ((n)>>16 & 0xF)), \ + ('0' + ((n)>>12 & 0xF)), \ + ('0' + ((n)>>8 & 0xF)), \ + ('0' + ((n)>>4 & 0xF)), \ + ('0' + ((n) & 0xF)) + +/* Construct a string literal encoding the version number components. */ +#ifdef COMPILER_VERSION_MAJOR +char const info_version[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', + COMPILER_VERSION_MAJOR, +# ifdef COMPILER_VERSION_MINOR + '.', COMPILER_VERSION_MINOR, +# ifdef COMPILER_VERSION_PATCH + '.', COMPILER_VERSION_PATCH, +# ifdef COMPILER_VERSION_TWEAK + '.', COMPILER_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct a string literal encoding the internal version number. */ +#ifdef COMPILER_VERSION_INTERNAL +char const info_version_internal[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', + 'i','n','t','e','r','n','a','l','[', + COMPILER_VERSION_INTERNAL,']','\0'}; +#endif + +/* Construct a string literal encoding the version number components. */ +#ifdef SIMULATE_VERSION_MAJOR +char const info_simulate_version[] = { + 'I', 'N', 'F', 'O', ':', + 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', + SIMULATE_VERSION_MAJOR, +# ifdef SIMULATE_VERSION_MINOR + '.', SIMULATE_VERSION_MINOR, +# ifdef SIMULATE_VERSION_PATCH + '.', SIMULATE_VERSION_PATCH, +# ifdef SIMULATE_VERSION_TWEAK + '.', SIMULATE_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; +char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; + + + + +#if !defined(__STDC__) +# if (defined(_MSC_VER) && !defined(__clang__)) \ + || (defined(__ibmxl__) || defined(__IBMC__)) +# define C_DIALECT "90" +# else +# define C_DIALECT +# endif +#elif __STDC_VERSION__ >= 201000L +# define C_DIALECT "11" +#elif __STDC_VERSION__ >= 199901L +# define C_DIALECT "99" +#else +# define C_DIALECT "90" +#endif +const char* info_language_dialect_default = + "INFO" ":" "dialect_default[" C_DIALECT "]"; + +/*--------------------------------------------------------------------------*/ + +#ifdef ID_VOID_MAIN +void main() {} +#else +# if defined(__CLASSIC_C__) +int main(argc, argv) int argc; char *argv[]; +# else +int main(int argc, char* argv[]) +# endif +{ + int require = 0; + require += info_compiler[argc]; + require += info_platform[argc]; + require += info_arch[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif +#ifdef COMPILER_VERSION_INTERNAL + require += info_version_internal[argc]; +#endif +#ifdef SIMULATE_ID + require += info_simulate[argc]; +#endif +#ifdef SIMULATE_VERSION_MAJOR + require += info_simulate_version[argc]; +#endif +#if defined(__CRAYXE) || defined(__CRAYXC) + require += info_cray[argc]; +#endif + require += info_language_dialect_default[argc]; + (void)argv; + return require; +} +#endif diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.obj b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.obj new file mode 100644 index 0000000000000000000000000000000000000000..0401121d5e34d84c3292d31b54ef05a5887adf4f Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.obj differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/cmakeccompilerid.exe b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/cmakeccompilerid.exe new file mode 100644 index 0000000000000000000000000000000000000000..fa8c525660346b789d8f32273fc4e40ea000d808 Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/cmakeccompilerid.exe differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.cpp b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.cpp new file mode 100644 index 0000000000000000000000000000000000000000..52ff6488186710c6066e5c83d94911b02601ce08 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.cpp @@ -0,0 +1,660 @@ +/* This source file must have a .cpp extension so that all C++ compilers + recognize the extension without flags. Borland does not know .cxx for + example. */ +#ifndef __cplusplus +# error "A C compiler has been selected for C++." +#endif + + +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + +#if defined(__COMO__) +# define COMPILER_ID "Comeau" + /* __COMO_VERSION__ = VRR */ +# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) +# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) + +#elif defined(__INTEL_COMPILER) || defined(__ICC) +# define COMPILER_ID "Intel" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# if defined(__GNUC__) +# define SIMULATE_ID "GNU" +# endif + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# if defined(__INTEL_COMPILER_UPDATE) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# else +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# endif +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# if defined(__GNUC__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUC__) +# elif defined(__GNUG__) +# define SIMULATE_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define SIMULATE_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define SIMULATE_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(__PATHCC__) +# define COMPILER_ID "PathScale" +# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# if defined(__PATHCC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# endif + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH DEC(__CODEGEARC_VERSION__ & 0xFFFF) + +#elif defined(__BORLANDC__) +# define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) + +#elif defined(__WATCOMC__) && __WATCOMC__ < 1200 +# define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__WATCOMC__) +# define COMPILER_ID "OpenWatcom" + /* __WATCOMC__ = VVRP + 1100 */ +# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif + +#elif defined(__SUNPRO_CC) +# define COMPILER_ID "SunPro" +# if __SUNPRO_CC >= 0x5100 + /* __SUNPRO_CC = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# endif + +#elif defined(__HP_aCC) +# define COMPILER_ID "HP" + /* __HP_aCC = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) + +#elif defined(__DECCXX) +# define COMPILER_ID "Compaq" + /* __DECCXX_VER = VVRRTPPPP */ +# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) +# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) +# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) + +#elif defined(__IBMCPP__) && defined(__COMPILER_VER__) +# define COMPILER_ID "zOS" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__ibmxl__) && defined(__clang__) +# define COMPILER_ID "XLClang" +# define COMPILER_VERSION_MAJOR DEC(__ibmxl_version__) +# define COMPILER_VERSION_MINOR DEC(__ibmxl_release__) +# define COMPILER_VERSION_PATCH DEC(__ibmxl_modification__) +# define COMPILER_VERSION_TWEAK DEC(__ibmxl_ptf_fix_level__) + + +#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800 +# define COMPILER_ID "XL" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800 +# define COMPILER_ID "VisualAge" + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) + +#elif defined(__PGI) +# define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif + +#elif defined(_CRAYC) +# define COMPILER_ID "Cray" +# define COMPILER_VERSION_MAJOR DEC(_RELEASE_MAJOR) +# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) + +#elif defined(__TI_COMPILER_VERSION__) +# define COMPILER_ID "TI" + /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ +# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) + +#elif defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version) +# define COMPILER_ID "Fujitsu" + +#elif defined(__ghs__) +# define COMPILER_ID "GHS" +/* __GHS_VERSION_NUMBER = VVVVRP */ +# ifdef __GHS_VERSION_NUMBER +# define COMPILER_VERSION_MAJOR DEC(__GHS_VERSION_NUMBER / 100) +# define COMPILER_VERSION_MINOR DEC(__GHS_VERSION_NUMBER / 10 % 10) +# define COMPILER_VERSION_PATCH DEC(__GHS_VERSION_NUMBER % 10) +# endif + +#elif defined(__SCO_VERSION__) +# define COMPILER_ID "SCO" + +#elif defined(__ARMCC_VERSION) && !defined(__clang__) +# define COMPILER_ID "ARMCC" +#if __ARMCC_VERSION >= 1000000 + /* __ARMCC_VERSION = VRRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#else + /* __ARMCC_VERSION = VRPPPP */ + # define COMPILER_VERSION_MAJOR DEC(__ARMCC_VERSION/100000) + # define COMPILER_VERSION_MINOR DEC(__ARMCC_VERSION/10000 % 10) + # define COMPILER_VERSION_PATCH DEC(__ARMCC_VERSION % 10000) +#endif + + +#elif defined(__clang__) && defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) + +#elif defined(__clang__) && defined(__ARMCOMPILER_VERSION) +# define COMPILER_ID "ARMClang" + # define COMPILER_VERSION_MAJOR DEC(__ARMCOMPILER_VERSION/1000000) + # define COMPILER_VERSION_MINOR DEC(__ARMCOMPILER_VERSION/10000 % 100) + # define COMPILER_VERSION_PATCH DEC(__ARMCOMPILER_VERSION % 10000) +# define COMPILER_VERSION_INTERNAL DEC(__ARMCOMPILER_VERSION) + +#elif defined(__clang__) +# define COMPILER_ID "Clang" +# if defined(_MSC_VER) +# define SIMULATE_ID "MSVC" +# endif +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif + +#elif defined(__GNUC__) || defined(__GNUG__) +# define COMPILER_ID "GNU" +# if defined(__GNUC__) +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# else +# define COMPILER_VERSION_MAJOR DEC(__GNUG__) +# endif +# if defined(__GNUC_MINOR__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# endif +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif + +#elif defined(_MSC_VER) +# define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif + +#elif defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) +# define COMPILER_ID "ADSP" +#if defined(__VISUALDSPVERSION__) + /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ +# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +#endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# define COMPILER_ID "IAR" +# if defined(__VER__) && defined(__ICCARM__) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 1000000) +# define COMPILER_VERSION_MINOR DEC(((__VER__) / 1000) % 1000) +# define COMPILER_VERSION_PATCH DEC((__VER__) % 1000) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__) || defined(__ICCV850__) || defined(__ICC8051__)) +# define COMPILER_VERSION_MAJOR DEC((__VER__) / 100) +# define COMPILER_VERSION_MINOR DEC((__VER__) - (((__VER__) / 100)*100)) +# define COMPILER_VERSION_PATCH DEC(__SUBVERSION__) +# define COMPILER_VERSION_INTERNAL DEC(__IAR_SYSTEMS_ICC__) +# endif + + +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID "HP" + +#else /* unknown compiler */ +# define COMPILER_ID "" +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; +#ifdef SIMULATE_ID +char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]"; +#endif + +#ifdef __QNXNTO__ +char const* qnxnto = "INFO" ":" "qnxnto[]"; +#endif + +#if defined(__CRAYXE) || defined(__CRAYXC) +char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]"; +#endif + +#define STRINGIFY_HELPER(X) #X +#define STRINGIFY(X) STRINGIFY_HELPER(X) + +/* Identify known platforms by name. */ +#if defined(__linux) || defined(__linux__) || defined(linux) +# define PLATFORM_ID "Linux" + +#elif defined(__CYGWIN__) +# define PLATFORM_ID "Cygwin" + +#elif defined(__MINGW32__) +# define PLATFORM_ID "MinGW" + +#elif defined(__APPLE__) +# define PLATFORM_ID "Darwin" + +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +# define PLATFORM_ID "Windows" + +#elif defined(__FreeBSD__) || defined(__FreeBSD) +# define PLATFORM_ID "FreeBSD" + +#elif defined(__NetBSD__) || defined(__NetBSD) +# define PLATFORM_ID "NetBSD" + +#elif defined(__OpenBSD__) || defined(__OPENBSD) +# define PLATFORM_ID "OpenBSD" + +#elif defined(__sun) || defined(sun) +# define PLATFORM_ID "SunOS" + +#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) +# define PLATFORM_ID "AIX" + +#elif defined(__hpux) || defined(__hpux__) +# define PLATFORM_ID "HP-UX" + +#elif defined(__HAIKU__) +# define PLATFORM_ID "Haiku" + +#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) +# define PLATFORM_ID "BeOS" + +#elif defined(__QNX__) || defined(__QNXNTO__) +# define PLATFORM_ID "QNX" + +#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) +# define PLATFORM_ID "Tru64" + +#elif defined(__riscos) || defined(__riscos__) +# define PLATFORM_ID "RISCos" + +#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) +# define PLATFORM_ID "SINIX" + +#elif defined(__UNIX_SV__) +# define PLATFORM_ID "UNIX_SV" + +#elif defined(__bsdos__) +# define PLATFORM_ID "BSDOS" + +#elif defined(_MPRAS) || defined(MPRAS) +# define PLATFORM_ID "MP-RAS" + +#elif defined(__osf) || defined(__osf__) +# define PLATFORM_ID "OSF1" + +#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) +# define PLATFORM_ID "SCO_SV" + +#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) +# define PLATFORM_ID "ULTRIX" + +#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) +# define PLATFORM_ID "Xenix" + +#elif defined(__WATCOMC__) +# if defined(__LINUX__) +# define PLATFORM_ID "Linux" + +# elif defined(__DOS__) +# define PLATFORM_ID "DOS" + +# elif defined(__OS2__) +# define PLATFORM_ID "OS2" + +# elif defined(__WINDOWS__) +# define PLATFORM_ID "Windows3x" + +# else /* unknown platform */ +# define PLATFORM_ID +# endif + +#elif defined(__INTEGRITY) +# if defined(INT_178B) +# define PLATFORM_ID "Integrity178" + +# else /* regular Integrity */ +# define PLATFORM_ID "Integrity" +# endif + +#else /* unknown platform */ +# define PLATFORM_ID + +#endif + +/* For windows compilers MSVC and Intel we can determine + the architecture of the compiler being used. This is because + the compilers do not have flags that can change the architecture, + but rather depend on which compiler is being used +*/ +#if defined(_WIN32) && defined(_MSC_VER) +# if defined(_M_IA64) +# define ARCHITECTURE_ID "IA64" + +# elif defined(_M_X64) || defined(_M_AMD64) +# define ARCHITECTURE_ID "x64" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# elif defined(_M_ARM64) +# define ARCHITECTURE_ID "ARM64" + +# elif defined(_M_ARM) +# if _M_ARM == 4 +# define ARCHITECTURE_ID "ARMV4I" +# elif _M_ARM == 5 +# define ARCHITECTURE_ID "ARMV5I" +# else +# define ARCHITECTURE_ID "ARMV" STRINGIFY(_M_ARM) +# endif + +# elif defined(_M_MIPS) +# define ARCHITECTURE_ID "MIPS" + +# elif defined(_M_SH) +# define ARCHITECTURE_ID "SHx" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__WATCOMC__) +# if defined(_M_I86) +# define ARCHITECTURE_ID "I86" + +# elif defined(_M_IX86) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC) +# if defined(__ICCARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__ICCRX__) +# define ARCHITECTURE_ID "RX" + +# elif defined(__ICCRH850__) +# define ARCHITECTURE_ID "RH850" + +# elif defined(__ICCRL78__) +# define ARCHITECTURE_ID "RL78" + +# elif defined(__ICCRISCV__) +# define ARCHITECTURE_ID "RISCV" + +# elif defined(__ICCAVR__) +# define ARCHITECTURE_ID "AVR" + +# elif defined(__ICC430__) +# define ARCHITECTURE_ID "MSP430" + +# elif defined(__ICCV850__) +# define ARCHITECTURE_ID "V850" + +# elif defined(__ICC8051__) +# define ARCHITECTURE_ID "8051" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif + +#elif defined(__ghs__) +# if defined(__PPC64__) +# define ARCHITECTURE_ID "PPC64" + +# elif defined(__ppc__) +# define ARCHITECTURE_ID "PPC" + +# elif defined(__ARM__) +# define ARCHITECTURE_ID "ARM" + +# elif defined(__x86_64__) +# define ARCHITECTURE_ID "x64" + +# elif defined(__i386__) +# define ARCHITECTURE_ID "X86" + +# else /* unknown architecture */ +# define ARCHITECTURE_ID "" +# endif +#else +# define ARCHITECTURE_ID +#endif + +/* Convert integer to decimal digit literals. */ +#define DEC(n) \ + ('0' + (((n) / 10000000)%10)), \ + ('0' + (((n) / 1000000)%10)), \ + ('0' + (((n) / 100000)%10)), \ + ('0' + (((n) / 10000)%10)), \ + ('0' + (((n) / 1000)%10)), \ + ('0' + (((n) / 100)%10)), \ + ('0' + (((n) / 10)%10)), \ + ('0' + ((n) % 10)) + +/* Convert integer to hex digit literals. */ +#define HEX(n) \ + ('0' + ((n)>>28 & 0xF)), \ + ('0' + ((n)>>24 & 0xF)), \ + ('0' + ((n)>>20 & 0xF)), \ + ('0' + ((n)>>16 & 0xF)), \ + ('0' + ((n)>>12 & 0xF)), \ + ('0' + ((n)>>8 & 0xF)), \ + ('0' + ((n)>>4 & 0xF)), \ + ('0' + ((n) & 0xF)) + +/* Construct a string literal encoding the version number components. */ +#ifdef COMPILER_VERSION_MAJOR +char const info_version[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', + COMPILER_VERSION_MAJOR, +# ifdef COMPILER_VERSION_MINOR + '.', COMPILER_VERSION_MINOR, +# ifdef COMPILER_VERSION_PATCH + '.', COMPILER_VERSION_PATCH, +# ifdef COMPILER_VERSION_TWEAK + '.', COMPILER_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct a string literal encoding the internal version number. */ +#ifdef COMPILER_VERSION_INTERNAL +char const info_version_internal[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_', + 'i','n','t','e','r','n','a','l','[', + COMPILER_VERSION_INTERNAL,']','\0'}; +#endif + +/* Construct a string literal encoding the version number components. */ +#ifdef SIMULATE_VERSION_MAJOR +char const info_simulate_version[] = { + 'I', 'N', 'F', 'O', ':', + 's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[', + SIMULATE_VERSION_MAJOR, +# ifdef SIMULATE_VERSION_MINOR + '.', SIMULATE_VERSION_MINOR, +# ifdef SIMULATE_VERSION_PATCH + '.', SIMULATE_VERSION_PATCH, +# ifdef SIMULATE_VERSION_TWEAK + '.', SIMULATE_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + +/* Construct the string literal in pieces to prevent the source from + getting matched. Store it in a pointer rather than an array + because some compilers will just produce instructions to fill the + array rather than assigning a pointer to a static array. */ +char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; +char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; + + + + +#if defined(__INTEL_COMPILER) && defined(_MSVC_LANG) && _MSVC_LANG < 201403L +# if defined(__INTEL_CXX11_MODE__) +# if defined(__cpp_aggregate_nsdmi) +# define CXX_STD 201402L +# else +# define CXX_STD 201103L +# endif +# else +# define CXX_STD 199711L +# endif +#elif defined(_MSC_VER) && defined(_MSVC_LANG) +# define CXX_STD _MSVC_LANG +#else +# define CXX_STD __cplusplus +#endif + +const char* info_language_dialect_default = "INFO" ":" "dialect_default[" +#if CXX_STD > 201703L + "20" +#elif CXX_STD >= 201703L + "17" +#elif CXX_STD >= 201402L + "14" +#elif CXX_STD >= 201103L + "11" +#else + "98" +#endif +"]"; + +/*--------------------------------------------------------------------------*/ + +int main(int argc, char* argv[]) +{ + int require = 0; + require += info_compiler[argc]; + require += info_platform[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif +#ifdef COMPILER_VERSION_INTERNAL + require += info_version_internal[argc]; +#endif +#ifdef SIMULATE_ID + require += info_simulate[argc]; +#endif +#ifdef SIMULATE_VERSION_MAJOR + require += info_simulate_version[argc]; +#endif +#if defined(__CRAYXE) || defined(__CRAYXC) + require += info_cray[argc]; +#endif + require += info_language_dialect_default[argc]; + (void)argv; + return require; +} diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.exe b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.exe new file mode 100644 index 0000000000000000000000000000000000000000..aba920e5d3565d88cede6abd6b8b394210710aaa Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.exe differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.obj b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.obj new file mode 100644 index 0000000000000000000000000000000000000000..cbec192e6414b4323d4264b36048cf0fbc5a9fd3 Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.obj differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeOutput.log b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeOutput.log new file mode 100644 index 0000000000000000000000000000000000000000..a177dc181dfb5e64a21efc0a12678d5c1fa05c2c --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeOutput.log @@ -0,0 +1,81 @@ +The system is: Windows - 10.0.18363 - AMD64 +Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded. +Compiler: E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe +Build flags: +Id flags: + +The output was: +0 +用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.25.28612 版 +版权所有(C) Microsoft Corporation。保留所有权利。 + +CMakeCCompilerId.c +Microsoft (R) Incremental Linker Version 14.25.28612.0 +Copyright (C) Microsoft Corporation. All rights reserved. + +/out:CMakeCCompilerId.exe +CMakeCCompilerId.obj + + +Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.exe" + +Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.obj" + +The C compiler identification is MSVC, found in "F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdC/CMakeCCompilerId.exe" + +Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded. +Compiler: E:/Visual Studio/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe +Build flags: +Id flags: + +The output was: +0 +用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.25.28612 版 +版权所有(C) Microsoft Corporation。保留所有权利。 + +CMakeCXXCompilerId.cpp +Microsoft (R) Incremental Linker Version 14.25.28612.0 +Copyright (C) Microsoft Corporation. All rights reserved. + +/out:CMakeCXXCompilerId.exe +CMakeCXXCompilerId.obj + + +Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.exe" + +Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.obj" + +The CXX compiler identification is MSVC, found in "F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/3.16.19112601-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.exe" + +Determining if the C compiler works passed with the following output: +Change Dir: F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeTmp + +Run Build Command(s):E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_a5094 && [1/2] Building C object CMakeFiles\cmTC_a5094.dir\testCCompiler.c.obj +[2/2] Linking C executable cmTC_a5094.exe + + + +Detecting C compiler ABI info compiled with the following output: +Change Dir: F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeTmp + +Run Build Command(s):E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_9797c && [1/2] Building C object CMakeFiles\cmTC_9797c.dir\CMakeCCompilerABI.c.obj +[2/2] Linking C executable cmTC_9797c.exe + + + +Determining if the CXX compiler works passed with the following output: +Change Dir: F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeTmp + +Run Build Command(s):E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_1d10b && [1/2] Building CXX object CMakeFiles\cmTC_1d10b.dir\testCXXCompiler.cxx.obj +[2/2] Linking CXX executable cmTC_1d10b.exe + + + +Detecting CXX compiler ABI info compiled with the following output: +Change Dir: F:/大四上/毕设/代码阅读/aflgo/distance_calculator/out/build/x64-Debug/CMakeFiles/CMakeTmp + +Run Build Command(s):E:/Visual Studio/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_c9753 && [1/2] Building CXX object CMakeFiles\cmTC_c9753.dir\CMakeCXXCompilerABI.cpp.obj +[2/2] Linking CXX executable cmTC_c9753.exe + + + diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/foo.h b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/foo.h new file mode 100644 index 0000000000000000000000000000000000000000..d3f5a12faa99758192ecc4ed3fc22c9249232e86 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/foo.h @@ -0,0 +1 @@ + diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.c b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.c new file mode 100644 index 0000000000000000000000000000000000000000..b63620b5c9deed37fa5b1091d8d2e0745242e2d1 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.c @@ -0,0 +1,2 @@ +#include "foo.h" +int main(){} diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.obj b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.obj new file mode 100644 index 0000000000000000000000000000000000000000..bbec5ea9cdc53bacdd91b61c6fadc23e0f3f3c7b Binary files /dev/null and b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/ShowIncludes/main.obj differ diff --git a/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/cmake.check_cache b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/cmake.check_cache new file mode 100644 index 0000000000000000000000000000000000000000..56c437b9b7acb76284e54ca56e02374aac6338f5 --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/instrument/distance_calculator/out/build/x64-Debug/VSInheritEnvironments.txt b/instrument/distance_calculator/out/build/x64-Debug/VSInheritEnvironments.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8cc9d8acececa5889772afcf808dd35dc59a7ed --- /dev/null +++ b/instrument/distance_calculator/out/build/x64-Debug/VSInheritEnvironments.txt @@ -0,0 +1 @@ +msvc_x64_x64 \ No newline at end of file diff --git a/instrument/gcc_mode/Makefile b/instrument/gcc_mode/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..63ad44bcd77ccfe2788407e3cf9a5d3ff3a2aab5 --- /dev/null +++ b/instrument/gcc_mode/Makefile @@ -0,0 +1,68 @@ +# +# GCC instrumentation for AFL +# ----------------------------------------- +# +# Designed and implemented by KB +# +# + +PREFIX ?= /usr/local +BIN_PATH = $(PREFIX)/bin +HELPER_PATH = $(PREFIX)/lib/afl +DOC_PATH = $(PREFIX)/share/doc/afl +MISC_PATH = $(PREFIX)/share/afl + +VERSION = $(shell grep '^\#define VERSION ' ../config.h | cut -d '"' -f2) + +CFLAGS ?= -O3 -funroll-loops +CFLAGS += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \ + -DAFL_PATH=\"$(HELPER_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\" \ + -DBIN_PATH=\"$(BIN_PATH)\" +ifdef AFL_TRACE_PC + CFLAGS += -DUSE_TRACE_PC=1 +endif + +CXXFLAGS ?= -O3 -funroll-loops +CXXFLAGS += -Wall -D_FORTIFY_SOURCE=2 -g -Wno-pointer-sign \ + -DVERSION=\"$(VERSION)\" -Wno-variadic-macros + +PLUGINDIR = $(shell $(CXX) -print-file-name=plugin) +CXXFLAGS += -I$(PLUGINDIR)/include + +LDFLAGS += -std=c++11 + +PROG = ../gcc-fast ../gcc_pass.so ../gcc-rt.o ../gcc-rt-32.o ../gcc-rt.64.o + +COMM_HDR = ../config.h ../debug.h + +#CC = gcc +#CXX = g++ + + +all: $(PROG) + +../gcc-fast: gcc-fast.c + $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) + ln -sf gcc-fast ../gcc-fast++ + ln -sf gcc-fast ../g++-fast + +../gcc_pass.so: gcc_pass.so.o + $(CXX) $(LDFLAGS) -shared -o $@ $< + +gcc_pass.so.o: gcc_pass.cc + $(CXX) $(CXXFLAGS) -fPIC -fno-rtti -c -o $@ $< + +../gcc-rt.o: gcc-rt.o.c + $(CC) $(CFLAGS) -fPIC -c $< -o $@ + +../gcc-rt-32.o: gcc-rt.o.c + @printf "[*] Building 32-bit variant of the runtime (-m32)... " + @$(CC) $(CFLAGS) -m32 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi + +../gcc-rt.64.o: gcc-rt.o.c + @printf "[*] Building 64-bit variant of the runtime (-m64)... " + @$(CC) $(CFLAGS) -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi + +clean: + rm -f ../gcc-fast gcc_pass.so.o ../gcc_pass.so ../gcc-rt.o ../gcc-rt-32.o ../gcc-rt.64.o ../gcc-fast++ ../g++-fast + diff --git a/instrument/gcc_mode/gcc-fast.c b/instrument/gcc_mode/gcc-fast.c new file mode 100644 index 0000000000000000000000000000000000000000..c2a56607ed15fe6d42f212085b588cc8ff4da807 --- /dev/null +++ b/instrument/gcc_mode/gcc-fast.c @@ -0,0 +1,359 @@ +/* + american fuzzy lop - LLVM-mode wrapper for clang + ------------------------------------------------ + + Written by Laszlo Szekeres and + Michal Zalewski + + LLVM integration design comes from Laszlo Szekeres. + + Copyright 2015, 2016 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + This program is a drop-in replacement for clang, similar in most respects + to ../afl-gcc. It tries to figure out compilation mode, adds a bunch + of flags, and then calls the real compiler. + + */ + +#define AFL_MAIN + +#include "../config.h" +#include "../types.h" +#include "../debug.h" +#include "../alloc-inl.h" + +#include +#include +#include +#include + +static u8* obj_path; /* Path to runtime libraries */ +static u8** cc_params; /* Parameters passed to the real CC */ +static u32 cc_par_cnt = 1; /* Param count, including argv0 */ + + +/* Try to find the runtime libraries. If that fails, abort. */ + +static void find_obj(u8* argv0) { + + u8 *afl_path = getenv("AFL_PATH"); + u8 *slash, *tmp; + + // 如果gcc-rt.o在AFL_PATH指向的目录中,将obj_path设为AFL_PATH + if (afl_path) { + + tmp = alloc_printf("%s/gcc-rt.o", afl_path); + + if (!access(tmp, R_OK)) { + obj_path = afl_path; + ck_free(tmp); + return; + } + + ck_free(tmp); + + } + + // + slash = strrchr(argv0, '/'); + + if (slash) { + + u8 *dir; + + *slash = 0; + dir = ck_strdup(argv0); + *slash = '/'; + + tmp = alloc_printf("%s/gcc-rt.o", dir); + + if (!access(tmp, R_OK)) { + obj_path = dir; + ck_free(tmp); + return; + } + + ck_free(tmp); + ck_free(dir); + + } + + if (!access(AFL_PATH "/gcc-rt.o", R_OK)) { + obj_path = AFL_PATH; + return; + } + + FATAL("Unable to find 'afl-llvm-rt.o' or 'afl-llvm-pass.so'. Please set AFL_PATH"); + +} + + +/* Copy argv to cc_params, making the necessary edits. */ + +static void edit_params(u32 argc, char** argv) { + + u8 fortify_set = 0, asan_set = 0, x_set = 0, maybe_linking = 1, bit_mode = 0; + u8 *name; + + cc_params = ck_alloc((argc + 128) * sizeof(u8*)); + + name = strrchr(argv[0], '/'); + if (!name) name = argv[0]; else name++; + + if (!strcmp(name, "gcc-fast++")) { + u8* alt_cxx = getenv("AFL_CXX"); + cc_params[0] = alt_cxx ? alt_cxx : (u8*)"g++"; + } else { + u8* alt_cc = getenv("AFL_CC"); + cc_params[0] = alt_cc ? alt_cc : (u8*)"gcc"; + } + + /* There are two ways to compile afl-clang-fast. In the traditional mode, we + use afl-llvm-pass.so to inject instrumentation. In the experimental + 'trace-pc-guard' mode, we use native LLVM instrumentation callbacks + instead. The latter is a very recent addition - see: + + http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs-with-guards */ + + + cc_params[cc_par_cnt++] = alloc_printf("-fplugin=%s/gcc_pass.so", obj_path); + + cc_params[cc_par_cnt++] = "-Wunused-parameter"; + cc_params[cc_par_cnt++] = "-ffat-lto-objects"; + + /* Detect stray -v calls from ./configure scripts. */ + + if (argc == 1 && !strcmp(argv[1], "-v")) maybe_linking = 0; + + while (--argc) { + u8* cur = *(++argv); + if (!strncmp(cur, "-distance", 9) + || !strncmp(cur, "-targets", 8) + || !strncmp(cur, "-outdir", 7)) { + cc_params[cc_par_cnt++] = alloc_printf("-fplugin-arg-gcc_pass%s", cur); + continue; + + } + if (!strcmp(cur, "-m32")) bit_mode = 32; + if (!strcmp(cur, "-m64")) bit_mode = 64; + + if (!strcmp(cur, "-x")) x_set = 1; + + if (!strcmp(cur, "-c") || !strcmp(cur, "-S") || !strcmp(cur, "-E")) + maybe_linking = 0; + + if (!strcmp(cur, "-fsanitize=address") || + !strcmp(cur, "-fsanitize=memory")) asan_set = 1; + + if (strstr(cur, "FORTIFY_SOURCE")) fortify_set = 1; + + if (!strcmp(cur, "-shared")) maybe_linking = 0; + + if (!strcmp(cur, "-Wl,-z,defs") || + !strcmp(cur, "-Wl,--no-undefined")) continue; + + cc_params[cc_par_cnt++] = cur; + + } + + if (getenv("AFL_HARDEN")) { + + cc_params[cc_par_cnt++] = "-fstack-protector-all"; + + if (!fortify_set) + cc_params[cc_par_cnt++] = "-D_FORTIFY_SOURCE=2"; + + } + + if (!asan_set) { + + if (getenv("AFL_USE_ASAN")) { + + if (getenv("AFL_USE_MSAN")) + FATAL("ASAN and MSAN are mutually exclusive"); + + if (getenv("AFL_HARDEN")) + FATAL("ASAN and AFL_HARDEN are mutually exclusive"); + + cc_params[cc_par_cnt++] = "-U_FORTIFY_SOURCE"; + cc_params[cc_par_cnt++] = "-fsanitize=address"; + + } else if (getenv("AFL_USE_MSAN")) { + + if (getenv("AFL_USE_ASAN")) + FATAL("ASAN and MSAN are mutually exclusive"); + + if (getenv("AFL_HARDEN")) + FATAL("MSAN and AFL_HARDEN are mutually exclusive"); + + cc_params[cc_par_cnt++] = "-U_FORTIFY_SOURCE"; + cc_params[cc_par_cnt++] = "-fsanitize=memory"; + + } + + } + +#ifdef USE_TRACE_PC + + if (getenv("AFL_INST_RATIO")) + FATAL("AFL_INST_RATIO not available at compile time with 'trace-pc'."); + +#endif /* USE_TRACE_PC */ + + if (!getenv("AFL_DONT_OPTIMIZE")) { + + cc_params[cc_par_cnt++] = "-g"; + // cc_params[cc_par_cnt++] = "-O3"; + cc_params[cc_par_cnt++] = "-funroll-loops"; + + } + + if (getenv("AFL_NO_BUILTIN")) { + + cc_params[cc_par_cnt++] = "-fno-builtin-strcmp"; + cc_params[cc_par_cnt++] = "-fno-builtin-strncmp"; + cc_params[cc_par_cnt++] = "-fno-builtin-strcasecmp"; + cc_params[cc_par_cnt++] = "-fno-builtin-strncasecmp"; + cc_params[cc_par_cnt++] = "-fno-builtin-memcmp"; + + } + + cc_params[cc_par_cnt++] = "-D__AFL_HAVE_MANUAL_CONTROL=1"; + cc_params[cc_par_cnt++] = "-D__AFL_COMPILER=1"; + cc_params[cc_par_cnt++] = "-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"; + + /* When the user tries to use persistent or deferred forkserver modes by + appending a single line to the program, we want to reliably inject a + signature into the binary (to be picked up by afl-fuzz) and we want + to call a function from the runtime .o file. This is unnecessarily + painful for three reasons: + + 1) We need to convince the compiler not to optimize out the signature. + This is done with __attribute__((used)). + + 2) We need to convince the linker, when called with -Wl,--gc-sections, + not to do the same. This is done by forcing an assignment to a + 'volatile' pointer. + + 3) We need to declare __afl_persistent_loop() in the global namespace, + but doing this within a method in a class is hard - :: and extern "C" + are forbidden and __attribute__((alias(...))) doesn't work. Hence the + __asm__ aliasing trick. + + */ + + cc_params[cc_par_cnt++] = "-D__AFL_LOOP(_A)=" + "({ static volatile char *_B __attribute__((used)); " + " _B = (char*)\"" PERSIST_SIG "\"; " +#ifdef __APPLE__ + "__attribute__((visibility(\"default\"))) " + "int _L(unsigned int) __asm__(\"___afl_persistent_loop\"); " +#else + "__attribute__((visibility(\"default\"))) " + "int _L(unsigned int) __asm__(\"__afl_persistent_loop\"); " +#endif /* ^__APPLE__ */ + "_L(_A); })"; + + cc_params[cc_par_cnt++] = "-D__AFL_INIT()=" + "do { static volatile char *_A __attribute__((used)); " + " _A = (char*)\"" DEFER_SIG "\"; " +#ifdef __APPLE__ + "__attribute__((visibility(\"default\"))) " + "void _I(void) __asm__(\"___afl_manual_init\"); " +#else + "__attribute__((visibility(\"default\"))) " + "void _I(void) __asm__(\"__afl_manual_init\"); " +#endif /* ^__APPLE__ */ + "_I(); } while (0)"; + + if (maybe_linking) { + + if (x_set) { + cc_params[cc_par_cnt++] = "-x"; + cc_params[cc_par_cnt++] = "none"; + } + + switch (bit_mode) { + + case 0: + cc_params[cc_par_cnt++] = alloc_printf("%s/gcc-rt.o", obj_path); + break; + + case 32: + cc_params[cc_par_cnt++] = alloc_printf("%s/gcc-rt-32.o", obj_path); + + if (access(cc_params[cc_par_cnt - 1], R_OK)) + FATAL("-m32 is not supported by your compiler"); + + break; + + case 64: + cc_params[cc_par_cnt++] = alloc_printf("%s/gcc-rt-64.o", obj_path); + + if (access(cc_params[cc_par_cnt - 1], R_OK)) + FATAL("-m64 is not supported by your compiler"); + + break; + + } + + } + + cc_params[cc_par_cnt] = NULL; + +} + + +/* Main entry point */ + +int main(int argc, char** argv) { + + if (isatty(2) && !getenv("AFL_QUIET")) { + +#ifdef USE_TRACE_PC + SAYF(cCYA "aflgo-compiler (yeah!) [tpcg] " cBRI VERSION cRST "\n"); +#else + SAYF(cCYA "aflgo-compiler (yeah!) " cBRI VERSION cRST "\n"); +#endif /* ^USE_TRACE_PC */ + + } + + if (argc < 2) { + + SAYF("\n" + "This is a helper application for afl-fuzz. It serves as a drop-in replacement\n" + "for clang, letting you recompile third-party code with the required runtime\n" + "instrumentation. A common use pattern would be one of the following:\n\n" + + " CC=%s/afl-clang-fast ./configure\n" + " CXX=%s/afl-clang-fast++ ./configure\n\n" + + "In contrast to the traditional afl-clang tool, this version is implemented as\n" + "an LLVM pass and tends to offer improved performance with slow programs.\n\n" + + "You can specify custom next-stage toolchain via AFL_CC and AFL_CXX. Setting\n" + "AFL_HARDEN enables hardening optimizations in the compiled code.\n\n", + BIN_PATH, BIN_PATH); + + exit(1); + + } + + find_obj(argv[0]); + + edit_params(argc, argv); + + execvp(cc_params[0], (char**)cc_params); + + FATAL("Oops, failed to execute '%s' - check your PATH", cc_params[0]); + + return 0; + +} + diff --git a/instrument/gcc_mode/gcc-rt.o.c b/instrument/gcc_mode/gcc-rt.o.c new file mode 100644 index 0000000000000000000000000000000000000000..e00b61a382664a6cc7ea54698eb5ec1c28b778c3 --- /dev/null +++ b/instrument/gcc_mode/gcc-rt.o.c @@ -0,0 +1,484 @@ +/* + american fuzzy lop - LLVM instrumentation bootstrap + --------------------------------------------------- + + Written by Laszlo Szekeres and + Michal Zalewski + + LLVM integration design comes from Laszlo Szekeres. + + Copyright 2015, 2016 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + This code is the rewrite of afl-as.h's main_payload. + +*/ + +#include "../config.h" +#include "../types.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef AFLGO_TRACING +#include "../hash.h" +#include "../hashset.h" +#include + +/* Variables for profiling */ +hashset_t edgeSet; +static FILE* filefd = NULL; +static char edgeStr[1024]; + +static const unsigned int prime_1 = 73; +static const unsigned int prime_2 = 5009; +/* End of profiling variables */ +#endif /* ^AFLGO_TRACING */ + + +/* This is a somewhat ugly hack for the experimental 'trace-pc-guard' mode. + Basically, we need to make sure that the forkserver is initialized after + the LLVM-generated runtime initialization pass, not before. */ + +#ifdef USE_TRACE_PC +# define CONST_PRIO 5 +#else +# define CONST_PRIO 0 +#endif /* ^USE_TRACE_PC */ + + +/* Globals needed by the injected instrumentation. The __afl_area_initial region + is used for instrumentation output before __afl_map_shm() has a chance to run. + It will end up as .comm, so it shouldn't be too wasteful. */ + +u8 __afl_area_initial[MAP_SIZE + 16]; +u8* __afl_area_ptr = __afl_area_initial; + +__thread u32 __afl_prev_loc; + + +/* Running in persistent mode? */ + +static u8 is_persistent; + + +/* SHM setup. */ + +static void __afl_map_shm(void) { + + printf("__afl_prev_loc = %u\n", __afl_prev_loc); + + u8 *id_str = getenv(SHM_ENV_VAR); + + /* If we're running under AFL, attach to the appropriate region, replacing the + early-stage __afl_area_initial region that is needed to allow some really + hacky .init code to work correctly in projects such as OpenSSL. */ + + if (id_str) { + + u32 shm_id = atoi(id_str); + + __afl_area_ptr = shmat(shm_id, NULL, 0); + + /* Whooooops. */ + + if (__afl_area_ptr == (void *)-1) _exit(1); + + /* Write something into the bitmap so that even with low AFL_INST_RATIO, + our parent doesn't give up on us. */ + + __afl_area_ptr[0] = 1; + + } + +} + + +/* Fork server logic. */ + +static void __afl_start_forkserver(void) { + + static u8 tmp[4]; + s32 child_pid; + + u8 child_stopped = 0; + + /* Phone home and tell the parent that we're OK. If parent isn't there, + assume we're not running in forkserver mode and just execute program. */ + + if (write(FORKSRV_FD + 1, tmp, 4) != 4) return; + + while (1) { + + u32 was_killed; + int status; + + /* Wait for parent by reading from the pipe. Abort if read fails. */ + + if (read(FORKSRV_FD, &was_killed, 4) != 4) _exit(1); + + /* If we stopped the child in persistent mode, but there was a race + condition and afl-fuzz already issued SIGKILL, write off the old + process. */ + + if (child_stopped && was_killed) { + child_stopped = 0; + if (waitpid(child_pid, &status, 0) < 0) _exit(1); + } + + if (!child_stopped) { + + /* Once woken up, create a clone of our process. */ + + child_pid = fork(); + if (child_pid < 0) _exit(1); + + /* In child process: close fds, resume execution. */ + + if (!child_pid) { + + close(FORKSRV_FD); + close(FORKSRV_FD + 1); + return; + + } + + } else { + + /* Special handling for persistent mode: if the child is alive but + currently stopped, simply restart it with SIGCONT. */ + + kill(child_pid, SIGCONT); + child_stopped = 0; + + } + + /* In parent process: write PID to pipe, then wait for child. */ + + if (write(FORKSRV_FD + 1, &child_pid, 4) != 4) _exit(1); + + if (waitpid(child_pid, &status, is_persistent ? WUNTRACED : 0) < 0) + _exit(1); + + /* In persistent mode, the child stops itself with SIGSTOP to indicate + a successful run. In this case, we want to wake it up without forking + again. */ + + if (WIFSTOPPED(status)) child_stopped = 1; + + /* Relay wait status to pipe, then loop back. */ + + if (write(FORKSRV_FD + 1, &status, 4) != 4) _exit(1); + + } + +} + + +/* A simplified persistent mode handler, used as explained in README.llvm. */ + +int __afl_persistent_loop(unsigned int max_cnt) { + + static u8 first_pass = 1; + static u32 cycle_cnt; + + if (first_pass) { + + /* Make sure that every iteration of __AFL_LOOP() starts with a clean slate. + On subsequent calls, the parent will take care of that, but on the first + iteration, it's our job to erase any trace of whatever happened + before the loop. */ + + if (is_persistent) { + + memset(__afl_area_ptr, 0, MAP_SIZE + 16); + __afl_area_ptr[0] = 1; + __afl_prev_loc = 0; + } + + cycle_cnt = max_cnt; + first_pass = 0; + return 1; + + } + + if (is_persistent) { + + if (--cycle_cnt) { + + raise(SIGSTOP); + + __afl_area_ptr[0] = 1; + __afl_prev_loc = 0; + + return 1; + + } else { + + /* When exiting __AFL_LOOP(), make sure that the subsequent code that + follows the loop is not traced. We do that by pivoting back to the + dummy output region. */ + + __afl_area_ptr = __afl_area_initial; + + } + + } + + return 0; + +} + + +/* This one can be called from user code when deferred forkserver mode + is enabled. */ + +void __afl_manual_init(void) { + + static u8 init_done; + + if (!init_done) { + + __afl_map_shm(); + __afl_start_forkserver(); + init_done = 1; + + } + +} + + +/* Proper initialization routine. */ + +__attribute__((constructor(CONST_PRIO))) void __afl_auto_init(void) { + + is_persistent = !!getenv(PERSIST_ENV_VAR); + + if (getenv(DEFER_ENV_VAR)) return; + + __afl_manual_init(); + +} + + + +/* The following stuff deals with supporting -fsanitize-coverage=trace-pc-guard. + It remains non-operational in the traditional, plugin-backed LLVM mode. + For more info about 'trace-pc-guard', see README.llvm. + + The first function (__sanitizer_cov_trace_pc_guard) is called back on every + edge (as opposed to every basic block). */ + +void __sanitizer_cov_trace_pc_guard(uint32_t* guard) { + __afl_area_ptr[*guard]++; +} + + +/* Init callback. Populates instrumentation IDs. Note that we're using + ID of 0 as a special value to indicate non-instrumented bits. That may + still touch the bitmap, but in a fairly harmless way. */ + +void __sanitizer_cov_trace_pc_guard_init(uint32_t* start, uint32_t* stop) { + + u32 inst_ratio = 100; + u8* x; + + if (start == stop || *start) return; + + x = getenv("AFL_INST_RATIO"); + if (x) inst_ratio = atoi(x); + + if (!inst_ratio || inst_ratio > 100) { + fprintf(stderr, "[-] ERROR: Invalid AFL_INST_RATIO (must be 1-100).\n"); + abort(); + } + + /* Make sure that the first element in the range is always set - we use that + to avoid duplicate calls (which can happen as an artifact of the underlying + implementation in LLVM). */ + + *(start++) = R(MAP_SIZE - 1) + 1; + + while (start < stop) { + + if (R(100) < inst_ratio) *start = R(MAP_SIZE - 1) + 1; + else *start = 0; + + start++; + + } + +} + + +#ifdef AFLGO_TRACING +/* Hashset implementation for C */ +hashset_t hashset_create() +{ + hashset_t set = (hashset_t) calloc(1, sizeof(struct hashset_st)); + + if (set == NULL) { + return NULL; + } + set->nbits = 3; + set->capacity = (size_t)(1 << set->nbits); + set->mask = set->capacity - 1; + set->items = (unsigned long*) calloc(set->capacity, sizeof(size_t)); + if (set->items == NULL) { + hashset_destroy(set); + return NULL; + } + set->nitems = 0; + set->n_deleted_items = 0; + return set; +} + +size_t hashset_num_items(hashset_t set) +{ + return set->nitems; +} + +void hashset_destroy(hashset_t set) +{ + if (set) { + free(set->items); + } + free(set); +} + +static int hashset_add_member(hashset_t set, void *item) +{ + size_t value = (size_t)item; + size_t ii; + + if (value == 0 || value == 1) { + return -1; + } + + ii = set->mask & (prime_1 * value); + + while (set->items[ii] != 0 && set->items[ii] != 1) { + if (set->items[ii] == value) { + return 0; + } else { + /* search free slot */ + ii = set->mask & (ii + prime_2); + } + } + set->nitems++; + if (set->items[ii] == 1) { + set->n_deleted_items--; + } + set->items[ii] = value; + return 1; +} + +static void maybe_rehash(hashset_t set) +{ + size_t *old_items; + size_t old_capacity, ii; + + + if (set->nitems + set->n_deleted_items >= (double)set->capacity * 0.85) { + old_items = set->items; + old_capacity = set->capacity; + set->nbits++; + set->capacity = (size_t)(1 << set->nbits); + set->mask = set->capacity - 1; + set->items = (unsigned long*) calloc(set->capacity, sizeof(size_t)); + set->nitems = 0; + set->n_deleted_items = 0; + assert(set->items); + for (ii = 0; ii < old_capacity; ii++) { + hashset_add_member(set, (void *)old_items[ii]); + } + free(old_items); + } +} + +int hashset_add(hashset_t set, void *item) +{ + int rv = hashset_add_member(set, item); + maybe_rehash(set); + return rv; +} + +int hashset_remove(hashset_t set, void *item) +{ + size_t value = (size_t)item; + size_t ii = set->mask & (prime_1 * value); + + while (set->items[ii] != 0) { + if (set->items[ii] == value) { + set->items[ii] = 1; + set->nitems--; + set->n_deleted_items++; + return 1; + } else { + ii = set->mask & (ii + prime_2); + } + } + return 0; +} + +int hashset_is_member(hashset_t set, void *item) +{ + size_t value = (size_t)item; + size_t ii = set->mask & (prime_1 * value); + + while (set->items[ii] != 0) { + if (set->items[ii] == value) { + return 1; + } else { + ii = set->mask & (ii + prime_2); + } + } + return 0; +} + +/*End of hashset implementation for C */ + +inline __attribute__((always_inline)) +void writeBB(const char* bbname) { + strcat(edgeStr, bbname); + size_t cksum=(size_t)hash32(bbname, strlen(edgeStr), 0xa5b35705); + if(!hashset_is_member(edgeSet,(void*)cksum)) { + fprintf(filefd, "[BB]: %s\n", bbname); + hashset_add(edgeSet, (void*)cksum); + } + strcpy(edgeStr, bbname); + fflush(filefd); +} + +void llvm_profiling_call(const char* bbname) + __attribute__((visibility("default"))); + +void llvm_profiling_call(const char* bbname) { + if (filefd != NULL) { + writeBB(bbname); + } else if (getenv("AFLGO_PROFILER_FILE")) { + filefd = fopen(getenv("AFLGO_PROFILER_FILE"), "a+"); + if (filefd != NULL) { + strcpy(edgeStr, "START"); + edgeSet = hashset_create(); + fprintf(filefd, "--------------------------\n"); + writeBB(bbname); + } + } +} +#endif /* ^AFLGO_TRACING */ + diff --git a/instrument/gcc_mode/gcc_pass.cc b/instrument/gcc_mode/gcc_pass.cc new file mode 100644 index 0000000000000000000000000000000000000000..3c41fa18caab0790cf8527f4c3c9434eaac073c0 --- /dev/null +++ b/instrument/gcc_mode/gcc_pass.cc @@ -0,0 +1,1227 @@ + +#define AFL_GCC_PASS + + + + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// This is the first gcc header to be included +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ + 60200 /* >= version 6.2.0 */ + #include +#endif +#include +#include +#include +#include + +#include + +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ + 60200 /* >= version 6.2.0 */ + #include "memmodel.h" +#endif + +#if BUILDING_GCC_VERSION >= 7000 +#include "tree-vrp.h" +#endif + +// We must assert that this plugin is GPL compatible +int plugin_is_GPL_compatible; + +static struct plugin_info aflgo_gcc_plugin_info = { + + "1.0", + "This is a very simple plugin" + +}; + +#define AFL_R(x) (random() % (x)) +#define MAP_SIZE_POW2 16 +#define MAP_SIZE (1 << MAP_SIZE_POW2) + +/* 全局变量 */ +std::string TargetsFile; // 目标点文件 +std::string DistanceFile; // 距离文件 +std::string OutDirectory; // 输出目录 + +static std::list allowListFiles; +static std::list allowListFunctions; +std::list targets; +std::map bb_to_dis; +std::vector basic_blocks; + +std::string dotfiles; + +bool is_aflgo = 0; +bool is_aflgo_preprocessing = 0; + +unsigned int inst_ratio = 100; +unsigned int dinst_ratio = 100; + +/* 测试,完成后删除 */ +int execute_time = 0; + +#ifdef MESSAGES_TO_STDOUT +# define SAYF(x...) printf(x) +#else +# define SAYF(x...) fprintf(stderr, x) +#endif /* ^MESSAGES_TO_STDOUT */ + +# define cBLK "\x1b[0;30m" +# define cRED "\x1b[0;31m" +# define cGRN "\x1b[0;32m" +# define cBRN "\x1b[0;33m" +# define cBLU "\x1b[0;34m" +# define cMGN "\x1b[0;35m" +# define cCYA "\x1b[0;36m" +# define cLGR "\x1b[0;37m" +# define cGRA "\x1b[1;90m" +# define cLRD "\x1b[1;91m" +# define cLGN "\x1b[1;92m" +# define cYEL "\x1b[1;93m" +# define cLBL "\x1b[1;94m" +# define cPIN "\x1b[1;95m" +# define cLCY "\x1b[1;96m" +# define cBRI "\x1b[1;97m" +# define cRST "\x1b[0m" + +# define bgBLK "\x1b[40m" +# define bgRED "\x1b[41m" +# define bgGRN "\x1b[42m" +# define bgBRN "\x1b[43m" +# define bgBLU "\x1b[44m" +# define bgMGN "\x1b[45m" +# define bgCYA "\x1b[46m" +# define bgLGR "\x1b[47m" +# define bgGRA "\x1b[100m" +# define bgLRD "\x1b[101m" +# define bgLGN "\x1b[102m" +# define bgYEL "\x1b[103m" +# define bgLBL "\x1b[104m" +# define bgPIN "\x1b[105m" +# define bgLCY "\x1b[106m" +# define bgBRI "\x1b[107m" + +#define VERSION "1.00" + +static bool isBlacklisted(const char* funName) { + + static const std::vector Blacklist = { + "asan.", + "llvm.", + "sancov.", + "__ubsan_handle_", + "free", + "malloc", + "calloc", + "realloc" + }; + + for (std::string BlackListFunc : Blacklist) { + + if (memcmp(funName, BlackListFunc.c_str(), BlackListFunc.size()) == 0) + return true; + + } + + return false; + +} + +std::string get_function_full_name(function& fun) { + std::string funcName = function_name(&fun); + std::string funcSuffix(":"); + + // 获取当前处理函数参数列表 + tree funcDecl = fun.decl; + tree funcArgs = DECL_ARGUMENTS(funcDecl); + + for (tree funcArg = funcArgs; funcArg; funcArg = TREE_CHAIN(funcArg)) { + + tree arg_type = TREE_TYPE(funcArg); + const char *arg_name_str = get_tree_code_name(TREE_CODE(arg_type)); + funcSuffix.append(arg_name_str); + funcSuffix.append(":"); + + } + + funcName.append(funcSuffix); + + return funcName; + +} + +/* 预处理pass */ +namespace { + + /* pass元数据 */ + const pass_data preprocessing_pass_data = { + + GIMPLE_PASS, // type + "aflgo_preprocessing_pass", // name + OPTGROUP_NONE, // optinfo_flags + TV_NONE, // tv_id + PROP_gimple_any, // properties_required + 0, // properties_provided + 0, // properties_destroyed + 0, // todo_flags_start + 0, // todo_flags_finish + + }; + + /* pass */ + struct preprocessing_pass : gimple_opt_pass { + + /* 构造函数 */ + preprocessing_pass(gcc::context* ctx) : gimple_opt_pass(preprocessing_pass_data, ctx) { + + } + + /* pass主体,该函数将被gcc调用 */ + virtual unsigned int execute(function* fun) override { + + // 测试pass执行次数 + //std::cerr << "executing preprocessing pass, the " << execute_time << "th time, " << "target size : " << targets.size() << "\n"; + //execute_time++; + + /* 预处理阶段主要目标为生成一下文件,因此均为ofstream */ + std::ofstream bbnames(OutDirectory + "/BBnames.txt", std::ofstream::out | std::ofstream::app); // 记录基本块名字的文件 + std::ofstream bbcalls(OutDirectory + "/BBcalls.txt", std::ofstream::out | std::ofstream::app); // 记录callsite的文件,格式为[基本快,函数名] + std::ofstream fnames(OutDirectory + "/Fnames.txt", std::ofstream::out | std::ofstream::app); // 记录函数名的文件 + std::ofstream ftargets(OutDirectory + "/Ftargets.txt", std::ofstream::out | std::ofstream::app); // 记录目标基本块所在函数名的文件 + + /* 遍历基本块 */ + // 获取当前处理函数名称 + std::string funcName = get_function_full_name(*fun); + + + // 跳过黑名单函数 + if (isBlacklisted(funcName.c_str())) + return 1; + + basic_block bb; + bool has_BBs = false; + bool is_target = false; + + + std::string fjjname =function_name(fun); + for (auto & allowFunctions: allowListFunctions) { + if(fjjname.length()==allowFunctions.length()){ + if(!fjjname.compare(allowFunctions)){ + is_target = true; + break; + } + } + } + + FOR_ALL_BB_FN(bb, fun) { + + std::string bb_name(""); + std::string filename; + unsigned line; + + /* 遍历gimple指令 */ + gimple_stmt_iterator gsi; + + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { + + // 注意,有可能多个gimle语句对应源码中的一行, + + // 获取gimple + gimple* stmt = gsi_stmt(gsi); + + // 获取gimple的位置信息 + location_t l = gimple_location(stmt); + filename = LOCATION_FILE(l) ? LOCATION_FILE(l) : ""; + line = LOCATION_LINE(l) ? LOCATION_LINE(l) : 0; + + // 获取gimple语句类型 + enum gimple_code stmt_code = gimple_code(stmt); + + // 检查位置信息 + /* + std::cerr << "[" << gimple_code_name[stmt_code] + << "] " << filename << ":" << line << "\n"; + */ + + // 跳过external libs和没有位置信息的指令 + static const std::string Xlibs("/usr/"); + if (filename.empty() || line == 0 || !filename.compare(0, Xlibs.size(), Xlibs)) + continue; + + // 当前语句为基本块第一条gimple语句时,以该语句位置作为基本块名 + if (bb_name.empty()) { + + std::size_t found = filename.find_last_of("/\\"); + if (found != std::string::npos) + filename = filename.substr(found + 1); + + bb_name = filename + ":" + std::to_string(line); + + } + + // 如果is_target还没有置为true,则比对target的位置信息和当前语句位置信息 + + if (!is_target) { + for (auto & allowFiles: allowListFiles) { + std::size_t found = allowFiles.find_last_of("/\\"); + if (found != std::string::npos) + allowFiles = allowFiles.substr(found + 1); + if(filename.length()==allowFiles.length()){ + if(!filename.compare(allowFiles)){ + is_target = true; + } + } + } + } + + if (!is_target) { + + + + for (auto& target : targets) { + + std::size_t found = target.find_last_of("/\\"); + if (found != std::string::npos) + target = target.substr(found + 1); + + std::size_t pos = target.find_last_of(":"); + std::string target_file = target.substr(0, pos); + unsigned int target_line = atoi(target.substr(pos + 1).c_str()); + + if (!target_file.compare(filename) && target_line == line) + is_target = true; + + } + + } + + + // 查看gimple + /* + FILE* fp = fopen("./fuz.txt", "a"); + print_gimple_stmt(fp, stmt, 0); + fclose(fp);*/ + + // 如果遇到call语句,则记录[当前基本块名,被调函数名] + if (stmt_code == GIMPLE_CALL) { + + std::size_t found = filename.find_last_of("/\\"); + if (found != std::string::npos) + filename = filename.substr(found + 1); + + // 获取函数名 + std::string called_funName; + tree current_fn_decl = gimple_call_fndecl(stmt); + + if (current_fn_decl) { + + std::string funNameA(get_name(current_fn_decl)); + std::string funNameB(function_name(DECL_STRUCT_FUNCTION(current_fn_decl))); + + if (funNameB != "(nofn)") + called_funName.append(funNameB); + else + called_funName.append(funNameA); + + // 获取函数后缀,由所在文件名、函数参数列表组成,用于区分函数重载 + std::string funName_suffix(""); + funName_suffix.append(get_called_arg_types(*stmt)); + + + if (!isBlacklisted(called_funName.c_str())) + bbcalls << bb_name << "," << called_funName << funName_suffix << "\n"; + + } + + + + } + + } // 遍历gimple语句 + + if (!bb_name.empty()) { + + // 待解决:基本块重名问题 + // 有一些基本块在源码中位置在同一行,因此会导致重名 + + bbnames << bb_name << "\n"; + has_BBs = true; + + } + + } // 遍历基本块 + + // 如果当前函数有基本块,则将CFG写入文件 + if (has_BBs) { + + std::string cfgFileName = dotfiles + "/cfg." + funcName + ".dot"; + + write_cfgraph(cfgFileName, fun); + if (is_target) + ftargets << funcName << "\n"; + + fnames << funcName << "\n"; + + } + + // 生成CG + + std::string cgFileName = dotfiles + "/callgraph_log.txt"; + + write_cgraph_info(cgFileName, fun); + + + return 0; + + } + + /* 不复制自身 */ + virtual preprocessing_pass* clone() override { + + return this; + + } + + private: + /* 生成Graphviz风格的函数的控制流图 */ + void write_cfgraph(const std::string& graph_file, function* fun) { + + if (fileExists(graph_file)) + return; + + std::ofstream dotfile(graph_file, std::ofstream::out); + + // 绘制头部 + dotfile << "digraph \"CFG for '" << function_name(fun) <<"' function\" {" << "\n"; + dotfile << "\tlabel=\"CFG for '" << function_name(fun) << "' function\";\n\n"; + + // 绘制节点与边 + basic_block bb; + + FOR_ALL_BB_FN(bb, fun) { + + gimple_bb_info* bb_info = &bb->il.gimple; + + gimple_stmt_iterator gsi; + + std::string bb_name(""); + + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { + + // 获取gimple + gimple* stmt = gsi_stmt(gsi); + + std::string filename; + unsigned line; + + // 获取gimple的位置信息 + location_t l = gimple_location(stmt); + filename = LOCATION_FILE(l) ? LOCATION_FILE(l) : ""; + line = LOCATION_LINE(l) ? LOCATION_LINE(l) : 0; + + // 当前语句为基本块第一条gimple语句时,以该语句位置作为基本块名 + if (bb_name.empty()) { + + std::size_t found = filename.find_last_of("/\\"); + if (found != std::string::npos) + filename = filename.substr(found + 1); + + bb_name = filename + ":" + std::to_string(line); + + break; + + } + + } + + //dotfile << "\tNode" << fun << "_" << bb->index << "[shape=record,label=\"{" << bb_name <<":}\"];" << "\n"; + + dotfile << "\tNode" << fun << "_" << bb->index << "[shape=record,label=\"{"; + if (bb->index == 0) { + + dotfile << (LOCATION_FILE(fun->function_start_locus) ? : "") + << ":" << LOCATION_LINE(fun->function_start_locus); + + } + else if (bb->index == 1) { + + dotfile << (LOCATION_FILE(fun->function_end_locus) ? : "") + << ":" << LOCATION_LINE(fun->function_end_locus); + + } + else { + + dotfile << bb_name; + + } + dotfile << ":}\"];" << "\n"; + + edge e; + edge_iterator ei; + + FOR_EACH_EDGE(e, ei, bb->succs) { + + basic_block dest = e->dest; + dotfile << "\t" + << "Node" << fun << "_" + << bb->index + << " -> Node" << fun << "_" + << dest->index << ";\n"; + + } + + } + + // 绘制尾部 + dotfile << "}\n"; + + + dotfile.close(); + + } + + /* 保存函数调用信息 */ + void write_cgraph_info(const std::string& graph_file, function* fun) { + + std::ofstream dotfile(graph_file, std::ofstream::app); + + // 记录当前函数的信息 + std::string funcName = get_function_full_name(*fun); + dotfile << "NEWFUN Node" << '{' << funcName << '}' << '\n'; + + // 遍历函数内部基本块及指令,记录GIMPLE_CALL语句 + basic_block bb; + + FOR_ALL_BB_FN(bb, fun) { + + gimple_stmt_iterator gsi; + + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { + + gimple* stmt = gsi_stmt(gsi); + + // 获取gimple的位置信息 + location_t l = gimple_location(stmt); + std::string filename = LOCATION_FILE(l) ? LOCATION_FILE(l) : ""; + std::uint32_t line = LOCATION_LINE(l) ? LOCATION_LINE(l) : 0; + + // 获取gimple语句类型 + enum gimple_code stmt_code = gimple_code(stmt); + + // 如果是GIMPLE_CALL语句 + if (stmt_code == GIMPLE_CALL) { + + std::string called_funName; + + tree current_fn_decl = gimple_call_fndecl(stmt); + + if (current_fn_decl) { + + std::string funNameA(get_name(current_fn_decl)); + std::string funNameB(function_name(DECL_STRUCT_FUNCTION(current_fn_decl))); + + + if (funNameB != "(nofn)") + called_funName.append(funNameB); + else + called_funName.append(funNameA); + + // 获取函数后缀,由所在文件名、函数参数列表组成,用于区分函数重载 + std::string funName_suffix(""); + funName_suffix.append(get_called_arg_types(*stmt)); + + dotfile << funcName << " -> " << called_funName << funName_suffix << '\n'; + + } + + + } + + } + + } + + dotfile.close(); + + } + + std::string get_called_arg_types(const gimple& stmt) { + + enum gimple_code stmt_code = gimple_code(&stmt); + + std::string suffix(":"); + + if (stmt_code != GIMPLE_CALL) + return suffix; + + unsigned nargs = gimple_call_num_args(&stmt); + + for (unsigned i = 0; i < nargs; i++) { + + tree arg = gimple_call_arg(&stmt, i); + tree arg_type = TREE_TYPE(arg); + + const char *arg_name = get_tree_code_name(TREE_CODE(arg_type)); + + suffix.append(arg_name); + suffix.append(":"); + + } + + return suffix; + + } + + /* 检查文件是否存在 */ + bool fileExists(const std::string& filename) { + + std::ifstream file(filename); + return file.good(); + + } + + std::string my_get_function_name(gimple* stmt) { + + + + } + + }; // struct preprocessing_pass + +} // anymous namespace + +/* 插桩pass */ +namespace { + + const pass_data instrument_pass_data = { + + GIMPLE_PASS, // type + "aflgo_instrument_pass", // name + OPTGROUP_NONE, // optinfo_flags + TV_NONE, // tv_id + PROP_gimple_any, // properties_required + 0, // properties_provided + 0, // properties_destroyed + 0, // todo_flags_start + 0, // todo_flags_finish + + }; + + struct instrument_pass : gimple_opt_pass { + + instrument_pass(gcc::context* ctx) + : gimple_opt_pass(instrument_pass_data, ctx), + inst_blocks(0) { + + } + + unsigned int inst_blocks; + + virtual unsigned int execute(function* fun) override { + std::cerr << "execute " << execute_time << " in instrument pass, " << "\n"; + execute_time++; + + // 根据机器位数确定存储距离的共享内存偏移位置 +#ifdef __x86_64__ + int distance_unit_width = 8; +#else + int distance_unit_width = 4; +#endif + + // 获取当前处理函数名称 + std::string funcName = get_function_full_name(*fun); + + //std::cerr << "funcName: " << funcName << "\n"; + /*if (!ifInstrument(funcName)){ + std::cerr << "return\n"; + return 1; + + } + std::cerr << "not exit" << std::endl;*/ + + // 跳过黑名单函数 + if (isBlacklisted(funcName.c_str())) + return 1; + + /* 遍历基本块,进行插桩 */ + + int distance = -1; + + basic_block bb; + + int blocks = 0; + + /* These are temporaries used by inline instrumentation only, that + are live throughout the function. */ + tree ploc = NULL, indx = NULL, map = NULL, map_ptr = NULL, ntry = NULL, + cntr = NULL, xaddc = NULL, xincr = NULL, dists_idx = NULL, dists_mem = NULL; + + + FOR_EACH_BB_FN(bb, fun) { + + distance = -1; + + if (is_aflgo) { + + /* 插桩前,需要找到当前基本块对应的距离 */ + + std::string bb_name(""); + + // 获取基本块名称 + gimple_stmt_iterator gsi; + + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { + + std::string filename; + unsigned line; + + // 获取gimple + gimple* stmt = gsi_stmt(gsi); + + // 获取gimple的位置信息 + location_t l = gimple_location(stmt); + filename = LOCATION_FILE(l) ? LOCATION_FILE(l) : ""; + line = LOCATION_LINE(l) ? LOCATION_LINE(l) : 0; + + if (filename.empty() || line == 0) + continue; + + std::size_t found = filename.find_last_of("/\\"); + if (found != std::string::npos) + filename = filename.substr(found + 1); + + bb_name = filename + ":" + std::to_string(line); + + break; + + } // end : 遍历指令 + + // 找到当前基本块的距离 + if (!bb_name.empty()) { + + if (find(basic_blocks.begin(), basic_blocks.end(), bb_name) == basic_blocks.end()) { + + //if (is_selective) + continue; + + } + else { + + // 概率插桩,须补齐条件AFL_R(100) < dinst_ratio + if (AFL_R(100) < dinst_ratio) { + + std::map::iterator it; + + for (it = bb_to_dis.begin(); it != bb_to_dis.end(); ++it) { + + if (it->first.compare(bb_name) == 0) { + + distance = it->second; + + } + + } + } + } + } // end : 查找基本块距离 + + } // end : is_aflgo + + /* 开始给当前基本块插桩 */ + //if (AFL_R(100) >= inst_ratio) continue; + + /* Make up cur_loc */ + // 随机出当前基本块的编号cur_loc,并创建语法树节点 + unsigned bid = AFL_R(MAP_SIZE); // 随机出当前基本块的编号cur_loc + tree bidt = build_int_cst(sizetype, bid); + + gimple_seq seq = NULL; + + static tree afl_prev_loc = get_afl_prev_loc_decl(); // __afl_prev_loc + static tree afl_area_ptr = get_afl_area_ptr_decl(); // __afl_area_ptr + + //std::cout << "tree: "; + //print_generic_expr(stdout, afl_prev_loc, TDF_SLIM); + + /* Load __afl_prev_loc to a temporary ploc. */ + //std::cout << blocks << std::endl; + if (blocks == 0) // 遍历第一个基本块时创建临时变量,后续基本块直接使用(后同) + ploc = create_tmp_var(TREE_TYPE(afl_prev_loc), ".afl_prev_loc"); // .afl_prev_loc = __afl_prev_loc; + auto load_loc = gimple_build_assign(ploc, afl_prev_loc); + gimple_seq_add_stmt(&seq, load_loc); + + /* Compute the index into the map referenced by area_ptr + that we're to update: indx = (sizetype) ploc ^ bid. */ + if (blocks == 0) indx = create_tmp_var(TREE_TYPE(bidt), ".afl_index"); + auto conv_ploc = // .afl_index = (sizetype).afl_prev_loc + gimple_build_assign(indx, fold_convert(TREE_TYPE(indx), ploc)); + gimple_seq_add_stmt(&seq, conv_ploc); + auto xor_loc = gimple_build_assign(indx, BIT_XOR_EXPR, indx, bidt); // .afl_index = .afl_index ^ bid + gimple_seq_add_stmt(&seq, xor_loc); + + /* Compute the address of that map element. */ + if (blocks == 0) { + + map = afl_area_ptr; + map_ptr = create_tmp_var(TREE_TYPE(afl_area_ptr), ".afl_map_ptr"); + ntry = create_tmp_var(TREE_TYPE(afl_area_ptr), ".afl_map_entry"); + + } + + /* .map_ptr is initialized at the function entry point, if we + instrument any blocks, see below. */ + + /* .entry = &map_ptr[.index]; */ + auto idx_map = + gimple_build_assign(ntry, POINTER_PLUS_EXPR, map_ptr, indx); // .afl_map_entry = .afl_map_ptr + .afl_index + gimple_seq_add_stmt(&seq, idx_map); + + /* Prepare to add constant 1 to it. */ + tree incrv = build_one_cst(TREE_TYPE(TREE_TYPE(ntry))); + + + /* Use a serialized memory model. */ + tree memmod = build_int_cst(integer_type_node, MEMMODEL_SEQ_CST); + + tree fadd = builtin_decl_explicit(BUILT_IN_ATOMIC_FETCH_ADD_1); + auto incr_cntr = gimple_build_call(fadd, 3, ntry, incrv, memmod); // .afl_map_entry = .afl_map_entry + 1 + gimple_seq_add_stmt(&seq, incr_cntr); + + + /* Store bid >> 1 in __afl_prev_loc. */ + auto shift_loc = // .afl_prev_loc = bid >> 1 + gimple_build_assign(ploc, build_int_cst(TREE_TYPE(ploc), bid >> 1)); + gimple_seq_add_stmt(&seq, shift_loc); + auto store_loc = gimple_build_assign(afl_prev_loc, ploc); // __afl_prev_loc = .afl_prev_loc + gimple_seq_add_stmt(&seq, store_loc); + + /* 完成AFL插桩 */ + + /* AFLGO插桩 */ + if (blocks == 0) { + dists_idx = create_tmp_var(sizetype, ".aflgo_distance_index"); + dists_mem = create_tmp_var(sizetype, ".aflgo_distance_mem_unit"); + } + + if (distance >= 0) { + + //printf("distance : %d\n", distance); + + /* Add distance to shm[MAP_SIZE] */ + + tree distance_index = build_int_cst(TREE_TYPE(dists_idx), MAP_SIZE); // .aflgo_distance_index = MAP_SIZE + auto init_distance_index = gimple_build_assign(dists_idx, distance_index); + gimple_seq_add_stmt(&seq, init_distance_index); + + auto tracebits_distance_stmt = gimple_build_assign(ntry, POINTER_PLUS_EXPR, map_ptr, dists_idx); // .aflgo_distance_entry = .afl_map_ptr + .aflgo_distance_index + gimple_seq_add_stmt(&seq, tracebits_distance_stmt); + + tree memref = build2(MEM_REF, TREE_TYPE(TREE_TYPE(ntry)), ntry, build_zero_cst(TREE_TYPE(ntry))); // .aflgo_distance_value = *.aflgo_distance_entry + auto load_dis_mem_stmt = gimple_build_assign(dists_mem, memref); + gimple_seq_add_stmt(&seq, load_dis_mem_stmt); + + tree distance_value = build_int_cst(TREE_TYPE(dists_mem), distance); // .aflgo_distance_value = .aflgo_distance_value + distance + auto add_distance_stmt = gimple_build_assign(dists_mem, PLUS_EXPR, dists_mem, distance_value); + gimple_seq_add_stmt(&seq, add_distance_stmt); + + auto store_dis_mem_stmt = gimple_build_assign(unshare_expr(memref), dists_mem); // *.aflgo_distance_entry = .aflgo_distance_value + gimple_seq_add_stmt(&seq, store_dis_mem_stmt); + + + /* Increase count at shm[MAP_SIZE + (4 or 8)] */ + + // .aflgo_distance_index = MAP_SIZE + 4 or 8 + tree cnt_index = build_int_cst(TREE_TYPE(dists_idx), MAP_SIZE + distance_unit_width); + auto init_cnt_index = gimple_build_assign(dists_idx, cnt_index); + gimple_seq_add_stmt(&seq, init_cnt_index); + + // .aflgo_distance_entry = .afl_map_ptr + .aflgo_distance_index + auto tracebits_cnt_stmt = gimple_build_assign(ntry, POINTER_PLUS_EXPR, map_ptr, dists_idx); + gimple_seq_add_stmt(&seq, tracebits_cnt_stmt); + + // .aflgo_distance_value = *.aflgo_distance_entry + tree cnt_memref = build2(MEM_REF, TREE_TYPE(TREE_TYPE(ntry)), ntry, build_zero_cst(TREE_TYPE(ntry))); + auto load_cnt_mem_stmt = gimple_build_assign(dists_mem, cnt_memref); + gimple_seq_add_stmt(&seq, load_cnt_mem_stmt); + + // .aflgo_distance_value = .aflgo_distance_value + 1 + tree cnt_value = build_int_cst(TREE_TYPE(dists_mem), 1); + auto add_cnt_stmt = gimple_build_assign(dists_mem, PLUS_EXPR, dists_mem, cnt_value); + gimple_seq_add_stmt(&seq, add_cnt_stmt); + + // *.aflgo_distance_entry = .aflgo_distance_value + auto store_cnt_mem_stmt = gimple_build_assign(unshare_expr(cnt_memref), dists_mem); + gimple_seq_add_stmt(&seq, store_cnt_mem_stmt); + } + + /* Insert the generated sequence. */ + gimple_stmt_iterator insp = gsi_after_labels(bb); + gsi_insert_seq_before(&insp, seq, GSI_SAME_STMT); + + /* + printf("Basic Block %d:\n", bb->index); + + gimple_stmt_iterator gsi; + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) + { + gimple* stmt = gsi_stmt(gsi); + debug_gimple_stmt(stmt); // 打印Gimple语句 + } + printf("\n"); + */ + + /* 基本块计数加1 */ + blocks++; + + } // end : 遍历基本块 + + inst_blocks += blocks; + + if (blocks) { + + + gimple_seq seq = NULL; + + /* Load afl_area_ptr into map_ptr. We want to do this only + once per function. */ + auto load_ptr = gimple_build_assign(map_ptr, map); + gimple_seq_add_stmt(&seq, load_ptr); + + /* Insert it in the edge to the entry block. We don't want to + insert it in the first block, since there might be a loop + or a goto back to it. Insert in the edge, which may create + another block. */ + edge e = single_succ_edge(ENTRY_BLOCK_PTR_FOR_FN(fun)); + gsi_insert_seq_on_edge_immediate(e, seq); + + } + + + + return 0; + + } + + static inline tree get_afl_prev_loc_decl() { + + tree decl = build_decl(BUILTINS_LOCATION, VAR_DECL, + get_identifier("__afl_prev_loc"), uint32_type_node); + TREE_PUBLIC(decl) = 1; + DECL_EXTERNAL(decl) = 1; + DECL_ARTIFICIAL(decl) = 1; + TREE_STATIC(decl) = 1; + #if !defined(__ANDROID__) && !defined(__HAIKU__) + set_decl_tls_model( + decl, (flag_pic ? TLS_MODEL_INITIAL_EXEC : TLS_MODEL_LOCAL_EXEC)); + #endif + return decl; + + } + + /* Create and return a declaration for the __afl_prev_loc + thread-local variable. */ + static inline tree get_afl_area_ptr_decl() { + + /* If type changes, the size N in FETCH_ADD_ must be adjusted + in builtin calls above. */ + tree type = build_pointer_type(unsigned_char_type_node); + tree decl = build_decl(BUILTINS_LOCATION, VAR_DECL, + get_identifier("__afl_area_ptr"), type); + TREE_PUBLIC(decl) = 1; + DECL_EXTERNAL(decl) = 1; + DECL_ARTIFICIAL(decl) = 1; + TREE_STATIC(decl) = 1; + + return decl; + + } + + static inline bool ifInstrument(std::string funcName) { + + std::string function_list_file = DistanceFile; + + std::size_t pos = function_list_file.find_last_of("/"); + function_list_file = function_list_file.substr(0, pos + 1) + "Fnames.txt"; + + + std::ifstream cf(function_list_file); + + if (cf.is_open()) { + + std::string line; + + while (getline(cf, line)) { + if (line == funcName) { + + cf.close(); + return true; + + } + + } + + cf.close(); + return false; + + + } + else { + + std::cerr << "Unable to find " << function_list_file << std::endl; + return false; + + } + + + return false; + } + + virtual instrument_pass* clone() override { + + return this; + + } + + static void plugin_finalize(void *, void *p) { + + opt_pass *op = (opt_pass *)p; + instrument_pass &self = (instrument_pass &)*op; + + SAYF(cLGN "[+] " cRST "Instrumented %u locations.\n", self.inst_blocks); + + } + + + }; // struct instrument_pass + +} // anymous namespace + + +int plugin_init (struct plugin_name_args *plugin_info, struct plugin_gcc_version *version) { + + if (!plugin_default_version_check (version, &gcc_version)) + { + std::cerr << "This GCC plugin is for version " << GCCPLUGIN_VERSION_MAJOR << "." << GCCPLUGIN_VERSION_MINOR << "\n"; + return 1; + } + + register_callback(plugin_info->base_name, // + PLUGIN_INFO, // 事件 + NULL, // 回调函数 + &aflgo_gcc_plugin_info); // user_data + + /* 获取命令行参数 */ + for (int i = 0; i < plugin_info->argc; i++) { + + //std::cout << plugin_info->argv[i].key << " : " << plugin_info->argv[i].value << std::endl; + + // 获取targets + if (strcmp(plugin_info->argv[i].key, "targets") == 0) + TargetsFile = plugin_info->argv[i].value; + + // 获取outdir + if (strcmp(plugin_info->argv[i].key, "outdir") == 0) + OutDirectory = plugin_info->argv[i].value; + + // 获取distance + if (strcmp(plugin_info->argv[i].key, "distance") == 0) + DistanceFile = plugin_info->argv[i].value; + + } + + // 目标点文件和距离文件不能同时存在 + if (!TargetsFile.empty() && !DistanceFile.empty()) { + std::cerr << "Cannot specify both '-targets' and '-distance'!" << "\n"; + return 1; + } + + /* 根据是否通过命令行传入了参数targets来判断是第几次编译 */ + if (!TargetsFile.empty()) { + + // 第一次编译 + + if (OutDirectory.empty()) { + + std::cerr << "Provide output directory '-outdir '" << "\n"; + return 1; + + } + + // 读取目标点 + std::ifstream targetsfile(TargetsFile); + std::string line; + + while (std::getline(targetsfile, line)) { + + if (line.compare(0, 4, "fun:") == 0) { + line = line.substr(4); + if (line.length() > 0) { + allowListFunctions.push_back(line); + } + } + else if (line.compare(0, 4, "src:") == 0){ + line = line.substr(4); + if (line.length() > 0) { + allowListFiles.push_back(line); + } + } + else if (line.compare(0, 4, "line:") == 0){ + line = line.substr(5); + if (line.length() > 0) { + targets.push_back(line); + } + } + else{ + if (line.find(":") != std::string::npos) { + if (line.length() > 0) { + targets.push_back(line); + } + } + else if(line.length() > 0) { + allowListFiles.push_back(line); + } + } + + } + + targetsfile.close(); + + // 将预处理标志位置为1 + is_aflgo_preprocessing = 1; + + } + else if (!DistanceFile.empty()) { + + // 第二次编译 + + // 读取CFG距离,将每个基本块及其对应的距离保存在全局变量bb_to_dis中 + // 同时将所有基本块的名字保存在全局变量basic_blocks中 + std::ifstream cf(DistanceFile); + + if (cf.is_open()) { + + std::string line; + + while (getline(cf, line)) { + + std::size_t pos = line.find(","); + std::string bb_name = line.substr(0, pos); + int bb_dis = (int) (100.0 * atof(line.substr(pos + 1, line.length()).c_str())); + + bb_to_dis.emplace(bb_name, bb_dis); + basic_blocks.push_back(bb_name); + + } + + cf.close(); + + // 将is_aflgo置为1 + is_aflgo = true; + + } + else { + + std::cerr << "Unable to find " << DistanceFile << std::endl; + return false; + + } + + + + } + + /* show a banner */ + if (is_aflgo || is_aflgo_preprocessing) + SAYF(cCYA "abgo-gcc-pass (yeah!) " cBRI VERSION cRST " (%s mode)\n", + (is_aflgo_preprocessing ? "preprocessing" : "distance instrumentation")); + else + SAYF(cCYA "abgo-gcc-pass " cBRI VERSION cRST " by \n"); + + /* 确定插桩概率,待完善 */ + char* inst_ratio_str = getenv("AFL_INST_RATIO"); + unsigned int inst_ratio = 100; + + // ... + + /* pass work */ + /* 对aflgo进行优化,无需每次加载插件重新读取文件 */ + /* 预处理阶段 */ + if (is_aflgo_preprocessing) { + + /* 创建用于存放dot文件的文件夹 */ + dotfiles = OutDirectory + "/dot-files"; + if (mkdir(dotfiles.c_str(), 0777) == 0) { + std::cerr << "Could not create directory " << dotfiles.c_str() << "\n"; + } + + /* 注册预处理pass */ + + struct register_pass_info preprocessing_pass_info; + + preprocessing_pass_info.pass = new preprocessing_pass(g); + preprocessing_pass_info.reference_pass_name = "cfg"; + preprocessing_pass_info.ref_pass_instance_number = 1; + preprocessing_pass_info.pos_op = PASS_POS_INSERT_AFTER; + + register_callback (plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &preprocessing_pass_info); + + } + /* 插桩阶段 */ + else { + + /* 注册插桩pass */ + + instrument_pass* instru_pass = new instrument_pass(g); + + struct register_pass_info instrument_pass_info; + + instrument_pass_info.pass = instru_pass; + instrument_pass_info.reference_pass_name = "cfg"; + instrument_pass_info.ref_pass_instance_number = 1; + instrument_pass_info.pos_op = PASS_POS_INSERT_AFTER; + + register_callback (plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &instrument_pass_info); + //register_callback(plugin_info->base_name, PLUGIN_FINISH, instrument_pass::plugin_finalize, instrument_pass_info.pass); + + } + + + + + + + return 0; +} diff --git a/instrument/gcc_scripts/add_edges.py b/instrument/gcc_scripts/add_edges.py new file mode 100644 index 0000000000000000000000000000000000000000..77363b94ee6ea2abb9c899e69156528af656520b --- /dev/null +++ b/instrument/gcc_scripts/add_edges.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import argparse +import networkx as nx + +def node_name (name): + if is_cg: + return "\"{%s}\"" % name + else: + return "\"{%s:" % name + +def parse_edges (line): + edges = line.split ( ) + n1_name = node_name (edges[0]) + n1_list = filter (lambda (_, d): 'label' in d and n1_name in d['label'], G.nodes (data=True)) + if len (n1_list) > 0: + (n1, _) = n1_list[0] + for i in range (2, len(edges)): + n2_name = node_name (edges[i]) + n2_list = filter (lambda (_, d): 'label' in d and n2_name in d['label'], G.nodes (data=True)) + if len (n2_list) > 0: + (n2, _) = n2_list[0] + if G.has_edge (n1, n2): + print "[x] %s -> %s" % (n1_name, n2_name) + else: + print "[v] %s -> %s" % (n1_name, n2_name) + G.add_edge(n1,n2) + was_added = 1 +# else : +# print "Could not find %s" % n1_name + +# Main function +if __name__ == '__main__': + is_cg = 1 + was_added = 0 + parser = argparse.ArgumentParser () + parser.add_argument ('-d', '--dot', type=str, required=True, help="Path to dot-file representing the graph") + parser.add_argument ('-e', '--extra_edges', type=str, required=True, help="Extra edges to add to graph") + args = parser.parse_args () + + print "\nParsing %s .." % args.dot + G = nx.Graph(nx.drawing.nx_pydot.read_dot (args.dot)) + print nx.info (G) + + before = nx.number_connected_components (G) + + is_cg = 1 if "Name: Call graph" in nx.info (G) else 0 + print "\nWorking in %s mode.." % ("CG" if is_cg else "CFG") + + print "Adding edges.." + with open(args.extra_edges, "r") as f: + edges = map(parse_edges, f.readlines ()) + + print "\n############################################" + print "#Connected components reduced from %d to %d." % (before, nx.number_connected_components (G)) + print "############################################" + + +# print "\nWriting %s .." % args.dot + if was_added: + nx.drawing.nx_pydot.write_dot(G, args.dot) diff --git a/instrument/gcc_scripts/build/aflgo-build.sh b/instrument/gcc_scripts/build/aflgo-build.sh new file mode 100644 index 0000000000000000000000000000000000000000..c5d958d8065bab809de70ecc05be5a87e969963b --- /dev/null +++ b/instrument/gcc_scripts/build/aflgo-build.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e # exit on error + +# Build clang & LLVM +LLVM_DEP_PACKAGES="build-essential make cmake ninja-build git binutils-gold binutils-dev curl wget" +apt-get install -y $LLVM_DEP_PACKAGES + +UBUNTU_VERSION=`cat /etc/os-release | grep VERSION_ID | cut -d= -f 2` +UBUNTU_YEAR=`echo $UBUNTU_VERSION | cut -d. -f 1` +UBUNTU_MONTH=`echo $UBUNTU_VERSION | cut -d. -f 2` + +if [[ "$UBUNTU_YEAR" > "16" || "$UBUNTU_MONTH" > "04" ]] +then + apt-get install -y python3-distutils +fi + +export CXX=g++ +export CC=gcc +unset CFLAGS +unset CXXFLAGS + +mkdir ~/build; cd ~/build +mkdir llvm_tools; cd llvm_tools +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/llvm-11.0.0.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang-11.0.0.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/compiler-rt-11.0.0.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/libcxx-11.0.0.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/libcxxabi-11.0.0.src.tar.xz +tar xf llvm-11.0.0.src.tar.xz +tar xf clang-11.0.0.src.tar.xz +tar xf compiler-rt-11.0.0.src.tar.xz +tar xf libcxx-11.0.0.src.tar.xz +tar xf libcxxabi-11.0.0.src.tar.xz +mv clang-11.0.0.src ~/build/llvm_tools/llvm-11.0.0.src/tools/clang +mv compiler-rt-11.0.0.src ~/build/llvm_tools/llvm-11.0.0.src/projects/compiler-rt +mv libcxx-11.0.0.src ~/build/llvm_tools/llvm-11.0.0.src/projects/libcxx +mv libcxxabi-11.0.0.src ~/build/llvm_tools/llvm-11.0.0.src/projects/libcxxabi + +mkdir -p build-llvm/llvm; cd build-llvm/llvm +cmake -G "Ninja" \ + -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \ + -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" \ + -DLLVM_BINUTILS_INCDIR=/usr/include ~/build/llvm_tools/llvm-11.0.0.src +ninja; ninja install + +cd ~/build/llvm_tools +mkdir -p build-llvm/msan; cd build-llvm/msan +cmake -G "Ninja" \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_USE_SANITIZER=Memory -DCMAKE_INSTALL_PREFIX=/usr/msan/ \ + -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \ + -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" \ + ~/build/llvm_tools/llvm-11.0.0.src +ninja cxx; ninja install-cxx + +# Install LLVMgold in bfd-plugins +mkdir -p /usr/lib/bfd-plugins +cp /usr/local/lib/libLTO.so /usr/lib/bfd-plugins +cp /usr/local/lib/LLVMgold.so /usr/lib/bfd-plugins + +# install some packages +export LC_ALL=C +apt-get update +apt install -y python-dev python3 python3-dev python3-pip autoconf automake libtool-bin python-bs4 libboost-all-dev # libclang-11.0-dev +python3 -m pip install --upgrade pip +python3 -m pip install networkx pydot pydotplus + +export CXX=clang++ +export CC=clang +# build AFLGo +git clone https://github.com/aflgo/aflgo.git +cd aflgo +make clean all +pushd llvm_mode; make clean all; popd +pushd distance_calculator; cmake -G Ninja ./; cmake --build ./; popd +export AFLGO=`pwd`/aflgo diff --git a/instrument/gcc_scripts/deal.sh b/instrument/gcc_scripts/deal.sh new file mode 100644 index 0000000000000000000000000000000000000000..fbc0057ee1ace3a2de2c751c95ce7c351965c1c0 --- /dev/null +++ b/instrument/gcc_scripts/deal.sh @@ -0,0 +1,22 @@ +#!/bin/bash +cd $TMP_DIR/dot-files + + +function larger_mv() +{ + while read file; do + { + echo "$file" + awk '!a[$0]++' "$file" > "$file".smaller.dot + mv "$file".smaller.dot "$file" + sed -i 's/\\\\\"//g' "$file" + sed -i 's/\[.\"]//g' "$file" + sed -i 's/\(^\s*[0-9a-zA-Z_]*\):[a-zA-Z0-9]*\( -> \)/\1\2/g' "$file" + }& + done + wait +} + +export -f larger_mv + +find $TMP_DIR/dot-files/ -type f -name "cfg.*.dot" | larger_mv diff --git a/instrument/gcc_scripts/distance.py b/instrument/gcc_scripts/distance.py new file mode 100644 index 0000000000000000000000000000000000000000..4aba1b844a0d51f07caaabd15e03591e97e10342 --- /dev/null +++ b/instrument/gcc_scripts/distance.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python3 + +import argparse +import collections +import functools +import networkx as nx + + +class memoize: + # From https://github.com/S2E/s2e-env/blob/master/s2e_env/utils/memoize.py + + def __init__(self, func): + self._func = func + self._cache = {} + + def __call__(self, *args): + if not isinstance(args, collections.abc.Hashable): + return self._func(args) + + if args in self._cache: + return self._cache[args] + + value = self._func(*args) + self._cache[args] = value + return value + + def __repr__(self): + # Return the function's docstring + return self._func.__doc__ + + def __get__(self, obj, objtype): + # Support instance methods + return functools.partial(self.__call__, obj) + + +################################# +# Get graph node name +################################# +def node_name (name): + if is_cg: + return "\"{%s}\"" % name + else: + return "\"{%s:" % name + +################################# +# Find the graph node for a name +################################# +@memoize +def find_nodes (name): + n_name = node_name (name) + return [n for n, d in G.nodes(data=True) if n_name in d.get('label', '')] + +################################## +# Calculate Distance +################################## +def distance (name): # 这里传入的是每一个函数名 + if not is_cg and name in bb_distance.keys(): + out.write(name) + out.write(",") + out.write(str(10 * bb_distance[name])) + out.write("\n") + return + distance = -1 + for n in find_nodes (name): # find_node函数返回graph中该名字对应的节点,即传入函数名的函数所有节点 + d = 0.0 + i = 0 + + if is_cg: + for t in targets: + try: + shortest = nx.dijkstra_path_length (G, n, t) # dijkastr最短路径算法,计算从n到t经过的最短路径 + d += 1.0 / (1.0 + shortest) # 这里计算采用的是调和平均数,取倒数相加最后平均 + i += 1 + except nx.NetworkXNoPath: + pass + else: + for t_name, bb_d in bb_distance.items(): + di = 0.0 + ii = 0 + for t in find_nodes(t_name): + try: # 依然是取最短路径的距离 + shortest = nx.dijkstra_path_length(G, n, t) # 这里的计算实际为(10*func-distance + bb-distance),然后取调和平均数。 + di += 1.0 / (1.0 + 10 * bb_d + shortest) + ii += 1 + except nx.NetworkXNoPath: + pass + if ii != 0: + d += di / ii + i += 1 + + if d != 0 and (distance == -1 or distance > i / d) : # 如果在迭代后,发现有更短的路径,则更新为最短的距离 + distance = i / d + + if distance != -1: # 将距离写入到文件中 + out.write (name) + out.write (",") + out.write (str (distance)) + out.write ("\n") + +################################## +# Main function +################################## +if __name__ == '__main__': + parser = argparse.ArgumentParser () + parser.add_argument ('-d', '--dot', type=str, required=True, help="Path to dot-file representing the graph.") + parser.add_argument ('-t', '--targets', type=str, required=True, help="Path to file specifying Target nodes.") + parser.add_argument ('-o', '--out', type=str, required=True, help="Path to output file containing distance for each node.") + parser.add_argument ('-n', '--names', type=str, required=True, help="Path to file containing name for each node.") + parser.add_argument ('-c', '--cg_distance', type=str, help="Path to file containing call graph distance.") + parser.add_argument ('-s', '--cg_callsites', type=str, help="Path to file containing mapping between basic blocks and called functions.") + + args = parser.parse_args () + + print ("\nParsing %s .." % args.dot) + G = nx.DiGraph(nx.drawing.nx_pydot.read_dot(args.dot)) # 读取图 + print (nx.info(G)) + + is_cg = "Call graph" in nx.info(G) # 判断读进来的图是cg还是cfg + print ("\nWorking in %s mode.." % ("CG" if is_cg else "CFG")) + + # Process as ControlFlowGraph + caller = "" + cg_distance = {} + bb_distance = {} + if not is_cg : + + if args.cg_distance is None: # 首先需要函数维度的距离 + print ("Specify file containing CG-level distance (-c).") + exit(1) + + elif args.cg_callsites is None: # 以及基本块的callsite,即哪些基本块调用了哪些函数 + print ("Specify file containing mapping between basic blocks and called functions (-s).") + exit(1) + + else: + + caller = args.dot.split(".") + caller = caller[len(caller)-2] + print ("Loading cg_distance for function '%s'.." % caller) + + with open(args.cg_distance, 'r') as f: # 加载函数维度距离 + for l in f.readlines(): + s = l.strip().split(",") + cg_distance[s[0]] = float(s[1]) + + if not cg_distance: + print ("Call graph distance file is empty.") + exit(0) + + with open(args.cg_callsites, 'r') as f: # 初始化基本块距离为函数维度距离,取最小的值 + for l in f.readlines(): + s = l.strip().split(",") + if find_nodes(s[0]): + if s[1] in cg_distance: + if s[0] in bb_distance: + if bb_distance[s[0]] > cg_distance[s[1]]: + bb_distance[s[0]] = cg_distance[s[1]] + else: + bb_distance[s[0]] = cg_distance[s[1]] + + print ("Adding target BBs (if any)..") + with open(args.targets, "r") as f: + for l in f.readlines (): + s = l.strip().split("/"); + line = s[len(s) - 1] + if find_nodes(line): + bb_distance[line] = 0 + print ("Added target BB %s!" % line) + + # Process as CallGraph + else: + + print ("Loading targets..") + with open(args.targets, "r") as f: + targets = [] # 这里的target是Ftargets文件,即目标点所在的函数 + for line in f.readlines (): + line = line.strip () + for target in find_nodes(line): + targets.append (target) + + if (not targets and is_cg): + print ("No targets available") + exit(0) + + print ("Calculating distance..") + with open(args.out, "w") as out, open(args.names, "r") as f: + for line in f.readlines(): + distance (line.strip()) # 调用distance函数计算距离 diff --git a/instrument/gcc_scripts/fuzz/KTY_Pretty_Printer.sh b/instrument/gcc_scripts/fuzz/KTY_Pretty_Printer.sh new file mode 100644 index 0000000000000000000000000000000000000000..3ec623e2d4009539207efc4c3a1baf65662683e8 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/KTY_Pretty_Printer.sh @@ -0,0 +1,15 @@ +git clone https://github.com/trailofbits/cb-multios KTY_Pretty_Printer +cd KTY_Pretty_Printer; mv challenges all-challenges; mkdir -p challenges/KTY_Pretty_Printer; cp -r all-challenges/KTY_Pretty_Printer challenges +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'main.c:164\nmain.c:62\nkty.c:532\nkty.c:498\nkty.c:371\nkty.c:568\nfree.c:42' > $TMP_DIR/BBtargets.txt +LINK=STATIC CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ./build.sh +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd build/challenges/KTY_Pretty_Printer; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR KTY_Pretty_Printer +cd -; rm -rf build; LINK=STATIC CFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" ./build.sh +cd -; mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./KTY_Pretty_Printer \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/LMS.sh b/instrument/gcc_scripts/fuzz/LMS.sh new file mode 100644 index 0000000000000000000000000000000000000000..370450512490efbbbddb10ea1f1f33fa69bc468f --- /dev/null +++ b/instrument/gcc_scripts/fuzz/LMS.sh @@ -0,0 +1,15 @@ +git clone https://github.com/trailofbits/cb-multios LMS +cd LMS; mv challenges all-challenges; mkdir -p challenges/LMS; cp -r all-challenges/LMS challenges +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'service.c:227\nservice.c:183\nservice.c:91\nlibc.c:503\nlibc.c:385' > $TMP_DIR/BBtargets.txt # empty distance.cfg.txt ? +LINK=STATIC CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ./build.sh +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd build/challenges/LMS; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR LMS +cd -; rm -rf build; LINK=STATIC CFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" ./build.sh +cd -; mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./LMS \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/Palindrome.sh b/instrument/gcc_scripts/fuzz/Palindrome.sh new file mode 100644 index 0000000000000000000000000000000000000000..48574d38c5fc6e18c63e435e99ce6b8a88d3cdf1 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/Palindrome.sh @@ -0,0 +1,15 @@ +git clone https://github.com/trailofbits/cb-multios +cd cb-multios; mv challenges all-challenges; mkdir -p challenges/Palindrome; cp -r all-challenges/Palindrome challenges +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'service.c:65' > $TMP_DIR/BBtargets.txt +LINK=STATIC CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ./build.sh +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd build/challenges/Palindrome; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR Palindrome +cd -; rm -rf build; LINK=STATIC CFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-g -distance=$TMP_DIR/distance.cfg.txt" ./build.sh +cd -; mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./Palindrome \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/cxxfilt-CVE-2016-4487.sh b/instrument/gcc_scripts/fuzz/cxxfilt-CVE-2016-4487.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc59ed7769f62db176fee13397ee15d952bdb2a5 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/cxxfilt-CVE-2016-4487.sh @@ -0,0 +1,19 @@ +git clone git://sourceware.org/git/binutils-gdb.git cxxfilt-CVE-2016-4487 +cd cxxfilt-CVE-2016-4487; git checkout 2c49145 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'cxxfilt.c:227\ncxxfilt.c:62\ncplus-dem.c:886\ncplus-dem.c:1203\ncplus-dem.c:1490\ncplus-dem.c:2594\ncplus-dem.c:4319' > $TMP_DIR/BBtargets.txt +cd obj-aflgo; CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error $ADDITIONAL" LDFLAGS="-ldl -lutil" ../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld +make clean; make +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd binutils; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR cxxfilt +cd ../../; mkdir obj-dist; cd obj-dist; # work around because cannot run make distclean +CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error -distance=$TMP_DIR/distance.cfg.txt" LDFLAGS="-ldl -lutil" ../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld +make +mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out binutils/cxxfilt +# mkdir out; for i in {1..10}; do timeout -sHUP 60m $AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o "out/out_$i" binutils/cxxfilt > /dev/null 2>&1 & done \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/giflib-bugs-74.sh b/instrument/gcc_scripts/fuzz/giflib-bugs-74.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d5329f2968b5922bbbba2572c53d491f1516e15 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/giflib-bugs-74.sh @@ -0,0 +1,19 @@ +git clone https://git.code.sf.net/p/giflib/code giflib-bugs-74 +cd giflib-bugs-74; git checkout 72e31ff +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'gifsponge.c:44\negif_lib.c:92\ngifsponge.c:76\negif_lib.c:1144\negif_lib.c:802\ngifsponge.c:81\negif_lib.c:764' > $TMP_DIR/BBtargets.txt +./autogen.sh; make distclean +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR gifsponge +CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +mkdir in; echo "GIF" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out util/gifsponge +# mkdir out; for i in {1..10}; do timeout -sHUP 60m $AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o "out/out_$i" util/gifsponge > /dev/null 2>&1 & done \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/jasper-CVE-2015-5221.sh b/instrument/gcc_scripts/fuzz/jasper-CVE-2015-5221.sh new file mode 100644 index 0000000000000000000000000000000000000000..e01aa6e9b82be7b7e59970c8f1da3a4c50d51c69 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/jasper-CVE-2015-5221.sh @@ -0,0 +1,17 @@ +git clone https://github.com/mdadams/jasper.git jasper-CVE-2015-5221 +cd jasper-CVE-2015-5221; git checkout 142245b +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'jas_tvp.c:111\nmif_cod.c:587\nmif_cod.c:497\nmif_cod.c:166\njas_image.c:372\njasper.c:229\nmif_cod.c:573\njas_tvp.c:96\nmif_cod.c:536' > $TMP_DIR/BBtargets.txt +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd src/appl; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR jasper +cd -; CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out src/appl/jasper -f @@ -t mif -F /tmp/out -T jpg \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/libming-CVE-2018-8807.sh b/instrument/gcc_scripts/fuzz/libming-CVE-2018-8807.sh new file mode 100644 index 0000000000000000000000000000000000000000..e2ecb20c60e984a4872625b3b24419e13a0a5b9d --- /dev/null +++ b/instrument/gcc_scripts/fuzz/libming-CVE-2018-8807.sh @@ -0,0 +1,18 @@ +git clone https://github.com/libming/libming.git libming-CVE-2018-8807 +cd libming-CVE-2018-8807/; git checkout b72cc2f # version 0.4.8 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'decompile.c:349' > $TMP_DIR/BBtargets.txt +./autogen.sh; +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --disable-shared --prefix=`pwd` +make clean; make +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd util; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR swftophp +cd -; CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --disable-shared --prefix=`pwd` +make clean; make +mkdir in; wget -P in http://condor.depaul.edu/sjost/hci430/flash-examples/swf/bumble-bee1.swf +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./util/swftophp @@ \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/libming-CVE-2018-8962.sh b/instrument/gcc_scripts/fuzz/libming-CVE-2018-8962.sh new file mode 100644 index 0000000000000000000000000000000000000000..040a8e88c607abb8a1b72003f011963be89725e3 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/libming-CVE-2018-8962.sh @@ -0,0 +1,18 @@ +git clone https://github.com/libming/libming.git libming-CVE-2018-8962 +cd libming-CVE-2018-8962/; git checkout b72cc2f # version 0.4.8 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'decompile.c:398' > $TMP_DIR/BBtargets.txt +./autogen.sh; +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --disable-shared --prefix=`pwd` +make clean; make +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd util; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR swftophp +cd -; CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --disable-shared --prefix=`pwd` +make clean; make +mkdir in; wget -P in http://condor.depaul.edu/sjost/hci430/flash-examples/swf/bumble-bee1.swf +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./util/swftophp @@ \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/libxml2-ef709ce2.sh b/instrument/gcc_scripts/fuzz/libxml2-ef709ce2.sh new file mode 100644 index 0000000000000000000000000000000000000000..af792dfe5f7b9ddb6213f33f4e71fdf189f00e59 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/libxml2-ef709ce2.sh @@ -0,0 +1,22 @@ +git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2_ef709ce2 +cd libxml2_ef709ce2; git checkout ef709ce2 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +git diff -U0 HEAD^ HEAD > $TMP_DIR/commit.diff +wget https://raw.githubusercontent.com/jay/showlinenum/develop/showlinenum.awk +chmod +x showlinenum.awk +mv showlinenum.awk $TMP_DIR +cat $TMP_DIR/commit.diff | $TMP_DIR/showlinenum.awk show_header=0 path=1 | grep -e "\.[ch]:[0-9]*:+" -e "\.cpp:[0-9]*:+" -e "\.cc:[0-9]*:+" | cut -d+ -f1 | rev | cut -c2- | rev > $TMP_DIR/BBtargets.txt +./autogen.sh; make distclean +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR xmllint +CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --disable-shared --prefix=`pwd` +make clean; make -j4 +mkdir in; cp $SUBJECT/test/dtd* in; cp $SUBJECT/test/dtds/* in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./xmllint --valid --recover @@ diff --git a/instrument/gcc_scripts/fuzz/lrzip-CVE-2017-8846.sh b/instrument/gcc_scripts/fuzz/lrzip-CVE-2017-8846.sh new file mode 100644 index 0000000000000000000000000000000000000000..59fc462acbfd02153f645457505c680fedd6937c --- /dev/null +++ b/instrument/gcc_scripts/fuzz/lrzip-CVE-2017-8846.sh @@ -0,0 +1,18 @@ +git clone https://github.com/ckolivas/lrzip.git lrzip-CVE-2017-8846 +cd lrzip-CVE-2017-8846; git checkout 9de7ccb +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'stream.c:1756' > $TMP_DIR/BBtargets.txt +./autogen.sh; make distclean +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --prefix=`pwd` +make clean; make -j4 +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR lrzip +CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --prefix=`pwd` +make clean; make -j4 +mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./lrzip -t @@ \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/lrzip-CVE-2018-11496.sh b/instrument/gcc_scripts/fuzz/lrzip-CVE-2018-11496.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0c1110973d85efb5b6045f5f9efb3422fcaab7e --- /dev/null +++ b/instrument/gcc_scripts/fuzz/lrzip-CVE-2018-11496.sh @@ -0,0 +1,19 @@ +git clone https://github.com/ckolivas/lrzip.git lrzip-CVE-2018-11496 +cd lrzip-CVE-2018-11496/; git checkout ed51e14 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'stream.c:1756' > $TMP_DIR/BBtargets.txt +./autogen.sh; make distclean +cd obj-aflgo; CFLAGS="$ADDITIONAL" CXXFLAGS="$ADDITIONAL" ../configure --prefix=`pwd` +make clean; make -j4 +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR lrzip +CFLAGS="-distance=$TMP_DIR/distance.cfg.txt" CXXFLAGS="-distance=$TMP_DIR/distance.cfg.txt" ../configure --prefix=`pwd` +make clean; make -j4 +mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ./lrzip -t @@ +# mkdir out; for i in {1..10}; do timeout -sHUP 20m $AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o "out/out_$i" ./lrzip -t @@ > /dev/null 2>&1 & done \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/mjs-issues-57.sh b/instrument/gcc_scripts/fuzz/mjs-issues-57.sh new file mode 100644 index 0000000000000000000000000000000000000000..4102b27002fff54377c27f2d5c1d1fca0ba75d23 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/mjs-issues-57.sh @@ -0,0 +1,16 @@ +git clone https://github.com/cesanta/mjs.git mjs-issues-57 +cd mjs-issues-57; git checkout d6c06a6 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'mjs.c:13732' > $TMP_DIR/BBtargets.txt +$CC -DMJS_MAIN mjs.c $ADDITIONAL -ldl -g -o mjs-bin +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR mjs-bin +$CC -DMJS_MAIN mjs.c -distance=$TMP_DIR/distance.cfg.txt -ldl -g -o mjs-bin +cd obj-aflgo; mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ../mjs-bin -f @@ +# mkdir out; for i in {1..10}; do timeout -sHUP 180m $AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o "out/out_$i" ../mjs-bin -f @@ > /dev/null 2>&1 & done \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/mjs-issues-78.sh b/instrument/gcc_scripts/fuzz/mjs-issues-78.sh new file mode 100644 index 0000000000000000000000000000000000000000..9502fe54c8716386c5686adad4335329f8ff48c9 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/mjs-issues-78.sh @@ -0,0 +1,16 @@ +git clone https://github.com/cesanta/mjs.git mjs-issues-78 +cd mjs-issues-78; git checkout 9eae0e6 +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'mjs.c:4908' > $TMP_DIR/BBtargets.txt +$CC -DMJS_MAIN mjs.c $ADDITIONAL -ldl -g -o mjs-bin +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +$AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR mjs-bin +$CC -DMJS_MAIN mjs.c -distance=$TMP_DIR/distance.cfg.txt -ldl -g -o mjs-bin +cd obj-aflgo; mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out ../mjs-bin -f @@ +# mkdir out; for i in {1..10}; do timeout -sHUP 180m $AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o "out/out_$i" ../mjs-bin -f @@ > /dev/null 2>&1 & done \ No newline at end of file diff --git a/instrument/gcc_scripts/fuzz/objdump-CVE-2017-8392.sh b/instrument/gcc_scripts/fuzz/objdump-CVE-2017-8392.sh new file mode 100644 index 0000000000000000000000000000000000000000..f490542bde7696f37b6e8d385f989046770976d8 --- /dev/null +++ b/instrument/gcc_scripts/fuzz/objdump-CVE-2017-8392.sh @@ -0,0 +1,18 @@ +git clone git://sourceware.org/git/binutils-gdb.git CVE-2017-8392 +cd CVE-2017-8392; git checkout a6c21d4a553de184562fd8409a5bcd3f2cc2561a +mkdir obj-aflgo; mkdir obj-aflgo/temp +export SUBJECT=$PWD; export TMP_DIR=$PWD/obj-aflgo/temp +export CC=$AFLGO/afl-clang-fast; export CXX=$AFLGO/afl-clang-fast++ +export LDFLAGS=-lpthread +export ADDITIONAL="-targets=$TMP_DIR/BBtargets.txt -outdir=$TMP_DIR -flto -fuse-ld=gold -Wl,-plugin-opt=save-temps" +echo $'dwarf2.c:4212\nelf.c:8642\nobjdump.c:1486\nobjdump.c:1791\nobjdump.c:2304\nsection.c:1395\nobjdump.c:2438\nobjdump.c:3532\nobjdump.c:3589\nobjdump.c:3678\nobjdump.c:3699\nobjdump.c:4001\nlibc-start.c:287' > $TMP_DIR/BBtargets.txt +cd obj-aflgo; CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error $ADDITIONAL" LDFLAGS="-ldl -lutil" ../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld +make clean; make +cat $TMP_DIR/BBnames.txt | rev | cut -d: -f2- | rev | sort | uniq > $TMP_DIR/BBnames2.txt && mv $TMP_DIR/BBnames2.txt $TMP_DIR/BBnames.txt +cat $TMP_DIR/BBcalls.txt | sort | uniq > $TMP_DIR/BBcalls2.txt && mv $TMP_DIR/BBcalls2.txt $TMP_DIR/BBcalls.txt +cd binutils; $AFLGO/scripts/genDistance.sh $SUBJECT $TMP_DIR objdump -SD @@ +cd ../../; mkdir obj-dist; cd obj-dist; # work around because cannot run make distclean +CFLAGS="-DFORTIFY_SOURCE=2 -fstack-protector-all -fno-omit-frame-pointer -g -Wno-error -distance=$TMP_DIR/distance.cfg.txt" LDFLAGS="-ldl -lutil" ../configure --disable-shared --disable-gdb --disable-libdecnumber --disable-readline --disable-sim --disable-ld +make +mkdir in; echo "" > in/in +$AFLGO/afl-fuzz -m none -z exp -c 45m -i in -o out binutils/objdump -SD @@ diff --git a/instrument/gcc_scripts/genDistance.sh b/instrument/gcc_scripts/genDistance.sh new file mode 100644 index 0000000000000000000000000000000000000000..8baf3476ec50e18847f167bd42152898a2b9b6be --- /dev/null +++ b/instrument/gcc_scripts/genDistance.sh @@ -0,0 +1,150 @@ +#!/bin/bash +if [ $# -lt 2 ]; then + echo "Usage: $0 [fuzzer-name]" + echo "" + exit 1 +fi + +BINARIES=$(readlink -e $1) +TMPDIR=$(readlink -e $2) +AFLGO="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +fuzzer="" +if [ $# -eq 3 ]; then + fuzzer=$(find $BINARIES -name "$3.0.0.*.bc" | rev | cut -d. -f5- | rev) + if [ $(echo "$fuzzer" | wc -l) -ne 1 ]; then + echo "Couldn't find bytecode for fuzzer $3 in folder $BINARIES." + exit 1 + fi +fi + +SCRIPT=$0 +ARGS=$@ + +#SANITY CHECKS +if [ -z "$BINARIES" ]; then echo "Couldn't find binaries folder ($1)."; exit 1; fi +if ! [ -d "$BINARIES" ]; then echo "No directory: $BINARIES."; exit 1; fi +if [ -z "$TMPDIR" ]; then echo "Couldn't find temporary directory ($3)."; exit 1; fi + +binaries=$(find $BINARIES -name "*.0.0.*.bc" | rev | cut -d. -f5- | rev) +if [ -z "$binaries" ]; then echo "Couldn't find any binaries in folder $BINARIES."; exit; fi + +if [ -z $(which python) ] && [ -z $(which python3) ]; then echo "Please install Python"; exit 1; fi +#if python -c "import pydotplus"; then echo "Install python package: pydotplus (sudo pip install pydotplus)"; exit 1; fi +#if python -c "import pydotplus; import networkx"; then echo "Install python package: networkx (sudo pip install networkx)"; exit 1; fi + +FAIL=0 +STEP=1 + +RESUME=$(if [ -f $TMPDIR/state ]; then cat $TMPDIR/state; else echo 0; fi) + +function next_step { + echo $STEP > $TMPDIR/state + if [ $FAIL -ne 0 ]; then + tail -n30 $TMPDIR/step${STEP}.log + echo "-- Problem in Step $STEP of generating $OUT!" + echo "-- You can resume by executing:" + echo "$ $SCRIPT $ARGS $TMPDIR" + exit 1 + fi + STEP=$((STEP + 1)) +} + + +#------------------------------------------------------------------------------- +# Construct control flow graph and call graph +#------------------------------------------------------------------------------- +if [ $RESUME -le $STEP ]; then + + cd $TMPDIR/dot-files + + if [ -z "$fuzzer" ]; then + for binary in $(echo "$binaries"); do + + echo "($STEP) Constructing CG for $binary.." + prefix="$TMPDIR/dot-files/$(basename $binary)" + while ! opt -dot-callgraph $binary.0.0.*.bc -callgraph-dot-filename-prefix $prefix >/dev/null 2> $TMPDIR/step${STEP}.log ; do + echo -e "\e[93;1m[!]\e[0m Could not generate call graph. Repeating.." + done + + #Remove repeated lines and rename + awk '!a[$0]++' $(basename $binary).callgraph.dot > callgraph.$(basename $binary).dot + rm $(basename $binary).callgraph.dot + done + + #Integrate several call graphs into one + $AFLGO/merge_callgraphs.py -o callgraph.dot $(ls callgraph.*) + echo "($STEP) Integrating several call graphs into one." + + else + + echo "($STEP) Constructing CG for $fuzzer.." + prefix="$TMPDIR/dot-files/$(basename $fuzzer)" + while ! opt -dot-callgraph $fuzzer.0.0.*.bc -callgraph-dot-filename-prefix $prefix >/dev/null 2> $TMPDIR/step${STEP}.log ; do + echo -e "\e[93;1m[!]\e[0m Could not generate call graph. Repeating.." + done + + #Remove repeated lines and rename + awk '!a[$0]++' $(basename $fuzzer).callgraph.dot > callgraph.dot + rm $(basename $fuzzer).callgraph.dot + + fi +fi +next_step + +#------------------------------------------------------------------------------- +# Generate config file keeping distance information for code instrumentation +#------------------------------------------------------------------------------- +if [ $RESUME -le $STEP ]; then + echo "($STEP) Computing distance for call graph .." + + $AFLGO/distance.py -d $TMPDIR/dot-files/callgraph.dot -t $TMPDIR/Ftargets.txt -n $TMPDIR/Fnames.txt -o $TMPDIR/distance.callgraph.txt > $TMPDIR/step${STEP}.log 2>&1 || FAIL=1 + + if [ $(cat $TMPDIR/distance.callgraph.txt | wc -l) -eq 0 ]; then + FAIL=1 + next_step + fi + + printf "($STEP) Computing distance for control-flow graphs " + for f in $(ls -1d $TMPDIR/dot-files/cfg.*.dot); do + + # Skip CFGs of functions we are not calling + if ! grep "$(basename $f | cut -d. -f2)" $TMPDIR/dot-files/callgraph.dot >/dev/null; then + printf "\nSkipping $f..\n" + continue + fi + + #Clean up duplicate lines and \" in labels (bug in Pydotplus) + awk '!a[$0]++' $f > ${f}.smaller.dot + mv $f $f.bigger.dot + mv $f.smaller.dot $f + sed -i s/\\\\\"//g $f + sed -i 's/\[.\"]//g' $f + sed -i 's/\(^\s*[0-9a-zA-Z_]*\):[a-zA-Z0-9]*\( -> \)/\1\2/g' $f + + #Compute distance + printf "\nComputing distance for $f..\n" + $AFLGO/distance.py -d $f -t $TMPDIR/BBtargets.txt -n $TMPDIR/BBnames.txt -s $TMPDIR/BBcalls.txt -c $TMPDIR/distance.callgraph.txt -o ${f}.distances.txt >> $TMPDIR/step${STEP}.log 2>&1 #|| FAIL=1 + if [ $? -ne 0 ]; then + echo -e "\e[93;1m[!]\e[0m Could not calculate distance for $f." + fi + #if [ $FAIL -eq 1 ]; then + # next_step #Fail asap. + #fi + done + echo "" + + cat $TMPDIR/dot-files/*.distances.txt > $TMPDIR/distance.cfg.txt + +fi +next_step + +echo "" +echo "----------[DONE]----------" +echo "" +echo "Now, you may wish to compile your sources with " +echo "CC=\"$AFLGO/../afl-clang-fast\"" +echo "CXX=\"$AFLGO/../afl-clang-fast++\"" +echo "CFLAGS=\"\$CFLAGS -distance=$(readlink -e $TMPDIR/distance.cfg.txt)\"" +echo "CXXFLAGS=\"\$CXXFLAGS -distance=$(readlink -e $TMPDIR/distance.cfg.txt)\"" +echo "" +echo "--------------------------" diff --git a/instrument/gcc_scripts/gen_distance_fast.py b/instrument/gcc_scripts/gen_distance_fast.py new file mode 100644 index 0000000000000000000000000000000000000000..154910ce28c1b807b017de727b1d1e3d1fc01c20 --- /dev/null +++ b/instrument/gcc_scripts/gen_distance_fast.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python3 +""" +Construct CG and calculate distances, similarly to genDistance.sh. +The distance is parallelized and uses the compiled distance calculation +version by default. +""" +import argparse +import multiprocessing as mp +import sys +import subprocess +from argparse import ArgumentTypeError as ArgTypeErr +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + + +STEP = 0 +STATE_FN = "state-fast" +DOT_DIR_NAME = "dot-files" +CALLGRAPH_NAME = "callgraph.dot" +PROJ_ROOT = Path(__file__).resolve().parent.parent +DIST_BIN = PROJ_ROOT / "distance_calculator/distance_calculator" +DIST_PY = PROJ_ROOT / "scripts/distance.py" + + +def next_step(args): + global STEP + STEP += 1 + fn = args.temporary_directory / STATE_FN + with fn.open("w") as f: + print(STEP, file=f) + + +def get_resume(args): + fn = args.temporary_directory / STATE_FN + r = 0 + try: + with fn.open("r") as f: + r = int(f.read()) + except FileNotFoundError: + pass + return r + + +def abort(args): + print(f"Failed in step {STEP}", file=sys.stderr) + log_p = args.temporary_directory / f"step{STEP}.log" + print(f"Check {log_p} for more information", file=sys.stderr) + sys.exit(1) + + +def remove_repeated_lines(in_path, out_path): + lines_seen = set() + with out_path.open("w") as out, in_path.open("r") as in_f: + for line in in_f.readlines(): + if line not in lines_seen: + out.write(line) + lines_seen.add(line) + + +def merge_callgraphs(dots, outfilepath): + import networkx as nx + print(f"({STEP}) Integrating several call-graphs into one.") + G = nx.DiGraph() + for dot in dots: + G.update(nx.DiGraph(nx.drawing.nx_pydot.read_dot(dot))) + with outfilepath.open('w') as f: + nx.drawing.nx_pydot.write_dot(G, f) + + +def opt_callgraph(args, binary): # 使用opt工具构建二进制文件的调用图 + print(f"({STEP}) Constructing CG for {binary}..") + dot_files = args.temporary_directory / DOT_DIR_NAME + prefix = dot_files / f"{binary.name}" + cmd = ["opt", "-dot-callgraph", f"{binary}", + "-callgraph-dot-filename-prefix", prefix, + "-o", "/dev/null"] + log_p = args.temporary_directory / f"step{STEP}.log" + with log_p.open("w") as f: + try: + subprocess.run(cmd, stderr=f, check=True, cwd=dot_files) + except subprocess.CalledProcessError: + abort(args) + + +def construct_callgraph(args): + + + tmp_dir = args.temporary_directory + callgraph_generator = str(args.script_directory) + "/generate_cg.py" + + cmd = "python3 " + callgraph_generator + " " + str(tmp_dir) + subprocess.run(cmd, shell=True) + + print("[+] Complete generate callgraph!\n") + + + next_step(args) # 将步骤标识符加一,以便下一步处理。 + + +def exec_distance_prog(dot, targets, out, names, cg_distance=None, + cg_callsites=None, py_version=False): + """ + Args: + dot: Path to dot-file representing the graph. + targets: Path to file specifying Target nodes. + out: Path to output file containing distance for each node. + names: Path to file containing name for each node. + cg_distance: Path to file containing call-graph distance. + cg_callsites: Path to file containing mapping between basic blocks and + called functions. + py_version: If true, the python version is used. + """ + + prog = DIST_BIN if not py_version else DIST_PY + cmd = [prog, + "-d", dot, + "-t", targets, + "-o", out, + "-n", names] + if cg_distance is not None and cg_callsites is not None: + cmd.extend(["-c", cg_distance, + "-s", cg_callsites]) + pipe = subprocess.PIPE + r = subprocess.run(cmd, stdout=pipe, stderr=pipe, check=True) + return r + +def dd_cleanup(): + cmd = './deal.sh' + result = subprocess.run(["bash", cmd]) + # subprocess.run([cmd], shell=True) + +def merge_distance_files(cfg_cg_path, output): + with output.open('w') as f: + for dist in cfg_cg_path.glob("*.distances.txt"): + with dist.open("r") as df: + f.write(df.read()) + + +def calculating_distances(args): + dot_files = args.temporary_directory / DOT_DIR_NAME + bbcalls = args.temporary_directory / "BBcalls.txt" + bbnames = args.temporary_directory / "BBnames.txt" + fnames = args.temporary_directory / "Fnames.txt" + bbtargets = args.temporary_directory / "BBtargets.txt" + ftargets = args.temporary_directory / "Ftargets.txt" + callgraph = dot_files / CALLGRAPH_NAME + callgraph_distance = args.temporary_directory / "callgraph.distance.txt" + + if STEP == 1: + print(f"({STEP}) Computing distance for callgraph") + log_p = args.temporary_directory / f"step{STEP}.log" + try: + r = exec_distance_prog( # 生成cg_distance, 参数分别是,dot格式的cg,目标节点,生成的距离文件,节点名字 + callgraph, + ftargets, + callgraph_distance, + fnames, + py_version=args.python_only) + except subprocess.CalledProcessError as err: + with log_p.open("w") as f: + f.write(err.stderr.decode()) + abort(args) + if not callgraph_distance.exists(): + with log_p.open("w") as f: + f.write(r.stdout.decode()) + f.write(r.stderr.decode()) + abort(args) + next_step(args) + + with callgraph.open("r") as f: + callgraph_dot = f.read() + + # Helper + def calculate_cfg_distance_from_file(cfg: Path): + if cfg.stat().st_size == 0: return + # for python version + name = cfg.name.split('.')[-2] + if name not in callgraph_dot: return + outname = name + ".distances.txt" + outpath = cfg.parent / outname + exec_distance_prog( # 生成cfg_distance + cfg, + bbtargets, + outpath, + bbnames, + callgraph_distance, + bbcalls, + py_version=args.python_only) + print(f"({STEP}) Computing distance for control-flow graphs (this might " + "take a while)") + dd_cleanup() + with ThreadPoolExecutor(max_workers=mp.cpu_count()) as executor: + results = executor.map(calculate_cfg_distance_from_file, + dot_files.glob("cfg.*.dot")) + + try: + for r in results: pass # forward Exceptions + except subprocess.CalledProcessError as err: + log_p = args.temporary_directory / f"step{STEP}.log" + with log_p.open("w") as f: + f.write(err.stderr.decode()) + abort(args) + + print(f"({STEP}) Done computing distance for CFG") + merge_distance_files( + dot_files, + args.temporary_directory / "distance.cfg.txt") + next_step(args) + + +def done(args): + fn = args.temporary_directory / STATE_FN + fn.unlink() + print(f""" +----------[DONE]---------- + +Now, you may wish to compile your sources with +CC=\"{PROJ_ROOT}/afl-clang-fast\" +CXX=\"{PROJ_ROOT}/afl-clang-fast++\" +CFLAGS=\"$CFLAGS -distance=$(readlink -e $TMPDIR/distance.cfg.txt)\" +CXXFLAGS=\"$CXXFLAGS -distance=$(readlink -e $TMPDIR/distance.cfg.txt)\" + +-------------------------- +""") + + +# -- Argparse -- +def is_path_to_dir(path): + """Returns Path object when path is an existing directory""" + p = Path(path) + if not p.exists(): + raise ArgTypeErr("path doesn't exist") + if not p.is_dir(): + raise ArgTypeErr("not a directory") + return p +# ---- + + +def main(): + global STEP + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument("script_directory", metavar="script-directory", + type=is_path_to_dir, + help="Directory where this script is located") + parser.add_argument("temporary_directory", metavar="temporary-directory", + type=is_path_to_dir, + help="Directory where dot files and target files are " + "located") + parser.add_argument("fuzzer_name", metavar="fuzzer-name", + nargs='?', + help="Name of fuzzer binary") + parser.add_argument("-p" ,"--python-only", + action="store_true", + default=False, + help="Use the python version for distance calculation") + args = parser.parse_args() + + STEP = get_resume(args) # 脚本因为其他原因断掉后,可以直接接着上次结果运行 + + if not STEP: + construct_callgraph(args), # 将cfg加入到有向图中, + calculating_distances(args), # 使用dijkstra算法计算距离 + done(args) + + +if __name__ == '__main__': + main() + diff --git a/instrument/gcc_scripts/generate_cg.py b/instrument/gcc_scripts/generate_cg.py new file mode 100644 index 0000000000000000000000000000000000000000..1b4cf0b03d24803630964e8b06376df66375532d --- /dev/null +++ b/instrument/gcc_scripts/generate_cg.py @@ -0,0 +1,142 @@ +import argparse +import re +import hashlib +from typing import Dict, Set +import argparse + + + + +# Determine whether a row is a node +def is_node(string): + + pattern = r"NEWFUN .+{.+}" + match = re.match(pattern, string) + if match: + return True + return False + +# Determine whether a row is an edge +def is_edge(string): + + pattern = r".+ -> .+" + match = re.match(pattern, string) + if match: + return True + return False + +# Hash the string and output the first len digits of the hash result +def hash_string(string, len): + sha256_hash = hashlib.sha256(string.encode()).hexdigest() + output = sha256_hash[:len] + return output + +# Extract function name from node row +def extract_node_name(string): + pattern = r"\{(.+?)\}" + match = re.search(pattern, string) + if match: + content = match.group(1) + return content + else: + return None + +# Extract the edge start function name and end point function name from the edge row +def extract_edge_name(string): + pattern = r"(.+) -> (.+)" + match = re.match(pattern, string) + if match: + content1 = match.group(1) + content2 = match.group(2) + return content1, content2 + else: + return None, None + +# Organize the cglog file and put the edges with the same starting node under the same node +def merge_edges(cglog): + nodes: Dict[str, Set[str]] = {} + + with open(cglog, "r") as fp: + for line in fp.readlines(): + if is_edge(line): + start_name, end_name = extract_edge_name(line) + if start_name not in nodes: + nodes[start_name] = set() + nodes[start_name].add(end_name) + + with open(cglog, "w") as fp: + for key, value in nodes.items(): + node_line = "NEWFUN Node{" + key + "}\n" + fp.write(node_line) + for v in value: + edge_line = key + " -> " + v + "\n" + fp.write(edge_line) + + + + +if __name__ == "__main__": + #print("hello") + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument("temporary_directory", metavar="temporary-directory", + help="Directory where dot files and target files are " + "located") + + args = parser.parse_args() + + cglog_path = args.temporary_directory + "/dot-files/callgraph_log.txt" + cg_path = args.temporary_directory + "/dot-files/callgraph.dot" + + #print(cglog_path) + + nodes = set() + exist_nodes = set() + hash_len = 12 + hash_to_node = {} + + merge_edges(cglog_path) + + with open(cglog_path, "r") as cglogfp: + cgfp = open(cg_path, "w") + + digraph = "digraph \"Call graph: \" {\n" + label = "\tlabel=\"Call graph: \";\n\n" + cgfp.write(digraph) + cgfp.write(label) + + for line in cglogfp.readlines(): + if is_node(line): + node_name = extract_node_name(line) + hash = hash_string(node_name, hash_len) + #print(node_name, ":", hash) + nodes.add(node_name) + exist_nodes.add(node_name) + + in_line = "\tNode0x" + hash +" " + "[shape=record, label=\"{" + node_name + "}\"];\n" + cgfp.write(in_line) + + + if is_edge(line): + start_name, end_name = extract_edge_name(line) + start_hash = hash_string(start_name, hash_len) + end_hash = hash_string(end_name, hash_len) + #print(start_name, "(", start_hash, ")", " -> ", end_name, "(", end_hash, ")") + nodes.add(start_name) + nodes.add(end_name) + + in_line = "\tNode0x" + start_hash + " -> " + "Node0x" + end_hash + ";\n" + cgfp.write(in_line) + + for node in nodes: + if node not in exist_nodes: + hash = hash_string(node, hash_len) + in_line = "\tNode0x" + hash + "[shape=record, label=\"{" + node + "}\"];\n" + cgfp.write(in_line) + + cgfp.write("}") + + cgfp.close() + + + diff --git a/instrument/gcc_scripts/merge_callgraphs.py b/instrument/gcc_scripts/merge_callgraphs.py new file mode 100644 index 0000000000000000000000000000000000000000..592f4fb5d1256729a92ceaf0333af3af4e79ae0e --- /dev/null +++ b/instrument/gcc_scripts/merge_callgraphs.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import argparse +import networkx as nx + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-o', '--out', type=str, required=True, help="Path to output dot file.") + parser.add_argument('dot', nargs='+', help="Path to input dot files.") + + args = parser.parse_args() + + G = nx.DiGraph() + for dot in args.dot: + G.update(nx.DiGraph(nx.drawing.nx_pydot.read_dot(dot))) + + with open(args.out, 'w') as f: + nx.drawing.nx_pydot.write_dot(G, f) + + +# Main function +if __name__ == '__main__': + main() diff --git a/instrument/types.h b/instrument/types.h new file mode 100644 index 0000000000000000000000000000000000000000..21187fc82ef998e5d873168d309ef040655924c6 --- /dev/null +++ b/instrument/types.h @@ -0,0 +1,86 @@ +/* + american fuzzy lop - type definitions and minor macros + ------------------------------------------------------ + + Written and maintained by Michal Zalewski + + Copyright 2013, 2014, 2015 Google Inc. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + */ + +#ifndef _HAVE_TYPES_H +#define _HAVE_TYPES_H + +#include +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; + +/* + + Ugh. There is an unintended compiler / glibc #include glitch caused by + combining the u64 type an %llu in format strings, necessitating a workaround. + + In essence, the compiler is always looking for 'unsigned long long' for %llu. + On 32-bit systems, the u64 type (aliased to uint64_t) is expanded to + 'unsigned long long' in , so everything checks out. + + But on 64-bit systems, it is #ifdef'ed in the same file as 'unsigned long'. + Now, it only happens in circumstances where the type happens to have the + expected bit width, *but* the compiler does not know that... and complains + about 'unsigned long' being unsafe to pass to %llu. + + */ + +#ifdef __x86_64__ +typedef unsigned long long u64; +#else +typedef uint64_t u64; +#endif /* ^__x86_64__ */ + +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; +typedef int64_t s64; + +#ifndef MIN +# define MIN(_a,_b) ((_a) > (_b) ? (_b) : (_a)) +# define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b)) +#endif /* !MIN */ + +#define SWAP16(_x) ({ \ + u16 _ret = (_x); \ + (u16)((_ret << 8) | (_ret >> 8)); \ + }) + +#define SWAP32(_x) ({ \ + u32 _ret = (_x); \ + (u32)((_ret << 24) | (_ret >> 24) | \ + ((_ret << 8) & 0x00FF0000) | \ + ((_ret >> 8) & 0x0000FF00)); \ + }) + +#ifdef AFL_LLVM_PASS +# define AFL_R(x) (random() % (x)) +#else +# define R(x) (random() % (x)) +#endif /* ^AFL_LLVM_PASS */ + +#define STRINGIFY_INTERNAL(x) #x +#define STRINGIFY(x) STRINGIFY_INTERNAL(x) + +#define MEM_BARRIER() \ + asm volatile("" ::: "memory") + +#define likely(_x) __builtin_expect(!!(_x), 1) +#define unlikely(_x) __builtin_expect(!!(_x), 0) + +#endif /* ! _HAVE_TYPES_H */