#include #include #include #include #include typedef unsigned long ulg; /********************************************************************** * * The following are support routines for inflate.c * **********************************************************************/ static ulg crc_32_tab[256]; /* * Code to compute the CRC-32 table. Borrowed from * gzip-1.0.3/makecrc.c. */ static void makecrc(void) { /* Not copyrighted 1990 Mark Adler */ unsigned long c; /* crc shift register */ unsigned long e; /* polynomial exclusive-or pattern */ int i; /* counter for all possible eight bit values */ int k; /* byte being shifted into crc apparatus */ /* terms of polynomial defining this crc (except x^32): */ static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; /* Make exclusive-or pattern from polynomial */ e = 0; for (i = 0; i < sizeof(p)/sizeof(int); i++) e |= 1L << (31 - p[i]); crc_32_tab[0] = 0; for (i = 1; i < 256; i++) { c = 0; for (k = i | 256; k != 1; k >>= 1) { c = c & 1 ? (c >> 1) ^ e : c >> 1; if (k & 1) c ^= e; } crc_32_tab[i] = c; } } unsigned long comp_crc(unsigned char *p, unsigned long len) { unsigned long crc = 0xFFFFFFFFUL; while (len--) { crc = crc_32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8); } return crc ^ 0xFFFFFFFFUL; } unsigned char buffer[0xc0000+10]; /* Original version by Petr Novak for SMC7004ABR rev.2 * Modified to support SMC7004VWBR PN720.x version by BLFC from Openline ISP */ unsigned char signature[] = { 'B', 'R', 'N', 'A', 'W', 0, 0, 0, 0, 0, }; int main(int argc, char *argv[]) { int i; unsigned char c; unsigned long len = 0; unsigned long crc; unsigned long *p; int fd; makecrc(); memset(buffer, 0xff, sizeof(buffer)); fd = open(argv[1], O_RDONLY); if (fd<0) { perror("open PFS (192K) SOHO (576K)"); exit(1); } len = read(fd, buffer, 0x30000); fprintf(stderr, "Web (PFS) has %lu bytes\n", len); memcpy(buffer+len, signature, 10); crc = comp_crc(buffer, len+10); p = (unsigned long *)(buffer + 0x2fff4); p[0] = len + 10; p[1] = 0x12345678; p[2] = crc; close(fd); fd = open(argv[2], O_RDONLY); if (fd<0) { perror("open SOHO (576K)"); exit(1); } len = read(fd, buffer+0x30000, 0x90000); fprintf(stderr, "Firmware (SOHO) has %lu bytes\n", len); crc = comp_crc(buffer+0x30000, len); p = (unsigned long *)(buffer + 0xbfff4); p[0] = len; p[1] = 0x12345678; p[2] = crc; close(fd); memcpy(buffer+0xc0000, signature, 10); write(1, buffer, sizeof(buffer)); }