- Timestamp:
- Dec 14, 2006, 3:23:07 PM (15 years ago)
- Location:
- zzuf/trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/configure.ac
r1463 r1464 26 26 fi 27 27 28 AC_CHECK_HEADERS( getopt.h)28 AC_CHECK_HEADERS(inttypes.h stdint.h getopt.h) 29 29 30 30 AC_CHECK_FUNCS(getopt_long, -
zzuf/trunk/src/Makefile.am
r1463 r1464 1 1 2 2 bin_PROGRAMS = zzuf 3 zzuf_SOURCES = zzuf.c 3 zzuf_SOURCES = zzuf.c random.c 4 4 -
zzuf/trunk/src/zzuf.c
r1463 r1464 1 int main(void) { return 0; } 1 /* 2 * zzuf - general purpose fuzzer 3 * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> 4 * All Rights Reserved 5 * 6 * $Id$ 7 * 8 * This program is free software. It comes without any warranty, to 9 * the extent permitted by applicable law. You can redistribute it 10 * and/or modify it under the terms of the Do What The Fuck You Want 11 * To Public License, Version 2, as published by Sam Hocevar. See 12 * http://sam.zoy.org/wtfpl/COPYING for more details. 13 */ 14 15 /* 16 * main.c: main program 17 */ 18 19 #include "config.h" 20 21 #if defined HAVE_STDINT_H 22 # include <stdint.h> 23 #elif defined HAVE_INTTYPES_H 24 # include <inttypes.h> 25 #endif 26 #if defined(HAVE_GETOPT_H) 27 # include <getopt.h> 28 #endif 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <unistd.h> 32 33 #include "random.h" 34 35 static void version(void); 36 #if defined(HAVE_GETOPT_H) 37 static void usage(void); 38 #endif 39 40 int main(int argc, char *argv[]) 41 { 42 char *input = NULL, *output = NULL; 43 FILE *in, *out; 44 char *data; 45 long int i, todo, size, seed = -1; 46 float percent = -1.0; 47 48 #if defined(HAVE_GETOPT_H) 49 for(;;) 50 { 51 # ifdef HAVE_GETOPT_LONG 52 # define MOREINFO "Try `%s --help' for more information.\n" 53 int option_index = 0; 54 static struct option long_options[] = 55 { 56 /* Long option, needs arg, flag, short option */ 57 { "input", 1, NULL, 'i' }, 58 { "output", 1, NULL, 'o' }, 59 { "seed", 1, NULL, 's' }, 60 { "percent", 1, NULL, 'p' }, 61 { "help", 0, NULL, 'h' }, 62 { "version", 0, NULL, 'v' }, 63 }; 64 65 int c = getopt_long(argc, argv, "i:o:s:p:hv", 66 long_options, &option_index); 67 # else 68 # define MOREINFO "Try `%s -h' for more information.\n" 69 int c = getopt(argc, argv, "i:o:s:p:hv"); 70 # endif 71 if(c == -1) 72 break; 73 74 switch(c) 75 { 76 case 'i': /* --input */ 77 input = optarg; 78 break; 79 case 'o': /* --output */ 80 output = optarg; 81 break; 82 case 's': /* --seed */ 83 seed = atol(optarg); 84 break; 85 case 'p': /* --percent */ 86 percent = atof(optarg); 87 break; 88 case 'h': /* --help */ 89 usage(); 90 return 0; 91 case 'v': /* --version */ 92 version(); 93 return 0; 94 default: 95 printf("%s: invalid option -- %c\n", argv[0], c); 96 printf(MOREINFO, argv[0]); 97 return 1; 98 } 99 } 100 #else 101 # define MOREINFO "Usage: %s message...\n" 102 int optind = 1; 103 #endif 104 105 /* Open the files */ 106 if(input) 107 { 108 in = fopen(input, "rb"); 109 if(!in) 110 { 111 fprintf(stderr, "could not open `%s'\n", input); 112 return 1; 113 } 114 } 115 else 116 in = stdin; 117 118 if(output) 119 { 120 out = fopen(output, "wb"); 121 if(!out) 122 { 123 fprintf(stderr, "could not open `%s' for writing\n", output); 124 return 1; 125 } 126 } 127 else 128 out = stdout; 129 130 /* Checking parameters */ 131 if(seed == -1) 132 { 133 unsigned long int a = getpid(); 134 seed = (0x7931fea7 * a) ^ (0xb7390af7 + a); 135 fprintf(stderr, "no seed specified, using %lu\n", seed); 136 } 137 138 if(percent == -1.0) 139 { 140 percent = 0.1; 141 fprintf(stderr, "no percent specified, using %g\n", percent); 142 } 143 144 /* Read file contents */ 145 fseek(in, 0, SEEK_END); 146 size = ftell(in); 147 data = malloc(size); 148 fseek(in, 0, SEEK_SET); 149 fread(data, size, 1, in); 150 fclose(in); 151 152 /* Randomise shit */ 153 zzuf_srand(seed); 154 todo = percent * 0.01 * size; 155 while(todo--) 156 { 157 i = zzuf_rand(size); 158 data[i] ^= 1 << zzuf_rand(8); 159 } 160 161 /* Write result */ 162 fwrite(data, size, 1, out); 163 fclose(out); 164 165 return 0; 166 } 167 168 static void version(void) 169 { 170 printf("zzuf %s by Sam Hocevar <sam@zoy.org>\n", VERSION); 171 } 172 173 #if defined(HAVE_GETOPT_H) 174 static void usage(void) 175 { 176 printf("Usage: zuff [ -vh ] [ -i input ] [ -o output ]\n"); 177 printf(" [ -p percent ] [ -s seed ]\n"); 178 # ifdef HAVE_GETOPT_LONG 179 printf(" -h, --help display this help and exit\n"); 180 printf(" -v, --version output version information and exit\n"); 181 # else 182 printf(" -h display this help and exit\n"); 183 printf(" -v output version information and exit\n"); 184 # endif 185 } 186 #endif 187 188
Note: See TracChangeset
for help on using the changeset viewer.