Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <std::uint8_t...Bytes>
- class BufferCall
- {
- public:
- constexpr BufferCall() :
- _buffer(nullptr),
- _bytes{ Bytes... }
- {
- _buffer = (std::uint8_t*)VirtualAlloc(0, sizeof...(Bytes), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
- if (_buffer)
- {
- memcpy(_buffer, _bytes, sizeof...(Bytes));
- }
- }
- virtual ~BufferCall()
- {
- if (_buffer)
- {
- VirtualFree(_buffer, sizeof...(Bytes), MEM_RELEASE);
- _buffer = nullptr;
- }
- }
- template <typename Ret, typename...Args>
- Ret Call(Args...args)
- {
- typedef Ret(*function)(Args...);
- function func = (function)_buffer;
- return func(args...);
- }
- void EmplaceUInt64(std::uint32_t offset, std::uint64_t target)
- {
- if (_buffer)
- {
- std::uint64_t* ptr = (std::uint64_t*)&_buffer[offset];
- *ptr = target;
- }
- }
- std::uint8_t* _buffer;
- std::uint8_t _bytes[sizeof...(Bytes)];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement