/* amsinfo - a tool for examining AMS firmware files Copyright (C) Dave Chapman 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA */ #include #include #include #include #include #include #include /* Win32 compatibility */ #ifndef O_BINARY #define O_BINARY 0 #endif #define PAD_TO_BOUNDARY(x) ((x) + 0x1ff) & ~0x1ff; static off_t filesize(int fd) { struct stat buf; if (fstat(fd,&buf) < 0) { perror("[ERR] Checking filesize of input file"); return -1; } else { return(buf.st_size); } } static uint32_t get_uint32le(unsigned char* p) { return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } static uint16_t get_uint16le(unsigned char* p) { return p[0] | (p[1] << 8); } static int calc_checksum(unsigned char* buf, int n) { int sum = 0; int i; for (i=0;i 1) { for (j=0;j