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
| #include <stdio.h>
#include <stdlib.h>
#define SIGN_START 0x800
#define SIG_POS 0x2d0
#define INIT_SUM 0x00000000
int main(int argc, char **argv)
{
FILE *fp;
int sum, buf;
if (argc != 2) {
printf("Bad args. should be %s <mapfile>\n", argv[0]);
exit(0);
}
if (!(fp = fopen(argv[1], "r+"))) {
printf("Error opening file.\n");
exit(0);
}
// initialize xor sum
sum = INIT_SUM;
// go to start of hash
fseek(fp, SIGN_START, SEEK_SET);
// assuming 4 byte ints.
while (!feof(fp)) {
fread(&buf, sizeof(int), 1, fp);
sum = sum ^ buf;
}
sum = sum ^ buf;
clearerr(fp);
fseek(fp, SIG_POS, SEEK_SET);
fwrite(&sum, sizeof(int), 1, fp);
fclose(fp);
} |
Partager