]> cvs.zerfleddert.de Git - rsbs2/blobdiff - rsb-lz.c
better corruption check by calculating the number of fill bytes
[rsbs2] / rsb-lz.c
index 24977029e52f2cb64f00764f27202a732dd96399..3e6e63820f6ab8c5251b367cac208e6c7d56f6b5 100644 (file)
--- a/rsb-lz.c
+++ b/rsb-lz.c
@@ -1,16 +1,12 @@
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <libgen.h>
 #include "rsb-crc.h"
 #include "rsb-lz.h"
+#include "extract.h"
 
 /* TODO: IMPLEMET THIS! */
 /* Probably very broken lzw implementation by Agilent:
@@ -638,72 +634,6 @@ unsigned int crc_check_59684(unsigned char *arg1, unsigned int arg2, unsigned in
        return 4;
 }
 
-void mkdir_p(char *dir)
-{
-       char *copy, *parent;
-
-       if ((dir == NULL) || (!strcmp(dir, ".")))
-               return;
-
-       if ((copy = strdup(dir)) == NULL) {
-               perror("strdup");
-               exit(1);
-       }
-       parent = dirname(copy);
-       mkdir_p(parent);
-
-       errno = 0;
-       if (mkdir(dir, 0755) == -1) {
-               if (errno != EEXIST) {
-                       fprintf(stderr, "%s: ", dir);
-                       perror("mkdir");
-                       exit(1);
-               }
-       }
-       free(copy);
-}
-
-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) {
-               perror("strdup");
-               exit(1);
-       }
-       dirn = dirname(filename_c);
-       mkdir_p(dirn);
-       free(filename_c);
-
-       if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) == -1) {
-               fprintf(stderr, "%s: ", filename);
-               perror("open");
-               exit(1);
-       }
-
-       remaining = len;
-
-       while(remaining) {
-               ret = write(fd, buf + (len - remaining), remaining);
-               if (ret < 0) {
-                       perror("write");
-                       exit(1);
-               }
-               remaining -= ret;
-       }
-
-       printf(", %s written.\n", filename);
-
-       close(fd);
-}
-
 void extract_lz_file(unsigned char *buf, unsigned char *name)
 {
        unsigned char *r3;
@@ -719,7 +649,7 @@ void extract_lz_file(unsigned char *buf, unsigned char *name)
 
        r3 = r11 + 4;
        r5 = *((unsigned int*)r3);
-       printf(", length: %d\n", r5);
+       printf(", length: %d", r5);
 
        if ((r7 = malloc(r5)) == NULL) {
                perror("malloc");
@@ -757,31 +687,3 @@ void extract_lz_file(unsigned char *buf, unsigned char *name)
        
        free(r7);
 }
-
-void search_lz_sections(unsigned char *fw, int len)
-{
-       int i;
-       unsigned char *j;
-
-       for(i = 0; i < len - 4; i++) {
-               if (*((unsigned int*)(fw+i)) == LZ_MAGIC) {
-                       j = fw + i - 1;
-                       if (*j != 0x00)
-                               continue;
-                       printf("0x%02x: ", i);
-                       j--;
-                       while (j > fw) {
-                               if (*j == 0x00) {
-                                       if ( *(j+1) != '/') {
-                                               printf("ignoring...\n");
-                                               break;
-                                       }
-                                       printf("%s", j+1);
-                                       extract_lz_file(fw + i, j+1);
-                                       break;
-                               }
-                               j--;
-                       }
-               }
-       }
-}
Impressum, Datenschutz