This commit is contained in:
Changhua
2023-02-25 02:11:04 +08:00
parent b6b38376f8
commit a54b221bbe
11 changed files with 308 additions and 27 deletions
+1 -1
View File
@@ -126,7 +126,7 @@
<ModuleDefinitionFile>sdk.def</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(OutDir)sdk.dll $(SolutionDir)Out</Command>
<Command>xcopy /y $(OutDir)$(TargetFileName) $(SolutionDir)Out</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Copy files</Message>
-27
View File
@@ -1,27 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "sdk.h"
void help() { printf("Usage: sdk.exe start|stop [debug]"); }
int main(int argc, char *argv[])
{
int ret = -1;
bool debug = false;
if ((argc < 2) || (argc > 3)) {
help();
} else if (argc == 3) {
debug = (strcmp(argv[2], "debug") == 0);
}
if (strcmp(argv[1], "start") == 0) {
ret = WxInitSDK(debug);
} else if (strcmp(argv[1], "stop") == 0) {
ret = WxDestroySDK();
} else {
help();
}
return ret;
}
+62 -14
View File
@@ -8,16 +8,16 @@
#include "sdk.h"
#include "util.h"
static DWORD wcPid = 0;
#define WCF_LOCK ".wcf.lock"
static bool debugMode = false;
static HANDLE wcProcess = NULL;
static HMODULE spyBase = NULL;
static WCHAR spyDllPath[MAX_PATH] = { 0 };
int WxInitSDK(bool debug)
static int GetDllPath(bool debug, wchar_t *dllPath)
{
int status = 0;
InitLogger();
LOG_INFO("WxInitSDK.");
GetModuleFileName(GetModuleHandle(WECHATSDKDLL), spyDllPath, MAX_PATH);
PathRemoveFileSpec(spyDllPath);
if (debug) {
@@ -31,6 +31,19 @@ int WxInitSDK(bool debug)
return ERROR_FILE_NOT_FOUND;
}
return 0;
}
int WxInitSDK(bool debug)
{
int status = 0;
DWORD wcPid = 0;
status = GetDllPath(debug, spyDllPath);
if (status != 0) {
return status;
}
status = OpenWeChat(&wcPid);
if (status != 0) {
LOG_ERROR("OpenWeChat failed: {}.", status);
@@ -48,21 +61,56 @@ int WxInitSDK(bool debug)
LOG_ERROR("Failed to InitSpy.");
return -1;
}
#if 0
do {
if (!CallDllFunc(wcProcess, spyDllPath, spyBase, "IsLogin", (DWORD *)&status)) {
LOG_ERROR("Failed to check login status.");
return -1;
}
Sleep(1000);
} while (status == 0);
#ifdef WCF
FILE *fd = fopen(WCF_LOCK, "wb");
if (fd == NULL) {
LOG_ERROR("Failed to open {}.", WCF_LOCK);
return -2;
}
fwrite((uint8_t *)&debug, sizeof(debug), 1, fd);
fwrite((uint8_t *)&spyBase, sizeof(spyBase), 1, fd);
fclose(fd);
#endif
debugMode = debug;
LOG_INFO("WxInitSDK done.");
return 0;
}
int WxDestroySDK()
{
LOG_INFO("WxDestroySDK");
int status = 0;
#ifdef WCF
bool debug;
DWORD pid = GetWeChatPid();
if (pid == 0) {
LOG_ERROR("WeChat is not running.");
return status;
}
wcProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (wcProcess == NULL) {
LOG_ERROR("WeChat is not running.");
return -1;
}
FILE *fd = fopen(WCF_LOCK, "rb");
if (fd == NULL) {
LOG_ERROR("Failed to open {}.", WCF_LOCK);
return -2;
}
fread((uint8_t *)&debug, sizeof(debug), 1, fd);
fread((uint8_t *)&spyBase, sizeof(spyBase), 1, fd);
fclose(fd);
status = GetDllPath(debug, spyDllPath);
#else
status = GetDllPath(debugMode, spyDllPath);
#endif
if (status != 0) {
return status;
}
if (!CallDllFunc(wcProcess, spyDllPath, spyBase, "CleanupSpy", NULL)) {
LOG_ERROR("Failed to CleanupSpy.");
return -1;
@@ -72,6 +120,6 @@ int WxDestroySDK()
LOG_ERROR("Failed to Eject DLL.");
return -1; // TODO: Unify error codes
}
LOG_INFO("WxDestroySDK done.");
return 0;
}