Nick: roxfan E-mail: none Board: unlzint.c Contents: #include "lzint_decode.h" #ifdef _WIN32 #include #include #endif int err(int n, char *str) { fprintf(stderr, str); return n; } int unpack_file(FILE *f, int pos, char *fn) { int origpos = ftell(f); int res; struct { dword compressed_module_length; dword uncompressed_length; } hdr; FILE *fw; interfacing iface; output_header outhdr; //printf("Found module at position 0x%X.\n", pos); fseek(f, pos, SEEK_SET); fread(&hdr, sizeof(hdr), 1, f); if ( strcmp(fn, "-") == 0 ) { #ifdef _WIN32 _setmode( _fileno( stdout ), _O_BINARY ); #endif fw = stdout; } else { fw = fopen(fn, "wb"); if ( !fw ) return err(5, "Cannot open output file.\n"); } //printf("lzint compression (%X, %X).\n", hdr.compression, hdr.length); iface.infile = f; iface.outfile = fw; iface.original = hdr.uncompressed_length; iface.packed = hdr.compressed_module_length; iface.dicbit = 13; iface.method = 5; if (decode(iface)) res = 0; else res = 2; if ( strcmp(fn, "-") != 0 ) fclose(fw); fseek(f, origpos, SEEK_SET); return res; } int main(int argc, char **argv) { FILE *f; if (argc != 3) { printf("Usage:\n unlzint input output\n\n"); return 0; } if ( strcmp(argv[1], "-") == 0 ) { #ifdef _WIN32 _setmode( _fileno( stdin ), _O_BINARY ); #endif f = stdin; } else { f = fopen(argv[1], "rb"); if ( !f ) return err(5, "Cannot open input file"); } unpack_file(f, 0, argv[2]); if ( strcmp(argv[1], "-") != 0 ) fclose(f); // printf("Done.\n"); return 0; }