Class to track data flow and detect a specific pattern

Committer:
chris215
Date:
Wed Jan 13 05:30:23 2016 +0000
Revision:
1:038d0018a542
Parent:
0:b8cca837d413
Removed templates and changed to using void* to make the class more generic.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris215 0:b8cca837d413 1 #include "PatternFinder.h"
chris215 1:038d0018a542 2 PatternFinder::PatternFinder(void* PatternData, uint32_t PatternLength, uint32_t PatternElementSize)
chris215 0:b8cca837d413 3 {
chris215 1:038d0018a542 4 m_PatternSize = PatternLength;
chris215 1:038d0018a542 5 m_PatternElementSize = PatternElementSize;
chris215 1:038d0018a542 6 m_RefPattern = new uint8_t[m_PatternSize*m_PatternElementSize];
chris215 0:b8cca837d413 7
chris215 1:038d0018a542 8 uint8_t *src = (uint8_t*)PatternData;
chris215 1:038d0018a542 9 uint8_t *dst = (uint8_t*)m_RefPattern + (m_PatternSize-1)*m_PatternElementSize;
chris215 0:b8cca837d413 10 //We must invert the given pattern so that it better fits the matching algorithm
chris215 1:038d0018a542 11 for(int x = 0; x < m_PatternSize ;x++)
chris215 0:b8cca837d413 12 {
chris215 1:038d0018a542 13 memcpy(dst,src,m_PatternElementSize);
chris215 1:038d0018a542 14 dst-=m_PatternElementSize;
chris215 1:038d0018a542 15 src+=m_PatternElementSize;
chris215 0:b8cca837d413 16 }
chris215 1:038d0018a542 17 m_CurDataStream = new uint8_t[m_PatternSize*m_PatternElementSize];
chris215 0:b8cca837d413 18 return;
chris215 0:b8cca837d413 19 }
chris215 0:b8cca837d413 20
chris215 1:038d0018a542 21 PatternFinder::~PatternFinder()
chris215 0:b8cca837d413 22 {
chris215 1:038d0018a542 23 delete [] m_RefPattern;
chris215 1:038d0018a542 24 delete [] m_CurDataStream;
chris215 0:b8cca837d413 25 return;
chris215 0:b8cca837d413 26 }
chris215 0:b8cca837d413 27