2004-03-20 14:49:22 +00:00
|
|
|
/*
|
2020-01-03 15:44:07 -05:00
|
|
|
* Copyright (C) 2013-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
2014-04-30 15:42:11 -04:00
|
|
|
* Copyright (C) 2007-2013 Sourcefire, Inc.
|
2007-12-14 22:39:37 +00:00
|
|
|
*
|
2008-04-02 15:24:51 +00:00
|
|
|
* Authors: Tomasz Kojm
|
2004-03-20 14:49:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-03-31 20:31:04 +00:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2004-03-20 14:49:22 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2004-03-20 14:49:22 +00:00
|
|
|
*/
|
|
|
|
|
2004-07-02 23:00:58 +00:00
|
|
|
#ifndef __FILETYPES_H
|
|
|
|
#define __FILETYPES_H
|
|
|
|
|
2006-03-25 00:10:15 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2007-12-14 22:39:37 +00:00
|
|
|
#include "clamav.h"
|
2009-09-01 13:49:36 +02:00
|
|
|
#include "fmap.h"
|
2007-12-14 22:39:37 +00:00
|
|
|
|
2013-09-17 16:45:48 -04:00
|
|
|
#define CL_FILE_MBUFF_SIZE 1024
|
2013-09-23 03:19:07 -04:00
|
|
|
#define CL_PART_MBUFF_SIZE 1028
|
2013-09-17 16:45:48 -04:00
|
|
|
/* MAGIC_BUFFER_SIZE must be the bigger of the two sizes above */
|
2013-09-23 03:19:07 -04:00
|
|
|
#define MAGIC_BUFFER_SIZE 1028
|
2013-09-17 16:45:48 -04:00
|
|
|
|
2004-07-02 23:00:58 +00:00
|
|
|
#define CL_TYPENO 500
|
2007-03-12 21:31:40 +00:00
|
|
|
#define MAX_EMBEDDED_OBJ 10
|
2004-03-20 14:49:22 +00:00
|
|
|
|
2019-02-27 00:47:38 -05:00
|
|
|
typedef enum cli_file {
|
2018-12-03 12:40:13 -05:00
|
|
|
CL_TYPE_ANY = 0,
|
2008-01-07 14:20:38 +00:00
|
|
|
CL_TYPE_TEXT_ASCII = CL_TYPENO, /* X3.4, ISO-8859, non-ISO ext. ASCII */
|
|
|
|
CL_TYPE_TEXT_UTF8,
|
|
|
|
CL_TYPE_TEXT_UTF16LE,
|
|
|
|
CL_TYPE_TEXT_UTF16BE,
|
|
|
|
CL_TYPE_BINARY_DATA,
|
|
|
|
/* Please do not add any new types above this line */
|
2007-12-14 22:39:37 +00:00
|
|
|
CL_TYPE_ERROR,
|
2004-09-13 16:44:01 +00:00
|
|
|
CL_TYPE_MSEXE,
|
2005-08-29 15:02:38 +00:00
|
|
|
CL_TYPE_ELF,
|
2009-07-08 15:05:22 +02:00
|
|
|
CL_TYPE_MACHO,
|
2009-07-14 18:19:54 +02:00
|
|
|
CL_TYPE_MACHO_UNIBIN,
|
2005-03-22 21:26:27 +00:00
|
|
|
CL_TYPE_POSIX_TAR,
|
|
|
|
CL_TYPE_OLD_TAR,
|
2009-07-06 16:15:33 +02:00
|
|
|
CL_TYPE_CPIO_OLD,
|
|
|
|
CL_TYPE_CPIO_ODC,
|
|
|
|
CL_TYPE_CPIO_NEWC,
|
|
|
|
CL_TYPE_CPIO_CRC,
|
2004-09-13 16:44:01 +00:00
|
|
|
CL_TYPE_GZ,
|
|
|
|
CL_TYPE_ZIP,
|
|
|
|
CL_TYPE_BZ,
|
|
|
|
CL_TYPE_RAR,
|
2007-07-11 10:14:08 +00:00
|
|
|
CL_TYPE_ARJ,
|
2004-09-13 16:44:01 +00:00
|
|
|
CL_TYPE_MSSZDD,
|
|
|
|
CL_TYPE_MSOLE2,
|
|
|
|
CL_TYPE_MSCAB,
|
|
|
|
CL_TYPE_MSCHM,
|
2005-12-15 02:02:29 +00:00
|
|
|
CL_TYPE_SIS,
|
2004-09-13 16:44:01 +00:00
|
|
|
CL_TYPE_SCRENC,
|
2004-09-17 23:29:44 +00:00
|
|
|
CL_TYPE_GRAPHICS,
|
2017-03-04 00:08:03 +01:00
|
|
|
CL_TYPE_GIF,
|
2017-02-21 19:58:09 +01:00
|
|
|
CL_TYPE_PNG,
|
2005-02-05 15:50:18 +00:00
|
|
|
CL_TYPE_RIFF,
|
2004-11-18 19:30:29 +00:00
|
|
|
CL_TYPE_BINHEX,
|
2005-03-22 22:43:45 +00:00
|
|
|
CL_TYPE_TNEF,
|
2005-11-14 21:02:26 +00:00
|
|
|
CL_TYPE_CRYPTFF,
|
2005-05-01 00:47:39 +00:00
|
|
|
CL_TYPE_PDF,
|
2006-01-21 18:37:48 +00:00
|
|
|
CL_TYPE_UUENCODED,
|
2008-02-04 21:38:34 +00:00
|
|
|
CL_TYPE_SCRIPT,
|
2006-10-25 15:40:47 +00:00
|
|
|
CL_TYPE_HTML_UTF16,
|
2006-12-04 00:10:46 +00:00
|
|
|
CL_TYPE_RTF,
|
2009-08-06 18:22:46 +02:00
|
|
|
CL_TYPE_7Z,
|
2011-03-28 20:25:40 +02:00
|
|
|
CL_TYPE_SWF,
|
2013-02-07 14:08:03 -05:00
|
|
|
CL_TYPE_JAVA,
|
2013-08-27 13:44:11 -04:00
|
|
|
CL_TYPE_XAR,
|
2013-10-08 17:17:44 -04:00
|
|
|
CL_TYPE_XZ,
|
2013-10-17 16:54:21 -04:00
|
|
|
CL_TYPE_OOXML_WORD,
|
|
|
|
CL_TYPE_OOXML_PPT,
|
|
|
|
CL_TYPE_OOXML_XL,
|
2014-04-29 17:15:07 -04:00
|
|
|
CL_TYPE_INTERNAL,
|
2015-12-08 15:05:30 -05:00
|
|
|
CL_TYPE_HWP3,
|
2015-12-17 16:16:55 -05:00
|
|
|
CL_TYPE_OOXML_HWP,
|
2016-06-28 17:39:06 -04:00
|
|
|
CL_TYPE_PS,
|
2018-10-08 12:59:42 -04:00
|
|
|
CL_TYPE_EGG,
|
2007-01-07 20:51:43 +00:00
|
|
|
|
2013-09-17 16:45:48 -04:00
|
|
|
/* Section for partition types */
|
|
|
|
CL_TYPE_PART_ANY, /* unknown partition type */
|
|
|
|
CL_TYPE_PART_HFSPLUS,
|
|
|
|
|
2004-07-03 15:24:43 +00:00
|
|
|
/* bigger numbers have higher priority (in o-t-f detection) */
|
2014-03-24 18:45:29 -04:00
|
|
|
CL_TYPE_MBR,
|
2018-12-03 12:40:13 -05:00
|
|
|
CL_TYPE_HTML, /* on the fly */
|
|
|
|
CL_TYPE_MAIL, /* magic + on the fly */
|
|
|
|
CL_TYPE_SFX, /* foo SFX marker */
|
2005-07-26 01:33:15 +00:00
|
|
|
CL_TYPE_ZIPSFX, /* on the fly */
|
2006-11-01 18:02:04 +00:00
|
|
|
CL_TYPE_RARSFX, /* on the fly */
|
2011-11-01 12:27:46 +01:00
|
|
|
CL_TYPE_7ZSFX,
|
2007-05-20 21:02:46 +00:00
|
|
|
CL_TYPE_CABSFX,
|
2007-07-11 10:14:08 +00:00
|
|
|
CL_TYPE_ARJSFX,
|
2018-10-08 12:59:42 -04:00
|
|
|
CL_TYPE_EGGSFX,
|
2007-10-30 18:53:25 +00:00
|
|
|
CL_TYPE_NULSFT, /* on the fly */
|
2008-02-20 22:04:48 +00:00
|
|
|
CL_TYPE_AUTOIT,
|
2009-07-13 01:02:13 +02:00
|
|
|
CL_TYPE_ISHIELD_MSI,
|
2011-11-14 21:23:15 +01:00
|
|
|
CL_TYPE_ISO9660,
|
2013-08-27 13:44:11 -04:00
|
|
|
CL_TYPE_DMG,
|
2014-01-24 14:24:56 -05:00
|
|
|
CL_TYPE_GPT,
|
2014-02-06 19:01:26 -05:00
|
|
|
CL_TYPE_APM,
|
2014-07-31 19:11:22 -04:00
|
|
|
CL_TYPE_XDP,
|
2015-03-10 14:01:35 -04:00
|
|
|
CL_TYPE_XML_WORD,
|
|
|
|
CL_TYPE_XML_XL,
|
2015-12-15 10:54:20 -05:00
|
|
|
CL_TYPE_XML_HWP,
|
2015-12-17 11:04:00 -05:00
|
|
|
CL_TYPE_HWPOLE2,
|
2016-05-02 17:32:03 -04:00
|
|
|
CL_TYPE_MHTML,
|
2018-10-19 20:25:38 -07:00
|
|
|
CL_TYPE_LNK,
|
2015-07-23 16:37:15 -04:00
|
|
|
|
2018-12-03 12:40:13 -05:00
|
|
|
CL_TYPE_OTHER, /* on-the-fly, used for target 14 (OTHER) */
|
2008-02-20 22:04:48 +00:00
|
|
|
CL_TYPE_IGNORED /* please don't add anything below */
|
2004-03-20 14:49:22 +00:00
|
|
|
} cli_file_t;
|
|
|
|
|
2007-12-14 22:39:37 +00:00
|
|
|
struct cli_ftype {
|
|
|
|
cli_file_t type;
|
|
|
|
uint32_t offset;
|
|
|
|
unsigned char *magic;
|
|
|
|
char *tname;
|
|
|
|
struct cli_ftype *next;
|
2008-01-10 19:37:27 +00:00
|
|
|
uint16_t length;
|
2007-12-14 22:39:37 +00:00
|
|
|
};
|
|
|
|
|
2006-01-15 15:46:36 +00:00
|
|
|
struct cli_matched_type {
|
2008-01-10 19:37:27 +00:00
|
|
|
struct cli_matched_type *next;
|
2006-03-25 00:10:15 +00:00
|
|
|
off_t offset;
|
2008-01-10 19:37:27 +00:00
|
|
|
cli_file_t type;
|
2006-03-25 00:10:15 +00:00
|
|
|
unsigned short cnt;
|
2006-01-15 15:46:36 +00:00
|
|
|
};
|
|
|
|
|
2007-12-14 22:39:37 +00:00
|
|
|
cli_file_t cli_ftcode(const char *name);
|
2011-03-04 18:27:32 +01:00
|
|
|
const char *cli_ftname(cli_file_t code);
|
2008-10-19 16:16:49 +00:00
|
|
|
void cli_ftfree(const struct cl_engine *engine);
|
2007-12-14 22:39:37 +00:00
|
|
|
cli_file_t cli_filetype(const unsigned char *buf, size_t buflen, const struct cl_engine *engine);
|
2013-09-17 16:45:48 -04:00
|
|
|
cli_file_t cli_filetype2(fmap_t *map, const struct cl_engine *engine, cli_file_t basetype);
|
2005-09-23 02:23:36 +00:00
|
|
|
int cli_addtypesigs(struct cl_engine *engine);
|
2004-03-20 14:49:22 +00:00
|
|
|
|
|
|
|
#endif
|