1 /*
2  *  Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3  *  Copyright (C) 2007-2013 Sourcefire, Inc.
4  *
5  *  Authors: Tomasz Kojm
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA 02110-1301, USA.
20  */
21 
22 #ifndef __MATCHER_BM_H
23 #define __MATCHER_BM_H
24 
25 #include "matcher.h"
26 #include "filetypes.h"
27 #include "clamav-types.h"
28 #include "fmap.h"
29 #include "others.h"
30 
31 #define BM_BOUNDARY_EOL 1
32 
33 struct cli_bm_patt {
34     unsigned char *pattern, *prefix;
35     char *virname;
36     uint32_t offdata[4], offset_min, offset_max;
37     struct cli_bm_patt *next;
38     uint16_t length, prefix_length;
39     uint16_t cnt;
40     unsigned char pattern0;
41     uint32_t boundary, filesize;
42 };
43 
44 struct cli_bm_off {
45     uint32_t *offset, *offtab, cnt, pos;
46 };
47 
48 cl_error_t cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset);
49 cl_error_t cli_bm_init(struct cli_matcher *root);
50 cl_error_t cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info);
51 void cli_bm_freeoff(struct cli_bm_off *data);
52 cl_error_t cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_bm_patt **patt, const struct cli_matcher *root, uint32_t offset, const struct cli_target_info *info, struct cli_bm_off *offdata, cli_ctx *ctx);
53 void cli_bm_free(struct cli_matcher *root);
54 
55 #endif
56