Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. template <std::uint8_t...Bytes>
  2. class BufferCall
  3. {
  4. public:
  5. constexpr BufferCall() :
  6. _buffer(nullptr),
  7. _bytes{ Bytes... }
  8. {
  9. _buffer = (std::uint8_t*)VirtualAlloc(0, sizeof...(Bytes), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  10.  
  11. if (_buffer)
  12. {
  13. memcpy(_buffer, _bytes, sizeof...(Bytes));
  14. }
  15. }
  16.  
  17. virtual ~BufferCall()
  18. {
  19. if (_buffer)
  20. {
  21. VirtualFree(_buffer, sizeof...(Bytes), MEM_RELEASE);
  22. _buffer = nullptr;
  23. }
  24. }
  25.  
  26. template <typename Ret, typename...Args>
  27. Ret Call(Args...args)
  28. {
  29. typedef Ret(*function)(Args...);
  30. function func = (function)_buffer;
  31. return func(args...);
  32. }
  33.  
  34. void EmplaceUInt64(std::uint32_t offset, std::uint64_t target)
  35. {
  36. if (_buffer)
  37. {
  38. std::uint64_t* ptr = (std::uint64_t*)&_buffer[offset];
  39. *ptr = target;
  40. }
  41. }
  42.  
  43. std::uint8_t* _buffer;
  44. std::uint8_t _bytes[sizeof...(Bytes)];
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement