]> cvs.zerfleddert.de Git - rsbs2/blobdiff - filesystem.c
correctly retrieve empty settings
[rsbs2] / filesystem.c
index d05361d7304c6bae8d5ff8ceac9bf1182245713e..d4b207e7b8b5cca78e86a9c82f6b72dc83ec48e0 100644 (file)
@@ -86,11 +86,11 @@ void extract_files(unsigned char *fw, int len)
        fent = get_next_file(fw, len);
        
        while (fent) {
-               printf("%s: unknown: 0x%02x, length: %d",
+               printf("%s: unknown: 0x%02x, length: %d",
                        fent->name, fent->unknown, fent->length);
 
                if (fent->length > 0) {
-                       write_file(fent->name, fent->start, fent->length);
+                       write_file(extracted_file(fent->name), fent->start, fent->length);
                        if (*((unsigned int*)fent->start) == LZ_MAGIC) {
                                char *lzname;
 
@@ -105,9 +105,9 @@ void extract_files(unsigned char *fw, int len)
                                }
                                lzname[strlen(lzname) - 3] = 0x00;
 
-                               printf("%s: packed file found", lzname);
+                               printf("%s: packed file found", lzname);
 
-                               extract_lz_file(fent->start, (unsigned char*)lzname);
+                               extract_lz_file(fent->start, (unsigned char*)lzname, 0);
                                free(lzname);
                        } else if (!strcmp(fent->name, "firmware")) {
                                unsigned char *lzpos;
@@ -120,8 +120,8 @@ void extract_files(unsigned char *fw, int len)
                                memcpy(lzname + strlen(lzname), lzpos - 4, 4);
                                lzpos += 4;
                                if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
-                                       printf("%s: compressed firmware part found", lzname);
-                                       extract_lz_file(lzpos, (unsigned char*)lzname);
+                                       printf("%s: compressed firmware part found", lzname);
+                                       extract_lz_file(lzpos, (unsigned char*)lzname, 1);
                                }
                        }
                } else {
@@ -137,6 +137,16 @@ void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname)
        exit(1);
 }
 
+void list_files(unsigned char *fw, int len)
+{
+       struct file_entry *fent;
+
+       for (fent = get_next_file(fw, len); fent != NULL; fent = get_next_file(NULL, 0)) {
+               printf("0x%x %8d %s\n", fent->unknown, fent->length, fent->name);
+       }
+
+}
+
 void mkdir_p(char *dir)
 {
        char *copy, *parent;
@@ -164,16 +174,12 @@ void mkdir_p(char *dir)
 
 void write_file(char *fname, unsigned char *buf, int len)
 {
-       char filename[PATH_MAX];
        char *filename_c, *dirn;
        int fd;
        int remaining;
        int ret;
 
-       strcpy(filename, "extracted/");
-       strcat(filename, fname);
-
-       if ((filename_c = strdup(filename)) == NULL) {
+       if ((filename_c = strdup(fname)) == NULL) {
                perror("strdup");
                exit(1);
        }
@@ -181,8 +187,8 @@ void write_file(char *fname, unsigned char *buf, int len)
        mkdir_p(dirn);
        free(filename_c);
 
-       if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) == -1) {
-               fprintf(stderr, "%s: ", filename);
+       if ((fd = open(fname, O_WRONLY|O_CREAT, 0644)) == -1) {
+               fprintf(stderr, "%s: ", fname);
                perror("open");
                exit(1);
        }
@@ -198,7 +204,17 @@ void write_file(char *fname, unsigned char *buf, int len)
                remaining -= ret;
        }
 
-       printf(", %s written.\n", filename);
+       printf("%s written.\n", fname);
 
        close(fd);
 }
+
+char *extracted_file(char *fname)
+{
+       static char filename[PATH_MAX];
+
+       strcpy(filename, "extracted/");
+       strcat(filename, fname);
+
+       return filename;
+}
Impressum, Datenschutz