/* * Extract uclinux kernel image from Billion/Telewell firmware update * * Written by Harry Sintonen . * Public Domain. * * USAGE * * ./twuclinixextract < bla.afw > bla.img * * NOTES * * Doesn't decode the image in any way. If someone has ideas * how to do that, please let me know. * * Works with at least: * http://www.telewell.fi/paivitykset/tw_ea501/Telewell-TWEA501v3A-V1.23-B002a.zip * http://www.telewell.fi/paivitykset/tw_ea501/Telewell-TWEA501v2A-V1.23-B002a.zip * http://www.telewell.fi/paivitykset/tw_ea510/Telewell-TWEA510v2A-V1.23-B002a.zip * http://www.telewell.fi/paivitykset/tw_ea510/Telewell-TWEA510v2rA-V1.23-B002a.zip * http://www.telewell.fi/paivitykset/tw_ea510/Telewell-TWEA510v3A-V1.23-B002a.zip */ #include #include #ifdef __GNUC__ void peof(void) __attribute__ ((__noreturn__)); #endif void peof(void) { fprintf(stderr, "premature EOF\n"); exit(20); } void myseek(FILE *fh, int cnt) { while (cnt--) { if (fgetc(fh) == EOF) { peof(); } } } unsigned int be32(FILE *fh) { unsigned int v = 0; int i; for (i = 0; i < 4; i++) { int c; if ((c = fgetc(fh)) == EOF) { peof(); } v = (v << 8) | (unsigned char) c; } return v; } int main(void) { unsigned int size; myseek(stdin, 0x3c); size = be32(stdin); fprintf(stderr, "size: %u\n", size); if (size < 0x40) { fprintf(stderr, "bogus size\n"); return 20; } size -= 0x40; myseek(stdin, 0x100 - 0x40); while (size--) { int c; c = getchar(); if (c == EOF || putchar(c) == EOF) { peof(); } } fprintf(stderr, "Ok\n"); return 0; }