]> git.zerfleddert.de Git - rsbs2/commitdiff
fileaccess cleanups
authorMichael Gernoth <michael@gernoth.net>
Thu, 5 Feb 2009 07:07:28 +0000 (08:07 +0100)
committerMichael Gernoth <michael@gernoth.net>
Thu, 5 Feb 2009 07:07:28 +0000 (08:07 +0100)
filesystem.c
rsb-lz.c
rsb-lz.h

index d4b207e7b8b5cca78e86a9c82f6b72dc83ec48e0..d6446796e7e33918ed1ca531ffe09dcbb6e2a1a5 100644 (file)
@@ -93,6 +93,8 @@ void extract_files(unsigned char *fw, int len)
                        write_file(extracted_file(fent->name), fent->start, fent->length);
                        if (*((unsigned int*)fent->start) == LZ_MAGIC) {
                                char *lzname;
+                               unsigned char *outbuf;
+                               unsigned int outlen;
 
                                if ((lzname = strdup(fent->name)) == NULL) {
                                        perror("strdup");
@@ -107,7 +109,10 @@ void extract_files(unsigned char *fw, int len)
 
                                printf("%s: packed file found, ", lzname);
 
-                               extract_lz_file(fent->start, (unsigned char*)lzname, 0);
+                               outbuf = extract_lz_file(fent->start, &outlen, 0);
+                               write_file(extracted_file((char*)lzname), outbuf, outlen);
+
+                               free(outbuf);
                                free(lzname);
                        } else if (!strcmp(fent->name, "firmware")) {
                                unsigned char *lzpos;
@@ -120,8 +125,15 @@ 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, 1);
+                                       unsigned char *outbuf;
+                                       unsigned int outlen;
+
+                                       printf("%s: compressed firmware part found", lzname);
+                                       outbuf = extract_lz_file(lzpos, &outlen, 1);
+                                       printf(", ");
+                                       write_file(extracted_file((char*)lzname), outbuf, outlen);
+
+                                       free(outbuf);
                                }
                        }
                } else {
index c771b894ffa4ddc314635bf23e1677de0d3cf687..bb735d6cebaf040b318eae11fa88ec4c9f67a2fb 100644 (file)
--- a/rsb-lz.c
+++ b/rsb-lz.c
@@ -271,9 +271,8 @@ unsigned int crc_check(unsigned char *buf, unsigned int len, unsigned int magic)
        return 0;
 }
 
-void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char check_crc)
+unsigned char *extract_lz_file(unsigned char *inbuf, unsigned int *outlen , unsigned char check_crc)
 {
-       unsigned int len;
        unsigned char *outbuf;
        struct data_in_s data_in;
        struct data_out_s data_out;
@@ -281,23 +280,23 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch
        if (*((unsigned int*)inbuf) != LZ_MAGIC)
                err_exit(__func__);
 
-       len = *((unsigned int*)(inbuf + 4));
-       printf(", length: %d", len);
+       *outlen = *((unsigned int*)(inbuf + 4));
+       printf(", length: %d", *outlen);
 
-       if ((outbuf = malloc(len)) == NULL) {
+       if ((outbuf = malloc(*outlen)) == NULL) {
                perror("malloc");
                exit(1);
        }
 
-       bzero(outbuf, len);
+       bzero(outbuf, *outlen);
 
        data_in.start = inbuf + 8;
-       data_in.stop = inbuf + len;
+       data_in.stop = inbuf + *outlen;
        data_in.byte = 0x00;
        data_in.bitpos = 0x80;
 
        data_out.pos = outbuf;
-       data_out.end = outbuf + len;
+       data_out.end = outbuf + *outlen;
 
        lz_expand(&data_in, &data_out);
 
@@ -312,7 +311,6 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch
                        err_exit(__func__);
                }
        }
-       write_file(extracted_file((char*)name), outbuf, len);
-       
-       free(outbuf);
+
+       return outbuf;
 }
index 442ec43aa9dd932388a78b5c0086fee4841228dd..4cf2c821afadc0bcd122c03f3bf37846c3a37924 100644 (file)
--- a/rsb-lz.h
+++ b/rsb-lz.h
@@ -1,4 +1,4 @@
 #define LZ_MAGIC 0x6110beef
 
-void extract_lz_file(unsigned char *buf, unsigned char *name, unsigned char check_crc);
+unsigned char *extract_lz_file(unsigned char *inbuf, unsigned int *outlen , unsigned char check_crc);
 unsigned char *compress_lz(unsigned char *inbuf, int inlen, int *outlen);
Impressum, Datenschutz