Compare commits

...
5 Commits
Author SHA1 Message Date
hugy f9a7924658 fix: 修复utf8的校验和json返回类型 2023-04-25 08:48:16 +08:00
hugy 6105789fcc fix: 修复部分字段未知的编码方式,转换成base64 close #51 2023-04-24 20:37:41 +08:00
hugy dffdbfb9d7 文档更新 2023-04-08 14:55:08 +08:00
hugy 8279303614 @消息和ocr 2023-04-08 14:53:04 +08:00
hugy 5ba4f72d5c ocr 2023-04-08 14:40:58 +08:00
8 changed files with 145 additions and 39 deletions

No files matched your search

+3 -2
View File
@@ -3,7 +3,8 @@
#### 功能预览: #### 功能预览:
0.检查是否登录 0.检查是否登录
1.获取登录微信信息 1.获取登录微信信息
2.发送文本 2.发送文本
3.发送@文本
5.发送图片 5.发送图片
6.发送文件 6.发送文件
9.hook消息 9.hook消息
@@ -31,7 +32,7 @@
46.联系人列表 46.联系人列表
47.获取群详情 47.获取群详情
48.获取解密图片 48.获取解密图片
<!-- 49.图片提取文字ocr --> 49.图片提取文字ocr
50.拍一拍 50.拍一拍
51.群消息置顶消息 51.群消息置顶消息
52.群消息取消置顶 52.群消息取消置顶
+11 -2
View File
@@ -5,6 +5,7 @@
#include "easylogging++.h" #include "easylogging++.h"
#include "wechat_function.h" #include "wechat_function.h"
#include "utils.h"
using namespace std; using namespace std;
namespace wxhelper { namespace wxhelper {
@@ -117,8 +118,16 @@ int DB::Select(DWORD db_hanle, const char *sql,
vector<string> item; vector<string> item;
for (size_t i = 0; i < it.size(); i++) { for (size_t i = 0; i < it.size(); i++) {
if (!it[i].is_blob) { if (!it[i].is_blob) {
string content(it[i].content); bool is_utf8 = Utils::IsTextUtf8(it[i].content, it[i].content_len);
item.push_back(content); if (is_utf8) {
string content(it[i].content);
item.push_back(content);
} else {
string base64_str =
base64_encode((BYTE *)it[i].content, it[i].content_len);
item.push_back(base64_str);
}
} else { } else {
string b64_str = string b64_str =
base64_encode((BYTE *)it[i].content, it[i].content_len); base64_encode((BYTE *)it[i].content, it[i].content_len);
+6 -7
View File
@@ -131,7 +131,6 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
break; break;
} }
case WECHAT_MSG_SEND_AT: { case WECHAT_MSG_SEND_AT: {
break;
wstring chat_room_id = GetWStringParam(j_param, "chatRoomId"); wstring chat_room_id = GetWStringParam(j_param, "chatRoomId");
vector<wstring> wxids = getArrayParam(j_param, "wxids"); vector<wstring> wxids = getArrayParam(j_param, "wxids");
wstring msg = GetWStringParam(j_param, "msg"); wstring msg = GetWStringParam(j_param, "msg");
@@ -502,11 +501,11 @@ string Dispatch(struct mg_connection *c, struct mg_http_message *hm) {
break; break;
} }
case WECHAT_DO_OCR: { case WECHAT_DO_OCR: {
// wstring image_path = GetWStringParam(j_param, "imagePath"); wstring image_path = GetWStringParam(j_param, "imagePath");
// string text(""); string text("");
// int success = g_context.misc_mgr->DoOCRTask(WS2LPWS(image_path), text); int success = g_context.misc_mgr->DoOCRTask(WS2LPWS(image_path), text);
// json ret_data = {{"code", success}, {"result", "OK"}, {"text", text}}; json ret_data = {{"code", success}, {"result", "OK"}, {"text", text}};
// ret = ret_data.dump(); ret = ret_data.dump();
break; break;
} }
case WECHAT_SEND_PAT_MSG: { case WECHAT_SEND_PAT_MSG: {
@@ -589,7 +588,7 @@ void HttpHandler::HandlerRequest(struct mg_connection *c, void *ev_data) {
ret = res.dump(); ret = res.dump();
} }
if (ret != "") { if (ret != "") {
mg_http_reply(c, 200, "", ret.c_str(), 0, 0); mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n", ret.c_str());
} }
} else { } else {
mg_http_reply(c, 500, NULL, "%s", "Invalid URI"); mg_http_reply(c, 500, NULL, "%s", "Invalid URI");
+1 -1
View File
@@ -90,7 +90,7 @@ int MiscMgr::DoOCRTask(wchar_t *img_path, std::string &result) {
for (unsigned int i = 0; i < num - 1; i++) { for (unsigned int i = 0; i < num - 1; i++) {
DWORD content = *(DWORD *)header; DWORD content = *(DWORD *)header;
result += Utils::WstringToUTF8(READ_WSTRING(content, 0x14)); result += Utils::WstringToUTF8(READ_WSTRING(content, 0x14));
result += "\r\n";
header = content; header = content;
} }
} }
+75 -17
View File
@@ -5,6 +5,7 @@
#include "wechat_function.h" #include "wechat_function.h"
#include "db.h" #include "db.h"
#include "contact_mgr.h"
namespace wxhelper { namespace wxhelper {
SendMessageMgr::SendMessageMgr(DWORD base):BaseMgr(base) {} SendMessageMgr::SendMessageMgr(DWORD base):BaseMgr(base) {}
@@ -14,10 +15,9 @@ int SendMessageMgr::SendText(wchar_t* wxid, wchar_t* msg) {
WeChatString to_user(wxid); WeChatString to_user(wxid);
WeChatString text_msg(msg); WeChatString text_msg(msg);
wchar_t** msg_pptr = &text_msg.ptr; wchar_t** msg_pptr = &text_msg.ptr;
DWORD base = Utils::GetWeChatWinBase(); DWORD send_message_mgr_addr = base_addr_ + WX_SEND_MESSAGE_MGR_OFFSET;
DWORD send_message_mgr_addr = base + WX_SEND_MESSAGE_MGR_OFFSET; DWORD send_text_msg_addr = base_addr_ + WX_SEND_TEXT_OFFSET;
DWORD send_text_msg_addr = base + WX_SEND_TEXT_OFFSET; DWORD free_chat_msg_addr = base_addr_ + WX_FREE_CHAT_MSG_OFFSET;
DWORD free_chat_msg_addr = base + WX_FREE_CHAT_MSG_OFFSET;
char chat_msg[0x2D8] = {0}; char chat_msg[0x2D8] = {0};
__asm { __asm {
PUSHAD PUSHAD
@@ -44,6 +44,67 @@ int SendMessageMgr::SendText(wchar_t* wxid, wchar_t* msg) {
int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len, int SendMessageMgr::SendAtText(wchar_t* chat_room_id, wchar_t** wxids, int len,
wchar_t* msg) { wchar_t* msg) {
int success = -1; int success = -1;
WeChatString * at_users = new WeChatString[len+1];
std::wstring at_msg = L"";
int number =0;
for (int i = 0; i < len; i++) {
std::wstring nickname;
if (!lstrcmpiW((wchar_t *)wxids[i], (wchar_t *)L"notify@all")) {
nickname = L"所有人";
} else {
ContactMgr contact{base_addr_};
nickname = contact.GetContactOrChatRoomNickname(wxids[i]);
}
if (nickname.length() == 0) {
continue;
}
WeChatString temp = {0};
temp.ptr = (wchar_t *)wxids[i];
temp.length = wcslen((wchar_t *)wxids[i]);
temp.max_length = wcslen((wchar_t *)wxids[i]) * 2;
memcpy(&at_users[number], &temp, sizeof(WeChatString));
at_msg = at_msg + L"@" + nickname + L" ";
number++;
}
if (number < 1){
return success;
}
std::wstring origin(msg);
at_msg += origin;
AtInner at_list = {0};
at_list.start = (DWORD)at_users;
at_list.finsh = (DWORD)&at_users[number];
at_list.end = (DWORD)&at_users[number];
WeChatString to_user(chat_room_id);
WeChatString text_msg((wchar_t *)at_msg.c_str());
wchar_t **msg_pptr = &text_msg.ptr;
DWORD send_message_mgr_addr = base_addr_ + WX_SEND_MESSAGE_MGR_OFFSET;
DWORD send_text_msg_addr = base_addr_ + WX_SEND_TEXT_OFFSET;
DWORD free_chat_msg_addr = base_addr_ + WX_FREE_CHAT_MSG_OFFSET;
char chat_msg[0x2D8] = {0};
__asm{
PUSHAD
CALL send_message_mgr_addr
PUSH 0x0
PUSH 0x0
PUSH 0x0
PUSH 0x1
LEA EAX,at_list
PUSH EAX
MOV EAX,msg_pptr
PUSH EAX
LEA EDX,to_user
LEA ECX,chat_msg
CALL send_text_msg_addr
MOV success,EAX
ADD ESP,0x18
LEA ECX,chat_msg
CALL free_chat_msg_addr
POPAD
}
LOG_IF((success == -1), ERROR) << "SendText fail";
return success; return success;
} }
int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) { int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) {
@@ -51,11 +112,10 @@ int SendMessageMgr::SendImage(wchar_t* wxid, wchar_t* image_path) {
WeChatString to_user(wxid); WeChatString to_user(wxid);
WeChatString path(image_path); WeChatString path(image_path);
char chat_msg[0x2D8] = {0}; char chat_msg[0x2D8] = {0};
DWORD base = Utils::GetWeChatWinBase(); DWORD send_message_mgr_addr = base_addr_ + WX_SEND_MESSAGE_MGR_OFFSET;
DWORD send_message_mgr_addr = base + WX_SEND_MESSAGE_MGR_OFFSET; DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD init_chat_msg_addr = base + WX_INIT_CHAT_MSG_OFFSET; DWORD send_image_msg_addr = base_addr_ + WX_SEND_IMAGE_OFFSET;
DWORD send_image_msg_addr = base + WX_SEND_IMAGE_OFFSET; DWORD free_msg_addr = base_addr_ + WX_FREE_CHAT_MSG_OFFSET;
DWORD free_msg_addr = base + WX_FREE_CHAT_MSG_OFFSET;
DWORD temp = 0; DWORD temp = 0;
WeChatString null_obj = {0}; WeChatString null_obj = {0};
__asm { __asm {
@@ -88,11 +148,10 @@ int SendMessageMgr::SendFile(wchar_t* wxid, wchar_t* file_path) {
WeChatString to_user(wxid); WeChatString to_user(wxid);
WeChatString path(file_path); WeChatString path(file_path);
char chat_msg[0x2D8] = {0}; char chat_msg[0x2D8] = {0};
DWORD base = Utils::GetWeChatWinBase(); DWORD app_msg_mgr_addr = base_addr_ + WX_APP_MSG_MGR_OFFSET;
DWORD app_msg_mgr_addr = base + WX_APP_MSG_MGR_OFFSET; DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD init_chat_msg_addr = base + WX_INIT_CHAT_MSG_OFFSET; DWORD send_file_addr = base_addr_ + WX_SEND_FILE_OFFSET;
DWORD send_file_addr = base + WX_SEND_FILE_OFFSET; DWORD free_msg_addr = base_addr_ + WX_FREE_CHAT_MSG_OFFSET;
DWORD free_msg_addr = base + WX_FREE_CHAT_MSG_OFFSET;
DWORD temp = 0; DWORD temp = 0;
WeChatString null_obj = {0}; WeChatString null_obj = {0};
__asm { __asm {
@@ -150,9 +209,8 @@ int SendMessageMgr::ForwardMsg(wchar_t* wxid, unsigned long long msgid) {
if (localid == 0) return 0; if (localid == 0) return 0;
WeChatString to_user(wxid); WeChatString to_user(wxid);
DWORD base = Utils::GetWeChatWinBase(); DWORD forward_msg_addr = base_addr_ + WX_FORWARD_MSG_OFFSET;
DWORD forward_msg_addr = base + WX_FORWARD_MSG_OFFSET; DWORD init_chat_msg_addr = base_addr_ + WX_INIT_CHAT_MSG_OFFSET;
DWORD init_chat_msg_addr = base + WX_INIT_CHAT_MSG_OFFSET;
__asm { __asm {
PUSHAD PUSHAD
PUSHFD PUSHFD
+44 -7
View File
@@ -1,7 +1,6 @@
#include "pch.h" #include "utils.h"
#include "utils.h"
#include "pch.h"
namespace wxhelper { namespace wxhelper {
std::wstring Utils::UTF8ToWstring(const std::string &str) { std::wstring Utils::UTF8ToWstring(const std::string &str) {
@@ -19,7 +18,7 @@ std::wstring Utils::AnsiToWstring(const std::string &input, DWORD locale) {
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len); MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len);
return std::wstring(&temp[0]); return std::wstring(&temp[0]);
} }
return std::wstring(); return std::wstring();
} }
@@ -102,8 +101,6 @@ void Utils::Hex2Bytes(const std::string &hex, BYTE *bytes) {
} }
} }
bool Utils::IsDigit(std::string str) { bool Utils::IsDigit(std::string str) {
if (str.length() == 0) { if (str.length() == 0) {
return false; return false;
@@ -119,7 +116,8 @@ bool Utils::IsDigit(std::string str) {
bool Utils::FindOrCreateDirectoryW(const wchar_t *path) { bool Utils::FindOrCreateDirectoryW(const wchar_t *path) {
WIN32_FIND_DATAW fd; WIN32_FIND_DATAW fd;
HANDLE hFind = ::FindFirstFileW(path, &fd); HANDLE hFind = ::FindFirstFileW(path, &fd);
if (hFind != INVALID_HANDLE_VALUE && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (hFind != INVALID_HANDLE_VALUE &&
(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
FindClose(hFind); FindClose(hFind);
return true; return true;
} }
@@ -174,4 +172,43 @@ std::string Utils::WCharToUTF8(wchar_t *wstr) {
return std::string(); return std::string();
} }
bool Utils::IsTextUtf8(const char *str,int length) {
char endian = 1;
bool littlen_endian = (*(char *)&endian == 1);
size_t i;
int bytes_num;
unsigned char chr;
i = 0;
bytes_num = 0;
while (i < length) {
if (littlen_endian) {
chr = *(str + i);
} else { // Big Endian
chr = (*(str + i) << 8) | *(str + i + 1);
i++;
}
if (bytes_num == 0) {
if ((chr & 0x80) != 0) {
while ((chr & 0x80) != 0) {
chr <<= 1;
bytes_num++;
}
if ((bytes_num < 2) || (bytes_num > 6)) {
return false;
}
bytes_num--;
}
} else {
if ((chr & 0xC0) != 0x80) {
return false;
}
bytes_num--;
}
i++;
}
return (bytes_num == 0);
}
} // namespace wxhelper } // namespace wxhelper
+2
View File
@@ -47,6 +47,8 @@ class Utils {
static std::string WCharToUTF8(wchar_t *wstr); static std::string WCharToUTF8(wchar_t *wstr);
static bool IsTextUtf8(const char * str,int length) ;
template <typename T1, typename T2> template <typename T1, typename T2>
static std::vector<T1> split(T1 str, T2 letter) { static std::vector<T1> split(T1 str, T2 letter) {
std::vector<T1> arr; std::vector<T1> arr;
+3 -3
View File
@@ -133,9 +133,9 @@
//ocr //ocr
#define WX_INIT_OBJ_OFFSET 0x7a98f0 #define WX_INIT_OBJ_OFFSET 0x80a800
#define WX_OCR_MANAGER_OFFSET 0x7ae470 #define WX_OCR_MANAGER_OFFSET 0x80f270
#define WX_DO_OCR_TASK_OFFSET 0x13230c0 #define WX_DO_OCR_TASK_OFFSET 0x13da3e0
//storage //storage