Skip to content

Commit 975fb38

Browse files
committed
fix QQMojoIPC DLL Export Err
1 parent fa218f1 commit 975fb38

4 files changed

Lines changed: 141 additions & 201 deletions

File tree

MMMojoCall/examples/cpp/childipc_test.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ void __stdcall OnChildReceiveMsg32(void* pArg, char* msg, int arg3, int arg4, ch
88
{
99
//std::cout << "[ " << __FUNCTION__ << "] | Arg: 0x" << std::hex << pArg << std::endl;
1010
std::string msg_str = msg, add_msg_str(addition_msg, addition_msg_size);
11-
std::cout << "[ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
12-
std::cout << "[ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
11+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
12+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
1313
if (addition_msg_size != 0)
1414
{
15-
std::cout << "[ " << __FUNCTION__ << "] | The Addition Msg: ";
15+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | The Addition Msg: ";
1616
for (size_t i = 0; i < addition_msg_size; i++)
17-
printf("0x%02X ", (byte)(addition_msg[i]));
17+
printf_s("0x%02X ", (byte)(addition_msg[i]));
18+
printf_s("(%s)", addition_msg);
1819
puts("");
1920
}
2021
}
@@ -24,13 +25,14 @@ void OnChildReceiveMsg64(void* pArg, char* msg, int arg3, char* addition_msg, in
2425
//std::cout << "[ " << __FUNCTION__ << "] | Arg: 0x" << std::hex << pArg << std::endl;
2526

2627
std::string msg_str = msg, add_msg_str(addition_msg, addition_msg_size);
27-
std::cout << "[ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
28-
std::cout << "[ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
28+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
29+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
2930
if (addition_msg_size != 0)
3031
{
31-
std::cout << "[ " << __FUNCTION__ << "] | The Addition Msg: ";
32+
std::cout << "[*] [C] [ " << __FUNCTION__ << "] | The Addition Msg: ";
3233
for (size_t i = 0; i < addition_msg_size; i++)
33-
printf("0x%02X ", (byte)(addition_msg[i]));
34+
printf_s("0x%02X ", (byte)(addition_msg[i]));
35+
printf_s("(%s)", addition_msg);
3436
puts("");
3537
}
3638

@@ -39,13 +41,13 @@ void OnChildReceiveMsg64(void* pArg, char* msg, int arg3, char* addition_msg, in
3941

4042
int main()
4143
{
42-
std::cout << "Child Begin!\n";
44+
std::cout << "[+] [C] Child Begin!\n";
4345

4446
qqipc::QQIpcChildWrapper child_ipc;
4547

4648
if (!child_ipc.InitEnv())
4749
{
48-
std::cout << "[!] Init Child Err: " << child_ipc.GetLastErrStrA() << std::endl;
50+
std::cout << "[!] [C] Init Child Err: " << child_ipc.GetLastErrStr() << std::endl;
4951
getchar(); return 0;
5052
}
5153

@@ -57,9 +59,11 @@ int main()
5759
#endif // _WIN64
5860
child_ipc.InitChildIpc();
5961

60-
std::cout << "Press any key to SendIpcMessage to Parent: ";
62+
std::cout << "[=] [C] Press any key to SendIpcMessage to Parent: \n";
6163
getchar();
62-
child_ipc.SendIpcMessage("child_test", "addition_test_child");
64+
65+
std::string addtion_msg = "addition_test_child";
66+
child_ipc.SendIpcMessage("child_test", addtion_msg.data(), addtion_msg.size());
6367

6468
MSG msg;
6569
// 主消息循环:

MMMojoCall/examples/cpp/parentipc_test.cpp

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,61 @@
55

66
using namespace qqimpl;
77

8-
void __stdcall OnUsrReceiveMsg32(void*, char*, int, int, char*, int);
9-
void OnUsrReceiveMsg64(void*, char*, int, char*, int);
8+
void __stdcall OnParentReceiveMsg32(void*, char*, int, int, char*, int);
9+
void OnParentReceiveMsg64(void*, char*, int, char*, int);
1010

1111
int main()
1212
{
13-
std::cout << "Parent Ipc Begin!\n";
13+
std::cout << "[+] [P] Parent Ipc Begin!\n";
1414
int child_pid_1 = 0, child_pid_2 = 0;
1515

1616
qqipc::QQIpcParentWrapper parent_ipc;
1717
//初始化环境
1818
if (!parent_ipc.InitEnv())
1919
{
20-
std::cout << "[!] Init ParentIpc Err: " << parent_ipc.GetLastErrStrA() << std::endl;
20+
std::cout << "[!] [P] Init ParentIpc Err: " << parent_ipc.GetLastErrStr() << std::endl;
2121
getchar(); return 0;
2222
}
2323
parent_ipc.InitLog(5);
2424
parent_ipc.InitParentIpc();
2525

2626
qqipc::callback_ipc cb_ptr;
2727
#ifdef _WIN64
28-
cb_ptr = OnUsrReceiveMsg64;
28+
cb_ptr = OnParentReceiveMsg64;
2929
#else
30-
cb_ptr = OnUsrReceiveMsg32;
30+
cb_ptr = OnParentReceiveMsg32;
3131
#endif // _WIN64
3232

33+
const char* child_path;
34+
#ifdef _DEBUG
35+
child_path = "qqipc_child_test_d.exe";
36+
#else
37+
child_path = "qqipc_child_test.exe";
38+
#endif // _WIN64
39+
40+
3341
const char* cmd_args[] = {"-test1", "-test2"};//传递命令行参数
34-
child_pid_1 = parent_ipc.LaunchChildProcess(L"ChildIpc.exe", cb_ptr, (void*)"Child_1", (char**)cmd_args, 2);// "Child_1"为传递给OnUsrReceiveMsg的参数
42+
child_pid_1 = parent_ipc.LaunchChildProcess(child_path, cb_ptr, (void*)"Child_1", (char**)cmd_args, 2);// "Child_1"为传递给OnUsrReceiveMsg的参数
3543
if (child_pid_1 == 0)
3644
{
37-
std::cout << "[!] Launch CihldIpc.exe Err: " << parent_ipc.GetLastErrStrA() << std::endl;
45+
std::cout << "[!] [P] Launch CihldIpc.exe Err: " << parent_ipc.GetLastErrStr() << std::endl;
3846
getchar(); return 0;
3947
}
4048

41-
std::cout << "Launch OK! Ready to Connect!\n";
49+
std::cout << "[+] [P] Launch OK! Ready to Connect!\n";
4250
parent_ipc.ConnectedToChildProcess(child_pid_1);
4351

44-
std::cout << "Press any key to SendIpcMessage to Child1: ";
52+
std::cout << "[=] [P] Press any key to SendIpcMessage to Child1: \n";
4553
getchar();
46-
parent_ipc.SendIpcMessage(child_pid_1, "test_parent", "addition_parent");
54+
std::string addtion_msg = "addition_parent";
55+
parent_ipc.SendIpcMessage(child_pid_1, "test_parent", addtion_msg.data(), addtion_msg.size());
4756

4857

49-
std::cout << "Press any key to Terminate Child1: ";
58+
std::cout << "[=] [P] Press any key to Terminate Child1: \n";
5059
getchar();
5160
parent_ipc.TerminateChildProcess(child_pid_1, 0, true);
5261

53-
std::cout << "Press any key to ReLaunchChildProcess Child1: ";
62+
std::cout << "[=] [P] Press any key to ReLaunchChildProcess Child1: \n";
5463
getchar();
5564
child_pid_1 = parent_ipc.ReLaunchChildProcess(child_pid_1);
5665
parent_ipc.ConnectedToChildProcess(child_pid_1);
@@ -66,58 +75,60 @@ int main()
6675
return 0;
6776
}
6877

69-
void __stdcall OnUsrReceiveMsg32(void* pArg, char* msg, int arg3, int arg4, char* addition_msg, int addition_msg_size)
78+
void __stdcall OnParentReceiveMsg32(void* pArg, char* msg, int arg3, int arg4, char* addition_msg, int addition_msg_size)
7079
{
7180
char* cb_arg = (char*)pArg;
72-
std::cout << "[ " << __FUNCTION__ << "] | Arg: " << cb_arg << std::endl;
81+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Arg: " << cb_arg << std::endl;
7382

7483
std::string msg_str = msg, add_msg_str(addition_msg, addition_msg_size);
75-
std::cout << "[ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
76-
std::cout << "[ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
84+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
85+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
7786
if (addition_msg_size != 0)
7887
{
79-
std::cout << "[ " << __FUNCTION__ << "] | The Addition Msg: ";
88+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | The Addition Msg: ";
8089
for (size_t i = 0; i < addition_msg_size; i++)
81-
printf("0x%02X ", (byte)(addition_msg[i]));
90+
printf_s("0x%02X ", (byte)(addition_msg[i]));
91+
printf_s("(%s)", addition_msg);
8292
puts("");
8393
}
8494

8595
if (msg_str == "IPC_CONNECTED")
8696
{
87-
std::cout << "[ " << __FUNCTION__ << "] | " << cb_arg << " : Alive!" << std::endl;
97+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | " << cb_arg << " : Alive!" << std::endl;
8898
}
8999
else if (msg_str == "IPC_DISCONNECTED")
90100
{
91-
std::cout << "[ " << __FUNCTION__ << "] | " << cb_arg << " : Dead!" << std::endl;
101+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | " << cb_arg << " : Dead!" << std::endl;
92102
}
93103

94104
//qqimpl::QQIpcParentWrapper::OnDefaultReceiveMsg(pArg, msg, arg3, arg4, addition_msg, addition_msg_size);
95105
}
96106

97107

98-
void OnUsrReceiveMsg64(void* pArg, char* msg, int arg3, char* addition_msg, int addition_msg_size)
108+
void OnParentReceiveMsg64(void* pArg, char* msg, int arg3, char* addition_msg, int addition_msg_size)
99109
{
100110
char* cb_arg = (char*)pArg;
101-
std::cout << "[ " << __FUNCTION__ << "] | Arg: " << cb_arg << std::endl;
111+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Arg: " << cb_arg << std::endl;
102112

103113
std::string msg_str = msg, add_msg_str(addition_msg, addition_msg_size);
104-
std::cout << "[ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
105-
std::cout << "[ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
114+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Msg: " << msg_str << std::endl;
115+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | Addition Msg Size: " << addition_msg_size << std::endl;
106116
if (addition_msg_size != 0)
107117
{
108-
std::cout << "[ " << __FUNCTION__ << "] | The Addition Msg: ";
118+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | The Addition Msg: ";
109119
for (size_t i = 0; i < addition_msg_size; i++)
110-
printf("0x%02X ", (byte)(addition_msg[i]));
120+
printf_s("0x%02X ", (byte)(addition_msg[i]));
121+
printf_s("(%s)", addition_msg);
111122
puts("");
112123
}
113124

114125
if (msg_str == "IPC_CONNECTED")
115126
{
116-
std::cout << "[ " << __FUNCTION__ << "] | " << cb_arg << " : Alive!" << std::endl;
127+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | " << cb_arg << " : Alive!" << std::endl;
117128
}
118129
else if (msg_str == "IPC_DISCONNECTED")
119130
{
120-
std::cout << "[ " << __FUNCTION__ << "] | " << cb_arg << " : Dead!" << std::endl;
131+
std::cout << "[*] [P] [ " << __FUNCTION__ << "] | " << cb_arg << " : Dead!" << std::endl;
121132
}
122133

123134
//qqimpl::QQIpcParentWrapper::OnDefaultReceiveMsg(pArg, msg, arg3, addition_msg, addition_msg_size);

MMMojoCall/src/include/qq_mojoipc/qq_ipc.h

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22
/*****************************************************************//**
33
* @file QQIpc.h
4-
* @brief 此模块用于实现QQ Mojo IPC
4+
* @brief 此模块用于实现QQ Mojo IPC (改为DLL导出)
55
* @version 2.0
66
*
77
* @author 0xEEEE
8-
* @date 2023.9.13
8+
* @date 2023.11.03
99
*********************************************************************/
1010

1111
//此版本分离了IPC和OCR的实现 去除了C++20标准的依赖 并将32位和64位实现合并
@@ -95,32 +95,19 @@ namespace qqimpl
9595
* @param dll_path parent-ipc-core-x86/x64.dll的路径 默认为运行目录下
9696
* @return 成功返回true
9797
*/
98-
bool InitEnvA(std::string dll_path = "");
99-
100-
/**
101-
* @brief 初始化环境.
102-
* @param dll_path parent-ipc-core-x86/x64.dll的路径 默认为运行目录下
103-
* @return 成功返回true
104-
*/
105-
bool InitEnv(std::wstring dll_path = L"");
98+
bool InitEnv(const char* dll_path = NULL);
10699

107100
/**
108101
* @brief 设置dll内部的日志等级 [已被弃用].
109102
* @param level 0-4 5则关闭
110103
*/
111104
void SetLogLevel(int level);
112105

113-
/**
114-
* @brief 获取上一次的错误信息字符串.
115-
* @return 错误信息
116-
*/
117-
std::string GetLastErrStrA();
118-
119106
/**
120107
* @brief 获取上一次的错误信息字符串.
121108
* @return 错误信息
122109
*/
123-
std::wstring GetLastErrStr();
110+
const char* GetLastErrStr();
124111

125112
/**
126113
* @brief 对pIMojoIpc->InitParentLog的封装.
@@ -133,17 +120,6 @@ namespace qqimpl
133120
* @brief 对pIMojoIpc->InitParentIpc()的封装.
134121
*/
135122
void InitParentIpc();
136-
137-
/**
138-
* @brief 对pIMojoIpc->LaunchChildProcess的封装.
139-
* @param file_path 子进程路径
140-
* @param callback 用户自定义接收消息的函数
141-
* @param cb_arg 传递给接收ipc消息回调函数的第一个参数
142-
* @param cmdlines 要添加的命令行参数 例如const char* cmd_args[] = {"-t", "-m"};
143-
* @param cmd_num 要添加的命令行参数的个数
144-
* @return 子进程PID 失败返回0
145-
*/
146-
int LaunchChildProcessA(std::string file_path, callback_ipc callback = nullptr, void* cb_arg = nullptr, char** cmdlines = nullptr, int cmd_num = 0);
147123

148124
/**
149125
* @brief 对pIMojoIpc->LaunchChildProcess的封装.
@@ -154,7 +130,7 @@ namespace qqimpl
154130
* @param cmd_num 要添加的命令行参数的个数
155131
* @return 子进程PID 失败返回0
156132
*/
157-
int LaunchChildProcess(std::wstring file_path, callback_ipc callback = nullptr, void* cb_arg = nullptr, char** cmdlines = nullptr, int cmd_num = 0);
133+
int LaunchChildProcess(const char* file_path, callback_ipc callback = NULL, void* cb_arg = NULL, char** cmdlines = NULL, int cmd_num = 0);
158134

159135
/**
160136
* @brief 对pIMojoIpc->ConnectedToChildProcess的封装.
@@ -166,11 +142,12 @@ namespace qqimpl
166142
/**
167143
* @brief 对pIMojoIpc->SendMessageUsingBufferInIPCThread的封装.
168144
* @param pid 子进程的pid
169-
* @param command IPC_MSG
145+
* @param command IPC_MSG 以'\0'结尾的字符串
170146
* @param addition_msg 参数
147+
* @param addition_msg_size 参数大小
171148
* @return 成功返回true
172149
*/
173-
bool SendIpcMessage(int pid, std::string command, std::string addition_msg = "");
150+
bool SendIpcMessage(int pid, const char* command, const char* addition_msg = NULL, int addition_msg_size = 0);
174151

175152
/**
176153
* @brief 对pIMojoIpc->TerminateChildProcess的封装.
@@ -192,40 +169,27 @@ namespace qqimpl
192169
HMODULE m_ipc_dll;
193170
DWORD_PTR* m_ptr_IMojoIpc;
194171

195-
std::wstring _last_err;
172+
std::string _last_err;
196173
};
197174

198175
class MMMOJOCALL_API QQIpcChildWrapper
199176
{
200177
public:
201178
QQIpcChildWrapper();
202179
~QQIpcChildWrapper();
203-
204-
/**
205-
* @brief 获取上一次的错误信息字符串.
206-
* @return 错误信息
207-
*/
208-
std::string GetLastErrStrA();
209180

210181
/**
211182
* @brief 获取上一次的错误信息字符串.
212183
* @return 错误信息
213184
*/
214-
std::wstring GetLastErrStr();
215-
216-
/**
217-
* @brief 初始化环境.
218-
* @param dll_path child(或parent, 因为这俩是一样的)-ipc.dll的路径 默认为运行目录下
219-
* @return 成功返回true
220-
*/
221-
bool InitEnvA(std::string dll_path = "");
185+
const char* GetLastErrStr();
222186

223187
/**
224188
* @brief 初始化环境.
225189
* @param dll_path child(或parent, 因为这俩是一样的)-ipc.dll的路径 默认为运行目录下
226190
* @return 成功返回true
227191
*/
228-
bool InitEnv(std::wstring dll_path = L"");
192+
bool InitEnv(const char* dll_path = NULL);
229193

230194
/**
231195
* @brief 对pIMojoIpc->InitChildIpc()的封装.
@@ -248,13 +212,13 @@ namespace qqimpl
248212
* @param command IPC_MSG
249213
* @param addition_msg 参数
250214
*/
251-
void SendIpcMessage(std::string command, std::string addition_msg = "");
215+
void SendIpcMessage(const char* command, const char* addition_msg = NULL, int addition_msg_size = 0);
252216

253217
private:
254218
HMODULE m_ipc_dll;
255219
DWORD_PTR* m_ptr_IMojoIpc;
256220

257-
std::wstring _last_err;
221+
std::string _last_err;
258222
};
259223

260224

0 commit comments

Comments
 (0)