Removed module_pattern and range_pattern in favour of make_* helper functions

This commit is contained in:
Silent 2017-12-23 18:59:25 +01:00
parent 344d70800f
commit 0c3679711d

View file

@ -89,16 +89,6 @@ namespace hook
}; };
protected: protected:
inline pattern(void* module)
: m_module(module), m_rangeEnd(0)
{
}
inline pattern(uintptr_t begin, uintptr_t end)
: m_rangeStart(begin), m_rangeEnd(end)
{
}
void Initialize(std::string_view pattern); void Initialize(std::string_view pattern);
private: private:
@ -111,6 +101,16 @@ namespace hook
return m_matches[index]; return m_matches[index];
} }
inline pattern(void* module)
: m_module(module), m_rangeEnd(0)
{
}
inline pattern(uintptr_t begin, uintptr_t end)
: m_rangeStart(begin), m_rangeEnd(end)
{
}
public: public:
template<size_t Len> template<size_t Len>
pattern(const char (&pattern)[Len]) pattern(const char (&pattern)[Len])
@ -119,6 +119,20 @@ namespace hook
Initialize(std::string_view(pattern, Len-1)); Initialize(std::string_view(pattern, Len-1));
} }
template<size_t Len>
inline pattern(void* module, const char (&pattern)[Len])
: pattern(module)
{
Initialize(std::string_view(pattern, Len-1));
}
template<size_t Len>
inline pattern(uintptr_t begin, uintptr_t end, const char (&pattern)[Len])
: m_rangeStart(begin), m_rangeEnd(end)
{
Initialize(std::string_view(pattern, Len-1));
}
inline pattern&& count(uint32_t expected) inline pattern&& count(uint32_t expected)
{ {
EnsureMatches(expected); EnsureMatches(expected);
@ -184,30 +198,17 @@ namespace hook
#endif #endif
}; };
class module_pattern template<size_t Len>
: public pattern pattern make_module_pattern(void* module, const char (&bytes)[Len])
{ {
public: return pattern(module, bytes);
template<size_t Len> }
module_pattern(void* module, const char(&pattern)[Len])
: pattern(module)
{
Initialize(pattern, Len-1);
}
};
class range_pattern template<size_t Len>
: public pattern pattern make_range_pattern(uintptr_t begin, uintptr_t end, const char(&bytes)[Len])
{ {
public: return pattern(begin, end, bytes);
template<size_t Len> }
range_pattern(uintptr_t begin, uintptr_t end, const char(&pattern)[Len])
: pattern(begin, end)
{
Initialize(std::string_view(pattern, Len-1));
}
};
template<typename T = void, size_t Len> template<typename T = void, size_t Len>
auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0) auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0)