From 198621f19ced0ed80651deb66811507d890c70f8 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 2 Jun 2021 02:53:55 +0200 Subject: [PATCH] FIX(client): Use ReadProcessMemory() instead of Toolhelp32ReadProcessMemory() I was wrong in d7f0302ce721c28ab9b4928ac5e65c0670f9d266. Turns out Toolhelp32ReadProcessMemory() is simply a wrapper for ReadProcessMemory() that takes care of opening an handle to the process and closing it. For reference: https://github.com/MicrosoftDocs/sdk-api/pull/793 --- plugins/HostWindows.cpp | 6 +++++- plugins/HostWindows.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/HostWindows.cpp b/plugins/HostWindows.cpp index 1c0574fc5..9e6b512c5 100644 --- a/plugins/HostWindows.cpp +++ b/plugins/HostWindows.cpp @@ -11,14 +11,18 @@ #include HostWindows::HostWindows(const procid_t pid) : m_pid(pid) { + m_handle = OpenProcess(PROCESS_VM_READ, false, m_pid); } HostWindows::~HostWindows() { + if (m_handle) { + CloseHandle(m_handle); + } } bool HostWindows::peek(const procptr_t address, void *dst, const size_t size) const { SIZE_T read; - const auto ok = Toolhelp32ReadProcessMemory(m_pid, reinterpret_cast< void * >(address), dst, size, &read); + const auto ok = ReadProcessMemory(m_handle, reinterpret_cast< void * >(address), dst, size, &read); return (ok && read == size); } diff --git a/plugins/HostWindows.h b/plugins/HostWindows.h index 45502cfc1..c7ff52e86 100644 --- a/plugins/HostWindows.h +++ b/plugins/HostWindows.h @@ -13,6 +13,7 @@ typedef uint32_t procid_t; class HostWindows { protected: procid_t m_pid; + void *m_handle; public: bool peek(const procptr_t address, void *dst, const size_t size) const;