Skip to content

Commit

Permalink
fix: better logic (per-family resolved ips etc) in getaddrinfo() seri…
Browse files Browse the repository at this point in the history
…es; ipc bookkeeping unexpected child exit protection; add ctrlhandler to handle ctrl-c in cygwin; update to 0.4.5
  • Loading branch information
shunf4 committed Mar 3, 2020
1 parent dcc83de commit 05d5bc7
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 233 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,5 @@ cygwin_build/**/MAKING_*
cygwin_build/**/distx*
cygwin_build/**/*.stackdump
cygwin_build/**/*.bin
win32_output/
win32_output/
dist/
21 changes: 2 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,10 @@ programs). See "To-do and Known Issues". Perhaps solution based on

- [ ] Remote DNS resolving based on UDP associate
- [ ] Hook `sendto()`, coping with applications which do TCP fast open
- [ ] ~~Fix Cygwin proxychains pip failure (0xc0000005 Access Denied)~~
Not reproduced
- [ ] ~~Adapt proxychains_hook.dll to Sandboxie (???)~~
- [X] ~~Make -lVERBOSE available in proxychainsd.exe (The debug versions)~~
Fixed in 0.4
- [X] ~~Suppress connect() warning log when connection has target BLOCK~~
Fixed in 0.4
- [X] ~~Add ".bat" etc. extension (PATHEXT) when SearchPath()~~ Fixed in 0.4
- [ ] ~~Fix 32-bit proxychains SearchPath(ssh) failure~~
(Windows Filesystem Redirection)
- [X] ~~Dynamic selection of 32-bit DLL and 64-bit DLL~~ ~~Fixed in 0.4~~
Finally fixed in ~~0.4.3~~ ~~0.4.4~~ 0.4.5
- [ ] ~~Try to fix `proxychains git clone https://...` under Cygwin~~
Using `-q` in 0.4.1 reduces the probability to happen
- [X] ~~Try to fix `proxychains npm install` in a huge project~~
~~(may be caused by excess usage of stack in GetAddrInfoW, turning off
`proxy_dns` in 0.4 fixes this)~~ Fixed in 0.4.3
- [X] ~~Resolve race condition in `FormatHostPortToStr()`~~ Fixed in 0.4.3
- [X] ~~Resolve remote thread exit code `0xc0000005` (Access Denied)
when calling `C:\ProgramData\chocolatey\tools\7z.exe`~~
Finally fixed in ~~0.4.3~~ ~~0.4.4~~ 0.4.5
- [ ] Try to fix hang when executing `git clone https://` and
`git submodule update --init --recursive`
- [X] ~~Resolve race condition in `StdWprintf()`~~ Fixed in 0.4.5

# Licensing
Expand Down
16 changes: 9 additions & 7 deletions cygwin_build/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,26 @@ fi

echo Distributing "$PXCH_VERSION"...

mkdir -p ../dist/

# Build/Install/Dist/Clean for Win32
cmd /c win32_build.bat

if [ "$1" = "--install" ]; then
cmd /c win32_install.bat
fi

zip -FS -j ../../proxychains_"$PXCH_VERSION"_win32_x64_debug.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x64d.exe ../win32_output/proxychains_hook_x64d.dll ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_helper_x64d.exe ../win32_output/proxychains_helper_x86d.exe
zip -FS -j ../../proxychains_"$PXCH_VERSION"_win32_x64.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x64.exe ../win32_output/proxychains_hook_x64.dll ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_helper_x64.exe ../win32_output/proxychains_helper_x86.exe
zip -FS -j ../../proxychains_"$PXCH_VERSION"_win32_x86_debug.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86d.exe ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_helper_x86d.exe
zip -FS -j ../../proxychains_"$PXCH_VERSION"_win32_x86.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86.exe ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_helper_x86.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_win32_x64_debug.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x64d.exe ../win32_output/proxychains_hook_x64d.dll ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_helper_x64d.exe ../win32_output/proxychains_helper_x86d.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_win32_x64.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x64.exe ../win32_output/proxychains_hook_x64.dll ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_helper_x64.exe ../win32_output/proxychains_helper_x86.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_win32_x86_debug.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86d.exe ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_helper_x86d.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_win32_x86.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86.exe ../win32_output/proxychains_hook_x86.dll ../win32_output/proxychains_helper_x86.exe

cmd /c win32_clean.bat

# Some proxychains_helper_x64* is left at this moment
rm -rf ../win32_output/*

# Build/Install/Dist//Clean for Cygwin
# Build/Install/Dist/Clean for Cygwin
make release

if [ "$1" = "--install" ]; then
Expand All @@ -52,7 +54,7 @@ if [ "$1" = "--install" ]; then
cp proxychains_helper_*.exe /bin/
fi

zip -FS -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64.exe cygproxychains_hook_x64.dll proxychains_helper_x64.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_cygwin_x64.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64.exe cygproxychains_hook_x64.dll proxychains_helper_x64.exe

make debug

Expand All @@ -63,7 +65,7 @@ if [ "$1" = "--install" ]; then
cp proxychains_helper_*.exe /bin/
fi

zip -FS -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64_debug.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64d.exe cygproxychains_hook_x64d.dll proxychains_helper_x64.exe
zip -FS -j ../dist/proxychains_"$PXCH_VERSION"_cygwin_x64_debug.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64d.exe cygproxychains_hook_x64d.dll proxychains_helper_x64.exe

make clean
rm -rf ../include/remote_func_bin_*.h
3 changes: 2 additions & 1 deletion include/defines_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ typedef unsigned int PXCH_UINT_PTR;
#define PXCH_MAX_ERROR_MESSAGE_BUFSIZE 256
#define PXCH_MAX_DUMP_MEMORY_BUFSIZE 1024
#define PXCH_MAX_FORMAT_HOST_PORT_BUFSIZE 512
#define PXCH_MAX_ARRAY_IP_NUM 10
#define PXCH_MAX_ARRAY_IP_NUM_PER_FAMILY 5
#define PXCH_MAX_ARRAY_IP_NUM (PXCH_MAX_ARRAY_IP_NUM_PER_FAMILY * 2)
#define PXCH_MAX_PATHEXT_BUFSIZE 256

#define PXCH_LOG_IPC_BUFSIZE 1024
Expand Down
8 changes: 6 additions & 2 deletions proxychains_helper/proxychains_helper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<TargetName>$(ProjectName)_x86d</TargetName>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<TargetName>$(ProjectName)_x64d</TargetName>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
Expand All @@ -148,6 +148,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -161,6 +162,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -175,6 +177,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -191,6 +194,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
10 changes: 6 additions & 4 deletions proxychains_hook.dll/proxychains_hook.dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,28 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
<TargetName>proxychains_hook_x64d</TargetName>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
<TargetName>proxychains_hook_x86d</TargetName>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
<TargetName>proxychains_hook_x86</TargetName>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(SolutionDir)uthash\src;$(SolutionDir)minhook\include;$(SolutionDir)include;$(IncludePath)</IncludePath>
<TargetName>proxychains_hook_x64</TargetName>
<OutDir>$(SolutionDir)win32_output\</OutDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -109,6 +109,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -133,6 +134,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
95 changes: 56 additions & 39 deletions src/dll/hook_connect_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ PROXY_FUNC2(Ws2_32, gethostbyname)
int iWSALastError;
DWORD dwLastError;

// Stack size is limited. We need to store big data on heap
// Stack size is limited (?????). We need to store big data on heap
struct {
ADDRINFOW RequeryAddrInfoHints;
ADDRINFOW* pRequeryAddrInfo;
Expand All @@ -1180,6 +1180,13 @@ PROXY_FUNC2(Ws2_32, gethostbyname)
PXCH_IP_ADDRESS Ips[PXCH_MAX_ARRAY_IP_NUM];
PXCH_UINT32 dwTarget;
BOOL bMatchedHostnameRule;

PXCH_IPC_MSGBUF chMessageBuf;
PXCH_UINT32 cbMessageSize;
PXCH_IPC_MSGBUF chRespMessageBuf;
PXCH_UINT32 cbRespMessageSize;
PXCH_IP_ADDRESS FakeIps[2];
PXCH_IP_ADDRESS* pFakeIps;
} *pLocalData;

pLocalData = HeapAlloc(GetProcessHeap(), 0, sizeof(*pLocalData));
Expand Down Expand Up @@ -1217,35 +1224,38 @@ PROXY_FUNC2(Ws2_32, gethostbyname)
pLocalData->dwTarget = GetTargetByRule(&pLocalData->bMatchedHostnameRule, NULL, NULL, NULL, (PXCH_HOST_PORT*)&pLocalData->OriginalHostname, g_pPxchConfig->dwDefaultTarget);

if (pLocalData->bMatchedHostnameRule || g_pPxchConfig->dwWillUseFakeIpWhenHostnameNotMatched) {
PXCH_IPC_MSGBUF chMessageBuf;
PXCH_UINT32 cbMessageSize;
PXCH_IPC_MSGBUF chRespMessageBuf;
PXCH_UINT32 cbRespMessageSize;
PXCH_IP_ADDRESS FakeIps[2];
struct hostent* pNewHostentResult;
int iIpFamilyAllowed;
PXCH_IP_ADDRESS* pFakeIps;

FUNCIPCLOGD(L"Ws2_32.dll gethostbyname(" WPRS L") : 5", name);
// DWORD dw;
// BOOL bAnyResolvedIpv4 = FALSE;
// BOOL bAnyResolvedIpv6 = FALSE;

// for (dw = 0; dw < pLocalData->dwIpNum; dw++) {
// if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV4) {
// bAnyResolvedIpv4 = TRUE;
// }
// if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV6) {
// bAnyResolvedIpv6 = TRUE;
// }
// }

if ((dwLastError = HostnameAndIpsToMessage(chMessageBuf, &cbMessageSize, GetCurrentProcessId(), &pLocalData->OriginalHostname, g_pPxchConfig->dwWillMapResolvedIpToHost, pLocalData->dwIpNum, pLocalData->Ips, pLocalData->dwTarget)) != NO_ERROR) goto err;
if ((dwLastError = HostnameAndIpsToMessage(pLocalData->chMessageBuf, &pLocalData->cbMessageSize, GetCurrentProcessId(), &pLocalData->OriginalHostname, g_pPxchConfig->dwWillMapResolvedIpToHost, pLocalData->dwIpNum, pLocalData->Ips, pLocalData->dwTarget)) != NO_ERROR) goto err;

if ((dwLastError = IpcCommunicateWithServer(chMessageBuf, cbMessageSize, chRespMessageBuf, &cbRespMessageSize)) != NO_ERROR) goto err;
if ((dwLastError = IpcCommunicateWithServer(pLocalData->chMessageBuf, pLocalData->cbMessageSize, pLocalData->chRespMessageBuf, &pLocalData->cbRespMessageSize)) != NO_ERROR) goto err;

if ((dwLastError = MessageToHostnameAndIps(NULL, NULL, NULL, NULL /*Must be 2*/, FakeIps, NULL, chRespMessageBuf, cbRespMessageSize)) != NO_ERROR) goto err;
if ((dwLastError = MessageToHostnameAndIps(NULL, NULL, NULL, NULL /*Must be 2*/, pLocalData->FakeIps, NULL, pLocalData->chRespMessageBuf, pLocalData->cbRespMessageSize)) != NO_ERROR) goto err;

iIpFamilyAllowed = 0;
pFakeIps = FakeIps + 1;
pLocalData->pFakeIps = pLocalData->FakeIps + 1;

if (g_pPxchConfig->dwWillFirstTunnelUseIpv4) {
if (g_pPxchConfig->dwWillFirstTunnelUseIpv4 /* && bAnyResolvedIpv4*/) {
iIpFamilyAllowed++;
pFakeIps--;
pLocalData->pFakeIps--;
}
if (g_pPxchConfig->dwWillFirstTunnelUseIpv6) {
if (g_pPxchConfig->dwWillFirstTunnelUseIpv6 /* && bAnyResolvedIpv6*/) {
iIpFamilyAllowed++;
}
HostnameAndIpsToHostent(&pNewHostentResult, TlsGetValue(g_dwTlsIndex), &pLocalData->OriginalHostname, iIpFamilyAllowed, pFakeIps);
HostnameAndIpsToHostent(&pNewHostentResult, TlsGetValue(g_dwTlsIndex), &pLocalData->OriginalHostname, iIpFamilyAllowed, pLocalData->pFakeIps);
iWSALastError = NO_ERROR;
dwLastError = NO_ERROR;

Expand Down Expand Up @@ -1325,6 +1335,7 @@ PROXY_FUNC2(Ws2_32, getaddrinfo)
iReturn = ProxyWs2_32_GetAddrInfoW(pNodeName ? pLocalData->pNodeNameW : NULL, pServiceName ? pLocalData->pServiceNameW : NULL, pHintsCastW, &pResultCastW);
iWSALastError = WSAGetLastError();
dwLastError = GetLastError();
FUNCIPCLOGD(L"Ws2_32.dll getaddrinfo(%S, %S, AF%#010x, FL%#010x, ST%#010x, PT%#010x): ProxyWs2_32_GetAddrInfoW ret: %d", pNodeName, pServiceName, pHintsCast ? pHintsCast->ai_family : -1, pHintsCast ? pHintsCast->ai_flags : -1, pHintsCast ? pHintsCast->ai_socktype : -1, pHintsCast ? pHintsCast->ai_protocol : -1, iReturn);

HeapLock(GetProcessHeap());

Expand Down Expand Up @@ -1397,12 +1408,12 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)

ADDRINFOW* pRequeryAddrInfo;

DWORD dw;
// DWORD dw;

// Stack size is limited. We need to store big data on heap
// Stack size is limited (?????). We need to store big data on heap
struct {
ADDRINFOW DefaultHints;
WCHAR szAddrsBuf[200];
WCHAR szAddrsBuf[1024];
PXCH_HOST_PORT HostPort;
PXCH_HOSTNAME Hostname;
ADDRINFOW RequeryAddrInfoHints;
Expand Down Expand Up @@ -1431,16 +1442,18 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)
iWSALastError = WSAGetLastError();
dwLastError = GetLastError();
pOriginalResultCast = *ppResultCast;
FUNCIPCLOGD(L"Ws2_32.dll GetAddrInfoW(%ls, %ls, AF%#010x, FL%#010x, ST%#010x, PT%#010x): orig_fpWs2_32_GetAddrInfoW ret: %d", pNodeName, pServiceName, pHintsCast->ai_family, pHintsCast->ai_flags, pHintsCast->ai_socktype, pHintsCast->ai_protocol, iReturn);

pLocalData->szAddrsBuf[0] = L'\0';
pszAddrsBuf = pLocalData->szAddrsBuf;

for (pResultCast = pOriginalResultCast; pResultCast; pResultCast = pResultCast->ai_next) {
StringCchPrintfExW(pszAddrsBuf, _countof(pLocalData->szAddrsBuf) - (pszAddrsBuf - pLocalData->szAddrsBuf), &pszAddrsBuf, NULL, 0, L"%ls%ls", pResultCast == pOriginalResultCast ? L"" : L", ", FormatHostPortToStr(pResultCast->ai_addr, (int)pResultCast->ai_addrlen));
if (g_pPxchConfig->dwLogLevel >= PXCH_LOG_LEVEL_DEBUG) {
for (pResultCast = pOriginalResultCast; pResultCast; pResultCast = pResultCast->ai_next) {
StringCchPrintfExW(pszAddrsBuf, _countof(pLocalData->szAddrsBuf) - (pszAddrsBuf - pLocalData->szAddrsBuf), &pszAddrsBuf, NULL, 0, L"%ls%ls", pResultCast == pOriginalResultCast ? L"" : L", ", FormatHostPortToStr(pResultCast->ai_addr, (int)pResultCast->ai_addrlen));
}
FUNCIPCLOGD(L"Ws2_32.dll GetAddrInfoW(%ls, %ls, ...) result %p: %ls", pNodeName, pServiceName, pOriginalResultCast, pLocalData->szAddrsBuf);
}

FUNCIPCLOGD(L"Ws2_32.dll GetAddrInfoW(%ls, %ls, ...) result %p: %ls", pNodeName, pServiceName, pOriginalResultCast, pLocalData->szAddrsBuf);

if (!g_pPxchConfig->dwWillUseFakeIpAsRemoteDns) goto out;

pLocalData->DefaultHints.ai_family = AF_UNSPEC;
Expand Down Expand Up @@ -1495,19 +1508,19 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)
ADDRINFOW* pNewAddrInfoWResult;
int iIpFamilyAllowed;
PXCH_IP_PORT* pFakeIpPorts;
BOOL bAnyResolvedIpv4 = FALSE;
BOOL bAnyResolvedIpv6 = FALSE;
// BOOL bAnyResolvedIpv4 = FALSE;
// BOOL bAnyResolvedIpv6 = FALSE;

AddrInfoToIps(&dwIpNum, pLocalData->Ips, pOriginalResultCast, TRUE);

for (dw = 0; dw < dwIpNum; dw++) {
if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV4) {
bAnyResolvedIpv4 = TRUE;
}
if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV6) {
bAnyResolvedIpv6 = TRUE;
}
}
// for (dw = 0; dw < dwIpNum; dw++) {
// if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV4) {
// bAnyResolvedIpv4 = TRUE;
// }
// if (pLocalData->Ips[dw].CommonHeader.wTag == PXCH_HOST_TYPE_IPV6) {
// bAnyResolvedIpv6 = TRUE;
// }
// }

if ((dwLastError = HostnameAndIpsToMessage(pLocalData->chMessageBuf, &cbMessageSize, GetCurrentProcessId(), &pLocalData->Hostname, g_pPxchConfig->dwWillMapResolvedIpToHost, dwIpNum, pLocalData->Ips, dwTarget)) != NO_ERROR) goto err;

Expand All @@ -1521,11 +1534,11 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)
iIpFamilyAllowed = 0;
pFakeIpPorts = pLocalData->FakeIpPorts + 1;

if (g_pPxchConfig->dwWillFirstTunnelUseIpv4 && bAnyResolvedIpv4) {
if (g_pPxchConfig->dwWillFirstTunnelUseIpv4 /* && bAnyResolvedIpv4*/) {
iIpFamilyAllowed++;
pFakeIpPorts--;
}
if (g_pPxchConfig->dwWillFirstTunnelUseIpv6 && bAnyResolvedIpv6) {
if (g_pPxchConfig->dwWillFirstTunnelUseIpv6 /* && bAnyResolvedIpv6*/) {
iIpFamilyAllowed++;
}
HostnameAndIpPortsToAddrInfo_WillAllocate(&pNewAddrInfoWResult, &pLocalData->Hostname, iIpFamilyAllowed, pFakeIpPorts, !!(pHintsCast->ai_flags & AI_CANONNAME), pOriginalResultCast->ai_socktype, pOriginalResultCast->ai_protocol);
Expand All @@ -1534,10 +1547,14 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)
iReturn = 0;

*ppResultCast = pNewAddrInfoWResult;
if (*ppResultCast == NULL) {
dwLastError = ERROR_NOT_FOUND;
goto err;
}
if (pOriginalResultCast) orig_fpWs2_32_FreeAddrInfoW(pOriginalResultCast);
}

out:
if (pOriginalResultCast) orig_fpWs2_32_FreeAddrInfoW(pOriginalResultCast);
HeapFree(GetProcessHeap(), 0, pLocalData);
WSASetLastError(iWSALastError);
SetLastError(dwLastError);
Expand All @@ -1546,9 +1563,9 @@ PROXY_FUNC2(Ws2_32, GetAddrInfoW)
err:
if (pOriginalResultCast) orig_fpWs2_32_FreeAddrInfoW(pOriginalResultCast);
HeapFree(GetProcessHeap(), 0, pLocalData);
WSASetLastError(WSAENOMORE);
WSASetLastError(WSAHOST_NOT_FOUND);
SetLastError(dwLastError);
return SOCKET_ERROR;
return WSAHOST_NOT_FOUND;
}

// Hook GetAddrInfoExA
Expand Down
Loading

0 comments on commit 05d5bc7

Please sign in to comment.