From: <tw...@us...> - 2003-08-12 12:36:40
|
Update of /cvsroot/synce/unshield/lib In directory sc8-pr-cvs1:/tmp/cvs-serv26946/lib Modified Files: cabfile.h file.c unshield_internal.h Log Message: InstallShield 6 working much better now Index: cabfile.h =================================================================== RCS file: /cvsroot/synce/unshield/lib/cabfile.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cabfile.h 10 Aug 2003 11:41:39 -0000 1.2 +++ cabfile.h 12 Aug 2003 12:36:36 -0000 1.3 @@ -101,8 +101,14 @@ P uint32_t unknown1; /* 32 */ P uint32_t unknown2; /* 36 */ P uint32_t name_offset; /* 3a */ - P uint8_t unknown3[0x19]; /* 3e */ + P uint8_t unknown3[0x17]; /* 3e */ + P uint16_t volume; /* 55 */ } FileDescriptor6; + +#define FILE_SPLIT 1L +#define FILE_ENCRYPTED 2L +#define FILE_COMPRESSED 4L +#define FILE_INVALID 8L #undef P Index: file.c =================================================================== RCS file: /cvsroot/synce/unshield/lib/file.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- file.c 10 Aug 2003 11:41:39 -0000 1.2 +++ file.c 12 Aug 2003 12:36:36 -0000 1.3 @@ -3,6 +3,7 @@ #include "cabfile.h" #include <synce_log.h> #include <stdlib.h> +#include <string.h> #include <zlib.h> static FileDescriptor5* unshield_file_descriptor5(Header* header, int index)/*{{{*/ @@ -107,7 +108,11 @@ unsigned char* output_buffer = (unsigned char*)malloc(BUFFER_SIZE); int bytes_left; uint32_t data_offset; - + uint32_t expanded_size; + uLong total_written = 0; + bool compressed = true; + int volume; + if (!unshield || !filename) goto exit; @@ -119,17 +124,44 @@ case 5: { FileDescriptor5* fd = unshield_file_descriptor5(header, index); - data_offset = letoh32(fd->data_offset); - bytes_left = letoh32(fd->compressed_size); + data_offset = letoh32(fd->data_offset); + bytes_left = letoh32(fd->compressed_size); + expanded_size = letoh32(fd->expanded_size); + volume = header->index; } break; case 6: { FileDescriptor6* fd = unshield_file_descriptor6(header, index); - data_offset = letoh32(fd->data_offset); - bytes_left = letoh32(fd->compressed_size); - synce_trace("Compressed size: %i", bytes_left); + uint32_t status = letoh32(fd->status); + + if (status & FILE_INVALID) + { + synce_error("Not a valid file"); + goto exit; + } + + if (status & FILE_SPLIT) + { + synce_trace("Split file!"); + } + + if (status & FILE_COMPRESSED) + { + compressed = true; + bytes_left = letoh32(fd->compressed_size); + } + else + { + compressed = false; + bytes_left = letoh32(fd->expanded_size); + } + + data_offset = letoh32(fd->data_offset); + expanded_size = letoh32(fd->expanded_size); + volume = letoh16(fd->volume); + /*synce_trace("Compressed size: %i", bytes_left);*/ } break; @@ -138,10 +170,10 @@ return NULL; } - input = unshield_fopen_for_reading(unshield, header->index, CABINET_SUFFIX); + input = unshield_fopen_for_reading(unshield, volume, CABINET_SUFFIX); if (!input) { - synce_error("Failed to open input cabinet file %i", header->index); + synce_error("Failed to open input cabinet file %i", volume); goto exit; } @@ -154,39 +186,75 @@ if (fseek(input, data_offset, SEEK_SET)) { - synce_error("Failed to seek in input cabinet file %i", header->index); + synce_error("Failed to seek in input cabinet file %i", volume); goto exit; } while (bytes_left > 0) { - uint16_t bytes_to_read = 0; uLong bytes_to_write = BUFFER_SIZE; int result; - fread(&bytes_to_read, 1, sizeof(bytes_to_read), input); - bytes_to_read = letoh16(bytes_to_read); - if (bytes_to_read != fread(input_buffer, 1, bytes_to_read, input)) + if (compressed) { - synce_error("Failed to read %i bytes from input cabinet file %i", bytes_to_read); - goto exit; + uint16_t bytes_to_read = 0; + + if (sizeof(bytes_to_read) != fread(&bytes_to_read, 1, sizeof(bytes_to_read), input)) + { + synce_error("Failed to read %i bytes from input cabinet file %i", + sizeof(bytes_to_read), volume); + goto exit; + } + + bytes_to_read = letoh16(bytes_to_read); + if (bytes_to_read != fread(input_buffer, 1, bytes_to_read, input)) + { + synce_error("Failed to read %i bytes from input cabinet file %i", + bytes_to_read, volume); + goto exit; + } + + /* add a null byte to make inflate happy */ + input_buffer[bytes_to_read] = 0; + result = unshield_uncompress(output_buffer, &bytes_to_write, input_buffer, bytes_to_read+1); + + if (Z_OK != result) + { + synce_error("Decompression failed with code %i. bytes_to_read=%i, bytes_left=%i", + result, bytes_to_read, bytes_left); + /* abort();*/ + goto exit; + } + + bytes_left -= 2; + bytes_left -= bytes_to_read; } + else + { + bytes_to_write = (bytes_left > BUFFER_SIZE) ? BUFFER_SIZE : bytes_left; + if (bytes_to_write != fread(input_buffer, 1, bytes_to_write, input)) + { + synce_error("Failed to read %i bytes from input cabinet file %i", + bytes_to_write, volume); + goto exit; + } - /* add a null byte to make inflate happy */ - input_buffer[bytes_to_read] = 0; - result = unshield_uncompress(output_buffer, &bytes_to_write, input_buffer, bytes_to_read+1); + bytes_left -= bytes_to_write; + } - if (Z_OK != result) + if (bytes_to_write != fwrite(output_buffer, 1, bytes_to_write, output)) { - synce_error("Decompression failed with code %i", result); - abort(); + synce_error("Failed to write %i bytes to file '%s'", bytes_to_write, filename); goto exit; } - fwrite(output_buffer, bytes_to_write, 1, output); + total_written += bytes_to_write; + } - bytes_left -= 2; - bytes_left -= bytes_to_read; + if (expanded_size != total_written) + { + synce_error("Expanded size expected to be %i, but was %i", expanded_size, total_written); + goto exit; } success = true; Index: unshield_internal.h =================================================================== RCS file: /cvsroot/synce/unshield/lib/unshield_internal.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- unshield_internal.h 10 Aug 2003 11:41:39 -0000 1.3 +++ unshield_internal.h 12 Aug 2003 12:36:36 -0000 1.4 @@ -49,10 +49,10 @@ Macros for safer development */ -#define FREE(ptr) { if (ptr) { free(ptr); (ptr) = NULL; } } +#define FREE(ptr) { if (ptr) { free(ptr); ptr = NULL; } } #define STRDUP(str) ((str) ? strdup(str) : NULL) #define NEW1(type) ((type*)calloc(1, sizeof(type))) -#define FCLOSE(file) if (file) fclose(file) +#define FCLOSE(file) if (file) { fclose(file); file = NULL; } #define FSIZE(file) (file ? unshield_fsize(file) : 0) #endif |