daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top