Skip to content

Commit b8cb4fa

Browse files
authored
Merge pull request #393 from CoderTyn/master
chore: add CMake support for MinGW-w64 environment
2 parents 57e3567 + e1b9aa1 commit b8cb4fa

24 files changed

Lines changed: 289 additions & 64 deletions

WeChatFerry/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
# Common compiler flags
4+
# 设置 C 语言标准为 C17
5+
set(CMAKE_C_STANDARD 17)
6+
# 确保要求该标准为必须
7+
# set(CMAKE_C_STANDARD_REQUIRED ON)
8+
# 默认情况下禁用 GNU 扩展
9+
set(CMAKE_C_EXTENSIONS OFF)
10+
# 设置 C++ 语言标准为 C++17
11+
set(CMAKE_CXX_STANDARD 17)
12+
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
13+
set(CMAKE_CXX_EXTENSIONS OFF)
14+
15+
# 集成vcpkg
16+
set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "Vcpkg target triplet")
17+
set(VCPKG_HOST_TRIPLET "x64-mingw-static" CACHE STRING "Vcpkg host triplet")
18+
set(VCPKG_MANIFEST_MODE ON CACHE BOOL "Enable manifest mode")
19+
20+
if(DEFINED ENV{VCPKG_ROOT})
21+
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
22+
else()
23+
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
24+
endif()
25+
26+
# include(FetchContent)
27+
# include(ExternalProject)
28+
29+
project(WeChatFerry LANGUAGES C CXX)
30+
31+
add_compile_options(
32+
-Wall
33+
-Wextra
34+
-fPIC
35+
)
36+
37+
add_link_options(
38+
-static
39+
)
40+
41+
# Include directories
42+
include_directories(
43+
${CMAKE_SOURCE_DIR}/com
44+
${CMAKE_SOURCE_DIR}/rpc
45+
${CMAKE_SOURCE_DIR}/rpc/nanopb
46+
${CMAKE_SOURCE_DIR}/rpc/proto
47+
${CMAKE_SOURCE_DIR}/sdk
48+
${CMAKE_SOURCE_DIR}/spy
49+
${CMAKE_SOURCE_DIR}/smc
50+
)
51+
52+
# Add subdirectories
53+
54+
add_subdirectory(sdk)
55+
add_subdirectory(spy)
56+

WeChatFerry/com/log.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <spdlog/sinks/rotating_file_sink.h>
1414
#include <spdlog/sinks/stdout_color_sinks.h>
1515
#include <spdlog/spdlog.h>
16+
#include "framework.h"
1617

1718
#define LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__)
1819
#define LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__)

WeChatFerry/com/util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <strsafe.h>
88
#include <wchar.h>
99

10-
#include "framework.h"
1110
#include <Shlwapi.h>
1211
#include <tlhelp32.h>
1312

@@ -64,8 +63,8 @@ static DWORD get_wechat_pid()
6463
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
6564
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
6665

67-
PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
68-
while (Process32Next(hSnapshot, &pe32)) {
66+
PROCESSENTRY32W pe32 = { sizeof(PROCESSENTRY32W) };
67+
while (Process32NextW(hSnapshot, &pe32)) {
6968
if (pe32.szExeFile == s2w(WECHATEXE)) {
7069
pid = pe32.th32ProcessID;
7170
break;

WeChatFerry/com/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct PortPath {
1414
char path[MAX_PATH];
1515
};
1616

17-
DWORD get_wechat_pid();
17+
static DWORD get_wechat_pid();
1818
int open_wechat(DWORD &pid);
1919
std::string get_wechat_version();
2020
uint32_t get_memory_int_by_address(HANDLE hProcess, uint64_t addr);

WeChatFerry/rpc/tool/proto/nanopb_pb2.py

Lines changed: 28 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WeChatFerry/sdk/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SDK project - dynamic library
2+
project(SDK LANGUAGES C CXX)
3+
4+
find_package(spdlog REQUIRED)
5+
6+
add_library(sdk SHARED
7+
dllmain.cpp
8+
injector.cpp
9+
injector.h
10+
sdk.cpp
11+
sdk.h
12+
sdk.def
13+
14+
# Common files
15+
${CMAKE_SOURCE_DIR}/com/util.cpp
16+
${CMAKE_SOURCE_DIR}/com/util.h
17+
)
18+
19+
target_link_libraries(sdk PRIVATE
20+
version
21+
shlwapi
22+
spdlog::spdlog
23+
c++
24+
)
25+
26+
# Set compiler definitions
27+
target_compile_definitions(sdk PRIVATE
28+
SDK_EXPORTS
29+
_WINDOWS
30+
_USRDLL
31+
)
32+
33+
# add_compile_options(
34+
# # -Wall
35+
# -fPIC
36+
# # -fms-extensions
37+
# )
38+
# Set output name for debug builds
39+
set_target_properties(sdk PROPERTIES
40+
DEBUG_POSTFIX "d"
41+
)
42+
43+
# # Post-build copy commands
44+
# add_custom_command(TARGET sdk POST_BUILD
45+
# COMMAND ${CMAKE_COMMAND} -E copy
46+
# $<TARGET_FILE:sdk>
47+
# ${CMAKE_SOURCE_DIR}/Out
48+
# COMMAND ${CMAKE_COMMAND} -E copy
49+
# $<TARGET_FILE:sdk>
50+
# ${CMAKE_SOURCE_DIR}/../clients/python/wcferry
51+
# COMMAND ${CMAKE_COMMAND} -E copy
52+
# ${CMAKE_SOURCE_DIR}/DISCLAIMER.md
53+
# ${CMAKE_SOURCE_DIR}/Out
54+
# COMMAND ${CMAKE_COMMAND} -E copy
55+
# ${CMAKE_SOURCE_DIR}/DISCLAIMER.md
56+
# ${CMAKE_SOURCE_DIR}/../clients/python/wcferry
57+
# )

WeChatFerry/sdk/SDK.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ xcopy /y $(OutDir)$(TargetFileName) $(SolutionDir)..\clients\python\wcferry</Com
142142
</ItemDefinitionGroup>
143143
<ItemGroup>
144144
<ClInclude Include="..\com\util.h" />
145-
<ClInclude Include="framework.h" />
145+
<ClInclude Include="..\com\framework.h" />
146146
<ClInclude Include="injector.h" />
147147
<ClInclude Include="sdk.h" />
148148
</ItemGroup>

WeChatFerry/sdk/SDK.vcxproj.filters

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</Filter>
1616
</ItemGroup>
1717
<ItemGroup>
18-
<ClInclude Include="framework.h">
18+
<ClInclude Include="..\com\framework.h">
1919
<Filter>头文件</Filter>
2020
</ClInclude>
2121
<ClInclude Include="sdk.h">

WeChatFerry/sdk/injector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static uint64_t get_func_offset(const string &dll_path, const string &func_name)
122122
return 0;
123123
}
124124

125-
LPVOID absAddr = GetProcAddress(dll, func_name.c_str());
125+
LPVOID absAddr = reinterpret_cast<LPVOID>(GetProcAddress(dll, func_name.c_str()));
126126
uint64_t offset = reinterpret_cast<uint64_t>(absAddr) - reinterpret_cast<uint64_t>(dll);
127127
FreeLibrary(dll);
128128

0 commit comments

Comments
 (0)