2
2
* Process Hacker Network Tools -
3
3
* Whois dialog
4
4
*
5
- * Copyright (C) 2013-2020 dmex
5
+ * Copyright (C) 2013-2021 dmex
6
6
*
7
7
* This file is part of Process Hacker.
8
8
*
@@ -181,9 +181,9 @@ BOOLEAN WhoisExtractServerUrl(
181
181
ULONG_PTR whoisServerHostnameLength ;
182
182
PPH_STRING whoisServerName ;
183
183
184
- if ((whoisServerHostnameIndex = PhFindStringInString (WhoisResponse , 0 , L"whois:" )) == -1 )
184
+ if ((whoisServerHostnameIndex = PhFindStringInString (WhoisResponse , 0 , L"whois:" )) == SIZE_MAX )
185
185
return FALSE;
186
- if ((whoisServerHostnameLength = PhFindStringInString (WhoisResponse , whoisServerHostnameIndex , L"\n" )) == -1 )
186
+ if ((whoisServerHostnameLength = PhFindStringInString (WhoisResponse , whoisServerHostnameIndex , L"\n" )) == SIZE_MAX )
187
187
return FALSE;
188
188
if ((whoisServerHostnameLength = whoisServerHostnameLength - whoisServerHostnameIndex ) == 0 )
189
189
return FALSE;
@@ -217,9 +217,9 @@ BOOLEAN WhoisExtractReferralServer(
217
217
WCHAR urlPort [0x100 ] = L"" ;
218
218
WCHAR urlPath [0x100 ] = L"" ;
219
219
220
- if ((whoisServerHostnameIndex = PhFindStringInString (WhoisResponse , 0 , L"ReferralServer:" )) == -1 )
220
+ if ((whoisServerHostnameIndex = PhFindStringInString (WhoisResponse , 0 , L"ReferralServer:" )) == SIZE_MAX )
221
221
return FALSE;
222
- if ((whoisServerHostnameLength = PhFindStringInString (WhoisResponse , whoisServerHostnameIndex , L"\n" )) == -1 )
222
+ if ((whoisServerHostnameLength = PhFindStringInString (WhoisResponse , whoisServerHostnameIndex , L"\n" )) == SIZE_MAX )
223
223
return FALSE;
224
224
if ((whoisServerHostnameLength = whoisServerHostnameLength - whoisServerHostnameIndex ) == 0 )
225
225
return FALSE;
@@ -293,11 +293,23 @@ BOOLEAN WhoisConnectServer(
293
293
SOCKET whoisSocketHandle = INVALID_SOCKET ;
294
294
PDNS_RECORD dnsRecordList ;
295
295
296
- dnsRecordList = PhDnsQuery (
297
- NULL ,
298
- WhoisServerAddress ,
299
- DnsQueryMessageType
300
- );
296
+ if (PhGetIntegerSetting (L"EnableNetworkResolveDoH" ))
297
+ {
298
+ dnsRecordList = PhDnsQuery (
299
+ NULL ,
300
+ WhoisServerAddress ,
301
+ DnsQueryMessageType
302
+ );
303
+ }
304
+ else
305
+ {
306
+ dnsRecordList = PhDnsQuery2 (
307
+ NULL ,
308
+ WhoisServerAddress ,
309
+ DnsQueryMessageType ,
310
+ DNS_QUERY_NO_HOSTS_FILE // DNS_QUERY_BYPASS_CACHE
311
+ );
312
+ }
301
313
302
314
if (!dnsRecordList )
303
315
return FALSE;
@@ -320,6 +332,31 @@ BOOLEAN WhoisConnectServer(
320
332
321
333
if ((whoisSocketHandle = WSASocket (AF_INET , SOCK_STREAM , IPPROTO_TCP , NULL , 0 , 0 )) != INVALID_SOCKET )
322
334
{
335
+ ULONG bestInterfaceIndex ;
336
+
337
+ if (GetBestInterfaceEx ((PSOCKADDR )& remoteAddr , & bestInterfaceIndex ) == ERROR_SUCCESS )
338
+ {
339
+ MIB_IPFORWARD_ROW2 bestAddressRoute = { 0 };
340
+ SOCKADDR_INET destinationAddress = { 0 };
341
+ SOCKADDR_INET bestSourceAddress = { 0 };
342
+
343
+ destinationAddress .si_family = AF_INET ;
344
+ destinationAddress .Ipv4 = remoteAddr ;
345
+
346
+ if (GetBestRoute2 (
347
+ NULL ,
348
+ bestInterfaceIndex ,
349
+ NULL ,
350
+ & destinationAddress ,
351
+ 0 ,
352
+ & bestAddressRoute ,
353
+ & bestSourceAddress
354
+ ) == ERROR_SUCCESS )
355
+ {
356
+ bind (whoisSocketHandle , (PSOCKADDR )& bestSourceAddress .Ipv4 , sizeof (bestSourceAddress .Ipv4 ));
357
+ }
358
+ }
359
+
323
360
if (WSAConnect (whoisSocketHandle , (PSOCKADDR )& remoteAddr , sizeof (SOCKADDR_IN ), NULL , NULL , NULL , NULL ) != SOCKET_ERROR )
324
361
break ;
325
362
@@ -343,6 +380,31 @@ BOOLEAN WhoisConnectServer(
343
380
344
381
if ((whoisSocketHandle = WSASocket (AF_INET6 , SOCK_STREAM , IPPROTO_TCP , NULL , 0 , 0 )) != INVALID_SOCKET )
345
382
{
383
+ ULONG bestInterfaceIndex ;
384
+
385
+ if (GetBestInterfaceEx ((PSOCKADDR )& remoteAddr , & bestInterfaceIndex ) == ERROR_SUCCESS )
386
+ {
387
+ MIB_IPFORWARD_ROW2 bestAddressRoute = { 0 };
388
+ SOCKADDR_INET destinationAddress = { 0 };
389
+ SOCKADDR_INET bestSourceAddress = { 0 };
390
+
391
+ destinationAddress .si_family = AF_INET6 ;
392
+ destinationAddress .Ipv6 = remoteAddr ;
393
+
394
+ if (GetBestRoute2 (
395
+ NULL ,
396
+ bestInterfaceIndex ,
397
+ NULL ,
398
+ & destinationAddress ,
399
+ 0 ,
400
+ & bestAddressRoute ,
401
+ & bestSourceAddress
402
+ ) == ERROR_SUCCESS )
403
+ {
404
+ bind (whoisSocketHandle , (PSOCKADDR )& bestSourceAddress .Ipv6 , sizeof (bestSourceAddress .Ipv6 ));
405
+ }
406
+ }
407
+
346
408
if (WSAConnect (whoisSocketHandle , (PSOCKADDR )& remoteAddr , sizeof (SOCKADDR_IN6 ), NULL , NULL , NULL , NULL ) != SOCKET_ERROR )
347
409
break ;
348
410
0 commit comments