summaryrefslogtreecommitdiffstats
path: root/src/fiasco.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-06-23 14:09:33 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-06-23 14:09:33 +0200
commit8fdba437af4fb14960e87724b2164ff28dc5da55 (patch)
tree7b9018f6a7bea729d55bc4e387ea1e04755d5187 /src/fiasco.c
parent583cc8a963e6a294a4f583eb1887bb3a1f889af8 (diff)
download0xFFFF-8fdba437af4fb14960e87724b2164ff28dc5da55.tar.bz2
Unpacking fiasco - added support for FW headers (FW name)
Diffstat (limited to 'src/fiasco.c')
-rw-r--r--src/fiasco.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/fiasco.c b/src/fiasco.c
index cb577f2..dd2c938 100644
--- a/src/fiasco.c
+++ b/src/fiasco.c
@@ -36,7 +36,8 @@ int openfiasco(const char *name, const char *piece_grep, int v)
unsigned char buf[256];
unsigned char data[256];
unsigned char *pdata, *pdataend;
- unsigned int namelen;
+ unsigned int headerlen;
+ unsigned int blockcount;
off_t off, here;
int i;
@@ -57,21 +58,40 @@ int openfiasco(const char *name, const char *piece_grep, int v)
printf("Invalid header\n");
return close(header.fd);
}
- memcpy(&namelen,buf+1,4);
- namelen = ntohl(namelen);
- if (namelen>128) {
+
+ memcpy(&headerlen,buf+1,4);
+ headerlen = ntohl(headerlen);
+ if (headerlen>128) {
printf("Stupid length at header. Is this a joke?\n");
return close(header.fd);
}
+
memset(buf,'\0', 128);
- if (read(header.fd, buf, namelen) != namelen) {
- printf("Invalid read of %d bytes\n", namelen);
+ if (read(header.fd, buf, headerlen) != headerlen) {
+ printf("Invalid read of %d bytes\n", headerlen);
+ return close(header.fd);
+ }
+
+ memcpy(&blockcount,buf,4);
+ blockcount = ntohl(blockcount);
+ if (blockcount==0) {
+ printf("Error: No block in header\n");
return close(header.fd);
}
- if (v) printf("Fiasco version: %2d\n", buf[3]);
- strcpy(header.fwname, (char *)buf+6);
- if (v) for(i=6;i<namelen;i+=strlen((char *)(buf+i))+1)
- printf("Name: %s\n", buf+i);
+ if (v) printf("Number of blocks: %d\n", blockcount);
+
+ pdata = buf+4;
+ while (pdata < buf+headerlen-4) {
+ if (pdata[0] == 0xe8) {
+ if (v) printf("Header: %s\n", pdata+2);
+ } else if (pdata[0] == 0x31) {
+ strncpy(header.fwname, (char *)pdata+2, (int)pdata[1]);
+ if (v) printf("Name: %s\n", header.fwname);
+ } else {
+ if (v) printf("Unknown header 0x%x, length %d, data %s\n", pdata[0], pdata[1], pdata+2);
+ }
+ pdata += (int)pdata[1]+2;
+ }
/* walk the tree */
while(1) {