00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "bconfig.h"
00023 #include "system.h"
00024 #include "md5.h"
00025
00026 static void
00027 usage (void)
00028 {
00029 fputs ("Usage: genchecksums <filename>\n", stderr);
00030 }
00031
00032 static void
00033 dosum (const char *file)
00034 {
00035 FILE *f;
00036 unsigned char result[16];
00037 int i;
00038
00039 f = fopen (file, "rb");
00040 if (!f)
00041 {
00042 fprintf (stderr, "opening %s: %s\n", file, xstrerror (errno));
00043 exit (1);
00044 }
00045
00046
00047 if (fseek (f, 16, SEEK_SET) != 0)
00048 {
00049 fprintf (stderr, "seeking in %s: %s\n", file, xstrerror (errno));
00050 exit (1);
00051 }
00052
00053 if (md5_stream (f, result) != 0
00054 || fclose (f) != 0)
00055 {
00056 fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno));
00057 exit (1);
00058 }
00059
00060 fputs ("const unsigned char executable_checksum[16] = { ", stdout);
00061 for (i = 0; i < 16; i++)
00062 printf ("%#02x%s", result[i], i == 15 ? " };\n" : ", ");
00063 }
00064
00065 int
00066 main (int argc, char ** argv)
00067 {
00068 if (argc != 2)
00069 {
00070 usage ();
00071 return 1;
00072 }
00073
00074 dosum (argv[1]);
00075
00076 return 0;
00077 }