|
| 1 | +import os |
| 2 | +import argparse |
| 3 | + |
| 4 | + |
| 5 | +def parse_args(): |
| 6 | + parser = argparse.ArgumentParser() |
| 7 | + parser.add_argument("--folder", "-f", type=str, default="fuzz_out", |
| 8 | + help="The output folder after fuzzing a program") |
| 9 | + parser.add_argument("--program", "-p", type=str, default="none", |
| 10 | + help="The program which is fuzzing, such as: objdump, magick, readelf, nm, xmllint, jpegtran, mp3gain, tiffsplit") |
| 11 | + args_r = parser.parse_args() |
| 12 | + return args_r |
| 13 | + |
| 14 | + |
| 15 | +if __name__ == '__main__': |
| 16 | + args = parse_args() |
| 17 | + pre_path = os.path.abspath(args.folder) |
| 18 | + program = args.program |
| 19 | + f_p = "" |
| 20 | + o_p = "" |
| 21 | + command = "" |
| 22 | + if program == "objdump": |
| 23 | + command = " ../binutils-2.27/binutils/objdump -x -a -d " |
| 24 | + elif program == "readelf": |
| 25 | + command = " ../binutils-2.27/binutils/readelf -a " |
| 26 | + elif program == "nm": |
| 27 | + command = " ../binutils-2.27/binutils/nm-new -a " |
| 28 | + elif program == "xmllint": |
| 29 | + command = " ../libxml2-2.9.2/xmllint --valid --recover " |
| 30 | + elif program == "jpegtran": |
| 31 | + command = " ../jpeg-9e/jpegtran " |
| 32 | + elif program == "mp3gain": |
| 33 | + command = " ../mp3gain/mp3gain " |
| 34 | + elif program == "magick": |
| 35 | + command = " ../ImageMagick-7.1.0-49/utilities/magick identify " |
| 36 | + elif program == "tiffsplit": |
| 37 | + command = " ../libtiff-Release-v3-9-7/tools/tiffsplit " |
| 38 | + else: |
| 39 | + print("please input a program's name") |
| 40 | + sys.exit() |
| 41 | + folders = os.listdir(pre_path) |
| 42 | + if not os.path.exists(os.path.join(pre_path, "map_data")): |
| 43 | + os.system("mkdir " + os.path.join(pre_path, "map_data")) |
| 44 | + lines_list = [[], []] |
| 45 | + map_dic = [] |
| 46 | + if "queue" not in folders: |
| 47 | + for folder in folders: |
| 48 | + if folder == "map_data": |
| 49 | + continue |
| 50 | + if not os.path.exists(os.path.join(pre_path, "map_data", folder)): |
| 51 | + os.system("mkdir " + os.path.join(pre_path, "map_data", folder)) |
| 52 | + files = os.listdir(os.path.join(pre_path, folder, "queue")) |
| 53 | + for file in files: |
| 54 | + print(f"!!!!!!!!{pre_path}!!{folder}!{file}!!!!!!!!!") |
| 55 | + if "id" not in file: |
| 56 | + continue |
| 57 | + o_p = file + ".txt" |
| 58 | + f_p = os.path.join(os.path.join(pre_path, folder, "queue", file)) |
| 59 | + full_command = "afl-showmap -o " + os.path.join(pre_path, "map_data", folder, o_p) + command + f_p |
| 60 | + os.system(full_command) |
| 61 | + with open(os.path.join(pre_path, "map_data", folder, o_p), "r") as f: |
| 62 | + lines = f.readlines() |
| 63 | + line_number = str(len(lines)) |
| 64 | + lines_list[0].append(os.path.join(pre_path, "map_data", folder, o_p)) |
| 65 | + lines_list[1].append(line_number) |
| 66 | + for line in lines: |
| 67 | + pos = line.find(":") |
| 68 | + num = line[:pos] |
| 69 | + if num not in map_dic: |
| 70 | + map_dic.append(num) |
| 71 | + else: |
| 72 | + files = os.listdir(os.path.join(pre_path, "queue")) |
| 73 | + if not os.path.exists(os.path.join(pre_path, "map_data", "fuzzer-one")): |
| 74 | + os.system("mkdir " + os.path.join(pre_path, "map_data", "fuzzer-one")) |
| 75 | + for file in files: |
| 76 | + if "id" not in file: |
| 77 | + continue |
| 78 | + o_p = file + ".txt" |
| 79 | + f_p = os.path.join(pre_path, "queue", file) |
| 80 | + full_command = "afl-showmap -o " + os.path.join(pre_path, "map_data", "fuzzer-one", o_p) + command + f_p |
| 81 | + os.system(full_command) |
| 82 | + with open(os.path.join(pre_path, "map_data", "fuzzer-one", o_p), "r") as f: |
| 83 | + lines = f.readlines() |
| 84 | + line_number = str(len(lines)) |
| 85 | + lines_list[0].append(os.path.join(pre_path, "map_data", "fuzzer-one", o_p)) |
| 86 | + lines_list[1].append(line_number) |
| 87 | + for line in lines: |
| 88 | + pos = line.find(":") |
| 89 | + num = line[:pos] |
| 90 | + if num not in map_dic: |
| 91 | + map_dic.append(num) |
| 92 | + with open(os.path.join(pre_path, "map_data", "map_all.txt"), "w") as f: |
| 93 | + for i in range(len(lines_list[0])): |
| 94 | + f.write(lines_list[0][i] + ': ' + lines_list[1][i] + "\n") |
| 95 | + with open(os.path.join(pre_path, "map_data", "map_density.txt"), "w") as f: |
| 96 | + for i in map_dic: |
| 97 | + f.write(i + "\n") |
| 98 | + f.write(f"map_density_num:{len(map_dic)}\n") |
0 commit comments