Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Patch from Ignaz Forster. Thanks!
  • Loading branch information
twogood committed Jan 22, 2011
1 parent aea1c2d commit 0c81b16
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
8 changes: 5 additions & 3 deletions lib/component.c
Expand Up @@ -40,11 +40,13 @@ UnshieldComponent* unshield_component_new(Header* header, uint32_t offset)
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
default:
p += 0x6b;
break;

default:
abort();
}

self->file_group_count = READ_UINT16(p); p += 2;
Expand Down
18 changes: 10 additions & 8 deletions lib/file.c
Expand Up @@ -77,6 +77,11 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
default:
saved_p = p = header->data +
header->common.cab_descriptor_offset +
header->cab.file_table_offset +
Expand Down Expand Up @@ -117,10 +122,6 @@ static FileDescriptor* unshield_read_file_descriptor(Unshield* unshield, int ind

assert((p - saved_p) == 0x57);
break;

default:
unshield_error("Unknown major version: %i", header->major_version);
abort();
}

if (!(fd->flags & FILE_COMPRESSED) &&
Expand Down Expand Up @@ -363,6 +364,11 @@ static bool unshield_reader_open_volume(UnshieldReader* reader, int volume)/*{{{
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
default:
{
uint8_t six_header[VOLUME_HEADER_SIZE_V6];
uint8_t* p = six_header;
Expand All @@ -389,10 +395,6 @@ static bool unshield_reader_open_volume(UnshieldReader* reader, int volume)/*{{{
reader->volume_header.last_file_size_compressed_high = READ_UINT32(p); p += 4;
}
break;

default:
abort();
goto exit;
}

#if VERBOSE >= 2
Expand Down
27 changes: 21 additions & 6 deletions lib/libunshield.c
Expand Up @@ -205,7 +205,7 @@ static bool unshield_header_get_file_groups(Header* header)/*{{{*/
/**
Read all header files
*/
static bool unshield_read_headers(Unshield* unshield)/*{{{*/
static bool unshield_read_headers(Unshield* unshield, int version)/*{{{*/
{
int i;
bool iterate = true;
Expand Down Expand Up @@ -268,11 +268,21 @@ static bool unshield_read_headers(Unshield* unshield)/*{{{*/
unshield_error("Failed to read common header from header file %i", i);
goto error;
}

header->major_version = (header->common.version >> 12) & 0xf;

if (header->common.version == 0x020004b0)
header->major_version = 9;
if (version != -1)
{
header->major_version = version;
}
else if (header->common.version >> 24 == 1)
{
header->major_version = (header->common.version >> 12) & 0xf;
}
else if (header->common.version >> 24 == 2)
{
header->major_version = (header->common.version & 0xffff);
if (header->major_version != 0)
header->major_version = header->major_version / 100;
}

#if 0
if (header->major_version < 5)
Expand Down Expand Up @@ -328,6 +338,11 @@ static bool unshield_read_headers(Unshield* unshield)/*{{{*/
}/*}}}*/

Unshield* unshield_open(const char* filename)/*{{{*/
{
return unshield_open_force_version(filename, -1);
}/*}}}*/

Unshield* unshield_open_force_version(const char* filename, int version)/*{{{*/
{
Unshield* unshield = NEW1(Unshield);
if (!unshield)
Expand All @@ -342,7 +357,7 @@ Unshield* unshield_open(const char* filename)/*{{{*/
goto error;
}

if (!unshield_read_headers(unshield))
if (!unshield_read_headers(unshield, version))
{
unshield_error("Failed to read header files");
goto error;
Expand Down
1 change: 1 addition & 0 deletions lib/libunshield.h
Expand Up @@ -33,6 +33,7 @@ void unshield_set_log_level(int level);
*/

Unshield* unshield_open(const char* filename);
Unshield* unshield_open_force_version(const char* filename, int version);
void unshield_close(Unshield* unshield);

/*
Expand Down
12 changes: 9 additions & 3 deletions src/unshield.c
Expand Up @@ -58,6 +58,7 @@ static OVERWRITE overwrite = OVERWRITE_ASK;
static int log_level = UNSHIELD_LOG_LEVEL_LOWEST;
static int exit_status = 0;
static FORMAT format = FORMAT_NEW;
static int is_version = -1;

static bool make_sure_directory_exists(const char* directory)/*{{{*/
{
Expand Down Expand Up @@ -108,7 +109,7 @@ static void show_usage(const char* name)
fprintf(stderr,
"Syntax:\n"
"\n"
"\t%s [-c COMPONENT] [-d DIRECTORY] [-D LEVEL] [-g GROUP] [-GhlOrV] c|g|l|t|x CABFILE\n"
"\t%s [-c COMPONENT] [-d DIRECTORY] [-D LEVEL] [-g GROUP] [-i VERSION] [-GhlOrV] c|g|l|t|x CABFILE\n"
"\n"
"Options:\n"
"\t-c COMPONENT Only list/extract this component\n"
Expand All @@ -120,6 +121,7 @@ static void show_usage(const char* name)
"\t 3 - Errors, warnings and debug messages\n"
"\t-g GROUP Only list/extract this file group\n"
"\t-h Show this help message\n"
"\t-i VERSION Force InstallShield version number (don't autodetect)\n"
"\t-j Junk paths (do not make directories)\n"
"\t-L Make file and directory names lowercase\n"
"\t-O Use old compression\n"
Expand Down Expand Up @@ -152,7 +154,7 @@ static bool handle_parameters(
{
int c;

while ((c = getopt(argc, argv, "c:d:D:g:hjLnoOrV")) != -1)
while ((c = getopt(argc, argv, "c:d:D:g:hi:jLnoOrV")) != -1)
{
switch (c)
{
Expand All @@ -172,6 +174,10 @@ static bool handle_parameters(
file_group_name = optarg;
break;

case 'i':
is_version = atoi(optarg);
break;

case 'j':
junk_paths = true;
break;
Expand Down Expand Up @@ -532,7 +538,7 @@ int main(int argc, char** argv)

cabfile = argv[last_optind];

unshield = unshield_open(cabfile);
unshield = unshield_open_force_version(cabfile, is_version);
if (!unshield)
{
fprintf(stderr, "Failed to open %s as an InstallShield Cabinet File\n", cabfile);
Expand Down

0 comments on commit 0c81b16

Please sign in to comment.