diff options
| author | andretuta <andreviniciusmerlia@gmail.com> | 2026-11-24 00:53:14 -0300 |
|---|---|---|
| committer | andretuta <andreviniciusmerlia@gmail.com> | 2026-11-24 00:53:14 -0300 |
| commit | 9b59db02f974edc453bab4c2bf69e52f87447ebf (patch) | |
| tree | 20d377a3937b26b3a8a3d4a2c27dd4effc369c3b /runtime/shims/ws2_offline.cpp | |
| parent | f9e7e3e1bfa718eb4d8ca84fd1dbe617038d48d7 (diff) | |
ws2_offline: add offline loopback-only Winsock2 (ws2_32.dll) shim (RT-WS2-OFFLINE)
Diffstat (limited to 'runtime/shims/ws2_offline.cpp')
| -rw-r--r-- | runtime/shims/ws2_offline.cpp | 752 |
1 files changed, 752 insertions, 0 deletions
diff --git a/runtime/shims/ws2_offline.cpp b/runtime/shims/ws2_offline.cpp new file mode 100644 index 000000000..9a5980d2c --- /dev/null +++ b/runtime/shims/ws2_offline.cpp | |||
| @@ -0,0 +1,752 @@ | |||
| 1 | // ws2_offline: Winsock2 (ws2_32.dll) for a mapped title, restricted to loopback only. | ||
| 2 | // | ||
| 3 | // Nothing in Leonida goes online. While winhttp_offline.cpp owns winhttp.dll, a title can also import Winsock2 | ||
| 4 | // functions directly (both by name and by standard Windows ws2_32.dll ordinal) or resolve them through | ||
| 5 | // GetProcAddress / WSAIoctl. Bound straight to the host's ws2_32.dll, those calls could open external sockets or | ||
| 6 | // trigger DNS queries. | ||
| 7 | // | ||
| 8 | // ws2_32.dll stays host-owned in rt::shims::owns_dll (partial override, like kernel32.dll), so socket bookkeeping | ||
| 9 | // (WSAStartup, socket, closesocket, select, setsockopt, recv, send, byte-order helpers, freeaddrinfo) continues to | ||
| 10 | // run natively on loopback sockets while every outbound, bind, name-resolution, and extension-lookup entry point is | ||
| 11 | // vetted here: | ||
| 12 | // - connect (#4), WSAConnect, WSAConnectByNameA/W, WSAConnectByList, ConnectEx (from WSAIoctl), sendto (#20), | ||
| 13 | // WSASendTo, and WSASendMsg (direct and via WSAIoctl) permit only IPv4 loopback (127.0.0.0/8), IPv6 loopback | ||
| 14 | // (::1), and IPv4-mapped IPv6 loopback (::ffff:127.0.0.0/104). Every other destination fails with WSAENETUNREACH. | ||
| 15 | // - bind (#2) rewrites wildcard binds (0.0.0.0 or ::) to 127.0.0.1 or ::1 so no external peer can connect in, | ||
| 16 | // allows explicit loopback binds, and refuses any other address with WSAEADDRNOTAVAIL. | ||
| 17 | // - getaddrinfo, GetAddrInfoW, GetAddrInfoExA/W, gethostbyname (#52), gethostbyaddr (#51), and | ||
| 18 | // WSAAsyncGetHostByName/Addr (#103/#102) permit only null/empty nodes, "localhost", and loopback IP literals; | ||
| 19 | // everything else fails with WSAHOST_NOT_FOUND without sending DNS packets. | ||
| 20 | // - getnameinfo / GetNameInfoW force NI_NUMERICHOST for non-loopback addresses (or return WSAHOST_NOT_FOUND when | ||
| 21 | // NI_NAMEREQD is set), avoiding reverse DNS lookups. | ||
| 22 | // - WSAIoctl wraps WSAID_CONNECTEX and WSAID_WSASENDMSG and refuses SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER | ||
| 23 | // with WSAEINVAL so extension functions cannot bypass the checks. | ||
| 24 | // | ||
| 25 | // Every host ws2_32.dll call is resolved dynamically from System32 so gta6rt needs no static ws2_32.lib link | ||
| 26 | // dependency. Each refused destination is logged once ("[rt] ws2: offline, refused <op> <target>") with no payload. | ||
| 27 | #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS | ||
| 28 | #define _WINSOCK_DEPRECATED_NO_WARNINGS | ||
| 29 | #endif | ||
| 30 | #ifndef WIN32_LEAN_AND_MEAN | ||
| 31 | #define WIN32_LEAN_AND_MEAN | ||
| 32 | #endif | ||
| 33 | #ifndef NOMINMAX | ||
| 34 | #define NOMINMAX | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #include <winsock2.h> | ||
| 38 | #include <ws2tcpip.h> | ||
| 39 | #include <mswsock.h> | ||
| 40 | #include <windows.h> | ||
| 41 | |||
| 42 | #include <atomic> | ||
| 43 | #include <cstdint> | ||
| 44 | #include <cstdio> | ||
| 45 | #include <cstring> | ||
| 46 | #include <mutex> | ||
| 47 | #include <set> | ||
| 48 | #include <string> | ||
| 49 | |||
| 50 | #include "shims.h" | ||
| 51 | |||
| 52 | #ifndef SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER | ||
| 53 | #define SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER 0xC8000024u | ||
| 54 | #endif | ||
| 55 | |||
| 56 | namespace rt::ws2 { | ||
| 57 | namespace { | ||
| 58 | |||
| 59 | HMODULE host_ws2() { | ||
| 60 | static HMODULE mod = LoadLibraryExW(L"ws2_32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
| 61 | return mod; | ||
| 62 | } | ||
| 63 | |||
| 64 | template <typename Fn> | ||
| 65 | Fn host_proc(const char* name) { | ||
| 66 | HMODULE mod = host_ws2(); | ||
| 67 | return mod ? reinterpret_cast<Fn>(GetProcAddress(mod, name)) : nullptr; | ||
| 68 | } | ||
| 69 | |||
| 70 | void set_wsa_error(int err) { | ||
| 71 | using SetErrFn = void(WSAAPI*)(int); | ||
| 72 | static SetErrFn fn = host_proc<SetErrFn>("WSASetLastError"); | ||
| 73 | if (fn) { | ||
| 74 | fn(err); | ||
| 75 | } else { | ||
| 76 | SetLastError(static_cast<DWORD>(err)); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | uint16_t read_be16(uint16_t net_val) { | ||
| 81 | const auto* b = reinterpret_cast<const uint8_t*>(&net_val); | ||
| 82 | return static_cast<uint16_t>((static_cast<uint16_t>(b[0]) << 8) | b[1]); | ||
| 83 | } | ||
| 84 | |||
| 85 | bool is_ipv4_loopback_bytes(const uint8_t b[4]) { return b[0] == 127; } | ||
| 86 | |||
| 87 | bool is_ipv4_unspecified_bytes(const uint8_t b[4]) { return b[0] == 0 && b[1] == 0 && b[2] == 0 && b[3] == 0; } | ||
| 88 | |||
| 89 | bool is_ipv6_loopback_bytes(const uint8_t b[16]) { | ||
| 90 | // ::1 | ||
| 91 | bool exact_loopback = true; | ||
| 92 | for (int i = 0; i < 15; ++i) { | ||
| 93 | if (b[i] != 0) { | ||
| 94 | exact_loopback = false; | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | if (exact_loopback && b[15] == 1) return true; | ||
| 99 | |||
| 100 | // ::ffff:127.0.0.0/104 (IPv4-mapped loopback) | ||
| 101 | for (int i = 0; i < 10; ++i) { | ||
| 102 | if (b[i] != 0) return false; | ||
| 103 | } | ||
| 104 | return b[10] == 0xff && b[11] == 0xff && b[12] == 127; | ||
| 105 | } | ||
| 106 | |||
| 107 | bool is_ipv6_unspecified_bytes(const uint8_t b[16]) { | ||
| 108 | for (int i = 0; i < 16; ++i) { | ||
| 109 | if (b[i] != 0) return false; | ||
| 110 | } | ||
| 111 | return true; | ||
| 112 | } | ||
| 113 | |||
| 114 | bool is_loopback_sockaddr(const sockaddr* sa, int namelen) { | ||
| 115 | if (!sa || namelen < static_cast<int>(sizeof(ADDRESS_FAMILY))) return false; | ||
| 116 | if (sa->sa_family == AF_INET) { | ||
| 117 | if (namelen < static_cast<int>(sizeof(sockaddr_in))) return false; | ||
| 118 | sockaddr_in v4{}; | ||
| 119 | std::memcpy(&v4, sa, sizeof(v4)); | ||
| 120 | const auto* b = reinterpret_cast<const uint8_t*>(&v4.sin_addr); | ||
| 121 | return is_ipv4_loopback_bytes(b); | ||
| 122 | } | ||
| 123 | if (sa->sa_family == AF_INET6) { | ||
| 124 | if (namelen < static_cast<int>(sizeof(sockaddr_in6))) return false; | ||
| 125 | sockaddr_in6 v6{}; | ||
| 126 | std::memcpy(&v6, sa, sizeof(v6)); | ||
| 127 | const auto* b = reinterpret_cast<const uint8_t*>(&v6.sin6_addr); | ||
| 128 | return is_ipv6_loopback_bytes(b); | ||
| 129 | } | ||
| 130 | return false; | ||
| 131 | } | ||
| 132 | |||
| 133 | std::string format_sockaddr(const sockaddr* sa, int namelen) { | ||
| 134 | if (!sa || namelen < static_cast<int>(sizeof(ADDRESS_FAMILY))) return "<invalid>"; | ||
| 135 | char buf[96] = {}; | ||
| 136 | if (sa->sa_family == AF_INET && namelen >= static_cast<int>(sizeof(sockaddr_in))) { | ||
| 137 | sockaddr_in v4{}; | ||
| 138 | std::memcpy(&v4, sa, sizeof(v4)); | ||
| 139 | const auto* b = reinterpret_cast<const uint8_t*>(&v4.sin_addr); | ||
| 140 | std::snprintf(buf, sizeof(buf), "%u.%u.%u.%u:%u", b[0], b[1], b[2], b[3], | ||
| 141 | static_cast<unsigned>(read_be16(v4.sin_port))); | ||
| 142 | return buf; | ||
| 143 | } | ||
| 144 | if (sa->sa_family == AF_INET6 && namelen >= static_cast<int>(sizeof(sockaddr_in6))) { | ||
| 145 | sockaddr_in6 v6{}; | ||
| 146 | std::memcpy(&v6, sa, sizeof(v6)); | ||
| 147 | const auto* b = reinterpret_cast<const uint8_t*>(&v6.sin6_addr); | ||
| 148 | std::snprintf(buf, sizeof(buf), "[%02x%02x:%02x%02x:...:%02x%02x]:%u", b[0], b[1], b[2], b[3], b[14], b[15], | ||
| 149 | static_cast<unsigned>(read_be16(v6.sin6_port))); | ||
| 150 | return buf; | ||
| 151 | } | ||
| 152 | std::snprintf(buf, sizeof(buf), "family=%u", static_cast<unsigned>(sa->sa_family)); | ||
| 153 | return buf; | ||
| 154 | } | ||
| 155 | |||
| 156 | void log_refused(const char* op, const std::string& target) { | ||
| 157 | // Intentionally immortal: mapped-DLL teardown can run after normal statics are destroyed. | ||
| 158 | static auto* mutex = new std::mutex; | ||
| 159 | static auto* seen = new std::set<std::string>; | ||
| 160 | const std::string key = std::string(op) + " " + target; | ||
| 161 | std::lock_guard lock(*mutex); | ||
| 162 | if (seen->insert(key).second) { | ||
| 163 | std::fprintf(stderr, "[rt] ws2: offline, refused %s %s\n", op, target.c_str()); | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | bool ascii_iequals(const char* a, const char* b) { | ||
| 168 | if (!a || !b) return false; | ||
| 169 | while (*a && *b) { | ||
| 170 | unsigned char ca = static_cast<unsigned char>(*a++); | ||
| 171 | unsigned char cb = static_cast<unsigned char>(*b++); | ||
| 172 | if (ca >= 'A' && ca <= 'Z') ca = static_cast<unsigned char>(ca + 32); | ||
| 173 | if (cb >= 'A' && cb <= 'Z') cb = static_cast<unsigned char>(cb + 32); | ||
| 174 | if (ca != cb) return false; | ||
| 175 | } | ||
| 176 | return *a == '\0' && *b == '\0'; | ||
| 177 | } | ||
| 178 | |||
| 179 | std::string narrow_ascii(const wchar_t* w) { | ||
| 180 | std::string out; | ||
| 181 | if (!w) return out; | ||
| 182 | for (; *w; ++w) out += (*w < 0x80) ? static_cast<char>(*w) : '?'; | ||
| 183 | return out; | ||
| 184 | } | ||
| 185 | |||
| 186 | bool parse_ipv4_literal(const char* s, uint8_t out[4]) { | ||
| 187 | if (!s || !*s) return false; | ||
| 188 | const char* p = s; | ||
| 189 | for (int part = 0; part < 4; ++part) { | ||
| 190 | if (*p < '0' || *p > '9') return false; | ||
| 191 | unsigned val = 0; | ||
| 192 | int digits = 0; | ||
| 193 | while (*p >= '0' && *p <= '9') { | ||
| 194 | val = val * 10u + static_cast<unsigned>(*p - '0'); | ||
| 195 | if (val > 255u) return false; | ||
| 196 | ++p; | ||
| 197 | ++digits; | ||
| 198 | } | ||
| 199 | if (digits == 0) return false; | ||
| 200 | out[part] = static_cast<uint8_t>(val); | ||
| 201 | if (part < 3) { | ||
| 202 | if (*p != '.') return false; | ||
| 203 | ++p; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | return *p == '\0'; | ||
| 207 | } | ||
| 208 | |||
| 209 | bool is_loopback_node_a(const char* node) { | ||
| 210 | if (!node || !*node) return true; | ||
| 211 | if (ascii_iequals(node, "localhost") || ascii_iequals(node, "localhost.")) return true; | ||
| 212 | |||
| 213 | uint8_t v4[4] = {}; | ||
| 214 | if (parse_ipv4_literal(node, v4)) return is_ipv4_loopback_bytes(v4); | ||
| 215 | |||
| 216 | // Strip optional brackets and IPv6 zone suffix (%...) for literal check via host inet_pton. | ||
| 217 | std::string clean(node); | ||
| 218 | if (clean.size() >= 2 && clean.front() == '[' && clean.back() == ']') { | ||
| 219 | clean = clean.substr(1, clean.size() - 2); | ||
| 220 | } | ||
| 221 | if (const size_t pct = clean.find('%'); pct != std::string::npos) { | ||
| 222 | clean.resize(pct); | ||
| 223 | } | ||
| 224 | |||
| 225 | using InetPtonFn = INT(WSAAPI*)(INT, PCSTR, PVOID); | ||
| 226 | static InetPtonFn pton = host_proc<InetPtonFn>("inet_pton"); | ||
| 227 | if (pton) { | ||
| 228 | uint8_t v6[16] = {}; | ||
| 229 | if (pton(AF_INET6, clean.c_str(), v6) == 1) return is_ipv6_loopback_bytes(v6); | ||
| 230 | } else if (clean == "::1") { | ||
| 231 | return true; | ||
| 232 | } | ||
| 233 | return false; | ||
| 234 | } | ||
| 235 | |||
| 236 | bool is_loopback_node_w(const wchar_t* node) { | ||
| 237 | if (!node || !*node) return true; | ||
| 238 | for (const wchar_t* p = node; *p; ++p) { | ||
| 239 | if (*p >= 0x80) return false; | ||
| 240 | } | ||
| 241 | const std::string ascii = narrow_ascii(node); | ||
| 242 | return is_loopback_node_a(ascii.c_str()); | ||
| 243 | } | ||
| 244 | |||
| 245 | // ---- Socket connect / send / bind shims ---- | ||
| 246 | |||
| 247 | int WSAAPI connect_offline(SOCKET s, const sockaddr* name, int namelen) { | ||
| 248 | if (!is_loopback_sockaddr(name, namelen)) { | ||
| 249 | log_refused("connect", format_sockaddr(name, namelen)); | ||
| 250 | set_wsa_error(WSAENETUNREACH); | ||
| 251 | return SOCKET_ERROR; | ||
| 252 | } | ||
| 253 | using Fn = int(WSAAPI*)(SOCKET, const sockaddr*, int); | ||
| 254 | static Fn real_fn = host_proc<Fn>("connect"); | ||
| 255 | if (!real_fn) { | ||
| 256 | set_wsa_error(WSAENETUNREACH); | ||
| 257 | return SOCKET_ERROR; | ||
| 258 | } | ||
| 259 | return real_fn(s, name, namelen); | ||
| 260 | } | ||
| 261 | |||
| 262 | int WSAAPI wsa_connect_offline(SOCKET s, const sockaddr* name, int namelen, LPWSABUF caller_data, | ||
| 263 | LPWSABUF callee_data, LPQOS sqos, LPQOS gqos) { | ||
| 264 | if (!is_loopback_sockaddr(name, namelen)) { | ||
| 265 | log_refused("WSAConnect", format_sockaddr(name, namelen)); | ||
| 266 | set_wsa_error(WSAENETUNREACH); | ||
| 267 | return SOCKET_ERROR; | ||
| 268 | } | ||
| 269 | using Fn = int(WSAAPI*)(SOCKET, const sockaddr*, int, LPWSABUF, LPWSABUF, LPQOS, LPQOS); | ||
| 270 | static Fn real_fn = host_proc<Fn>("WSAConnect"); | ||
| 271 | if (!real_fn) { | ||
| 272 | set_wsa_error(WSAENETUNREACH); | ||
| 273 | return SOCKET_ERROR; | ||
| 274 | } | ||
| 275 | return real_fn(s, name, namelen, caller_data, callee_data, sqos, gqos); | ||
| 276 | } | ||
| 277 | |||
| 278 | BOOL WSAAPI wsa_connect_by_name_a_offline(SOCKET s, LPCSTR nodename, LPCSTR servicename, | ||
| 279 | LPDWORD local_addr_len, LPSOCKADDR local_addr, | ||
| 280 | LPDWORD remote_addr_len, LPSOCKADDR remote_addr, | ||
| 281 | const timeval* timeout, LPWSAOVERLAPPED reserved) { | ||
| 282 | if (!nodename || !*nodename || !is_loopback_node_a(nodename)) { | ||
| 283 | log_refused("WSAConnectByNameA", nodename ? nodename : "<null>"); | ||
| 284 | set_wsa_error(WSAENETUNREACH); | ||
| 285 | return FALSE; | ||
| 286 | } | ||
| 287 | using Fn = BOOL(WSAAPI*)(SOCKET, LPCSTR, LPCSTR, LPDWORD, LPSOCKADDR, LPDWORD, LPSOCKADDR, const timeval*, | ||
| 288 | LPWSAOVERLAPPED); | ||
| 289 | static Fn real_fn = host_proc<Fn>("WSAConnectByNameA"); | ||
| 290 | if (!real_fn) { | ||
| 291 | set_wsa_error(WSAENETUNREACH); | ||
| 292 | return FALSE; | ||
| 293 | } | ||
| 294 | return real_fn(s, nodename, servicename, local_addr_len, local_addr, remote_addr_len, remote_addr, timeout, | ||
| 295 | reserved); | ||
| 296 | } | ||
| 297 | |||
| 298 | BOOL WSAAPI wsa_connect_by_name_w_offline(SOCKET s, LPWSTR nodename, LPWSTR servicename, | ||
| 299 | LPDWORD local_addr_len, LPSOCKADDR local_addr, | ||
| 300 | LPDWORD remote_addr_len, LPSOCKADDR remote_addr, | ||
| 301 | const timeval* timeout, LPWSAOVERLAPPED reserved) { | ||
| 302 | if (!nodename || !*nodename || !is_loopback_node_w(nodename)) { | ||
| 303 | log_refused("WSAConnectByNameW", nodename ? narrow_ascii(nodename) : "<null>"); | ||
| 304 | set_wsa_error(WSAENETUNREACH); | ||
| 305 | return FALSE; | ||
| 306 | } | ||
| 307 | using Fn = BOOL(WSAAPI*)(SOCKET, LPWSTR, LPWSTR, LPDWORD, LPSOCKADDR, LPDWORD, LPSOCKADDR, const timeval*, | ||
| 308 | LPWSAOVERLAPPED); | ||
| 309 | static Fn real_fn = host_proc<Fn>("WSAConnectByNameW"); | ||
| 310 | if (!real_fn) { | ||
| 311 | set_wsa_error(WSAENETUNREACH); | ||
| 312 | return FALSE; | ||
| 313 | } | ||
| 314 | return real_fn(s, nodename, servicename, local_addr_len, local_addr, remote_addr_len, remote_addr, timeout, | ||
| 315 | reserved); | ||
| 316 | } | ||
| 317 | |||
| 318 | BOOL WSAAPI wsa_connect_by_list_offline(SOCKET s, PSOCKET_ADDRESS_LIST addr_list, LPDWORD local_addr_len, | ||
| 319 | LPSOCKADDR local_addr, LPDWORD remote_addr_len, LPSOCKADDR remote_addr, | ||
| 320 | const timeval* timeout, LPWSAOVERLAPPED reserved) { | ||
| 321 | if (!addr_list || addr_list->iAddressCount <= 0) { | ||
| 322 | set_wsa_error(WSAEINVAL); | ||
| 323 | return FALSE; | ||
| 324 | } | ||
| 325 | for (INT i = 0; i < addr_list->iAddressCount; ++i) { | ||
| 326 | const SOCKET_ADDRESS& entry = addr_list->Address[i]; | ||
| 327 | if (!is_loopback_sockaddr(entry.lpSockaddr, entry.iSockaddrLength)) { | ||
| 328 | log_refused("WSAConnectByList", format_sockaddr(entry.lpSockaddr, entry.iSockaddrLength)); | ||
| 329 | set_wsa_error(WSAENETUNREACH); | ||
| 330 | return FALSE; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | using Fn = BOOL(WSAAPI*)(SOCKET, PSOCKET_ADDRESS_LIST, LPDWORD, LPSOCKADDR, LPDWORD, LPSOCKADDR, const timeval*, | ||
| 334 | LPWSAOVERLAPPED); | ||
| 335 | static Fn real_fn = host_proc<Fn>("WSAConnectByList"); | ||
| 336 | if (!real_fn) { | ||
| 337 | set_wsa_error(WSAENETUNREACH); | ||
| 338 | return FALSE; | ||
| 339 | } | ||
| 340 | return real_fn(s, addr_list, local_addr_len, local_addr, remote_addr_len, remote_addr, timeout, reserved); | ||
| 341 | } | ||
| 342 | |||
| 343 | int WSAAPI sendto_offline(SOCKET s, const char* buf, int len, int flags, const sockaddr* to, int tolen) { | ||
| 344 | if (to && tolen > 0 && !is_loopback_sockaddr(to, tolen)) { | ||
| 345 | log_refused("sendto", format_sockaddr(to, tolen)); | ||
| 346 | set_wsa_error(WSAENETUNREACH); | ||
| 347 | return SOCKET_ERROR; | ||
| 348 | } | ||
| 349 | using Fn = int(WSAAPI*)(SOCKET, const char*, int, int, const sockaddr*, int); | ||
| 350 | static Fn real_fn = host_proc<Fn>("sendto"); | ||
| 351 | if (!real_fn) { | ||
| 352 | set_wsa_error(WSAENETUNREACH); | ||
| 353 | return SOCKET_ERROR; | ||
| 354 | } | ||
| 355 | return real_fn(s, buf, len, flags, to, tolen); | ||
| 356 | } | ||
| 357 | |||
| 358 | int WSAAPI wsa_send_to_offline(SOCKET s, LPWSABUF buffers, DWORD buffer_count, LPDWORD bytes_sent, DWORD flags, | ||
| 359 | const sockaddr* to, int tolen, LPWSAOVERLAPPED overlapped, | ||
| 360 | LPWSAOVERLAPPED_COMPLETION_ROUTINE completion) { | ||
| 361 | if (to && tolen > 0 && !is_loopback_sockaddr(to, tolen)) { | ||
| 362 | log_refused("WSASendTo", format_sockaddr(to, tolen)); | ||
| 363 | set_wsa_error(WSAENETUNREACH); | ||
| 364 | return SOCKET_ERROR; | ||
| 365 | } | ||
| 366 | using Fn = int(WSAAPI*)(SOCKET, LPWSABUF, DWORD, LPDWORD, DWORD, const sockaddr*, int, LPWSAOVERLAPPED, | ||
| 367 | LPWSAOVERLAPPED_COMPLETION_ROUTINE); | ||
| 368 | static Fn real_fn = host_proc<Fn>("WSASendTo"); | ||
| 369 | if (!real_fn) { | ||
| 370 | set_wsa_error(WSAENETUNREACH); | ||
| 371 | return SOCKET_ERROR; | ||
| 372 | } | ||
| 373 | return real_fn(s, buffers, buffer_count, bytes_sent, flags, to, tolen, overlapped, completion); | ||
| 374 | } | ||
| 375 | |||
| 376 | int WSAAPI wsa_send_msg_offline(SOCKET s, LPWSAMSG msg, DWORD flags, LPDWORD bytes_sent, | ||
| 377 | LPWSAOVERLAPPED overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion) { | ||
| 378 | if (msg && msg->name && msg->namelen > 0 && !is_loopback_sockaddr(msg->name, msg->namelen)) { | ||
| 379 | log_refused("WSASendMsg", format_sockaddr(msg->name, msg->namelen)); | ||
| 380 | set_wsa_error(WSAENETUNREACH); | ||
| 381 | return SOCKET_ERROR; | ||
| 382 | } | ||
| 383 | using Fn = int(WSAAPI*)(SOCKET, LPWSAMSG, DWORD, LPDWORD, LPWSAOVERLAPPED, LPWSAOVERLAPPED_COMPLETION_ROUTINE); | ||
| 384 | static Fn real_fn = host_proc<Fn>("WSASendMsg"); | ||
| 385 | if (!real_fn) { | ||
| 386 | set_wsa_error(WSAENETUNREACH); | ||
| 387 | return SOCKET_ERROR; | ||
| 388 | } | ||
| 389 | return real_fn(s, msg, flags, bytes_sent, overlapped, completion); | ||
| 390 | } | ||
| 391 | |||
| 392 | int WSAAPI bind_offline(SOCKET s, const sockaddr* name, int namelen) { | ||
| 393 | if (!name || namelen < static_cast<int>(sizeof(ADDRESS_FAMILY))) { | ||
| 394 | set_wsa_error(WSAEINVAL); | ||
| 395 | return SOCKET_ERROR; | ||
| 396 | } | ||
| 397 | using Fn = int(WSAAPI*)(SOCKET, const sockaddr*, int); | ||
| 398 | static Fn real_fn = host_proc<Fn>("bind"); | ||
| 399 | if (!real_fn) { | ||
| 400 | set_wsa_error(WSAEADDRNOTAVAIL); | ||
| 401 | return SOCKET_ERROR; | ||
| 402 | } | ||
| 403 | |||
| 404 | if (name->sa_family == AF_INET && namelen >= static_cast<int>(sizeof(sockaddr_in))) { | ||
| 405 | sockaddr_in v4{}; | ||
| 406 | std::memcpy(&v4, name, sizeof(v4)); | ||
| 407 | auto* b = reinterpret_cast<uint8_t*>(&v4.sin_addr); | ||
| 408 | if (is_ipv4_unspecified_bytes(b)) { | ||
| 409 | b[0] = 127; | ||
| 410 | b[1] = 0; | ||
| 411 | b[2] = 0; | ||
| 412 | b[3] = 1; | ||
| 413 | return real_fn(s, reinterpret_cast<const sockaddr*>(&v4), sizeof(v4)); | ||
| 414 | } | ||
| 415 | if (is_ipv4_loopback_bytes(b)) { | ||
| 416 | return real_fn(s, name, namelen); | ||
| 417 | } | ||
| 418 | } else if (name->sa_family == AF_INET6 && namelen >= static_cast<int>(sizeof(sockaddr_in6))) { | ||
| 419 | sockaddr_in6 v6{}; | ||
| 420 | std::memcpy(&v6, name, sizeof(v6)); | ||
| 421 | auto* b = reinterpret_cast<uint8_t*>(&v6.sin6_addr); | ||
| 422 | if (is_ipv6_unspecified_bytes(b)) { | ||
| 423 | b[15] = 1; | ||
| 424 | return real_fn(s, reinterpret_cast<const sockaddr*>(&v6), sizeof(v6)); | ||
| 425 | } | ||
| 426 | if (is_ipv6_loopback_bytes(b)) { | ||
| 427 | return real_fn(s, name, namelen); | ||
| 428 | } | ||
| 429 | } | ||
| 430 | |||
| 431 | log_refused("bind", format_sockaddr(name, namelen)); | ||
| 432 | set_wsa_error(WSAEADDRNOTAVAIL); | ||
| 433 | return SOCKET_ERROR; | ||
| 434 | } | ||
| 435 | |||
| 436 | // ---- Name resolution shims ---- | ||
| 437 | |||
| 438 | INT WSAAPI getaddrinfo_offline(PCSTR node, PCSTR service, const ADDRINFOA* hints, PADDRINFOA* result) { | ||
| 439 | if (result) *result = nullptr; | ||
| 440 | if (!is_loopback_node_a(node)) { | ||
| 441 | log_refused("getaddrinfo", node ? node : "<null>"); | ||
| 442 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 443 | return WSAHOST_NOT_FOUND; | ||
| 444 | } | ||
| 445 | using Fn = INT(WSAAPI*)(PCSTR, PCSTR, const ADDRINFOA*, PADDRINFOA*); | ||
| 446 | static Fn real_fn = host_proc<Fn>("getaddrinfo"); | ||
| 447 | if (!real_fn) { | ||
| 448 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 449 | return WSAHOST_NOT_FOUND; | ||
| 450 | } | ||
| 451 | return real_fn(node, service, hints, result); | ||
| 452 | } | ||
| 453 | |||
| 454 | INT WSAAPI get_addr_info_w_offline(PCWSTR node, PCWSTR service, const ADDRINFOW* hints, PADDRINFOW* result) { | ||
| 455 | if (result) *result = nullptr; | ||
| 456 | if (!is_loopback_node_w(node)) { | ||
| 457 | log_refused("GetAddrInfoW", node ? narrow_ascii(node) : "<null>"); | ||
| 458 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 459 | return WSAHOST_NOT_FOUND; | ||
| 460 | } | ||
| 461 | using Fn = INT(WSAAPI*)(PCWSTR, PCWSTR, const ADDRINFOW*, PADDRINFOW*); | ||
| 462 | static Fn real_fn = host_proc<Fn>("GetAddrInfoW"); | ||
| 463 | if (!real_fn) { | ||
| 464 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 465 | return WSAHOST_NOT_FOUND; | ||
| 466 | } | ||
| 467 | return real_fn(node, service, hints, result); | ||
| 468 | } | ||
| 469 | |||
| 470 | INT WSAAPI get_addr_info_ex_a_offline(PCSTR name, PCSTR service, DWORD ns, LPGUID nsp_id, const ADDRINFOEXA* hints, | ||
| 471 | PADDRINFOEXA* result, timeval* timeout, LPOVERLAPPED overlapped, | ||
| 472 | LPLOOKUPSERVICE_COMPLETION_ROUTINE completion, LPHANDLE cancel_handle) { | ||
| 473 | if (result) *result = nullptr; | ||
| 474 | if (cancel_handle) *cancel_handle = nullptr; | ||
| 475 | if (!is_loopback_node_a(name)) { | ||
| 476 | log_refused("GetAddrInfoExA", name ? name : "<null>"); | ||
| 477 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 478 | return WSAHOST_NOT_FOUND; | ||
| 479 | } | ||
| 480 | using Fn = INT(WSAAPI*)(PCSTR, PCSTR, DWORD, LPGUID, const ADDRINFOEXA*, PADDRINFOEXA*, timeval*, LPOVERLAPPED, | ||
| 481 | LPLOOKUPSERVICE_COMPLETION_ROUTINE, LPHANDLE); | ||
| 482 | static Fn real_fn = host_proc<Fn>("GetAddrInfoExA"); | ||
| 483 | if (!real_fn) { | ||
| 484 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 485 | return WSAHOST_NOT_FOUND; | ||
| 486 | } | ||
| 487 | return real_fn(name, service, ns, nsp_id, hints, result, timeout, overlapped, completion, cancel_handle); | ||
| 488 | } | ||
| 489 | |||
| 490 | INT WSAAPI get_addr_info_ex_w_offline(PCWSTR name, PCWSTR service, DWORD ns, LPGUID nsp_id, const ADDRINFOEXW* hints, | ||
| 491 | PADDRINFOEXW* result, timeval* timeout, LPOVERLAPPED overlapped, | ||
| 492 | LPLOOKUPSERVICE_COMPLETION_ROUTINE completion, LPHANDLE cancel_handle) { | ||
| 493 | if (result) *result = nullptr; | ||
| 494 | if (cancel_handle) *cancel_handle = nullptr; | ||
| 495 | if (!is_loopback_node_w(name)) { | ||
| 496 | log_refused("GetAddrInfoExW", name ? narrow_ascii(name) : "<null>"); | ||
| 497 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 498 | return WSAHOST_NOT_FOUND; | ||
| 499 | } | ||
| 500 | using Fn = INT(WSAAPI*)(PCWSTR, PCWSTR, DWORD, LPGUID, const ADDRINFOEXW*, PADDRINFOEXW*, timeval*, LPOVERLAPPED, | ||
| 501 | LPLOOKUPSERVICE_COMPLETION_ROUTINE, LPHANDLE); | ||
| 502 | static Fn real_fn = host_proc<Fn>("GetAddrInfoExW"); | ||
| 503 | if (!real_fn) { | ||
| 504 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 505 | return WSAHOST_NOT_FOUND; | ||
| 506 | } | ||
| 507 | return real_fn(name, service, ns, nsp_id, hints, result, timeout, overlapped, completion, cancel_handle); | ||
| 508 | } | ||
| 509 | |||
| 510 | hostent* WSAAPI gethostbyname_offline(const char* name) { | ||
| 511 | if (!is_loopback_node_a(name)) { | ||
| 512 | log_refused("gethostbyname", name ? name : "<null>"); | ||
| 513 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 514 | return nullptr; | ||
| 515 | } | ||
| 516 | using Fn = hostent*(WSAAPI*)(const char*); | ||
| 517 | static Fn real_fn = host_proc<Fn>("gethostbyname"); | ||
| 518 | if (!real_fn) { | ||
| 519 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 520 | return nullptr; | ||
| 521 | } | ||
| 522 | return real_fn(name); | ||
| 523 | } | ||
| 524 | |||
| 525 | bool is_loopback_raw_addr(const char* addr, int len, int type) { | ||
| 526 | if (!addr) return false; | ||
| 527 | if (type == AF_INET && len == 4) { | ||
| 528 | return is_ipv4_loopback_bytes(reinterpret_cast<const uint8_t*>(addr)); | ||
| 529 | } | ||
| 530 | if (type == AF_INET6 && len == 16) { | ||
| 531 | return is_ipv6_loopback_bytes(reinterpret_cast<const uint8_t*>(addr)); | ||
| 532 | } | ||
| 533 | return false; | ||
| 534 | } | ||
| 535 | |||
| 536 | hostent* WSAAPI gethostbyaddr_offline(const char* addr, int len, int type) { | ||
| 537 | if (!is_loopback_raw_addr(addr, len, type)) { | ||
| 538 | log_refused("gethostbyaddr", "non-loopback"); | ||
| 539 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 540 | return nullptr; | ||
| 541 | } | ||
| 542 | using Fn = hostent*(WSAAPI*)(const char*, int, int); | ||
| 543 | static Fn real_fn = host_proc<Fn>("gethostbyaddr"); | ||
| 544 | if (!real_fn) { | ||
| 545 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 546 | return nullptr; | ||
| 547 | } | ||
| 548 | return real_fn(addr, len, type); | ||
| 549 | } | ||
| 550 | |||
| 551 | HANDLE WSAAPI wsa_async_get_host_by_name_offline(HWND hWnd, u_int wMsg, const char* name, char* buf, int buflen) { | ||
| 552 | if (!is_loopback_node_a(name)) { | ||
| 553 | log_refused("WSAAsyncGetHostByName", name ? name : "<null>"); | ||
| 554 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 555 | return nullptr; | ||
| 556 | } | ||
| 557 | using Fn = HANDLE(WSAAPI*)(HWND, u_int, const char*, char*, int); | ||
| 558 | static Fn real_fn = host_proc<Fn>("WSAAsyncGetHostByName"); | ||
| 559 | if (!real_fn) { | ||
| 560 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 561 | return nullptr; | ||
| 562 | } | ||
| 563 | return real_fn(hWnd, wMsg, name, buf, buflen); | ||
| 564 | } | ||
| 565 | |||
| 566 | HANDLE WSAAPI wsa_async_get_host_by_addr_offline(HWND hWnd, u_int wMsg, const char* addr, int len, int type, | ||
| 567 | char* buf, int buflen) { | ||
| 568 | if (!is_loopback_raw_addr(addr, len, type)) { | ||
| 569 | log_refused("WSAAsyncGetHostByAddr", "non-loopback"); | ||
| 570 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 571 | return nullptr; | ||
| 572 | } | ||
| 573 | using Fn = HANDLE(WSAAPI*)(HWND, u_int, const char*, int, int, char*, int); | ||
| 574 | static Fn real_fn = host_proc<Fn>("WSAAsyncGetHostByAddr"); | ||
| 575 | if (!real_fn) { | ||
| 576 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 577 | return nullptr; | ||
| 578 | } | ||
| 579 | return real_fn(hWnd, wMsg, addr, len, type, buf, buflen); | ||
| 580 | } | ||
| 581 | |||
| 582 | INT WSAAPI getnameinfo_offline(const sockaddr* sa, socklen_t salen, PCHAR host, DWORD host_size, PCHAR serv, | ||
| 583 | DWORD serv_size, INT flags) { | ||
| 584 | if (!is_loopback_sockaddr(sa, static_cast<int>(salen))) { | ||
| 585 | if ((flags & NI_NAMEREQD) != 0) { | ||
| 586 | log_refused("getnameinfo", format_sockaddr(sa, static_cast<int>(salen))); | ||
| 587 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 588 | return WSAHOST_NOT_FOUND; | ||
| 589 | } | ||
| 590 | flags |= NI_NUMERICHOST; | ||
| 591 | } | ||
| 592 | using Fn = INT(WSAAPI*)(const sockaddr*, socklen_t, PCHAR, DWORD, PCHAR, DWORD, INT); | ||
| 593 | static Fn real_fn = host_proc<Fn>("getnameinfo"); | ||
| 594 | if (!real_fn) { | ||
| 595 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 596 | return WSAHOST_NOT_FOUND; | ||
| 597 | } | ||
| 598 | return real_fn(sa, salen, host, host_size, serv, serv_size, flags); | ||
| 599 | } | ||
| 600 | |||
| 601 | INT WSAAPI get_name_info_w_offline(const sockaddr* sa, socklen_t salen, PWCHAR host, DWORD host_size, PWCHAR serv, | ||
| 602 | DWORD serv_size, INT flags) { | ||
| 603 | if (!is_loopback_sockaddr(sa, static_cast<int>(salen))) { | ||
| 604 | if ((flags & NI_NAMEREQD) != 0) { | ||
| 605 | log_refused("GetNameInfoW", format_sockaddr(sa, static_cast<int>(salen))); | ||
| 606 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 607 | return WSAHOST_NOT_FOUND; | ||
| 608 | } | ||
| 609 | flags |= NI_NUMERICHOST; | ||
| 610 | } | ||
| 611 | using Fn = INT(WSAAPI*)(const sockaddr*, socklen_t, PWCHAR, DWORD, PWCHAR, DWORD, INT); | ||
| 612 | static Fn real_fn = host_proc<Fn>("GetNameInfoW"); | ||
| 613 | if (!real_fn) { | ||
| 614 | set_wsa_error(WSAHOST_NOT_FOUND); | ||
| 615 | return WSAHOST_NOT_FOUND; | ||
| 616 | } | ||
| 617 | return real_fn(sa, salen, host, host_size, serv, serv_size, flags); | ||
| 618 | } | ||
| 619 | |||
| 620 | // ---- WSAIoctl extension-function interception (ConnectEx / WSASendMsg) ---- | ||
| 621 | |||
| 622 | std::atomic<LPFN_CONNECTEX> g_host_connect_ex{nullptr}; | ||
| 623 | std::atomic<LPFN_WSASENDMSG> g_host_wsa_send_msg_ext{nullptr}; | ||
| 624 | |||
| 625 | BOOL PASCAL connect_ex_offline(SOCKET s, const sockaddr* name, int namelen, PVOID send_buf, DWORD send_len, | ||
| 626 | LPDWORD bytes_sent, LPOVERLAPPED overlapped) { | ||
| 627 | if (!is_loopback_sockaddr(name, namelen)) { | ||
| 628 | log_refused("ConnectEx", format_sockaddr(name, namelen)); | ||
| 629 | set_wsa_error(WSAENETUNREACH); | ||
| 630 | return FALSE; | ||
| 631 | } | ||
| 632 | LPFN_CONNECTEX real_fn = g_host_connect_ex.load(std::memory_order_acquire); | ||
| 633 | if (!real_fn) { | ||
| 634 | set_wsa_error(WSAENETUNREACH); | ||
| 635 | return FALSE; | ||
| 636 | } | ||
| 637 | return real_fn(s, name, namelen, send_buf, send_len, bytes_sent, overlapped); | ||
| 638 | } | ||
| 639 | |||
| 640 | int PASCAL wsa_send_msg_ext_offline(SOCKET s, LPWSAMSG msg, DWORD flags, LPDWORD bytes_sent, | ||
| 641 | LPWSAOVERLAPPED overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion) { | ||
| 642 | if (msg && msg->name && msg->namelen > 0 && !is_loopback_sockaddr(msg->name, msg->namelen)) { | ||
| 643 | log_refused("WSASendMsg(ext)", format_sockaddr(msg->name, msg->namelen)); | ||
| 644 | set_wsa_error(WSAENETUNREACH); | ||
| 645 | return SOCKET_ERROR; | ||
| 646 | } | ||
| 647 | LPFN_WSASENDMSG real_fn = g_host_wsa_send_msg_ext.load(std::memory_order_acquire); | ||
| 648 | if (!real_fn) { | ||
| 649 | set_wsa_error(WSAENETUNREACH); | ||
| 650 | return SOCKET_ERROR; | ||
| 651 | } | ||
| 652 | return real_fn(s, msg, flags, bytes_sent, overlapped, completion); | ||
| 653 | } | ||
| 654 | |||
| 655 | int WSAAPI wsa_ioctl_offline(SOCKET s, DWORD io_control_code, LPVOID in_buf, DWORD in_len, LPVOID out_buf, | ||
| 656 | DWORD out_len, LPDWORD bytes_returned, LPWSAOVERLAPPED overlapped, | ||
| 657 | LPWSAOVERLAPPED_COMPLETION_ROUTINE completion) { | ||
| 658 | using Fn = int(WSAAPI*)(SOCKET, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPWSAOVERLAPPED, | ||
| 659 | LPWSAOVERLAPPED_COMPLETION_ROUTINE); | ||
| 660 | static Fn real_fn = host_proc<Fn>("WSAIoctl"); | ||
| 661 | if (!real_fn) { | ||
| 662 | set_wsa_error(WSAEINVAL); | ||
| 663 | return SOCKET_ERROR; | ||
| 664 | } | ||
| 665 | |||
| 666 | if (io_control_code == SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER) { | ||
| 667 | set_wsa_error(WSAEINVAL); | ||
| 668 | return SOCKET_ERROR; | ||
| 669 | } | ||
| 670 | |||
| 671 | if (io_control_code == SIO_GET_EXTENSION_FUNCTION_POINTER && in_buf && in_len >= sizeof(GUID)) { | ||
| 672 | static constexpr GUID kConnectExGuid = WSAID_CONNECTEX; | ||
| 673 | static constexpr GUID kSendMsgGuid = WSAID_WSASENDMSG; | ||
| 674 | GUID requested{}; | ||
| 675 | std::memcpy(&requested, in_buf, sizeof(requested)); | ||
| 676 | |||
| 677 | if (std::memcmp(&requested, &kConnectExGuid, sizeof(GUID)) == 0) { | ||
| 678 | if (!out_buf || out_len < sizeof(void*) || !bytes_returned) { | ||
| 679 | set_wsa_error(WSAEFAULT); | ||
| 680 | return SOCKET_ERROR; | ||
| 681 | } | ||
| 682 | LPFN_CONNECTEX real_ext = nullptr; | ||
| 683 | DWORD returned = 0; | ||
| 684 | const int rc = real_fn(s, io_control_code, in_buf, in_len, &real_ext, sizeof(real_ext), &returned, | ||
| 685 | overlapped, completion); | ||
| 686 | if (rc != 0) return rc; | ||
| 687 | g_host_connect_ex.store(real_ext, std::memory_order_release); | ||
| 688 | LPFN_CONNECTEX wrapped = &connect_ex_offline; | ||
| 689 | std::memcpy(out_buf, &wrapped, sizeof(wrapped)); | ||
| 690 | *bytes_returned = sizeof(wrapped); | ||
| 691 | return 0; | ||
| 692 | } | ||
| 693 | if (std::memcmp(&requested, &kSendMsgGuid, sizeof(GUID)) == 0) { | ||
| 694 | if (!out_buf || out_len < sizeof(void*) || !bytes_returned) { | ||
| 695 | set_wsa_error(WSAEFAULT); | ||
| 696 | return SOCKET_ERROR; | ||
| 697 | } | ||
| 698 | LPFN_WSASENDMSG real_ext = nullptr; | ||
| 699 | DWORD returned = 0; | ||
| 700 | const int rc = real_fn(s, io_control_code, in_buf, in_len, &real_ext, sizeof(real_ext), &returned, | ||
| 701 | overlapped, completion); | ||
| 702 | if (rc != 0) return rc; | ||
| 703 | g_host_wsa_send_msg_ext.store(real_ext, std::memory_order_release); | ||
| 704 | LPFN_WSASENDMSG wrapped = &wsa_send_msg_ext_offline; | ||
| 705 | std::memcpy(out_buf, &wrapped, sizeof(wrapped)); | ||
| 706 | *bytes_returned = sizeof(wrapped); | ||
| 707 | return 0; | ||
| 708 | } | ||
| 709 | } | ||
| 710 | |||
| 711 | return real_fn(s, io_control_code, in_buf, in_len, out_buf, out_len, bytes_returned, overlapped, completion); | ||
| 712 | } | ||
| 713 | |||
| 714 | } // namespace | ||
| 715 | } // namespace rt::ws2 | ||
| 716 | |||
| 717 | namespace { | ||
| 718 | using namespace rt::ws2; | ||
| 719 | } // namespace | ||
| 720 | |||
| 721 | // Both named exports and the fixed Windows ws2_32.dll ordinals (#2 bind, #4 connect, #20 sendto, #51 gethostbyaddr, | ||
| 722 | // #52 gethostbyname, #102 WSAAsyncGetHostByAddr, #103 WSAAsyncGetHostByName) are registered so static imports by | ||
| 723 | // ordinal and dynamic GetProcAddress lookups resolve to the same offline wrappers. | ||
| 724 | SHIM_TABLE(ws2_offline, | ||
| 725 | {"ws2_32.dll", "bind", reinterpret_cast<void*>(&bind_offline)}, | ||
| 726 | {"ws2_32.dll", "#2", reinterpret_cast<void*>(&bind_offline)}, | ||
| 727 | {"ws2_32.dll", "connect", reinterpret_cast<void*>(&connect_offline)}, | ||
| 728 | {"ws2_32.dll", "#4", reinterpret_cast<void*>(&connect_offline)}, | ||
| 729 | {"ws2_32.dll", "sendto", reinterpret_cast<void*>(&sendto_offline)}, | ||
| 730 | {"ws2_32.dll", "#20", reinterpret_cast<void*>(&sendto_offline)}, | ||
| 731 | {"ws2_32.dll", "gethostbyaddr", reinterpret_cast<void*>(&gethostbyaddr_offline)}, | ||
| 732 | {"ws2_32.dll", "#51", reinterpret_cast<void*>(&gethostbyaddr_offline)}, | ||
| 733 | {"ws2_32.dll", "gethostbyname", reinterpret_cast<void*>(&gethostbyname_offline)}, | ||
| 734 | {"ws2_32.dll", "#52", reinterpret_cast<void*>(&gethostbyname_offline)}, | ||
| 735 | {"ws2_32.dll", "WSAAsyncGetHostByAddr", reinterpret_cast<void*>(&wsa_async_get_host_by_addr_offline)}, | ||
| 736 | {"ws2_32.dll", "#102", reinterpret_cast<void*>(&wsa_async_get_host_by_addr_offline)}, | ||
| 737 | {"ws2_32.dll", "WSAAsyncGetHostByName", reinterpret_cast<void*>(&wsa_async_get_host_by_name_offline)}, | ||
| 738 | {"ws2_32.dll", "#103", reinterpret_cast<void*>(&wsa_async_get_host_by_name_offline)}, | ||
| 739 | {"ws2_32.dll", "getaddrinfo", reinterpret_cast<void*>(&getaddrinfo_offline)}, | ||
| 740 | {"ws2_32.dll", "GetAddrInfoW", reinterpret_cast<void*>(&get_addr_info_w_offline)}, | ||
| 741 | {"ws2_32.dll", "GetAddrInfoExA", reinterpret_cast<void*>(&get_addr_info_ex_a_offline)}, | ||
| 742 | {"ws2_32.dll", "GetAddrInfoExW", reinterpret_cast<void*>(&get_addr_info_ex_w_offline)}, | ||
| 743 | {"ws2_32.dll", "getnameinfo", reinterpret_cast<void*>(&getnameinfo_offline)}, | ||
| 744 | {"ws2_32.dll", "GetNameInfoW", reinterpret_cast<void*>(&get_name_info_w_offline)}, | ||
| 745 | {"ws2_32.dll", "WSAConnect", reinterpret_cast<void*>(&wsa_connect_offline)}, | ||
| 746 | {"ws2_32.dll", "WSAConnectByNameA", reinterpret_cast<void*>(&wsa_connect_by_name_a_offline)}, | ||
| 747 | {"ws2_32.dll", "WSAConnectByNameW", reinterpret_cast<void*>(&wsa_connect_by_name_w_offline)}, | ||
| 748 | {"ws2_32.dll", "WSAConnectByList", reinterpret_cast<void*>(&wsa_connect_by_list_offline)}, | ||
| 749 | {"ws2_32.dll", "WSASendTo", reinterpret_cast<void*>(&wsa_send_to_offline)}, | ||
| 750 | {"ws2_32.dll", "WSASendMsg", reinterpret_cast<void*>(&wsa_send_msg_offline)}, | ||
| 751 | {"ws2_32.dll", "WSAIoctl", reinterpret_cast<void*>(&wsa_ioctl_offline)}, | ||
| 752 | ); | ||