--- a/LICENSE (revision 3441) +++ b/LICENSE (revision 4010) @@ -1,3 +1,5 @@ +id-shr-extract.c is Copyright (C) 2007 Hans de Goede + Copyright (c) 2003 David Eriksson Permission is hereby granted, free of charge, to any person obtaining a copy of --- a/lib/libdynamite.c (revision 3441) +++ b/lib/libdynamite.c (revision 4010) @@ -78,11 +78,17 @@ case 1: /* encoded literal representation, not (yet) supported, fall through */ dynamite->status = DYNAMITE_NOT_IMPLEMENTED; +#if DEBUG + fprintf(stderr, "Encoded literal representation not yet supported.\n"); +#endif goto exit; default: /* not compressed with this algorithm! */ dynamite->status = DYNAMITE_BAD_FORMAT; +#if DEBUG + fprintf(stderr, "Unknown format: %i\n", header[0]); +#endif goto exit; } @@ -100,6 +106,9 @@ default: /* not compressed with this algorithm! */ dynamite->status = DYNAMITE_BAD_FORMAT; +#if DEBUG + fprintf(stderr, "Unknown dictionary bits: %i\n", dynamite->dictionary_bits); +#endif goto exit; } --- a/ChangeLog (revision 3441) +++ b/ChangeLog (revision 4010) @@ -1,3 +1,13 @@ +2011-03-23 David Eriksson + + * VERSION: Upped the version number. + + * src/id-shr-extract.c: Added submitted code to extract ID Softwhare .SHR files. + +2008-05-11 Mark Ellis + + * man patch fix, thanks to Evgeni Golov + 2008-05-06 Jonny Lamb * VERSION: Upped the version number. --- a/src/id-shr-extract.c (revision 0) +++ b/src/id-shr-extract.c (revision 4010) @@ -0,0 +1,158 @@ +/* utility to extract the .SHR installer data files of early ID software + shareware games + + Copyright (C) 2007 Hans de Goede +*/ + +#include +#include +#include +#include +#include + +struct cookie_s { + char *in_buffer; + size_t in_buffer_remaining; + int in_buffer_index; + size_t in_buffer_size; + FILE* out_file; +}; + +size_t reader(void* buffer, size_t size, void* cookie) +{ + struct cookie_s *c = cookie; + if (size > c->in_buffer_remaining) + size = c->in_buffer_remaining; + + memcpy (buffer, c->in_buffer + c->in_buffer_index, size); + + c->in_buffer_index += size; + c->in_buffer_remaining -= size; + + return size; +} + +size_t writer(void* buffer, size_t size, void* cookie) +{ + struct cookie_s *c = cookie; + return fwrite(buffer, 1, size, c->out_file); +} + +int main(int argc, char *argv[]) +{ + struct cookie_s cookie; + FILE *in_file; + char filename[16]; + unsigned char buf[4]; + size_t i, compressed_size; + + if (argc != 2) { + fprintf(stderr, "%s: Usage: %s %d\n", argv[0], argv[0], argc); + return 1; + } + + in_file = fopen(argv[1], "r"); + if (!in_file) { + fprintf(stderr, "error opening: %s", argv[1]); + perror(NULL); + return 1; + } + + /* skip first 0x3A bytes header */ + if (fseek(in_file, 0x3A, SEEK_CUR)) { + perror("error skipping initial file header"); + return 1; + } + + cookie.in_buffer = malloc(65536); + if (!cookie.in_buffer) { + fprintf(stderr, "Error: out of memory\n"); + return 1; + } + cookie.in_buffer_size = 65536; + + while (1) + { + /* get the name of the file */ + if (fread(filename, 1, sizeof(filename), in_file) != sizeof(filename)) { + if (feof(in_file)) { + free(cookie.in_buffer); + fclose(in_file); + return 0; /* done */ + } + perror("error getting output filename from file"); + return 1; + } + + /* verify the filename and convert to lower case */ + for (i = 0 ; i < sizeof(filename); i++) { + if (filename[i] == 0) + break; /* done */ + if (!isprint(filename[i])) { + fprintf(stderr, "error invalid output filename\n"); + return 1; + } + filename[i] = tolower(filename[i]); + } + if (i == sizeof(filename)) { + fprintf(stderr, "error too long output filename\n"); + return 1; + } + + /* seek to compressed size */ + if (fseek(in_file, 0x88 - sizeof(filename), SEEK_CUR)) { + perror("error skipping file header before file size"); + return 1; + } + + if (fread(buf, 1, 4, in_file) != 4) { + perror("error reading file size"); + return 1; + } + compressed_size = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + if (compressed_size > cookie.in_buffer_size) { + cookie.in_buffer = realloc(cookie.in_buffer, compressed_size); + if (!cookie.in_buffer) { + fprintf(stderr, "Error: out of memory\n"); + return 1; + } + cookie.in_buffer_size = compressed_size; + } + + /* seek to begin of compressed data */ + if (fseek(in_file, 0x1C, SEEK_CUR)) { + perror("error skipping file header before file size"); + return 1; + } + + /* read compressed data */ + if (fread(cookie.in_buffer, 1, compressed_size, in_file) != + compressed_size) { + perror("error reading compressed data"); + return 1; + } + + cookie.in_buffer_index = 0; + cookie.in_buffer_remaining = compressed_size; + + cookie.out_file = fopen(filename, "w"); + if (!cookie.out_file) { + fprintf(stderr, "Error creating: %s for writing", filename); + perror(NULL); + return 1; + } + + printf("decompressing: %s, compressed size: %d\n", filename, + compressed_size); + + if ((i = dynamite_explode(reader, writer, &cookie))) { + fprintf(stderr, "Error: %d while decompressing\n", i); + return i; + } + + fclose(cookie.out_file); + } + + /* never reached */ + return 0; +} --- a/src/Makefile.am (revision 3441) +++ b/src/Makefile.am (revision 4010) @@ -1,10 +1,12 @@ INCLUDES = -I../lib LDADD = ../lib/libdynamite.la -bin_PROGRAMS = dynamite +bin_PROGRAMS = dynamite id-shr-extract dynamite_SOURCES = dynamite.c +id_shr_extract_SOURCES = id-shr-extract.c + noinst_PROGRAMS = queen_extract queen_extract_SOURCES = queen_extract.c --- a/man/dynamite.1 (revision 3441) +++ b/man/dynamite.1 (revision 4010) @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.33. .TH DYNAMITE "1" "June 2004" "dynamite" "User Commands" .SH NAME -dynamite \- manual page for dynamite +dynamite \- PKWARE Data Compression decompressor .SH SYNOPSIS dynamite [input_offset] .SH DESCRIPTION