Class to track data flow and detect a specific pattern
Diff: PatternFinder.cpp
- Revision:
- 0:b8cca837d413
- Child:
- 1:038d0018a542
diff -r 000000000000 -r b8cca837d413 PatternFinder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PatternFinder.cpp Mon Jan 11 04:48:08 2016 +0000 @@ -0,0 +1,39 @@ +#include "PatternFinder.h" +// make the linker aware of some possible types +template class PatternFinder<uint8_t>; +template class PatternFinder<int8_t>; +template class PatternFinder<uint16_t>; +template class PatternFinder<int16_t>; +template class PatternFinder<uint32_t>; +template class PatternFinder<int32_t>; +template class PatternFinder<uint64_t>; +template class PatternFinder<int64_t>; +template class PatternFinder<char>; +template class PatternFinder<wchar_t>; + +template <class T> +PatternFinder<T>::PatternFinder(T* Pattern,uint32_t PatternSize) +{ + m_PatternSize = PatternSize; + m_PatternReference = new T[PatternSize]; + + T *src = Pattern; + T *dst = &m_PatternReference[PatternSize-1]; + //We must invert the given pattern so that it better fits the matching algorithm + for(int x = 0; x < PatternSize ;x++) + { + *dst-- = *src++; + + } + m_CurrentPattern = new T[PatternSize]; + return; +} + +template <class T> +PatternFinder<T>::~PatternFinder() +{ + delete [] m_PatternReference; + delete [] m_CurrentPattern; + return; +} +