summaryrefslogtreecommitdiff
path: root/main.c
blob: 8cc0099978470472f6d030266f5dda254fd98a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define TOO_SMALL_ERROR 1

int main()
{
	char* filename;
	int file_name_size;
	
	FILE* fp;
	int file_size;
	int i;

	int pos;
	int amount;
	
	char* fileContents;

	srand(time(NULL));
	
	filename = malloc(1024);
	printf("File to destroy (it will be overwritten): ");
	
	fgets(filename, 1024, stdin);
	filename = strtok(filename, "\n");
	
	file_name_size = strlen(filename);
	
	fp = fopen(filename, "rb");

	fseek(fp, 0L, SEEK_END);
	file_size = ftell(fp);
	fseek(fp, 0L, SEEK_SET);

	
	if (file_size < 2100)
	{
		fprintf(stderr, "Error: File too small: %s.", filename);
		return TOO_SMALL_ERROR;
	}

	fileContents = malloc(file_size);
	fread(fileContents, 1, file_size, fp);
	fclose(fp);

	pos = file_size/4 + (int)(file_size/4 * ((double)rand()/RAND_MAX));

	printf("Destruction amount (~50 is recommended): ");
	scanf("%d", &amount);
	
	for (i = pos; i < pos+amount; i++)
	{
		fileContents[i] = '0';
	}

	fp = fopen(filename, "wb");
	fwrite(fileContents, 1, file_size, fp);

	fclose(fp);
	printf("Done! Your image might be corrupt.\n");

	
	return 0;
	
}