mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-28 23:03:01 +05:00
range patterns
This commit is contained in:
parent
560c925235
commit
477595bcd5
2 changed files with 41 additions and 4 deletions
|
@ -116,7 +116,7 @@ public:
|
|||
return (TReturn*)(m_begin + rva);
|
||||
}
|
||||
|
||||
executable_meta(void* module)
|
||||
explicit executable_meta(void* module)
|
||||
: m_begin((uintptr_t)module)
|
||||
{
|
||||
PIMAGE_DOS_HEADER dosHeader = getRVA<IMAGE_DOS_HEADER>(0);
|
||||
|
@ -125,6 +125,11 @@ public:
|
|||
m_end = m_begin + ntHeader->OptionalHeader.SizeOfCode;
|
||||
}
|
||||
|
||||
executable_meta(uintptr_t begin, uintptr_t end)
|
||||
: m_begin(begin), m_end(end)
|
||||
{
|
||||
}
|
||||
|
||||
inline uintptr_t begin() const { return m_begin; }
|
||||
inline uintptr_t end() const { return m_end; }
|
||||
};
|
||||
|
@ -173,7 +178,7 @@ void pattern::EnsureMatches(uint32_t maxCount)
|
|||
}
|
||||
|
||||
// scan the executable for code
|
||||
executable_meta executable(m_module);
|
||||
executable_meta executable = m_rangeStart != 0 && m_rangeEnd != 0 ? executable_meta(m_rangeStart, m_rangeEnd) : executable_meta(m_module);
|
||||
|
||||
auto matchSuccess = [&] (uintptr_t address)
|
||||
{
|
||||
|
|
|
@ -78,11 +78,24 @@ namespace hook
|
|||
|
||||
bool m_matched;
|
||||
|
||||
void* m_module;
|
||||
union
|
||||
{
|
||||
void* m_module;
|
||||
struct
|
||||
{
|
||||
uintptr_t m_rangeStart;
|
||||
uintptr_t m_rangeEnd;
|
||||
};
|
||||
};
|
||||
|
||||
protected:
|
||||
inline pattern(void* module)
|
||||
: m_module(module), m_matched(false)
|
||||
: m_module(module), m_rangeEnd(0), m_matched(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline pattern(uintptr_t begin, uintptr_t end)
|
||||
: m_rangeStart(begin), m_rangeEnd(end), m_matched(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -119,6 +132,13 @@ namespace hook
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline pattern& clear()
|
||||
{
|
||||
m_matches.clear();
|
||||
m_matched = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline size_t size()
|
||||
{
|
||||
EnsureMatches(UINT32_MAX);
|
||||
|
@ -166,6 +186,18 @@ namespace hook
|
|||
}
|
||||
};
|
||||
|
||||
class range_pattern
|
||||
: public pattern
|
||||
{
|
||||
public:
|
||||
template<size_t Len>
|
||||
range_pattern(uintptr_t begin, uintptr_t end, const char(&pattern)[Len])
|
||||
: pattern(begin, end)
|
||||
{
|
||||
Initialize(pattern, Len);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename T = void, size_t Len>
|
||||
auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0)
|
||||
|
|
Loading…
Reference in a new issue