From 53a7938335acc058a6f797b8776403bc91a4a236 Mon Sep 17 00:00:00 2001 From: hugy <504650082@qq.com> Date: Thu, 6 Jul 2023 21:15:56 +0800 Subject: [PATCH] fix: free heap bug --- src/manager.cc | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/manager.cc b/src/manager.cc index 1bce95a..697495f 100644 --- a/src/manager.cc +++ b/src/manager.cc @@ -251,25 +251,25 @@ INT64 Manager::SendImageMsg(const std::wstring& wxid, const std::wstring& image_ return success; } -// todo bug 9/10 + INT64 Manager::SendFileMsg(const std::wstring& wxid, const std::wstring& file_path){ INT64 success = -1; prototype::WeChatString* to_user= (prototype::WeChatString*)HeapAlloc(GetProcessHeap(),0,sizeof(prototype::WeChatString)); - wchar_t * ptr_wxid = (wchar_t*)HeapAlloc(GetProcessHeap(),0,wxid.length()+1); + wchar_t * ptr_wxid = (wchar_t*)HeapAlloc(GetProcessHeap(),0,(wxid.length()+1)*2); wmemcpy(ptr_wxid,wxid.c_str(),wxid.length()+1); to_user->ptr = ptr_wxid; to_user->length = static_cast(wxid.length()); to_user->max_length = static_cast(wxid.length()); to_user->c_len=0; to_user->c_ptr=0; - prototype::WeChatString* image_full_path= (prototype::WeChatString*)HeapAlloc(GetProcessHeap(),0,sizeof(prototype::WeChatString)); - wchar_t * ptr_path = (wchar_t*)HeapAlloc(GetProcessHeap(),0,file_path.length()+1); + prototype::WeChatString* file_full_path= (prototype::WeChatString*)HeapAlloc(GetProcessHeap(),0,sizeof(prototype::WeChatString)); + wchar_t * ptr_path = (wchar_t*)HeapAlloc(GetProcessHeap(),0,(file_path.length()+1)*2); wmemcpy(ptr_path,file_path.c_str(),file_path.length()+1); - image_full_path->ptr = ptr_path; - image_full_path->length = static_cast(file_path.length()); - image_full_path->max_length = static_cast(file_path.length()); - image_full_path->c_len = 0; - image_full_path->c_ptr = 0; + file_full_path->ptr = ptr_path; + file_full_path->length = static_cast(file_path.length()); + file_full_path->max_length = static_cast(file_path.length()); + file_full_path->c_len = 0; + file_full_path->c_ptr = 0; UINT64 get_app_msg_mgr_addr = base_addr_ + offset::kGetAppMsgMgr; UINT64 send_file_addr = base_addr_ + offset::kSendFileMsg; @@ -293,26 +293,15 @@ INT64 Manager::SendFileMsg(const std::wstring& wxid, const std::wstring& file_pa ZeroMemory(temp3,sizeof(UINT64)*4); ZeroMemory(temp4,sizeof(UINT64)*4); *temp4=0x1F; - UINT64 temp5 = 0xC; - - - UINT64 app_mgr = get_app_mgr(); - // UINT64 p_chat_msg = new_chat_msg(reinterpret_cast(chat_msg)); - // send_file(app_mgr, p_chat_msg, reinterpret_cast(to_user), - // reinterpret_cast(image_full_path), 1, - // reinterpret_cast(temp1), 0x300, - // reinterpret_cast(temp2), 0, - // reinterpret_cast(temp3), - // reinterpret_cast(temp4), - // temp5); - send_file(app_mgr, reinterpret_cast(chat_msg), reinterpret_cast(to_user), - reinterpret_cast(image_full_path), 1, + reinterpret_cast(file_full_path), 1, reinterpret_cast(temp1), 0, reinterpret_cast(temp2), - 0, reinterpret_cast(temp3), 0, 0x0); + 0, reinterpret_cast(temp3), 0, 0); free(reinterpret_cast(chat_msg)); + HeapFree(GetProcessHeap(),0,to_user); + HeapFree(GetProcessHeap(),0,file_full_path); HeapFree(GetProcessHeap(),0,temp1); HeapFree(GetProcessHeap(),0,temp2); HeapFree(GetProcessHeap(),0,temp3);