Skip to content

Commit

Permalink
Add Pattern::Pattern(const char* bin, const char* mask)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Dec 10, 2024
1 parent c43288b commit 842a2b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions soup/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ NAMESPACE_SOUP
computeMostUniqueByteIndex();
}

Pattern::Pattern(const char* bin, const char* mask)
{
const size_t len = strlen(mask);
bytes.reserve(len);
for (size_t i = 0; i != len; ++i)
{
if (mask[i] == '?')
{
bytes.emplace_back(std::nullopt);
}
else // if (mask[i] == 'x')
{
bytes.emplace_back(reinterpret_cast<const uint8_t*>(bin)[i]);
}
}
}

#if SOUP_X86 && SOUP_BITS == 64
// Stolen from https://github.com/0x1F9F1/mem/blob/master/include/mem/simd_scanner.h
static const uint8_t frequencies[256]
Expand Down
1 change: 1 addition & 0 deletions soup/Pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NAMESPACE_SOUP
Pattern(const CompiletimePatternWithOptBytesBase& sig);
Pattern(const std::string& str);
Pattern(const char* str, size_t len);
Pattern(const char* bin, const char* mask);
private:
void computeMostUniqueByteIndex();

Expand Down

0 comments on commit 842a2b8

Please sign in to comment.