Make port configurable

This commit is contained in:
Changhua
2023-04-08 22:52:35 +08:00
parent dd02c4b6ff
commit b643f92681
8 changed files with 33 additions and 35 deletions
+14 -7
View File
@@ -31,9 +31,9 @@
#include "user_info.h"
#include "util.h"
#define URL_SIZE 20
#define BASE_URL "tcp://0.0.0.0"
#define G_BUF_SIZE (16 * 1024 * 1024)
#define CMD_URL "tcp://0.0.0.0:10086"
#define MSG_URL "tcp://0.0.0.0:10087"
extern int IsLogin(void); // Defined in spy.cpp
@@ -42,6 +42,7 @@ mutex gMutex;
condition_variable gCV;
queue<WxMsg_t> gMsgQueue;
static int lport = 0;
static DWORD lThreadId = 0;
static bool lIsRunning = false;
static nng_socket sock;
@@ -297,7 +298,9 @@ static void PushMessage()
pb_ostream_t stream = pb_ostream_from_buffer(buffer, G_BUF_SIZE);
char *url = (char *)MSG_URL;
char url[URL_SIZE + 1] = { 0 };
sprintf_s(url, URL_SIZE, "%s:%d", BASE_URL, lport + 1);
LOG_ERROR("URL: {}", url);
if ((rv = nng_pair1_open(&msg_sock)) != 0) {
LOG_ERROR("nng_pair0_open error {}", nng_strerror(rv));
return;
@@ -560,9 +563,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
return ret;
}
static int RunServer(LPVOID url)
static int RunServer()
{
int rv = 0;
int rv = 0;
char url[URL_SIZE + 1] = { 0 };
sprintf_s(url, URL_SIZE, "%s:%d", BASE_URL, lport);
if ((rv = nng_pair1_open(&sock)) != 0) {
LOG_ERROR("nng_pair0_open error {}", nng_strerror(rv));
return rv;
@@ -612,13 +617,15 @@ static int RunServer(LPVOID url)
return rv;
}
int RpcStartServer(const char *url)
int RpcStartServer(int port)
{
if (lIsRunning) {
return 0;
}
HANDLE rpcThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RunServer, (LPVOID)url, NULL, &lThreadId);
lport = port;
HANDLE rpcThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RunServer, NULL, NULL, &lThreadId);
if (rpcThread != 0) {
CloseHandle(rpcThread);
}
+1 -1
View File
@@ -6,5 +6,5 @@
#define SPY_API __declspec(dllimport)
#endif
int RpcStartServer(const char *url);
int RpcStartServer(int port);
int RpcStopServer();
+3 -7
View File
@@ -7,7 +7,7 @@
WxCalls_t g_WxCalls = { 0 };
DWORD g_WeChatWinDllAddr = 0;
void InitSpy(const char *url)
void InitSpy(int port)
{
wchar_t version[16] = { 0 };
InitLogger();
@@ -28,13 +28,9 @@ void InitSpy(const char *url)
return;
}
RpcStartServer(url);
RpcStartServer(port);
}
void CleanupSpy()
{
RpcStopServer();
// FreeLibraryAndExitThread(hModule, 0);
}
void CleanupSpy() { RpcStopServer(); }
int IsLogin(void) { return (int)GET_DWORD(g_WeChatWinDllAddr + g_WxCalls.login); }
+1 -2
View File
@@ -2,6 +2,5 @@
#include "framework.h"
void InitSpy();
void InitSpy(int port);
void CleanupSpy();
int IsLogin(void);