//////////////////////////////////////////////////////////////////// // // Boyer-Moore implementation // version: 1.12 // (c)2006 Jeremy Collake / Bitsum Technologies // jeremy@bitsum.com // Use PECompact today! // ////////////////////////////////////////////////////////////////////// // // ! Not cleaned or made ready for general public consumption ! // // This implementation is designed to handle binary phrases, which // can include character arrays (strings), just be sure you // realize a null-terminator should not be included in the phrase // or total data size. // // Use: // // 1.) Initialize the search string table by passing to // it the phrase you're planning to search for. See // BoyerMooreBinBin_Init. // 2.) Search with BoyerMooreBinBin // 3.) De-initialize search table when done searching // for that particular phrase. // // // #include "stdafx.h" #pragma once #ifdef COMMON_EXPORTS #define COMMON_API __declspec(dllexport) #else #define COMMON_API __declspec(dllimport) #endif /////////////////////////////////////////////////////////// // // Boyer-Moore table state info // class CBoyerMooreHandle { public: unsigned long *m_pTable; unsigned char *m_pPhrase; unsigned long m_nPhraseLen; CBoyerMooreHandle(); ~CBoyerMooreHandle(); bool Init(unsigned char *pPhrase, unsigned long nPhraseLen); }; /////////////////////////////////////////////////////////// // // Boyer-Moore free functions // // Init - allocates phrase table COMMON_API CBoyerMooreHandle * __stdcall BoyerMooreBinBin_Init(unsigned char *pPhrase, unsigned long nPhraseLen); // BinBin - returns index of phrase, or -1 if not found COMMON_API int __stdcall BoyerMooreBinBin(CBoyerMooreHandle *pHandle, unsigned char *pBuffer, unsigned long nBufferSize, unsigned long nStart); // DeInit - deallocates phrase table COMMON_API void __stdcall BoyerMooreBinBin_Deinit(CBoyerMooreHandle *pHandle);