| 29 | } |
| 30 | |
| 31 | static void generate_input(uint64_t fid) { |
| 32 | char path[1000]; |
| 33 | std::string __output_dir = "/hyper/fuzz/tmp"; |
| 34 | std::string output_file = std::string(__output_dir) + "/" + |
| 35 | std::to_string(fid) + "-id"; |
| 36 | //std::string input_file = std::string(__output_dir) + "/" + taint_file; |
| 37 | std::string input_file = "/home/cju/e2e/filter_des/0-id"; |
| 38 | //std::cout << "out file is " << output_file << std::endl; |
| 39 | struct stat statbuf; |
| 40 | void *src, *dst; |
| 41 | int fdout, fdin; |
| 42 | int mode = 0x777; |
| 43 | |
| 44 | /* open the input file */ |
| 45 | if ((fdin = open (input_file.c_str(), O_RDONLY)) < 0) |
| 46 | { |
| 47 | //assert(false && "can't open file for reading"); |
| 48 | printf("cannot open input file!\n"); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | /* open/create the output file */ |
| 53 | if ((fdout = open (output_file.c_str(), O_RDWR | O_CREAT | O_TRUNC, mode)) < 0)//edited here |
| 54 | { |
| 55 | //assert(false && "can't create file for writing"); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | /* find size of input file */ |
| 60 | if (fstat (fdin,&statbuf) < 0) |
| 61 | { |
| 62 | //assert (false && "fstat error"); |
| 63 | close(fdin); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | /* mmap the input file */ |
| 68 | if ((src = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) |
| 69 | == (caddr_t) -1) { |
| 70 | close(fdin); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | dst = malloc(statbuf.st_size); |
| 75 | |
| 76 | /* this copies the input file to the output file */ |
| 77 | memcpy (dst, src, statbuf.st_size); |
| 78 | for (int i=0;i<4;i++) { |
| 79 | ((uint8_t*)dst)[i] = i; |
| 80 | //printf("generate_input index is %u and value is %u\n", it->first,(uint32_t)it->second); |
| 81 | } |
| 82 | |
| 83 | if (write(fdout, dst, statbuf.st_size) < 0) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | close(fdin); |
| 88 | close(fdout); |