diff --git a/.gitignore b/.gitignore index 62b467f..8e512d7 100644 --- a/.gitignore +++ b/.gitignore @@ -348,5 +348,5 @@ cygwin-build/**/*.a cygwin-build/**/*.lib cygwin-build/**/MAKING_* cygwin-build/**/distx* -windows_install.bat +cygwin-build/**/*.stackdump win32_output/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b2ff433..bc3a8da 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -52,6 +52,14 @@ "common_generic.h": "c", "sstream": "c", "version.h": "c", - "tls_generic.h": "c" + "tls_generic.h": "c", + "*.tcc": "c", + "cstdio": "c", + "array": "c", + "string_view": "c", + "initializer_list": "c", + "utility": "c", + "hookdll_interior_win32.h": "c", + "hookdll_interior_generic.h": "c" } } \ No newline at end of file diff --git a/README.md b/README.md index 87d9a7b..34b2ed9 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,8 @@ programs). See "To-do and Known Issues". Perhaps solution based on - [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 -- [ ] Try to fix `proxychains git clone https://...` under Cygwin +- [ ] ~~Try to fix `proxychains git clone https://...` under Cygwin~~ Use `-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, turn off `proxy_dns` in 0.4 fixes this) @@ -158,7 +159,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details. You should have received a copy of the GNU General Public License -version 2 along with this program. If not, see +version 2 along with this program (COPYING). If not, see . ## Uthash @@ -166,11 +167,62 @@ version 2 along with this program. If not, see https://github.com/troydhanson/uthash This program contains uthash as a git submodule, which is published -under The 1-clause BSD License. +under The 1-clause BSD License: + +``` +Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` ## Minhook https://github.com/TsudaKageyu/minhook This program contains minhook as a git submodule, which is published -under The 2-clause BSD License. \ No newline at end of file +under The 2-clause BSD License: + +``` +MinHook - The Minimalistic API Hooking Library for x64/x86 +Copyright (C) 2009-2017 Tsuda Kageyu. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` diff --git a/README_zh-Hans.md b/README_zh-Hans.md index 36d2df7..0a7d454 100644 --- a/README_zh-Hans.md +++ b/README_zh-Hans.md @@ -93,7 +93,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details. You should have received a copy of the GNU General Public License -version 2 along with this program. If not, see +version 2 along with this program (COPYING). If not, see . ## Uthash @@ -101,11 +101,62 @@ version 2 along with this program. If not, see https://github.com/troydhanson/uthash This program contains uthash as a git submodule, which is published -under The 1-clause BSD License. +under The 1-clause BSD License: + +``` +Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` ## Minhook https://github.com/TsudaKageyu/minhook This program contains minhook as a git submodule, which is published -under The 2-clause BSD License. \ No newline at end of file +under The 2-clause BSD License: + +``` +MinHook - The Minimalistic API Hooking Library for x64/x86 +Copyright (C) 2009-2017 Tsuda Kageyu. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` diff --git a/cygwin-build/Makefile b/cygwin-build/Makefile index e1dd0a7..a87d77c 100644 --- a/cygwin-build/Makefile +++ b/cygwin-build/Makefile @@ -157,8 +157,21 @@ dist : PXCH_VERSION=$$(gcc -dM -E - < ../include/version.h | grep PXCH_VERSION | sort | awk '{print $$3}' | head -c -1 | tr '\n' '.') ./dist.sh install : - (install $(EXEC_PATH_RELEASE) $(PREFIX)/bin/proxychains.exe && install $(DLL_PATH_RELEASE) $(PREFIX)/bin/) || \ - (install $(EXEC_PATH_DEBUG) $(PREFIX)/bin/proxychains.exe && install $(DLL_PATH_DEBUG) $(PREFIX)/bin/) + PXCH_VERSION=$$(gcc -dM -E - < ../include/version.h | grep PXCH_VERSION | sort | awk '{print $$3}' | head -c -1 | tr '\n' '.') ./dist.sh --install + +install_legacy: + make release + cp $(EXEC_PATH_RELEASE) $(PREFIX)/bin/proxychains.exe + cp $(EXEC_PATH_RELEASE) $(PREFIX)/bin/px.exe + cp $(DLL_PATH_RELEASE) $(PREFIX)/bin/ + cp proxychains_remote_function_*.bin $(PREFIX)/bin/ + + make debug + cp $(EXEC_PATH_DEBUG) $(PREFIX)/bin/proxychainsd.exe + cp $(EXEC_PATH_DEBUG) $(PREFIX)/bin/pxd.exe + cp $(DLL_PATH_DEBUG) $(PREFIX)/bin/ + cp proxychains_remote_function_*.bin $(PREFIX)/bin/ + rebuild : clean all rebuildrelease : clean release diff --git a/cygwin-build/dist.sh b/cygwin-build/dist.sh index 5e43739..555fafb 100644 --- a/cygwin-build/dist.sh +++ b/cygwin-build/dist.sh @@ -30,5 +30,25 @@ zip -j ../../proxychains_"$PXCH_VERSION"_win32_x64d.zip ../COPYING ../README*.md zip -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_remote_function_x64.bin ../win32_output/proxychains_remote_function_x86.bin zip -j ../../proxychains_"$PXCH_VERSION"_win32_x86d.zip ../COPYING ../README*.md ../proxychains.conf ../win32_output/proxychains_x86d.exe ../win32_output/proxychains_hook_x86d.dll ../win32_output/proxychains_remote_function_x86d.bin zip -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_remote_function_x86.bin + make release +if [ "$1" = "--install" ]; then + cp proxychains_x64.exe /bin/proxychains.exe + ln -sf /bin/proxychains.exe /bin/px.exe + cp cygproxychains_hook_x64.dll /bin/ + cp proxychains_remote_function_*.bin /bin/ +fi zip -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64.exe cygproxychains_hook_x64.dll proxychains_remote_function_x64.bin + +make debug +if [ "$1" = "--install" ]; then + cp proxychains_x64d.exe /bin/proxychainsd.exe + ln -sf /bin/proxychainsd.exe /bin/pxd.exe + cp cygproxychains_hook_x64d.dll /bin/ + cp proxychains_remote_function_*.bin /bin/ +fi +zip -j ../../proxychains_"$PXCH_VERSION"_cygwin_x64d.zip ../COPYING ../README*.md ../proxychains.conf proxychains_x64d.exe cygproxychains_hook_x64d.dll proxychains_remote_function_x64d.bin + +if [ "$1" = "--install" ]; then + cmd /c windows_install.bat +fi \ No newline at end of file diff --git a/cygwin-build/proxychains_remote_function_x64d.bin b/cygwin-build/proxychains_remote_function_x64d.bin new file mode 100644 index 0000000..668368e Binary files /dev/null and b/cygwin-build/proxychains_remote_function_x64d.bin differ diff --git a/cygwin-build/windows_install.bat b/cygwin-build/windows_install.bat new file mode 100644 index 0000000..a4e00bb --- /dev/null +++ b/cygwin-build/windows_install.bat @@ -0,0 +1,15 @@ +copy %cd%\..\win32_output\proxychains_x64.exe %USERPROFILE%\bin\proxychains.exe || pause +copy %cd%\..\win32_output\proxychains_x86.exe %USERPROFILE%\bin\proxychains32.exe || pause +copy %cd%\..\win32_output\proxychains_hook_x64.dll %USERPROFILE%\bin\ || pause +copy %cd%\..\win32_output\proxychains_hook_x86.dll %USERPROFILE%\bin\ || pause +copy %cd%\..\win32_output\proxychains_x64d.exe %USERPROFILE%\bin\proxychainsd.exe || pause +copy %cd%\..\win32_output\proxychains_x86d.exe %USERPROFILE%\bin\proxychains32d.exe || pause +copy %cd%\..\win32_output\proxychains_hook_x64d.dll %USERPROFILE%\bin\ || pause +copy %cd%\..\win32_output\proxychains_hook_x86d.dll %USERPROFILE%\bin\ || pause + +copy %cd%\..\win32_output\proxychains_x64.exe %USERPROFILE%\bin\px.exe || pause +copy %cd%\..\win32_output\proxychains_x86.exe %USERPROFILE%\bin\px32.exe || pause +copy %cd%\..\win32_output\proxychains_x64d.exe %USERPROFILE%\bin\pxd.exe || pause +copy %cd%\..\win32_output\proxychains_x86d.exe %USERPROFILE%\bin\px32d.exe || pause + +copy %cd%\..\win32_output\proxychains_remote_function_*.bin %USERPROFILE%\bin\ || pause \ No newline at end of file diff --git a/include/function_pointers_configured.h b/include/function_pointers_configured.h new file mode 100644 index 0000000..e12c8a2 --- /dev/null +++ b/include/function_pointers_configured.h @@ -0,0 +1,6 @@ +#define PXCH_ADDRESS_FreeLibrary 0x0 +#define PXCH_ADDRESS_GetModuleHandleW 0x0 +#define PXCH_ADDRESS_GetProcAddress 0x0 +#define PXCH_ADDRESS_LoadLibraryW 0x0 +#define PXCH_ADDRESS_GetLastError 0x0 +#define PXCH_ADDRESS_OutputDebugStringA 0x0 diff --git a/include/version.h b/include/version.h index c2ee2fb..391d84a 100644 --- a/include/version.h +++ b/include/version.h @@ -23,5 +23,5 @@ #define PXCH_VERSION_MINOR 4 #endif #ifndef PXCH_VERSION_PATCH -#define PXCH_VERSION_PATCH 0 +#define PXCH_VERSION_PATCH 1 #endif \ No newline at end of file diff --git a/src/dll/dllmain.c b/src/dll/dllmain.c index 83c62a2..7cdc828 100644 --- a/src/dll/dllmain.c +++ b/src/dll/dllmain.c @@ -339,6 +339,8 @@ PXCH_DLL_API DWORD __stdcall InitHook(PXCH_INJECT_REMOTE_DATA* pRemoteData) IPCLOGD(L"(In InitHook) g_pRemoteData->dwDebugDepth = " WPRDW, g_pRemoteData ? g_pRemoteData->dwDebugDepth : -1); + // ALL HOOKS MUST BE DONE HERE + // AFTER fork() RESTORES DATA SEGMENT, MINHOOK IS IN UNCERTAIN STATE Win32HookWs2_32(); //CygwinHook(); diff --git a/src/dll/hook_connect_win32.c b/src/dll/hook_connect_win32.c index e0aa99d..209c7e7 100644 --- a/src/dll/hook_connect_win32.c +++ b/src/dll/hook_connect_win32.c @@ -1049,26 +1049,8 @@ PROXY_FUNC2(Mswsock, ConnectEx) PROXY_FUNC2(Ws2_32, WSAStartup) { - int iReturn; - FUNCIPCLOGD(L"Ws2_32.dll WSAStartup() called"); - iReturn = orig_fpWs2_32_WSAStartup(wVersionRequested, lpWSAData); - if (iReturn == 0) { - SOCKET DummySocket; - GUID GuidConnectEx = WSAID_CONNECTEX; - LPFN_CONNECTEX fpConnectEx = NULL; - DWORD cb; - - DummySocket = socket(AF_INET, SOCK_STREAM, 0); - if (DummySocket == INVALID_SOCKET) goto out; - if (WSAIoctl(DummySocket, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof(GUID), &fpConnectEx, sizeof(LPFN_CONNECTEX), &cb, NULL, NULL) != 0) goto out; - if (!fpConnectEx) goto out; - - CREATE_HOOK3_IFNOTNULL(Mswsock, ConnectEx, fpConnectEx); - MH_EnableHook(fpConnectEx); - } - -out: - return iReturn; + // Not used + return 0; } // Hook WSAConnect diff --git a/src/dll/hook_installer.c b/src/dll/hook_installer.c index ca4862f..419589a 100644 --- a/src/dll/hook_installer.c +++ b/src/dll/hook_installer.c @@ -16,6 +16,13 @@ * version 2 along with this program. If not, see * . */ +#define PXCH_DO_NOT_INCLUDE_STD_HEADERS_NOW +#define PXCH_DO_NOT_INCLUDE_STRSAFE_NOW +#include "includes_win32.h" +#include "common_win32.h" +#include +#include +#include #include "hookdll_interior_win32.h" #include "log_win32.h" #include @@ -25,7 +32,7 @@ void Win32HookWs2_32(void) { HMODULE hWs2_32; - LPVOID pWs2_32_WSAStartup = NULL; + // LPVOID pWs2_32_WSAStartup = NULL; LPVOID pWs2_32_WSAConnect = NULL; LPVOID pWs2_32_connect = NULL; LPVOID pWs2_32_gethostbyname = NULL; @@ -44,11 +51,15 @@ void Win32HookWs2_32(void) LoadLibraryW(L"ws2_32.dll"); if ((hWs2_32 = GetModuleHandleW(L"ws2_32.dll"))) { - orig_fpWs2_32_WSAStartup = (void*)GetProcAddress(hWs2_32, "WSAStartup"); + int iReturn; + SOCKET DummySocket; + WSADATA DummyWsaData; + + // orig_fpWs2_32_WSAStartup = (void*)GetProcAddress(hWs2_32, "WSAStartup"); orig_fpWs2_32_WSAConnect = (void*)GetProcAddress(hWs2_32, "WSAConnect"); orig_fpWs2_32_connect = (void*)GetProcAddress(hWs2_32, "connect"); - pWs2_32_WSAStartup = orig_fpWs2_32_WSAStartup; + // pWs2_32_WSAStartup = orig_fpWs2_32_WSAStartup; pWs2_32_WSAConnect = orig_fpWs2_32_WSAConnect; pWs2_32_connect = orig_fpWs2_32_connect; @@ -78,28 +89,46 @@ void Win32HookWs2_32(void) pWs2_32_FreeAddrInfoExW = orig_fpWs2_32_FreeAddrInfoExW; pWs2_32_getnameinfo = orig_fpWs2_32_getnameinfo ; pWs2_32_GetNameInfoW = orig_fpWs2_32_GetNameInfoW ; - }; - } + } + + // CREATE_HOOK3_IFNOTNULL(Ws2_32, WSAStartup, pWs2_32_WSAStartup); + CREATE_HOOK3_IFNOTNULL(Ws2_32, WSAConnect, pWs2_32_WSAConnect); + CREATE_HOOK3_IFNOTNULL(Ws2_32, connect, pWs2_32_connect); + CREATE_HOOK3_IFNOTNULL(Ws2_32, gethostbyname, pWs2_32_gethostbyname); + CREATE_HOOK3_IFNOTNULL(Ws2_32, gethostbyaddr, pWs2_32_gethostbyaddr); + CREATE_HOOK3_IFNOTNULL(Ws2_32, getaddrinfo, pWs2_32_getaddrinfo); + CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoW, pWs2_32_GetAddrInfoW); + CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoExA, pWs2_32_GetAddrInfoExA); + CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoExW, pWs2_32_GetAddrInfoExW); + CREATE_HOOK3_IFNOTNULL(Ws2_32, freeaddrinfo, pWs2_32_freeaddrinfo); + CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoW, pWs2_32_FreeAddrInfoW); + CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoEx, pWs2_32_FreeAddrInfoEx); + CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoExW, pWs2_32_FreeAddrInfoExW); + CREATE_HOOK3_IFNOTNULL(Ws2_32, getnameinfo, pWs2_32_getnameinfo); + CREATE_HOOK3_IFNOTNULL(Ws2_32, GetNameInfoW, pWs2_32_GetNameInfoW); + + if (orig_fpWs2_32_FreeAddrInfoW == NULL) orig_fpWs2_32_FreeAddrInfoW = orig_fpWs2_32_freeaddrinfo; + if (orig_fpWs2_32_FreeAddrInfoExW == NULL) orig_fpWs2_32_FreeAddrInfoExW = orig_fpWs2_32_FreeAddrInfoEx; - // Another hook on ConnectEx() will take effect at WSAStartup() - CREATE_HOOK3_IFNOTNULL(Ws2_32, WSAStartup, pWs2_32_WSAStartup); - CREATE_HOOK3_IFNOTNULL(Ws2_32, WSAConnect, pWs2_32_WSAConnect); - CREATE_HOOK3_IFNOTNULL(Ws2_32, connect, pWs2_32_connect); - CREATE_HOOK3_IFNOTNULL(Ws2_32, gethostbyname, pWs2_32_gethostbyname); - CREATE_HOOK3_IFNOTNULL(Ws2_32, gethostbyaddr, pWs2_32_gethostbyaddr); - CREATE_HOOK3_IFNOTNULL(Ws2_32, getaddrinfo, pWs2_32_getaddrinfo); - CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoW, pWs2_32_GetAddrInfoW); - CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoExA, pWs2_32_GetAddrInfoExA); - CREATE_HOOK3_IFNOTNULL(Ws2_32, GetAddrInfoExW, pWs2_32_GetAddrInfoExW); - CREATE_HOOK3_IFNOTNULL(Ws2_32, freeaddrinfo, pWs2_32_freeaddrinfo); - CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoW, pWs2_32_FreeAddrInfoW); - CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoEx, pWs2_32_FreeAddrInfoEx); - CREATE_HOOK3_IFNOTNULL(Ws2_32, FreeAddrInfoExW, pWs2_32_FreeAddrInfoExW); - CREATE_HOOK3_IFNOTNULL(Ws2_32, getnameinfo, pWs2_32_getnameinfo); - CREATE_HOOK3_IFNOTNULL(Ws2_32, GetNameInfoW, pWs2_32_GetNameInfoW); - - if (orig_fpWs2_32_FreeAddrInfoW == NULL) orig_fpWs2_32_FreeAddrInfoW = orig_fpWs2_32_freeaddrinfo; - if (orig_fpWs2_32_FreeAddrInfoExW == NULL) orig_fpWs2_32_FreeAddrInfoExW = orig_fpWs2_32_FreeAddrInfoEx; + // Hook ConnectEx() + iReturn = WSAStartup(MAKEWORD(2, 2), &DummyWsaData); + + if (iReturn == 0) { + GUID GuidConnectEx = WSAID_CONNECTEX; + LPFN_CONNECTEX fpConnectEx = NULL; + DWORD cb; + + DummySocket = socket(AF_INET, SOCK_STREAM, 0); + if (DummySocket != INVALID_SOCKET) { + if (WSAIoctl(DummySocket, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof(GUID), &fpConnectEx, sizeof(LPFN_CONNECTEX), &cb, NULL, NULL) == 0) { + if (fpConnectEx) { + CREATE_HOOK3_IFNOTNULL(Mswsock, ConnectEx, fpConnectEx); + } + } + closesocket(DummySocket); + } + } + } } void CygwinHook(void)