diff --git a/pcireg/lh5_extract.c b/pcireg/lh5_extract.c index d740f3d..a00e86c 100644 --- a/pcireg/lh5_extract.c +++ b/pcireg/lh5_extract.c @@ -88,7 +88,7 @@ static int calc_sum(unsigned char *p, int len) unsigned int LH5HeaderParse(unsigned char *Buffer, int BufferSize, unsigned int *original_size, unsigned int *packed_size, - char **name, unsigned short *crc) + char **name, unsigned short *crc, unsigned char *method) { unsigned int offset; unsigned char header_size, checksum, name_length; @@ -106,8 +106,9 @@ LH5HeaderParse(unsigned char *Buffer, int BufferSize, } /* check method */ - if (memcmp(Buffer + 2, "-lh5-", 5) != 0) { - fprintf(stderr, "Error: Compression method is not LZHUFF5.\n"); + *method = Buffer[5]; + if (Buffer[2] != '-' || Buffer[3] != 'l' || Buffer[4] != 'h' || (*method != '0' && *method != '5') || Buffer[6] != '-') { + fprintf(stderr, "Error: Compression method %c is not supported.\n", method); return 0; } diff --git a/pcireg/lh5_extract.h b/pcireg/lh5_extract.h index fbcd4e9..228b9f8 100644 --- a/pcireg/lh5_extract.h +++ b/pcireg/lh5_extract.h @@ -22,16 +22,12 @@ unsigned int LH5HeaderParse(unsigned char *Buffer, int BufferSize, unsigned int *original_size, unsigned int *packed_size, - char **name, unsigned short *crc); + char **name, unsigned short *crc, + unsigned char *method); unsigned short CRC16Calculate(unsigned char *Buffer, int BufferSize); int LH5Decode(unsigned char *PackedBuffer, int PackedBufferSize, unsigned char *OutputBuffer, int OutputBufferSize); -extern int lzari_in_bruteforce; -int unlzari(unsigned char *in, int insz, unsigned char *out, int outsz, char common); - -int unlzh(unsigned char *in, int insz, unsigned char *out, int outsz); - #endif /* LH5_EXTRACT_H */ diff --git a/pcireg/pcireg.c b/pcireg/pcireg.c index 865cb13..06b867e 100644 --- a/pcireg/pcireg.c +++ b/pcireg/pcireg.c @@ -180,6 +180,7 @@ pciids_open_database(void **ptr, char id) char *filename; char target_filename[13]; unsigned short crc; + unsigned char method; uint8_t *buf = NULL; /* No action is required if the database is already loaded. */ @@ -204,7 +205,7 @@ pciids_open_database(void **ptr, char id) break; /* Parse LHA header. */ - header_size = LH5HeaderParse(header, sizeof(header), &original_size, &packed_size, &filename, &crc); + header_size = LH5HeaderParse(header, sizeof(header), &original_size, &packed_size, &filename, &crc, &method); if (!header_size) break; /* invalid header */ @@ -216,7 +217,7 @@ pciids_open_database(void **ptr, char id) *ptr = malloc(original_size); if (!*ptr) goto fail; - buf = malloc(packed_size); + buf = (method != '0') ? malloc(packed_size) : *ptr; if (!buf) goto fail; @@ -224,12 +225,13 @@ pciids_open_database(void **ptr, char id) fseek(f, pos + header_size, SEEK_SET); if (!fread(buf, packed_size, 1, f)) goto fail; - if (LH5Decode(buf, packed_size, *ptr, original_size) == -1) + if ((method != '0') && (LH5Decode(buf, packed_size, *ptr, original_size) == -1)) goto fail; /* All done, close archive. */ fclose(f); - free(buf); + if (buf != *ptr) + free(buf); return 0; }