mirror of
https://github.com/86Box/probing-tools.git
synced 2026-02-24 02:18:22 -07:00
pcireg: Add lh0 uncompressed file support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user