Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi-wechat #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions WeChatFerry/launcher/launcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,5 @@
<Image Include="..\icon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
</Project>
3 changes: 1 addition & 2 deletions WeChatFerry/sdk/SDK.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,5 @@
<None Include="sdk.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
</Project>
18 changes: 11 additions & 7 deletions WeChatFerry/sdk/sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int GetDllPath(bool debug, wchar_t *dllPath)
return 0;
}

int WxInitSDK(bool debug, int port)
int WxInitSDK(bool debug, bool multi, int port, int inputPid)
{
int status = 0;
DWORD wcPid = 0;
Expand All @@ -43,13 +43,17 @@ int WxInitSDK(bool debug, int port)
return status;
}

status = OpenWeChat(&wcPid);
if (status != 0) {
MessageBox(NULL, L"打开微信失败", L"WxInitSDK", 0);
return status;
}
if(inputPid != 0) {
wcPid = inputPid;
} else {
status = OpenWeChat(&wcPid, multi);
if (status != 0) {
MessageBox(NULL, L"打开微信失败", L"WxInitSDK", 0);
return status;
}

Sleep(2000); // 等待微信打开
Sleep(2000); // 等待微信打开
}
wcProcess = InjectDll(wcPid, spyDllPath, &spyBase);
if (wcProcess == NULL) {
MessageBox(NULL, L"注入失败", L"WxInitSDK", 0);
Expand Down
2 changes: 1 addition & 1 deletion WeChatFerry/sdk/sdk.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

int WxInitSDK(bool debug, int port);
int WxInitSDK(bool debug, bool multi, int port, int inputPid);
int WxDestroySDK();
5 changes: 2 additions & 3 deletions WeChatFerry/spy/Spy.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ xcopy /y $(OutDir)$(TargetFileName) $(SolutionDir)..\clients\python\wcferry</Com
</PostBuildEvent>
<PreBuildEvent>
<Command>cd $(SolutionDir)rpc\proto
$(SolutionDir)rpc\tool\protoc --nanopb_out=. wcf.proto</Command>
$(SolutionDir)rpc\tool\protoc.exe --nanopb_out=. wcf.proto</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Generating PB files</Message>
Expand Down Expand Up @@ -273,6 +273,5 @@ $(SolutionDir)rpc\tool\protoc --nanopb_out=. wcf.proto</Command>
<ResourceCompile Include="spy.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
</Project>
10 changes: 6 additions & 4 deletions WeChatFerry/spy/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ DWORD GetWeChatPid()
return pid;
}

int OpenWeChat(DWORD *pid)
int OpenWeChat(DWORD *pid, bool multi)
{
*pid = GetWeChatPid();
if (*pid) {
return ERROR_SUCCESS;
if (!multi) {
*pid = GetWeChatPid();
if (*pid) {
return ERROR_SUCCESS;
}
}

int ret = -1;
Expand Down
2 changes: 1 addition & 1 deletion WeChatFerry/spy/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct PortPath {
} PortPath_t;

DWORD GetWeChatPid();
int OpenWeChat(DWORD *pid);
int OpenWeChat(DWORD *pid, bool multi);
int GetWeChatVersion(wchar_t *version);
int GetWstringByAddress(DWORD address, wchar_t *buffer, DWORD buffer_size);
DWORD GetMemoryIntByAddress(HANDLE hProcess, DWORD address);
Expand Down
11 changes: 8 additions & 3 deletions WeChatFerry/wcf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@

void help()
{
printf("\nUsage: \n启动: wcf.exe start port [debug]\n关闭: wcf.exe stop\nport: 命令端口, 消息端口为命令端口+1\n");
printf("\nUsage: \n启动: wcf.exe start port [debug]\n关闭: wcf.exe stop\nport: 命令端口, 消息端口为命令端口+1\n指定微信pid启动: wcf.exe start port [pid]仅在你知道这是什么时候使用\n打开新的微信: wcf.exe start port [multi]\n");
}

int main(int argc, char *argv[])
{
int ret = -1;
bool debug = false;
bool multi = false;

if ((argc < 2) || (argc > 4)) {
help();
} else if (argc == 4) {
debug = (strcmp(argv[3], "debug") == 0);
multi = (strcmp(argv[3], "multi") == 0);
}

if (strcmp(argv[1], "start") == 0) {
int port = strtol(argv[2], NULL, 10);

ret = WxInitSDK(debug, port);
int inputPid = 0;
if (!debug && !multi && argc == 4) {
inputPid = strtol(argv[3], NULL, 10);
}
ret = WxInitSDK(debug, multi, port, inputPid);
} else if (strcmp(argv[1], "stop") == 0) {
ret = WxDestroySDK();
} else {
Expand Down
5 changes: 2 additions & 3 deletions WeChatFerry/wcf/wcf.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;WCF;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)sdk;$(SolutionDir)spy;C:\Tools\vcpkg\installed\x86-windows-static\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)sdk;$(SolutionDir)spy;C:\Tools\vcpkg\installed\x86-windows-static\include;D:\duguyifei\code\WX_AI\WeChatFerry\spdlog\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
Expand Down Expand Up @@ -168,6 +168,5 @@ xcopy /y $(OutDir)$(TargetFileName) $(SolutionDir)..\clients\python\wcferry</Com
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
</Project>