suricata
util-hyperscan.c
Go to the documentation of this file.
1
/* Copyright (C) 2016 Open Information Security Foundation
2
*
3
* You can copy, redistribute or modify this Program under the terms of
4
* the GNU General Public License version 2 as published by the Free
5
* Software Foundation.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* version 2 along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
* 02110-1301, USA.
16
*/
17
18
/**
19
* \file
20
*
21
* \author Justin Viiret <justin.viiret@intel.com>
22
*
23
* Support functions for Hyperscan library integration.
24
*/
25
26
#include "
suricata-common.h
"
27
#include "
suricata.h
"
28
29
#ifdef BUILD_HYPERSCAN
30
#include "
util-hyperscan.h
"
31
32
/**
33
* \internal
34
* \brief Convert a pattern into a regex string accepted by the Hyperscan
35
* compiler.
36
*
37
* For simplicity, we just take each byte of the original pattern and render it
38
* with a hex escape (i.e. ' ' -> "\x20")/
39
*/
40
char
*
HSRenderPattern
(
const
uint8_t *pat, uint16_t pat_len)
41
{
42
if
(pat == NULL) {
43
return
NULL;
44
}
45
const
size_t
hex_len = (pat_len * 4) + 1;
46
char
*
str
=
SCCalloc
(1, hex_len);
47
if
(
str
== NULL) {
48
return
NULL;
49
}
50
char
*sp =
str
;
51
for
(uint16_t i = 0; i < pat_len; i++) {
52
snprintf(sp, 5,
"\\x%02x"
, pat[i]);
53
sp += 4;
54
}
55
*sp =
'\0'
;
56
return
str
;
57
}
58
59
#endif
/* BUILD_HYPERSCAN */
util-hyperscan.h
suricata-common.h
HSRenderPattern
char * HSRenderPattern(const uint8_t *pat, uint16_t pat_len)
str
#define str(s)
Definition:
suricata-common.h:291
suricata.h
SCCalloc
#define SCCalloc(nm, sz)
Definition:
util-mem.h:53
src
util-hyperscan.c
Generated on Tue Dec 17 2024 23:30:38 for suricata by
1.8.18