LoginSignup
0
0

More than 3 years have passed since last update.

[メモ]`VirtualAllocEx`で確保した他プロセスメモリーをスマートポインターとして扱う

Posted at

現時点ではmicrosoft/wilにもラッパークラスが用意されていなかったので、作ってみました。

定義
struct virtualallocex_deleter {
    HANDLE const hProcess;

    template<typename T>
    void operator()(T* ptr) const
    {
        ::VirtualFreeEx(hProcess, ptr, 0, MEM_RELEASE);
    }
};

template<typename T = void>
using unique_virtualallocex_ptr = std::unique_ptr<T, virtualallocex_deleter>;
使用方法
unique_virtualallocex_ptr<> pRemote{
    ::VirtualAllocEx(hProcess.get(), nullptr, sizeof(localData), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE),
    virtualallocex_deleter{hProcess.get()}
};
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0