1169689Skan/* Generate checksums of executables for PCH validation 2169689Skan Copyright (C) 2005 3169689Skan Free Software Foundation, Inc. 4169689Skan 5169689SkanThis file is part of GCC. 6169689Skan 7169689SkanGCC is free software; you can redistribute it and/or modify it under 8169689Skanthe terms of the GNU General Public License as published by the Free 9169689SkanSoftware Foundation; either version 2, or (at your option) any later 10169689Skanversion. 11169689Skan 12169689SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 13169689SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 14169689SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15169689Skanfor more details. 16169689Skan 17169689SkanYou should have received a copy of the GNU General Public License 18169689Skanalong with GCC; see the file COPYING. If not, write to the Free 19169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 20169689Skan02110-1301, USA. */ 21169689Skan 22169689Skan#include "bconfig.h" 23169689Skan#include "system.h" 24169689Skan#include "md5.h" 25169689Skan 26169689Skanstatic void 27169689Skanusage (void) 28169689Skan{ 29169689Skan fputs ("Usage: genchecksums <filename>\n", stderr); 30169689Skan} 31169689Skan 32169689Skanstatic void 33169689Skandosum (const char *file) 34169689Skan{ 35169689Skan FILE *f; 36169689Skan unsigned char result[16]; 37169689Skan int i; 38169689Skan 39169689Skan f = fopen (file, "rb"); 40169689Skan if (!f) 41169689Skan { 42169689Skan fprintf (stderr, "opening %s: %s\n", file, xstrerror (errno)); 43169689Skan exit (1); 44169689Skan } 45169689Skan 46169689Skan /* Some executable formats have timestamps in the first 16 bytes, yuck. */ 47169689Skan if (fseek (f, 16, SEEK_SET) != 0) 48169689Skan { 49169689Skan fprintf (stderr, "seeking in %s: %s\n", file, xstrerror (errno)); 50169689Skan exit (1); 51169689Skan } 52169689Skan 53169689Skan if (md5_stream (f, result) != 0 54169689Skan || fclose (f) != 0) 55169689Skan { 56169689Skan fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno)); 57169689Skan exit (1); 58169689Skan } 59169689Skan 60169689Skan fputs ("const unsigned char executable_checksum[16] = { ", stdout); 61169689Skan for (i = 0; i < 16; i++) 62169689Skan printf ("%#02x%s", result[i], i == 15 ? " };\n" : ", "); 63169689Skan} 64169689Skan 65169689Skanint 66169689Skanmain (int argc, char ** argv) 67169689Skan{ 68169689Skan if (argc != 2) 69169689Skan { 70169689Skan usage (); 71169689Skan return 1; 72169689Skan } 73169689Skan 74169689Skan dosum (argv[1]); 75169689Skan 76169689Skan return 0; 77169689Skan} 78