From 04f9369aceb27c678de09cc080d088ca5a372629 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 16 Dec 2011 16:17:17 +0100 Subject: * Apply Pali Rohár patch fixing RX51 Fiasco Image parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fiasco.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/fiasco.c b/src/fiasco.c index 4192674..bb9a69a 100644 --- a/src/fiasco.c +++ b/src/fiasco.c @@ -1,6 +1,6 @@ /* * 0xFFFF - Open Free Fiasco Firmware Flasher - * Copyright (C) 2007-2009 pancake + * Copyright (C) 2007-2011 pancake * * 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 @@ -37,7 +37,7 @@ int openfiasco(const char *name, const char *piece_grep, int v) unsigned char *pdata, *pdataend; unsigned int namelen; off_t off, here; - int i,j; + int i; header.fd = open(name, O_RDONLY); @@ -74,22 +74,20 @@ int openfiasco(const char *name, const char *piece_grep, int v) /* walk the tree */ while(1) { here = lseek(header.fd, 0, SEEK_CUR); - if (read(header.fd, buf, 9) != 9) - break; - if (buf[0] != 0x54) { // 'T' - /* skipping some bytes */ - lseek(header.fd, -9, SEEK_CUR); - for(i=0;buf[0]!=0x54;i++) { - j = read(header.fd, buf, 1); - if (j == -1) { - printf("Cannot find next FIASCO header\n"); - return close(header.fd); - } - } - if (v) printf("Skipping %d padding bytes\n", i); - lseek(header.fd, -1, SEEK_CUR); - continue; + + i = 0; + while(1) { + if (read(header.fd, buf, 7)<7) + return close(header.fd); + if (buf[0] == 0x54 /*&& buf[1] == 0x04*/ && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00) + break; + lseek(header.fd, -6, SEEK_CUR); + ++i; } + if (i && v) printf("Skipping %d padding bytes\n", i); + + if (read(header.fd, buf+7, 2)<2) + break; header.hash = buf[7]<<8|buf[8]; /* piece name */ @@ -103,6 +101,12 @@ int openfiasco(const char *name, const char *piece_grep, int v) } else if (v) printf(" %s\n", data); strcpy(header.name, (char *)data); + if (v) { + printf(" header: "); + for (i=0; i<7;++i) printf(" 0x%.2X", (unsigned int)buf[i]); + printf("\n"); + } + if (read(header.fd, buf, 9)<9) break; memcpy(&header.size, buf,4); @@ -136,6 +140,10 @@ int openfiasco(const char *name, const char *piece_grep, int v) pdata = pdata+strlen((char*)pdata)+1; for(;*pdata=='\0' && pdata (%s) %s\n", piece_grep, header.name); + if (piece_grep) + printf("==> (%s) %s\n", piece_grep, header.name); + else + printf("==> %s\n", header.name); if (fiasco_callback != NULL) { fiasco_callback(&header); free(header.data); -- cgit v1.2.3