e3aaff8e |
/* |
33872a43 |
* Copyright (C) 2007-2009 Sourcefire, Inc. |
4addba22 |
* |
2023340a |
* Authors: Tomasz Kojm |
e3aaff8e |
*
* This program is free software; you can redistribute it and/or modify |
bb34cb31 |
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. |
e3aaff8e |
*
* 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 |
48b7b4a7 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
e3aaff8e |
*/
#ifndef __MATCHER_H
#define __MATCHER_H
|
841161e0 |
#include <sys/types.h>
|
e3aaff8e |
#include "clamav.h" |
a85bd2ac |
#include "filetypes.h" |
3c91998b |
#include "others.h" |
841161e0 |
#include "execs.h"
#include "cltypes.h" |
53721687 |
#include "md5.h" |
e3aaff8e |
|
bedc58de |
#include "matcher-ac.h"
#include "matcher-bm.h" |
c3671221 |
#include "hashtab.h" |
048d7677 |
#include "fmap.h" |
b94e66c4 |
#include "mpool.h"
|
bedc58de |
#define CLI_MATCH_WILDCARD 0xff00 |
ecf5865b |
#define CLI_MATCH_CHAR 0x0000 |
bedc58de |
#define CLI_MATCH_IGNORE 0x0100 |
a6d4c62e |
#define CLI_MATCH_SPECIAL 0x0200 |
bedc58de |
#define CLI_MATCH_NIBBLE_HIGH 0x0300
#define CLI_MATCH_NIBBLE_LOW 0x0400
|
677fc4ba |
struct cli_lsig_tdb {
#define CLI_TDB_UINT 0
#define CLI_TDB_RANGE 1
#define CLI_TDB_STR 2
#define CLI_TDB_RANGE2 3 |
4168b010 |
#define CLI_TDB_FTYPE 4 |
677fc4ba |
uint32_t *val, *range;
char *str;
uint32_t cnt[3];
const uint32_t *target; |
17cfd76f |
const uint32_t *engine, *nos, *ep, *filesize; |
4168b010 |
const uint32_t *container; |
0f7ba617 |
/* |
677fc4ba |
const uint32_t *sectoff, *sectrva, *sectvsz, *sectraw, *sectrsz,
*secturva, *sectuvsz, *secturaw, *sectursz; |
0f7ba617 |
*/
const char *icongrp1, *icongrp2; |
ab893605 |
uint32_t *macro_ptids;
uint32_t subsigs; |
0d9dbdef |
#ifdef USE_MPOOL |
47d40feb |
mpool_t *mempool; |
0d9dbdef |
#endif |
677fc4ba |
};
|
459b13ed |
struct cli_bc; |
677fc4ba |
struct cli_ac_lsig {
uint32_t id;
char *logic;
const char *virname;
struct cli_lsig_tdb tdb; |
57f14280 |
unsigned bc_idx; |
677fc4ba |
};
|
bedc58de |
struct cli_matcher { |
33872a43 |
unsigned int type;
|
bedc58de |
/* Extended Boyer-Moore */ |
ab1db3b3 |
uint8_t *bm_shift; |
006f5fe6 |
struct cli_bm_patt **bm_suffix, **bm_pattab; |
cc447ac8 |
struct cli_hashset md5_sizes_hs; |
0a3d4094 |
uint32_t *soff, soff_len; /* for PE section sigs */ |
006f5fe6 |
uint32_t bm_offmode, bm_patterns, bm_reloff_num, bm_absoff_num; |
bedc58de |
/* Extended Aho-Corasick */ |
677fc4ba |
uint32_t ac_partsigs, ac_nodes, ac_patterns, ac_lsigs;
struct cli_ac_lsig **ac_lsigtable; |
bedc58de |
struct cli_ac_node *ac_root, **ac_nodetable; |
fbcef1b0 |
struct cli_ac_patt **ac_pattable; |
33872a43 |
struct cli_ac_patt **ac_reloff; |
aca9ea82 |
uint32_t ac_reloff_num, ac_absoff_num; |
b5231f5f |
uint8_t ac_mindepth, ac_maxdepth; |
02eabc6d |
struct filter *filter; |
b5231f5f |
uint16_t maxpatlen;
uint8_t ac_only; |
0728972e |
#ifdef USE_MPOOL |
47d40feb |
mpool_t *mempool; |
0728972e |
#endif |
bedc58de |
};
|
55094a9c |
struct cli_cdb
{
char *virname; /* virus name */
cli_file_t ctype; /* container type */
regex_t name; /* filename regex */
size_t csize[2]; /* container size (min, max); if csize[0] != csize[1]
* then value of 0 makes the field ignored
*/
size_t fsizec[2]; /* file size in container */
size_t fsizer[2]; /* real file size */
int encrypted; /* file is encrypted; 2 == ignore */ |
15f413d1 |
int filepos[2]; /* file position in container */
int res1; /* reserved / format specific */ |
55094a9c |
void *res2; /* reserved / format specific */
struct cli_cdb *next;
};
|
4addba22 |
struct cli_mtarget {
cli_file_t target;
const char *name;
uint8_t idx; /* idx of matcher */
uint8_t ac_only; |
02eabc6d |
uint8_t enable_prefiltering; |
4addba22 |
};
|
8af7ccd0 |
#define CLI_MTARGETS 10 |
4addba22 |
static const struct cli_mtarget cli_mtargets[CLI_MTARGETS] = { |
02eabc6d |
{ 0, "GENERIC", 0, 0, 1 },
{ CL_TYPE_MSEXE, "PE", 1, 0, 1 },
{ CL_TYPE_MSOLE2, "OLE2", 2, 1, 0 },
{ CL_TYPE_HTML, "HTML", 3, 1, 0 },
{ CL_TYPE_MAIL, "MAIL", 4, 1, 1 },
{ CL_TYPE_GRAPHICS, "GRAPHICS", 5, 1, 0 },
{ CL_TYPE_ELF, "ELF", 6, 1, 0 },
{ CL_TYPE_TEXT_ASCII, "ASCII", 7, 1, 1 },
{ CL_TYPE_ERROR, "NOT USED", 8, 1, 0 },
{ CL_TYPE_MACHO, "MACH-O", 9, 1, 0 } |
4addba22 |
}; |
b68d11d2 |
|
841161e0 |
struct cli_target_info {
off_t fsize;
struct cli_exe_info exeinfo;
int8_t status; /* 0 == not initialised, 1 == initialised OK, -1 == error */
};
|
33872a43 |
#define CLI_OFF_ANY 0xffffffff
#define CLI_OFF_NONE 0xfffffffe
#define CLI_OFF_ABSOLUTE 1
#define CLI_OFF_EOF_MINUS 2
#define CLI_OFF_EP_PLUS 3
#define CLI_OFF_EP_MINUS 4
#define CLI_OFF_SL_PLUS 5
#define CLI_OFF_SX_PLUS 6 |
d2ba6f98 |
#define CLI_OFF_VERSION 7 |
ab893605 |
#define CLI_OFF_MACRO 8 |
33872a43 |
|
e06afe8e |
int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata); |
5612732c |
|
6038397e |
int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode); |
548b55be |
int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, unsigned char *refhash); |
49cc1e3c |
int cli_caloff(const char *offstr, struct cli_target_info *info, fmap_t *map, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max); |
53721687 |
|
32b1e04e |
int cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx); |
e4101980 |
|
570b1d00 |
int cli_matchmeta(cli_ctx *ctx, const char *fname, size_t fsizec, size_t fsizer, int encrypted, int filepos, int res1, void *res2); |
55094a9c |
|
e3aaff8e |
#endif |