]> cvs.zerfleddert.de Git - rsbs2/blobdiff - extract.c
typo in error message
[rsbs2] / extract.c
index 86491d1cfcf47541f5dc15a255832e6c8d030f77..b4208995f2bc9f8ae73ee6b8811dabfc89e29435 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -15,6 +15,7 @@
 struct file_entry* get_next_file(unsigned char *fw, int len)
 {
        static unsigned char *pos;
 struct file_entry* get_next_file(unsigned char *fw, int len)
 {
        static unsigned char *pos;
+       static unsigned char *start;
        static unsigned char *end;
        static struct file_entry fent;
        int name_length;
        static unsigned char *end;
        static struct file_entry fent;
        int name_length;
@@ -22,7 +23,10 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
        if (fw != NULL && len != 0) {
                pos = fw + 0x28;
 
        if (fw != NULL && len != 0) {
                pos = fw + 0x28;
 
+#if 0
                printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos));
                printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos));
+#endif
+               start = fw;
                pos = fw + *((unsigned int*)pos);
                end = fw + len;
        }
                pos = fw + *((unsigned int*)pos);
                end = fw + len;
        }
@@ -30,6 +34,28 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
        fent.unknown = *pos;
        pos++;
 
        fent.unknown = *pos;
        pos++;
 
+       if (fent.unknown == 0x00) {
+               /* EOF */
+               int fill = (4 - ((pos - start) % 4)) % 4;
+               int i;
+
+               for (i = 0; i < fill; i++) {
+                       if (*pos != 0xff) {
+                               fprintf(stderr, "Wrong fill byte after EOF: 0x%02x, aborting!\n", *pos);
+                               exit(1);
+                       }
+                       pos++;
+               }
+
+               if (pos != end) {
+                       fprintf(stderr, "EOF marker not at end-of-file %p <-> %p, aborting!\n", pos, end);
+                       exit(1);
+               }
+
+               return NULL;
+       }
+
+
        name_length = *((unsigned int*)pos);
        pos += 4;
 
        name_length = *((unsigned int*)pos);
        pos += 4;
 
@@ -38,8 +64,10 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
 
        if ((fent.length > (end - pos)) ||
            (name_length > (end - pos))) {
 
        if ((fent.length > (end - pos)) ||
            (name_length > (end - pos))) {
-               printf("EOF reached\n");
-               return NULL;
+               printf("EOF reached without hitting EOF marker, aborting "
+                       "(unknown: 0x%02x, namelen: 0x%08x, contentlen: 0x%08x!\n",
+                       fent.unknown, name_length, fent.length);
+               exit(1);
        }
 
        fent.name = (char*)pos;
        }
 
        fent.name = (char*)pos;
@@ -96,6 +124,8 @@ void extract_files(unsigned char *fw, int len)
                                        extract_lz_file(lzpos, (unsigned char*)lzname);
                                }
                        }
                                        extract_lz_file(lzpos, (unsigned char*)lzname);
                                }
                        }
+               } else {
+                       printf(", ignoring...\n");
                }
                fent = get_next_file(NULL, 0);
        }
                }
                fent = get_next_file(NULL, 0);
        }
Impressum, Datenschutz