]> cvs.zerfleddert.de Git - rsbs2/commitdiff
check crc of embedded compressed firmware after expansion
authorMichael Gernoth <michael@gernoth.net>
Mon, 2 Feb 2009 23:13:00 +0000 (00:13 +0100)
committerMichael Gernoth <michael@gernoth.net>
Mon, 2 Feb 2009 23:13:00 +0000 (00:13 +0100)
filesystem.c
rsb-lz.c
rsb-lz.h

index 84c592cac3b00e01760e8d8fb7e32601681b67ba..175cbc4d0670479af52999da0c800f3c69d4b24b 100644 (file)
@@ -107,7 +107,7 @@ void extract_files(unsigned char *fw, int len)
 
                                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;
@@ -121,7 +121,7 @@ void extract_files(unsigned char *fw, int len)
                                lzpos += 4;
                                if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
                                        printf("%s: compressed firmware part found", lzname);
-                                       extract_lz_file(lzpos, (unsigned char*)lzname);
+                                       extract_lz_file(lzpos, (unsigned char*)lzname, 1);
                                }
                        }
                } else {
index 93e9d79f2acfd41001d31febb9b4412f97b55ed6..c23dd5a02af56450920eb4f43f2e1e1c07155c8b 100644 (file)
--- a/rsb-lz.c
+++ b/rsb-lz.c
@@ -136,43 +136,36 @@ void lz_expand(struct data_in_s *data_in, struct data_out_s *data_out)
 }
 
 /* Checksum is only used for the compressed firmware in 'firmware' */
-#if 0
-unsigned int crc_check_59684(unsigned char *arg1, unsigned int arg2, unsigned int magic)
+unsigned int crc_check(unsigned char *buf, unsigned int len, unsigned int magic)
 {
-       unsigned int r3;
-       unsigned int r4;
-       unsigned int r5;
+       unsigned int file_crc;
+       unsigned int my_len;
+       unsigned int crc;
+       unsigned int my_magic;
 
-#if 0
-       if (r0 < 0xc0000000)
-               return 1;
-#endif
+       my_len = *((unsigned int*)(buf + 0x20));
+       my_magic = *((unsigned int*)(buf + 0x24));
 
-       /* ??? */
-       r4 = *((unsigned int*)arg1 + 0x20);
-       r5 = *((unsigned int*)arg1 + 0x24);
-
-       printf("magic: 0x%08x <-> 0x%08x\n", r5, magic);
-       if (r5 != magic)
+       if (my_magic != magic) {
+               printf("\nmagic: 0x%08x <-> 0x%08x\n", my_magic, magic);
                return 2;
+       }
        
-       if (arg2 >= r4)
-               r5 = 0;
-       else
+       if (len < my_len)
                return 3;
 
-       r5 = ~rsb_crc(~0x00, arg1, r4);
-       r3 = *((unsigned int*)(arg1 + r4));
-       printf("Checksums: 0x%02x <-> 0x%02x\n", r5, r3);
+       crc = ~rsb_crc(~0x00, buf, len);
+       file_crc = *((unsigned int*)(buf + len));
 
-       if (r3 == r5)
-               return 0;
+       if (file_crc != crc) {
+               printf("\nChecksums: 0x%08x <-> 0x%08x!\n", crc, file_crc);
+               return 4;
+       }
 
-       return 4;
+       return 0;
 }
-#endif
 
-void extract_lz_file(unsigned char *inbuf, unsigned char *name)
+void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char check_crc)
 {
        unsigned int len;
        unsigned char *outbuf;
@@ -202,16 +195,17 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name)
 
        lz_expand(&data_in, &data_out);
 
-#if 0
-       /* Checksum is only used for the compressed firmware in 'firmware' */
-       r3 = r7 + 0x20;
-       r5 = *((unsigned int*)r3);
+       if (check_crc) {
+               unsigned int crclen;
+               int ret;
 
-       if ((ret = crc_check_59684(r7, r5, 0x46335053)) != 0) {
-               printf("crc_check return: %d\n", ret);
-               err_exit(__func__);
+               crclen = *((unsigned int*)(outbuf + 0x20));
+
+               if ((ret = crc_check(outbuf, crclen, 0x46335053)) != 0) {
+                       printf("crc_check return: %d\n", ret);
+                       err_exit(__func__);
+               }
        }
-#endif
 
        write_file((char*)name, outbuf, len);
        
index ed0d4fb4fee992c2246587e9ee83c6194e79d8b2..767ceb9e9117875ea2fa7b66b5531a78da281fa9 100644 (file)
--- a/rsb-lz.h
+++ b/rsb-lz.h
@@ -1,3 +1,3 @@
 #define LZ_MAGIC 0x6110beef
 
-void extract_lz_file(unsigned char *buf, unsigned char *name);
+void extract_lz_file(unsigned char *buf, unsigned char *name, unsigned char check_crc);
Impressum, Datenschutz