@ -1,4 +1,4 @@
/* Copyright (C) 2007-201 3 Open Information Security Foundation
/* Copyright (C) 2007-201 4 Open Information Security Foundation
*
*
* You can copy , redistribute or modify this Program under the terms of
* You can copy , redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* the GNU General Public License version 2 as published by the Free
@ -103,16 +103,10 @@ uint8_t *Bs2bmNocaseSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uin
*/
*/
uint8_t * BoyerMooreSearch ( 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 )
{
{
uint16_t bmBc [ ALPHABET_SIZE ] ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
uint16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
if ( unlikely ( bmGs = = NULL ) )
return NULL ;
PreBmGs ( needle , needlelen , bmGs ) ;
PreBmBc ( needle , needlelen , bmBc ) ;
uint8_t * ret = BoyerMoore ( needle , needlelen , text , textlen , bm Gs, bmBc ) ;
uint8_t * ret = BoyerMoore ( needle , needlelen , text , textlen , bm_ctx ) ;
SCFree( bmGs ) ;
BoyerMooreCtxDeInit ( bm_ctx ) ;
return ret ;
return ret ;
}
}
@ -128,16 +122,11 @@ uint8_t *BoyerMooreSearch(uint8_t *text, uint32_t textlen, uint8_t *needle, uint
*/
*/
uint8_t * BoyerMooreNocaseSearch ( 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 )
{
{
uint16_t bmBc [ ALPHABET_SIZE ] ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
uint16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
BoyerMooreCtxToNocase ( bm_ctx , needle , needlelen ) ;
if ( unlikely ( bmGs = = NULL ) )
return NULL ;
PreBmGsNocase ( needle , needlelen , bmGs ) ;
PreBmBcNocase ( needle , needlelen , bmBc ) ;
uint8_t * ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bm Gs, bmBc ) ;
uint8_t * ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bm_ctx ) ;
SCFree( bmGs ) ;
BoyerMooreCtxDeInit ( bm_ctx ) ;
return ret ;
return ret ;
}
}
@ -241,50 +230,46 @@ uint8_t *BoyerMooreWrapper(uint8_t *text, uint8_t *needle, int times)
uint32_t textlen = strlen ( ( char * ) text ) ;
uint32_t textlen = strlen ( ( char * ) text ) ;
uint16_t needlelen = strlen ( ( char * ) needle ) ;
uint16_t needlelen = strlen ( ( char * ) needle ) ;
uint16_t bmBc [ ALPHABET_SIZE ] ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
uint16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
if ( unlikely ( bmGs = = NULL ) )
return NULL ;
uint8_t * ret = NULL ;
uint8_t * ret = NULL ;
int i = 0 ;
int i = 0 ;
PreBmGs ( needle , needlelen , bmGs ) ;
PreBmBc ( needle , needlelen , bmBc ) ;
CLOCK_INIT ;
CLOCK_INIT ;
if ( times > 1 ) CLOCK_START ;
if ( times > 1 ) CLOCK_START ;
for ( i = 0 ; i < times ; i + + ) {
for ( i = 0 ; i < times ; i + + ) {
ret = BoyerMoore ( needle , needlelen , text , textlen , bm Gs, bmBc ) ;
ret = BoyerMoore ( needle , needlelen , text , textlen , bm _ctx ) ;
}
}
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
SCFree( bmGs ) ;
BoyerMooreCtxDeInit( bm_ctx ) ;
return ret ;
return ret ;
}
}
uint8_t * BoyerMooreNocaseWrapper ( uint8_t * text , uint8_t * needle, int times )
uint8_t * BoyerMooreNocaseWrapper ( uint8_t * text , uint8_t * in_ needle, int times )
{
{
uint32_t textlen = strlen ( ( char * ) text ) ;
uint32_t textlen = strlen ( ( char * ) text ) ;
uint16_t needlelen = strlen ( ( char * ) needle) ;
uint16_t needlelen = strlen ( ( char * ) in_ needle) ;
uint16_t bmBc [ ALPHABET_SIZE ] ;
/* Make a copy of in_needle to be able to convert it to lowercase. */
uint 16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
uint 8_t * needle = SCMalloc ( needlelen ) ;
if ( unlikely ( bmGs = = NULL ) )
if ( needle = = NULL )
return NULL ;
return NULL ;
memcpy ( needle , in_needle , needlelen ) ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
BoyerMooreCtxToNocase ( bm_ctx , needle , needlelen ) ;
uint8_t * ret = NULL ;
uint8_t * ret = NULL ;
int i = 0 ;
int i = 0 ;
PreBmGsNocase ( needle , needlelen , bmGs ) ;
PreBmBcNocase ( needle , needlelen , bmBc ) ;
CLOCK_INIT ;
CLOCK_INIT ;
if ( times > 1 ) CLOCK_START ;
if ( times > 1 ) CLOCK_START ;
for ( i = 0 ; i < times ; i + + ) {
for ( i = 0 ; i < times ; i + + ) {
ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bm Gs, bmBc ) ;
ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bm _ctx ) ;
}
}
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
SCFree ( bmGs ) ;
BoyerMooreCtxDeInit ( bm_ctx ) ;
free ( needle ) ;
return ret ;
return ret ;
}
}
@ -379,10 +364,7 @@ uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times)
uint32_t textlen = strlen ( ( char * ) text ) ;
uint32_t textlen = strlen ( ( char * ) text ) ;
uint16_t needlelen = strlen ( ( char * ) needle ) ;
uint16_t needlelen = strlen ( ( char * ) needle ) ;
uint16_t bmBc [ ALPHABET_SIZE ] ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
uint16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
if ( unlikely ( bmGs = = NULL ) )
return NULL ;
uint8_t * ret = NULL ;
uint8_t * ret = NULL ;
int i = 0 ;
int i = 0 ;
@ -391,13 +373,11 @@ uint8_t *BoyerMooreCtxWrapper(uint8_t *text, uint8_t *needle, int times)
if ( times > 1 ) CLOCK_START ;
if ( times > 1 ) CLOCK_START ;
for ( i = 0 ; i < times ; i + + ) {
for ( i = 0 ; i < times ; i + + ) {
/* Stats including context building */
/* Stats including context building */
PreBmGs ( needle , needlelen , bmGs ) ;
ret = BoyerMoore ( needle , needlelen , text , textlen , bm_ctx ) ;
PreBmBc ( needle , needlelen , bmBc ) ;
ret = BoyerMoore ( needle , needlelen , text , textlen , bmGs , bmBc ) ;
}
}
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
SCFree ( bmGs ) ;
BoyerMooreCtxDeInit ( bm_ctx ) ;
return ret ;
return ret ;
}
}
@ -418,15 +398,18 @@ uint8_t *RawCtxWrapper(uint8_t *text, uint8_t *needle, int times)
return ret ;
return ret ;
}
}
uint8_t * BoyerMooreNocaseCtxWrapper ( uint8_t * text , uint8_t * needle, int times )
uint8_t * BoyerMooreNocaseCtxWrapper ( uint8_t * text , uint8_t * in_ needle, int times )
{
{
uint32_t textlen = strlen ( ( char * ) text ) ;
uint32_t textlen = strlen ( ( char * ) text ) ;
uint16_t needlelen = strlen ( ( char * ) needle) ;
uint16_t needlelen = strlen ( ( char * ) in_ needle) ;
uint16_t bmBc [ ALPHABET_SIZE ] ;
/* Make a copy of in_needle to be able to convert it to lowercase. */
uint 16_t * bmGs = SCMalloc ( sizeof ( uint16_t ) * ( needlelen + 1 ) ) ;
uint 8_t * needle = SCMalloc ( needlelen ) ;
if ( unlikely ( bmGs = = NULL ) )
if ( needle = = NULL )
return NULL ;
return NULL ;
memcpy ( needle , in_needle , needlelen ) ;
BmCtx * bm_ctx = BoyerMooreCtxInit ( needle , needlelen ) ;
uint8_t * ret = NULL ;
uint8_t * ret = NULL ;
int i = 0 ;
int i = 0 ;
@ -435,12 +418,12 @@ uint8_t *BoyerMooreNocaseCtxWrapper(uint8_t *text, uint8_t *needle, int times)
if ( times > 1 ) CLOCK_START ;
if ( times > 1 ) CLOCK_START ;
for ( i = 0 ; i < times ; i + + ) {
for ( i = 0 ; i < times ; i + + ) {
/* Stats including context building */
/* Stats including context building */
PreBmGsNocase ( needle , needlelen , bmGs ) ;
BoyerMooreCtxToNocase ( bm_ctx , needle , needlelen ) ;
PreBmBcNocase ( needle , needlelen , bmBc ) ;
ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bm_ctx ) ;
ret = BoyerMooreNocase ( needle , needlelen , text , textlen , bmGs , bmBc ) ;
}
}
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
if ( times > 1 ) { CLOCK_END ; CLOCK_PRINT_SEC ; } ;
SCFree ( bmGs ) ;
BoyerMooreCtxDeInit ( bm_ctx ) ;
free ( needle ) ;
return ret ;
return ret ;
}
}