OCT 1. 支持32位操作系统

This commit is contained in:
黄昕 2024-01-18 16:21:31 +08:00
parent b7f98fcdd6
commit ba79f478ed
7 changed files with 70 additions and 33 deletions

View File

@ -31,7 +31,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
@ -72,6 +72,10 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
@ -80,12 +84,29 @@
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>.\depends\WinDivert\include;.\include;.\depends\WireGuardNT\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC> <EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
<PostBuildEvent>
<Command>copy /y $(ProjectDir)depends\tunnel\x86\tunnel.dll $(TargetDir)
copy /y $(ProjectDir)depends\WireGuardNT\amd64\wireguard.dll $(TargetDir)
copy /y $(TargetDir)fmtd.dll $(SolutionDir)NetTunnelApp\bin\$(ConfigurationName)\
copy /y $(TargetDir)NetTunnelSDK.dll $(SolutionDir)NetTunnelApp\bin\$(ConfigurationName)\
copy /y $(ProjectDir)include\sccsdk.h $(ProjectDir)sdk\
copy /y $(ProjectDir)include\common.h $(ProjectDir)sdk\
copy /y $(ProjectDir)include\usrerr.h $(ProjectDir)sdk\
$(ProjectDir)scripts\gensdk.bat</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>$(ProjectDir)scripts\cleansdk.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>

View File

@ -438,13 +438,17 @@ int GetUserServerConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_SE
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
if (pUserName && lstrlen(pUserName) > 0) { memset(pUser->userName, 0, MAX_PATH);
memset(pUser->userName, 0, MAX_PATH);
#if 0
if (pUserName && lstrlen(pUserName) > 0) {
StringCbCopy(pUser->userName, MAX_PATH, pUserName); StringCbCopy(pUser->userName, MAX_PATH, pUserName);
} else { } else {
StringCbCopy(pUser->userName, MAX_PATH, TEXT("tunnel_svr")); StringCbCopy(pUser->userName, MAX_PATH, TEXT("tunnel_svr"));
} }
#else
StringCbCopy(pUser->userName, MAX_PATH, TEXT("tunnel_scc"));
#endif
StringCbCopy(pUser->userToken, MAX_PATH, pToken); StringCbCopy(pUser->userToken, MAX_PATH, pToken);
#if USER_REAL_PLATFORM #if USER_REAL_PLATFORM
@ -525,9 +529,13 @@ int GetUserClientConfigure(const TCHAR *pUserName, const TCHAR *pToken, PUSER_CL
} }
memset(pUser->userName, 0, MAX_PATH); memset(pUser->userName, 0, MAX_PATH);
#if 0
if (pUserName && lstrlen(pUserName) > 0) { if (pUserName && lstrlen(pUserName) > 0) {
StringCbCopy(pUser->userName, MAX_PATH, pUserName); StringCbCopy(pUser->userName, MAX_PATH, pUserName);
} }
#else
StringCbCopy(pUser->userName, MAX_PATH, TEXT("tunnel_scc"));
#endif
StringCbCopy(pUser->userToken, MAX_PATH, pToken); StringCbCopy(pUser->userToken, MAX_PATH, pToken);
#if USER_REAL_PLATFORM #if USER_REAL_PLATFORM

View File

@ -364,7 +364,7 @@ public:
std::map<std::string, std::string> GetMembersValueMap(const std::string valueStr) { std::map<std::string, std::string> GetMembersValueMap(const std::string valueStr) {
std::vector<std::string> array = StringSplit(valueStr); std::vector<std::string> array = StringSplit(valueStr);
std::map<std::string, std::string> ret; std::map<std::string, std::string> ret;
for (int i = 0; i < array.size(); i++) { for (unsigned int i = 0; i < array.size(); i++) {
std::vector<std::string> keyValue = StringSplit(array[i], '='); std::vector<std::string> keyValue = StringSplit(array[i], '=');
if (keyValue.size() != 2) { if (keyValue.size() != 2) {
continue; continue;

View File

@ -271,7 +271,7 @@ int GetWindowsServiceStatus(const TCHAR *pSvrName, PDWORD pStatus) {
int WideCharToTChar(const WCHAR *pWStr, TCHAR *pOutStr, int maxOutLen) { int WideCharToTChar(const WCHAR *pWStr, TCHAR *pOutStr, int maxOutLen) {
if constexpr (sizeof(TCHAR) == sizeof(WCHAR)) { if constexpr (sizeof(TCHAR) == sizeof(WCHAR)) {
if (wcslen(pWStr) * sizeof(WCHAR) >= maxOutLen) { if (wcslen(pWStr) * sizeof(WCHAR) >= static_cast<unsigned int>(maxOutLen)) {
SPDLOG_ERROR(TEXT("Output buffer is to short: {0} need {1}"), maxOutLen, wcslen(pWStr) * sizeof(WCHAR)); SPDLOG_ERROR(TEXT("Output buffer is to short: {0} need {1}"), maxOutLen, wcslen(pWStr) * sizeof(WCHAR));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
@ -293,7 +293,7 @@ int WideCharToTChar(const WCHAR *pWStr, TCHAR *pOutStr, int maxOutLen) {
int TCharToWideChar(const TCHAR *pTStr, WCHAR *pOutStr, int maxOutLen) { int TCharToWideChar(const TCHAR *pTStr, WCHAR *pOutStr, int maxOutLen) {
if constexpr (sizeof(TCHAR) == sizeof(WCHAR)) { if constexpr (sizeof(TCHAR) == sizeof(WCHAR)) {
if (lstrlen(pTStr) * sizeof(WCHAR) >= maxOutLen) { if (lstrlen(pTStr) * sizeof(WCHAR) >= static_cast<unsigned int>(maxOutLen)) {
SPDLOG_ERROR(TEXT("Output buffer is to short: {0} need {1}"), maxOutLen, lstrlen(pTStr) * sizeof(WCHAR)); SPDLOG_ERROR(TEXT("Output buffer is to short: {0} need {1}"), maxOutLen, lstrlen(pTStr) * sizeof(WCHAR));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }

View File

@ -14,7 +14,7 @@
#include <spdlog/fmt/bin_to_hex.h> #include <spdlog/fmt/bin_to_hex.h>
#include <array> #include <array>
#define SCG_UDP_HEAD_SIZE (13) #define SCG_UDP_HEAD_SIZE (14)
#endif #endif
@ -42,7 +42,7 @@ void StopUDPProxyServer() {
} }
#if !USED_PORTMAP_TUNNEL #if !USED_PORTMAP_TUNNEL
static DWORD UDPProxvRemoteThread(LPVOID lpParameter) { static DWORD WINAPI UDPProxvRemoteThread(LPVOID lpParameter) {
const auto pPeerSock = static_cast<sockaddr_in *>(lpParameter); const auto pPeerSock = static_cast<sockaddr_in *>(lpParameter);
const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy; const PSCG_PROXY_INFO pProxy = &GetGlobalCfgInfo()->scgProxy;
@ -104,7 +104,7 @@ static DWORD UDPProxvRemoteThread(LPVOID lpParameter) {
return 0; return 0;
} }
static DWORD UDPProxyRecvThread(LPVOID lpParameter) { static DWORD WINAPI UDPProxyRecvThread(LPVOID lpParameter) {
bool isRemoteInit = false; bool isRemoteInit = false;
sockaddr_in localWgAddr {}; sockaddr_in localWgAddr {};
sockaddr_in scgAddr {}; sockaddr_in scgAddr {};
@ -121,19 +121,21 @@ static DWORD UDPProxyRecvThread(LPVOID lpParameter) {
InetPton(AF_INET, pProxy->scgIpAddr, &scgAddr.sin_addr.s_addr); InetPton(AF_INET, pProxy->scgIpAddr, &scgAddr.sin_addr.s_addr);
// 构建 SCG UDP 包头 // 构建 SCG UDP 包头
recvBuf[0] = 0x01; // VERSION recvBuf[0] = 0x01; // VERSION
recvBuf[1] = 0x0A; // Length 0 recvBuf[1] = 0x00; // Length 0
recvBuf[2] = 0x09; // Length 1 recvBuf[2] = SCG_UDP_HEAD_SIZE - 3; // Length 1
recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE
recvBuf[4] = 0x04; // INFO[0] LENGTH recvBuf[4] = 0x00; // INFO[0] LENGTH 0
recvBuf[5] = 0; // INFO[0] VMID[0] recvBuf[5] = 0x04; // INFO[0] LENGTH 1
recvBuf[6] = 0; // INFO[0] VMID[1] recvBuf[6] = 0; // INFO[0] VMID[0]
recvBuf[7] = 0; // INFO[0] VMID[2] recvBuf[7] = 0; // INFO[0] VMID[1]
recvBuf[8] = 0; // INFO[0] VMID[3] recvBuf[8] = 0; // INFO[0] VMID[2]
recvBuf[9] = 0xF1; // INFO[1] TYPE recvBuf[9] = 0; // INFO[0] VMID[3]
recvBuf[10] = 0x00; // INFO[1] LENGTH 0 recvBuf[10] = 0xF1; // INFO[1] TYPE
recvBuf[11] = 0x01; // INFO[1] LENGTH 1 recvBuf[11] = 0x00; // INFO[1] LENGTH 0
recvBuf[12] = svrId; // ------ INFO[1] SCG Service ID recvBuf[12] = 0x01; // INFO[1] LENGTH 1
recvBuf[13] = svrId; // ------ INFO[1] SCG Service ID
pProxy->exitNow = false; pProxy->exitNow = false;
while (!pProxy->exitNow) { while (!pProxy->exitNow) {
@ -196,10 +198,10 @@ static DWORD UDPProxyRecvThread(LPVOID lpParameter) {
pProxy->hProxySCGThread = handle; pProxy->hProxySCGThread = handle;
} }
recvBuf[5] = vmid[0]; // INFO[0] VMID[0] recvBuf[6] = vmid[0]; // INFO[0] VMID[0]
recvBuf[6] = vmid[1]; // INFO[0] VMID[1] recvBuf[7] = vmid[1]; // INFO[0] VMID[1]
recvBuf[7] = vmid[2]; // INFO[0] VMID[2] recvBuf[8] = vmid[2]; // INFO[0] VMID[2]
recvBuf[8] = vmid[3]; // INFO[0] VMID[3] recvBuf[9] = vmid[3]; // INFO[0] VMID[3]
// 增加SCG包头数据长度 // 增加SCG包头数据长度
iRecvBytes += SCG_UDP_HEAD_SIZE; iRecvBytes += SCG_UDP_HEAD_SIZE;

View File

@ -48,9 +48,10 @@ int InitControlServer(const TCHAR *pUserSvrUrl) {
const auto svrId = static_cast<UINT8>(GetGlobalCfgInfo()->userCfg.cliConfig.scgCtrlAppId); const auto svrId = static_cast<UINT8>(GetGlobalCfgInfo()->userCfg.cliConfig.scgCtrlAppId);
unsigned char scgProxy[] = {0x01, // VERSION unsigned char scgProxy[] = {0x01, // VERSION
0x00, // Length 0 0x00, // Length 0
0x0A, // Length 1 0x0B, // Length 1
0xF0, // ++++++ INFO[0] TYPE 0xF0, // ++++++ INFO[0] TYPE
0x04, // INFO[0] LENGTH 0x00, // INFO[0] LENGTH 0
0x04, // INFO[0] LENGTH 1
0, // INFO[0] VMID[0] 0, // INFO[0] VMID[0]
0, // INFO[0] VMID[1] 0, // INFO[0] VMID[1]
0, // INFO[0] VMID[2] 0, // INFO[0] VMID[2]
@ -61,10 +62,10 @@ int InitControlServer(const TCHAR *pUserSvrUrl) {
svrId}; // ------ INFO[1] SCG Service ID svrId}; // ------ INFO[1] SCG Service ID
p = scgProxy; p = scgProxy;
memcpy(vmid, &id, 4); memcpy(vmid, &id, 4);
scgProxy[5] = vmid[0]; scgProxy[6] = vmid[0];
scgProxy[6] = vmid[1]; scgProxy[7] = vmid[1];
scgProxy[7] = vmid[2]; scgProxy[8] = vmid[2];
scgProxy[8] = vmid[3]; scgProxy[9] = vmid[3];
if (GetGlobalCfgInfo()->logLevel == spdlog::level::trace) { if (GetGlobalCfgInfo()->logLevel == spdlog::level::trace) {
std::array<unsigned char, sizeof(scgProxy)> arr; std::array<unsigned char, sizeof(scgProxy)> arr;

View File

@ -79,10 +79,15 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)NetTunnelSDK\sdk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>NetTunnelSDK.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">