Finding a byte-pattern in some memory area
I want to search some memory range for a specific byte pattern. Therefore开发者_如何学C, my approach is to build a function
void * FindPattern (std::vector<byte> pattern, byte wildcard,
void * startAddress, void * endAddress);
using the Boyer-Moore-Horspool algorithm to find the pattern in the memory range.
The wildcard
byte stays for some specific byte which should be treated as a wildcard.
So - for example - if wildcard
is 0xCC
, every 0xCC
in pattern
will be a wildcard.
The function should return the start of the memory range, where the pattern was found the first time.
My question is now: is there some similar function already done in the most common libraries or do I have to implement this for my own?
The Wikipedia page on BMH has an implementation. I think that Boost xpressive is also based on (a variant of) BMH.
No, it seems there isn't even a function like 'strstr' but for raw memory. Let alone wildcards!
精彩评论