50 lines
1.3 KiB
C
50 lines
1.3 KiB
C
//Tool to recalculate the checksum on a Mac ROM
|
|
/*
|
|
* ----------------------------------------------------------------------------
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
|
* this notice you can do whatever you want with this stuff. If we meet some day,
|
|
* and you think this stuff is worth it, you can buy me a beer in return.
|
|
* ----------------------------------------------------------------------------
|
|
*/
|
|
#include "stdio.h"
|
|
#include "stdint.h"
|
|
#include <stdlib.h>
|
|
|
|
#define MAXROMSZ 3*1024*1024
|
|
|
|
int main(int argc, char **argv) {
|
|
FILE *f;
|
|
int l, x;
|
|
unsigned int oldchs, newchs;
|
|
unsigned char rom[MAXROMSZ];
|
|
if (argc!=2) {
|
|
printf("Usage: %s mac-rom-image.bin\nRecalculate checksum on modified rom\n");
|
|
exit(0);
|
|
}
|
|
|
|
f=fopen(argv[1], "r+");
|
|
if (f<=0) {
|
|
perror(argv[1]);
|
|
exit(1);
|
|
}
|
|
l=fread(rom, 1, MAXROMSZ, f);
|
|
|
|
oldchs=(rom[0]<<24)+(rom[1]<<16)+(rom[2]<<8)+(rom[3]);
|
|
newchs=0;
|
|
for (x=4; x<l; x+=2) {
|
|
newchs+=(rom[x]<<8)+rom[x+1];
|
|
}
|
|
printf("ROM size: %X\n", l);
|
|
printf("Old checksum: %04X\n", oldchs);
|
|
printf("New checksum: %04X\n", newchs);
|
|
if (oldchs!=newchs) {
|
|
rom[0]=newchs>>24;
|
|
rom[1]=newchs>>16;
|
|
rom[2]=newchs>>8;
|
|
rom[3]=newchs>>0;
|
|
fseek(f, 0, SEEK_SET);
|
|
fwrite(rom, 4, 1, f);
|
|
}
|
|
fclose(f);
|
|
} |