2
* Extract component parts of MS CHM files
4
* Copyright (C) 2007-2008 Sourcefire, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
#ifndef __CHM_UNPACK_H
24
#define __CHM_UNPACK_H
27
#include "clamav-config.h"
34
#ifndef HAVE_ATTRIB_PACKED
35
#define __attribute__(x)
38
#ifdef HAVE_PRAGMA_PACK
42
#ifdef HAVE_PRAGMA_PACK_HPPA
46
#define CHM_ITSF_MIN_LEN (0x60)
47
typedef struct chm_itsf_header_tag
49
unsigned char signature[4];
50
int32_t version __attribute__ ((packed));
51
int32_t header_len __attribute__ ((packed));
52
uint32_t unknown __attribute__ ((packed));
53
uint32_t last_modified __attribute__ ((packed));
54
uint32_t lang_id __attribute__ ((packed));
55
unsigned char dir_clsid[16];
56
unsigned char stream_clsid[16];
57
uint64_t sec0_offset __attribute__ ((packed));
58
uint64_t sec0_len __attribute__ ((packed));
59
uint64_t dir_offset __attribute__ ((packed));
60
uint64_t dir_len __attribute__ ((packed));
61
uint64_t data_offset __attribute__ ((packed));
64
#define CHM_ITSP_LEN (0x54)
65
typedef struct chm_itsp_header_tag
67
unsigned char signature[4];
68
int32_t version __attribute__ ((packed));
69
int32_t header_len __attribute__ ((packed));
70
int32_t unknown1 __attribute__ ((packed));
71
uint32_t block_len __attribute__ ((packed));
72
int32_t blockidx_intvl __attribute__ ((packed));
73
int32_t index_depth __attribute__ ((packed));
74
int32_t index_root __attribute__ ((packed));
75
int32_t index_head __attribute__ ((packed));
76
int32_t index_tail __attribute__ ((packed));
77
int32_t unknown2 __attribute__ ((packed));
78
uint32_t num_blocks __attribute__ ((packed));
79
uint32_t lang_id __attribute__ ((packed));
80
unsigned char system_clsid[16];
81
unsigned char unknown4[16];
84
#ifdef HAVE_PRAGMA_PACK
88
#ifdef HAVE_PRAGMA_PACK_HPPA
92
typedef struct chm_sys_entry_tag
98
typedef struct chm_metadata_tag {
100
uint64_t file_offset;
101
chm_sys_entry_t sys_control;
102
chm_sys_entry_t sys_content;
103
chm_sys_entry_t sys_reset;
105
chm_itsf_header_t itsf_hdr;
106
chm_itsp_header_t itsp_hdr;
111
const char *chunk_data;
112
const char *chunk_current;
113
const char *chunk_end;
115
uint16_t chunk_entries;
118
int cli_chm_open(const char *dirname, chm_metadata_t *metadata, cli_ctx *ctx);
119
int cli_chm_prepare_file(chm_metadata_t *metadata);
120
int cli_chm_extract_file(char *dirname, chm_metadata_t *metadata, cli_ctx *ctx);
121
void cli_chm_close(chm_metadata_t *metadata);