2
* msexpand: Microsoft "compress.exe/expand.exe" compatible decompressor
4
* Copyright (c) 2000 Martin Hinner <mhi@penguin.cz>
5
* Algorithm & data structures by M. Winterhoff <100326.2776@compuserve.com>
7
* Corrected and adapted to ClamAV by Tomasz Kojm <tkojm@clamav.net>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
31
#include "clamav-config.h"
37
int cli_msexpand(FILE *in, FILE *out)
39
int bits, ch, i, j, len, mask;
40
unsigned char *buffer;
41
uint32_t magic1, magic2, magic3, filesize;
45
if(fread(&magic1, sizeof(magic1), 1, in) != 1) {
49
if(magic1 == le32_to_host(0x44445A53L))
51
if(fread(&magic2, sizeof(magic2), 1, in) != 1) {
55
if(fread(&reserved, sizeof(reserved), 1, in) != 1) {
59
if(fread(&filesize, sizeof(filesize), 1, in) != 1) {
63
if(magic2 != le32_to_host(0x3327F088L))
65
cli_warnmsg("msexpand: Not a MS-compressed file\n");
70
if(magic1 == le32_to_host(0x4A41574BL))
72
if(fread(&magic2, sizeof(magic2), 1, in) != 1) {
76
if(fread(&magic3, sizeof(magic3), 1, in) != 1) {
80
if(fread(&reserved, sizeof(reserved), 1, in) != 1) {
84
if(magic2 != le32_to_host(0xD127F088L) || magic3 != le32_to_host(0x00120003L))
86
cli_warnmsg("msexpand: Not a MS-compressed file\n");
90
cli_warnmsg("msexpand: unsupported version 6.22\n");
94
cli_warnmsg("msexpand: Not a MS-compressed file\n");
98
if((buffer = (unsigned char *) cli_calloc(4096, sizeof(char))) == NULL) {
99
cli_errmsg("msexpand: Can't allocate memory\n");
106
if((bits = fgetc(in)) == EOF)
109
for(mask = 0x01; mask & 0xFF; mask <<= 1) {
111
if((j = fgetc(in)) == EOF)
114
j += (len & 0xF0) << 4;
115
len = (len & 15) + 3;
117
buffer[i] = buffer[j];
118
if(fwrite(&buffer[i], sizeof(unsigned char), 1, out) != 1) {
128
if((ch = fgetc(in)) == EOF)
132
if(fwrite(&buffer[i], sizeof(unsigned char), 1, out) != 1) {