]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/fpga_compress.c
chg: moved to header file
[proxmark3-svn] / client / fpga_compress.c
index 814167ad1e0206da37bf9f91a62cd1e4e9625403..c67f676918c077c1e5ebcf0eb8f6f9e460fcce57 100644 (file)
@@ -77,7 +77,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
        uint8_t *fpga_config;
        uint32_t i;
        int ret;
        uint8_t *fpga_config;
        uint32_t i;
        int ret;
-       uint8_t c;              
+       int c;          
        z_stream compressed_fpga_stream;
 
        fpga_config = malloc(num_infiles * FPGA_CONFIG_SIZE);
        z_stream compressed_fpga_stream;
 
        fpga_config = malloc(num_infiles * FPGA_CONFIG_SIZE);
@@ -87,10 +87,11 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
        do {
 
                if (i >= num_infiles * FPGA_CONFIG_SIZE) {
        do {
 
                if (i >= num_infiles * FPGA_CONFIG_SIZE) {
-                       fprintf(stderr, "Input files too big (total > %lu bytes). These are probably not PM3 FPGA config files.\n", num_infiles*FPGA_CONFIG_SIZE);
-               for(uint16_t j = 0; j < num_infiles; j++) {
+                       fprintf(stderr, "Input files too big (total > %d bytes). These are probably not PM3 FPGA config files.\n", num_infiles*FPGA_CONFIG_SIZE);
+                       for(uint16_t j = 0; j < num_infiles; j++) {
                                fclose(infile[j]);
                        }
                                fclose(infile[j]);
                        }
+                       free(fpga_config);
                        return(EXIT_FAILURE);
                }
 
                        return(EXIT_FAILURE);
                }
 
@@ -98,7 +99,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
                        for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
                                c = fgetc(infile[j]);
                                if (!feof(infile[j])) {
                        for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
                                c = fgetc(infile[j]);
                                if (!feof(infile[j])) {
-                                       fpga_config[i++] = c;
+                                       fpga_config[i++] = c &0xFF;
                                } else if (num_infiles > 1) {
                                        fpga_config[i++] = '\0';
                                }
                                } else if (num_infiles > 1) {
                                        fpga_config[i++] = '\0';
                                }
@@ -112,6 +113,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
        compressed_fpga_stream.avail_in = i;
        compressed_fpga_stream.zalloc = fpga_deflate_malloc;
        compressed_fpga_stream.zfree = fpga_deflate_free;
        compressed_fpga_stream.avail_in = i;
        compressed_fpga_stream.zalloc = fpga_deflate_malloc;
        compressed_fpga_stream.zfree = fpga_deflate_free;
+       compressed_fpga_stream.opaque = Z_NULL;
        
        ret = deflateInit2(&compressed_fpga_stream, 
                                                COMPRESS_LEVEL,
        
        ret = deflateInit2(&compressed_fpga_stream, 
                                                COMPRESS_LEVEL,
@@ -138,7 +140,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
                ret = deflate(&compressed_fpga_stream, Z_FINISH);
        }
        
                ret = deflate(&compressed_fpga_stream, Z_FINISH);
        }
        
-       fprintf(stderr, "compressed %lu input bytes to %lu output bytes\n", i, compressed_fpga_stream.total_out);
+       fprintf(stderr, "compressed %u input bytes to %lu output bytes\n", i, compressed_fpga_stream.total_out);
 
        if (ret != Z_STREAM_END) {
                fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);
 
        if (ret != Z_STREAM_END) {
                fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);
@@ -187,6 +189,7 @@ int zlib_decompress(FILE *infile, FILE *outfile)
        compressed_fpga_stream.avail_out = DECOMPRESS_BUF_SIZE;
        compressed_fpga_stream.zalloc = fpga_deflate_malloc;
        compressed_fpga_stream.zfree = fpga_deflate_free;
        compressed_fpga_stream.avail_out = DECOMPRESS_BUF_SIZE;
        compressed_fpga_stream.zalloc = fpga_deflate_malloc;
        compressed_fpga_stream.zfree = fpga_deflate_free;
+       compressed_fpga_stream.opaque = Z_NULL;
        
        ret = inflateInit2(&compressed_fpga_stream, 0);
        
        
        ret = inflateInit2(&compressed_fpga_stream, 0);
        
@@ -195,7 +198,7 @@ int zlib_decompress(FILE *infile, FILE *outfile)
                        compressed_fpga_stream.next_in = inbuf;
                        uint16_t i = 0;
                        do {
                        compressed_fpga_stream.next_in = inbuf;
                        uint16_t i = 0;
                        do {
-                               uint8_t c = fgetc(infile);
+                               int c = fgetc(infile);
                                if (!feof(infile)) {
                                        inbuf[i++] = c;
                                        compressed_fpga_stream.avail_in++;
                                if (!feof(infile)) {
                                        inbuf[i++] = c;
                                        compressed_fpga_stream.avail_in++;
Impressum, Datenschutz