summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpancake <nopcode.org>2011-12-16 16:17:17 +0100
committerpancake <nopcode.org>2011-12-16 16:17:17 +0100
commit04f9369aceb27c678de09cc080d088ca5a372629 (patch)
tree05d94dbd3ee5774a513df912805212b3acfc79a0
parentb0f69c8b6b6c73440c5fd29fccd618d0046b4640 (diff)
download0xFFFF-04f9369aceb27c678de09cc080d088ca5a372629.tar.bz2
* Apply Pali Rohár patch fixing RX51 Fiasco Image parsing
-rw-r--r--src/fiasco.c47
1 files 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 <pancake@youterm.com>
+ * Copyright (C) 2007-2011 pancake <pancake@youterm.com>
*
* 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<pdataend; pdata++);
}
+ } else {
+ /* End of comments, ignore one char and next is image data */
+ lseek(header.fd, 1, SEEK_CUR);
+ break;
}
strcpy(header.version, (char *)data);
if (read(header.fd, buf+8, 1)<1)
@@ -148,7 +156,10 @@ int openfiasco(const char *name, const char *piece_grep, int v)
printf(" body-at: 0x%08x\n", (unsigned int)off);
}
if (piece_grep==NULL || (strstr(header.name, piece_grep))) {
- printf("==> (%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);