Memory::Patch with std::initializer_list

This commit is contained in:
Silent 2017-09-12 18:00:26 +02:00
parent e4a3d81e81
commit b002512132

View File

@ -21,6 +21,11 @@
#include <cstdint>
#ifndef _MEMORY_NO_CRT
#include <initializer_list>
#include <iterator>
#endif
enum
{
PATCH_CALL,
@ -422,6 +427,15 @@ namespace Memory
inline void Patch(AT address, T value)
{*(T*)address = value; }
#ifndef _MEMORY_NO_CRT
template<typename AT>
inline void Patch(AT address, std::initializer_list<uint8_t> list )
{
uint8_t* const addr = (uint8_t*)address;
std::copy( list.begin(), list.end(), stdext::checked_array_iterator<uint8_t*>(addr, list.size()) );
}
#endif
template<typename AT>
inline void Nop(AT address, size_t count)
#ifndef _MEMORY_NO_CRT
@ -474,6 +488,14 @@ namespace Memory
Memory::Patch(DynBaseAddress(address), value);
}
#ifndef _MEMORY_NO_CRT
template<typename AT>
inline void Patch(AT address, std::initializer_list<uint8_t> list )
{
Memory::Patch(DynBaseAddress(address), std::move(list));
}
#endif
template<typename AT>
inline void Nop(AT address, size_t count)
{
@ -510,6 +532,17 @@ namespace Memory
VirtualProtect((void*)address, sizeof(T), dwProtect[0], &dwProtect[1]);
}
#ifndef _MEMORY_NO_CRT
template<typename AT>
inline void Patch(AT address, std::initializer_list<uint8_t> list )
{
DWORD dwProtect[2];
VirtualProtect((void*)address, list.size(), PAGE_EXECUTE_READWRITE, &dwProtect[0]);
Memory::Patch(address, std::move(list));
VirtualProtect((void*)address, list.size(), dwProtect[0], &dwProtect[1]);
}
#endif
template<typename AT>
inline void Nop(AT address, size_t count)
{
@ -553,6 +586,14 @@ namespace Memory
VP::Patch(DynBaseAddress(address), value);
}
#ifndef _MEMORY_NO_CRT
template<typename AT>
inline void Patch(AT address, std::initializer_list<uint8_t> list )
{
VP::Patch(DynBaseAddress(address), std::move(list));
}
#endif
template<typename AT>
inline void Nop(AT address, size_t count)
{