views:

230

answers:

2

I want to search some memory range for a specific byte pattern. Therefore, 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?

+3  A: 

The Wikipedia page on BMH has an implementation. I think that Boost xpressive is also based on (a variant of) BMH.

Jason
The questino was more like if there is such a function in `windows.h` or some similar standard library.
Etan
As far as I know there is not but take a look at Boost's xpressive.
Jason
+1  A: 

No, it seems there isn't even a function like 'strstr' but for raw memory. Let alone wildcards!

Nicolás
Hmm... Wouldn't `std::search` work as `strstr`? Not that I suggest it as a replacement to gnu libc's `memmem`, but it exists and, perhaps, works ;-)
Michael Krelin - hacker