From d368e26318af9afd202201e6e220527e1f18e73d Mon Sep 17 00:00:00 2001 From: Changhua Date: Wed, 19 Feb 2025 00:58:24 +0800 Subject: [PATCH] fix(spy): fix WxString memory map --- WeChatFerry/spy/spy_types.h | 51 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/WeChatFerry/spy/spy_types.h b/WeChatFerry/spy/spy_types.h index 56f7c51..73c801e 100644 --- a/WeChatFerry/spy/spy_types.h +++ b/WeChatFerry/spy/spy_types.h @@ -7,40 +7,51 @@ typedef uint64_t QWORD; class WxString { - public: const wchar_t *wptr; DWORD size; - DWORD capacity; + DWORD length; const char *ptr; DWORD clen; - WxString() - { - wptr = nullptr; - size = 0; - capacity = 0; - ptr = nullptr; - clen = 0; - } + WxString() : wptr(nullptr), size(0), length(0), ptr(nullptr), clen(0) { } - WxString(std::wstring ws) : internal_ws(std::move(ws)) + explicit WxString(const std::wstring &ws) + : wptr(ws.c_str()), size(static_cast(ws.size())), length(static_cast(ws.length())), ptr(nullptr), + clen(0) { - wptr = internal_ws.c_str(); - size = static_cast(internal_ws.size()); - capacity = static_cast(internal_ws.capacity()); - ptr = nullptr; - clen = 0; } WxString(const WxString &) = delete; WxString &operator=(const WxString &) = delete; - WxString(WxString &&) noexcept = default; - WxString &operator=(WxString &&) noexcept = default; + WxString(WxString &&other) noexcept + : wptr(other.wptr), size(other.size), length(other.length), ptr(other.ptr), clen(other.clen) + { + other.wptr = nullptr; + other.size = 0; + other.length = 0; + other.ptr = nullptr; + other.clen = 0; + } -private: - std::wstring internal_ws; + WxString &operator=(WxString &&other) noexcept + { + if (this != &other) { + wptr = other.wptr; + size = other.size; + length = other.length; + ptr = other.ptr; + clen = other.clen; + + other.wptr = nullptr; + other.size = 0; + other.length = 0; + other.ptr = nullptr; + other.clen = 0; + } + return *this; + } }; typedef struct RawVector {