Revision 12e5e7c70e5342fbd6100bdc82b4242c60f8990c authored by Maqs on 22 April 2015, 19:47:56 UTC, committed by Maqs on 22 April 2015, 19:47:56 UTC
1 parent 0eb6892
xor_chk.c
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
if(argc != 2)
{
printf("Invalid parameter count (%d)\n", argc);
return -1;
}
FILE *f = fopen(argv[1], "r+");
if(!f)
{
printf("Failed to open file\n");
return -1;
}
uint32_t checksum = 0;
uint32_t data = 0;
uint32_t read = 0;
/* make sure we read from the beginning */
fseek(f, 0, SEEK_SET);
while(!feof(f))
{
if(fread(&data, 4, 1, f) != 1)
{
break;
}
checksum ^= data;
read++;
}
/* modify checksum */
data ^= checksum;
fseek(f, -4, SEEK_END);
if(fwrite(&data, 4, 1, f) != 1)
{
printf("Failed to write\n");
return -1;
}
fclose(f);
return 0;
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...