00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <inttypes.h>
00024
00025 static uint32_t state;
00026 static uint32_t ran(void)
00027 {
00028 return state = state * 1664525 + 1013904223;
00029 }
00030
00031 int main(int argc, char **argv)
00032 {
00033 FILE *f;
00034 int count, maxburst, length;
00035
00036 if (argc < 5) {
00037 printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
00038 return 1;
00039 }
00040
00041 f = fopen(argv[1], "rb+");
00042 if (!f) {
00043 perror(argv[1]);
00044 return 2;
00045 }
00046 count = atoi(argv[2]);
00047 maxburst = atoi(argv[3]);
00048 state = atoi(argv[4]);
00049
00050 fseek(f, 0, SEEK_END);
00051 length = ftell(f);
00052 fseek(f, 0, SEEK_SET);
00053
00054 while (count--) {
00055 int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX;
00056 int pos = ran() * (uint64_t) length / UINT32_MAX;
00057 fseek(f, pos, SEEK_SET);
00058
00059 if (maxburst < 0)
00060 burst = -maxburst;
00061
00062 if (pos + burst > length)
00063 continue;
00064
00065 while (burst--) {
00066 int val = ran() * 256ULL / UINT32_MAX;
00067
00068 if (maxburst < 0)
00069 val = 0;
00070
00071 fwrite(&val, 1, 1, f);
00072 }
00073 }
00074
00075 return 0;
00076 }