Compare commits

..
Author SHA1 Message Date
hugy 67949e16fc 日志hook退出还原 2023-03-16 12:06:56 +08:00
hugy 9f7b1dd273 新增日志hook 2023-03-16 12:02:44 +08:00
4 changed files with 163 additions and 0 deletions

No files matched your search

+69
View File
@@ -125,6 +125,8 @@ vcpkg
31.修改群昵称
32.获取数据库句柄
34.查询数据库
35.hook日志
36.关闭hook日志
40.转发消息
44.退出登录
45.确认收款
@@ -942,6 +944,73 @@ vcpkg
```
#### 35.hook日志**
###### 接口功能
> hook微信日志,在控制台打印日志,方便调试
###### 接口地址
> [/api/?type=35](/api/?type=35)
###### HTTP请求方式
> POST JSON
###### 请求参数
|参数|必选|类型|说明|
|---|---|---|---|
###### 返回字段
|返回字段|字段类型|说明 |
|---|---|---|
|code|int|返回状态,1成功, 0失败|
|result|string|成功提示|
###### 接口示例
入参:
``` javascript
```
响应:
``` javascript
{"code":1,"result":"OK"}
```
#### 36.取消hook日志**
###### 接口功能
> 取消hook日志
###### 接口地址
> [/api/?type=36](/api/?type=36)
###### HTTP请求方式
> POST JSON
###### 请求参数
|参数|必选|类型|说明|
|---|---|---|---|
###### 返回字段
|返回字段|字段类型|说明 |
|---|---|---|
|code|int|返回状态,1成功, 0失败|
|result|string|成功提示|
###### 接口示例
入参:
``` javascript
```
响应:
``` javascript
{"code":1,"result":"OK"}
```
#### 40.转发消息**
###### 接口功能
> 直接转发消息
+8
View File
@@ -24,6 +24,7 @@
#include "sns.h"
#include "search_contact.h"
#include "download.h"
#include "hook_log.h"
#pragma comment(lib, "ws2_32.lib")
using namespace std;
@@ -486,9 +487,15 @@ void api_handle(mg_http_message *hm, struct mg_connection *c, string &ret) {
break;
}
case WECHAT_LOG_START_HOOK: {
int success = HookLog();
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_LOG_STOP_HOOK: {
int success = UnHookLog();
json ret_data = {{"code", success}, {"result", "OK"}};
ret = ret_data.dump();
break;
}
case WECHAT_BROWSER_OPEN_WITH_URL: {
@@ -735,5 +742,6 @@ int http_close() {
UnHookRecvMsg();
UnHookImg();
UnHookSearchContact();
UnHookLog();
return 0;
}
+78
View File
@@ -0,0 +1,78 @@
#include "pch.h"
#include "hook_log.h"
#include "common.h"
using namespace std;
#define WX_HOOK_LOG_OFFSET 0xed1675
#define WX_HOOK_LOG_NEXT_OFFSET 0x2344832
static int kLogHooked = FALSE;
static DWORD kWeChatWinBase = GetWeChatWinBase();
static char kOriginLogAsmCode[5] = {0};
static DWORD kHookLogAddress = kWeChatWinBase + WX_HOOK_LOG_OFFSET;
static DWORD kHookLogNextAddress = kWeChatWinBase + WX_HOOK_LOG_NEXT_OFFSET;
static DWORD kHookLogJmpBackAddress = kWeChatWinBase + WX_HOOK_LOG_OFFSET + 0x5;
void log_print(DWORD addr) {
if (!addr) {
return;
}
DWORD dwId = 0;
char *msg = (char *)addr;
int size = MultiByteToWideChar(CP_UTF8, 0, msg, -1, 0, 0);
wchar_t *w_msg = new wchar_t[size + 1];
memset(w_msg, 0, (size + 1) * 2);
MultiByteToWideChar(CP_UTF8, 0, msg, -1, w_msg, size);
size = WideCharToMultiByte(CP_ACP, 0, w_msg, -1, 0, 0, 0, 0);
char *ansi_message = new char[size + 1];
memset(ansi_message, 0, size + 1);
WideCharToMultiByte(CP_ACP, 0, w_msg, -1, ansi_message, size, 0, 0);
delete[] w_msg;
w_msg = NULL;
cout << ansi_message;
delete[] ansi_message;
ansi_message = NULL;
}
_declspec(naked) void handle_log() {
__asm {
PUSHAD
PUSHFD
PUSH EAX
CALL log_print
ADD ESP, 0x4
POPFD
POPAD
CALL kHookLogNextAddress
JMP kHookLogJmpBackAddress
}
}
int HookLog() {
kWeChatWinBase = GetWeChatWinBase();
if (!kWeChatWinBase) {
return -1;
}
if (kLogHooked) {
return 2;
}
kHookLogAddress = kWeChatWinBase + WX_HOOK_LOG_OFFSET;
kHookLogNextAddress = kWeChatWinBase + WX_HOOK_LOG_NEXT_OFFSET;
kHookLogJmpBackAddress = kHookLogAddress + 0x5;
HookAnyAddress(kHookLogAddress, (LPVOID)handle_log, kOriginLogAsmCode);
kLogHooked = TRUE;
return 1;
}
int UnHookLog() {
if (!kLogHooked) {
return 1;
}
DWORD hook_img_addr = kWeChatWinBase + WX_HOOK_LOG_OFFSET;
UnHookAnyAddress(hook_img_addr, kOriginLogAsmCode);
kLogHooked = FALSE;
return 1;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef HOOK_LOG_H_
#define HOOK_LOG_H_
#include "windows.h"
int HookLog();
int UnHookLog();
#endif