#include "util-mem.h"
#include "util-memcmp.h"
#include "util-proto-name.h"
+#include "util-spm-bm.h"
/*
* we put this here, because we only use it here in main.
* \param str pointer to the pattern string
* \param size length of the string
*/
-void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint32_t needle_len) {
+void BoyerMooreCtxToNocase(BmCtx *bm_ctx, uint8_t *needle, uint16_t needle_len) {
/* Prepare bad chars with nocase chars */
PreBmBcNocase(needle, needle_len, bm_ctx->bmBc);
* \retval BmCtx pointer to the newly created Context for the pattern
* \initonly BoyerMoore contexts should be created at init
*/
-BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len) {
+BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len) {
BmCtx *new = SCMalloc(sizeof(BmCtx));
if (new == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in BoyerMooreCtxInit. Exiting...");
/* Prepare bad chars */
PreBmBc(needle, needle_len, new->bmBc);
- new->bmGs = SCMalloc(sizeof(int32_t) * (needle_len + 1));
+ new->bmGs = SCMalloc(sizeof(uint16_t) * (needle_len + 1));
if (new->bmGs == NULL) {
exit(EXIT_FAILURE);
}
* \param size length of the string
* \param result pointer to an empty array that will hold the badchars
*/
-void PreBmBc(const uint8_t *x, int32_t m, int32_t *bmBc) {
+void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc) {
int32_t i;
for (i = 0; i < 256; ++i) {
* \param m length of the string
* \param suff pointer to an empty array that will hold the prefixes (shifts)
*/
-void BoyerMooreSuffixes(const uint8_t *x, int32_t m, int32_t *suff) {
+void BoyerMooreSuffixes(const uint8_t *x, uint16_t m, uint16_t *suff) {
int32_t f = 0, g, i;
suff[m - 1] = m;
g = m - 1;
* \param bmGs pointer to an empty array that will hold the prefixes (shifts)
* \retval 0 ok, -1 failed
*/
-int PreBmGs(const uint8_t *x, int32_t m, int32_t *bmGs) {
+int PreBmGs(const uint8_t *x, uint16_t m, uint16_t *bmGs) {
int32_t i, j;
- int32_t *suff;
+ uint16_t *suff;
- suff = SCMalloc(sizeof(int32_t) * (m + 1));
+ suff = SCMalloc(sizeof(uint16_t) * (m + 1));
if (suff == NULL)
return -1;
* \param size length of the string
* \param result pointer to an empty array that will hold the badchars
*/
-void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc) {
+void PreBmBcNocase(const uint8_t *x, uint16_t m, uint16_t *bmBc) {
int32_t i;
for (i = 0; i < 256; ++i) {
}
}
-void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff) {
+void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, uint16_t *suff) {
int32_t f = 0, g, i;
suff[m - 1] = m;
* \param m length of the string
* \param bmGs pointer to an empty array that will hold the prefixes (shifts)
*/
-void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs) {
+void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs) {
int32_t i, j;
- int32_t* suff;
+ uint16_t* suff;
- suff = SCMalloc(sizeof(int32_t) * (m + 1));
+ suff = SCMalloc(sizeof(uint16_t) * (m + 1));
if (suff == NULL)
return;
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc) {
+uint8_t *BoyerMoore(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc) {
int i, j, m1, m2;
#if 0
printf("\nBad:\n");
printf("\n");
#endif
j = 0;
+
while (j <= n - m ) {
for (i = m - 1; i >= 0 && x[i] == y[i + j]; --i);
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc) {
+uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc) {
int i, j, m1, m2;
#if 0
printf("\nBad:\n");
/* Context for booyer moore */
typedef struct BmCtx_ {
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs; // = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs; // = SCMalloc(sizeof(int32_t)*(needlelen + 1));
} BmCtx;
/** Prepare and return a Boyer Moore context */
-BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint32_t needle_len);
-
-void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint32_t);
-void PreBmBc(const uint8_t *x, int32_t m, int32_t *bmBc);
-void BoyerMooreSuffixes(const uint8_t *x, int32_t m, int32_t *suff);
-int PreBmGs(const uint8_t *, int32_t, int32_t *);
-uint8_t *BoyerMoore(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc);
-void PreBmBcNocase(const uint8_t *x, int32_t m, int32_t *bmBc);
-void BoyerMooreSuffixesNocase(const uint8_t *x, int32_t m, int32_t *suff);
-void PreBmGsNocase(const uint8_t *x, int32_t m, int32_t *bmGs);
-uint8_t *BoyerMooreNocase(uint8_t *x, int32_t m, uint8_t *y, int32_t n, int32_t *bmGs, int32_t *bmBc);
+BmCtx *BoyerMooreCtxInit(uint8_t *needle, uint16_t needle_len);
+
+void BoyerMooreCtxToNocase(BmCtx *, uint8_t *, uint16_t);
+void PreBmBc(const uint8_t *x, uint16_t m, uint16_t *bmBc);
+void BoyerMooreSuffixes(const uint8_t *x, uint16_t m, uint16_t *suff);
+int PreBmGs(const uint8_t *, uint16_t, uint16_t *);
+uint8_t *BoyerMoore(uint8_t *x, int16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc);
+void PreBmBcNocase(const uint8_t *x, uint16_t m, uint16_t *bmBc);
+void BoyerMooreSuffixesNocase(const uint8_t *x, uint16_t m, uint16_t *suff);
+void PreBmGsNocase(const uint8_t *x, uint16_t m, uint16_t *bmGs);
+uint8_t *BoyerMooreNocase(uint8_t *x, uint16_t m, uint8_t *y, int32_t n, uint16_t *bmGs, uint16_t *bmBc);
void BoyerMooreCtxDeInit(BmCtx *);
+
#endif /* __UTIL_SPM_BM__ */
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len) {
+uint8_t *BasicSearch(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len) {
SCEnter();
const uint8_t *h, *n;
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *BasicSearchNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len) {
+uint8_t *BasicSearchNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len) {
const uint8_t *h, *n;
const uint8_t *hmax = haystack + haystack_len;
const uint8_t *nmax = needle + needle_len;
#include "suricata-common.h"
#include "suricata.h"
-uint8_t *BasicSearch(const uint8_t *, uint32_t, const uint8_t *, uint32_t);
-uint8_t *BasicSearchNocase(const uint8_t *, uint32_t, const uint8_t *, uint32_t);
+uint8_t *BasicSearch(const uint8_t *, uint32_t, const uint8_t *, uint16_t);
+uint8_t *BasicSearchNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t);
void BasicSearchInit (void);
#endif /* __UTIL_SPM_BS__ */
* characters that can't be inside the needle_len. So the skips can be
* faster
*/
-void Bs2BmBadchars(const uint8_t *needle, uint32_t needle_len, uint8_t *badchars) {
+void Bs2BmBadchars(const uint8_t *needle, uint16_t needle_len, uint8_t *badchars) {
uint32_t i;
for (i = 0; i < ALPHABET_SIZE; i++)
badchars[i] = 1;
* characters that can't be inside the needle_len. So the skips can be
* faster
*/
-void Bs2BmBadcharsNocase(const uint8_t *needle, uint32_t needle_len, uint8_t *badchars) {
+void Bs2BmBadcharsNocase(const uint8_t *needle, uint16_t needle_len, uint8_t *badchars) {
uint32_t i;
for (i = 0; i < ALPHABET_SIZE; i++)
badchars[i] = 1;
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t * Bs2Bm(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len, uint8_t badchars[])
+uint8_t * Bs2Bm(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len, uint8_t badchars[])
{
const uint8_t *h, *n;
const uint8_t *hmax = haystack + haystack_len;
*
* \retval ptr to start of the match; NULL if no match
*/
-uint8_t *Bs2BmNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint32_t needle_len, uint8_t badchars[])
+uint8_t *Bs2BmNocase(const uint8_t *haystack, uint32_t haystack_len, const uint8_t *needle, uint16_t needle_len, uint8_t badchars[])
{
const uint8_t *h, *n;
const uint8_t *hmax = haystack + haystack_len;
#define ALPHABET_SIZE 256
-void Bs2BmBadchars(const uint8_t *, uint32_t, uint8_t *);
-void Bs2BmBadcharsNocase(const uint8_t *, uint32_t, uint8_t *);
-uint8_t * Bs2Bm(const uint8_t *, uint32_t, const uint8_t *, uint32_t, uint8_t []);
-uint8_t *Bs2BmNocase(const uint8_t *, uint32_t, const uint8_t *, uint32_t, uint8_t []);
+void Bs2BmBadchars(const uint8_t *, uint16_t, uint8_t *);
+void Bs2BmBadcharsNocase(const uint8_t *, uint16_t, uint8_t *);
+uint8_t * Bs2Bm(const uint8_t *, uint32_t, const uint8_t *, uint16_t, uint8_t []);
+uint8_t *Bs2BmNocase(const uint8_t *, uint32_t, const uint8_t *, uint16_t, uint8_t []);
#endif /* __UTIL_SPM_BS2BM__ */
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) {
+uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) {
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) {
+uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) {
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) {
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) {
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
* \param needle pattern to search for
* \param needlelen length of the pattern
*/
-uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen) {
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen) {
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
*/
uint8_t *BasicSearchWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t *ret = NULL;
int i = 0;
uint8_t *BasicSearchNocaseWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t *ret = NULL;
int i = 0;
uint8_t *Bs2bmWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
uint8_t *Bs2bmNocaseWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t badchars[ALPHABET_SIZE];
Bs2BmBadchars(needle, needlelen, badchars);
uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
uint8_t *BoyerMooreNocaseWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
*/
uint8_t *BasicSearchCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t *ret = NULL;
int i = 0;
uint8_t *BasicSearchNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t *ret = NULL;
int i = 0;
uint8_t *Bs2bmCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t badchars[ALPHABET_SIZE];
uint8_t *Bs2bmNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t badchars[ALPHABET_SIZE];
uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
uint8_t *RawCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
uint8_t *ret = NULL;
int i = 0;
uint8_t *BoyerMooreNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times) {
uint32_t textlen = strlen((char *)text);
- uint32_t needlelen = strlen((char *)needle);
+ uint16_t needlelen = strlen((char *)needle);
- int32_t bmBc[ALPHABET_SIZE];
- int32_t *bmGs = SCMalloc(sizeof(int32_t)*(needlelen + 1));
+ uint16_t bmBc[ALPHABET_SIZE];
+ uint16_t *bmGs = SCMalloc(sizeof(uint16_t)*(needlelen + 1));
if (bmGs == NULL)
return NULL;
#include "util-spm-bm.h"
/** Default algorithm to use: Boyer Moore */
-uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen);
-uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen);
-uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen);
-uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint32_t needlelen);
+uint8_t *Bs2bmSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
+uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
+uint8_t *BoyerMooreNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint16_t needlelen);
/* Macros for automatic algorithm selection (use them only when you can't store the context) */
#define SpmSearch(text, textlen, needle, needlelen) ({\