From eee49f4abe9d02ab0ea5e86142699833c5112a4a Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Fri, 6 Jun 2025 01:53:58 +0800 Subject: [PATCH] exclude DNS over HTTPS protocol --- .../network/proxy/plugin/ProcessInfoPlugin.kt | 5 +++++ .../network/proxy/vpn/util/ProcessInfoManager.kt | 11 +++++++++++ lib/native/process_info.dart | 10 +++++++++- lib/network/channel/network.dart | 16 ++++++++++++---- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/kotlin/com/network/proxy/plugin/ProcessInfoPlugin.kt b/android/app/src/main/kotlin/com/network/proxy/plugin/ProcessInfoPlugin.kt index 548b7e1..a3bd400 100644 --- a/android/app/src/main/kotlin/com/network/proxy/plugin/ProcessInfoPlugin.kt +++ b/android/app/src/main/kotlin/com/network/proxy/plugin/ProcessInfoPlugin.kt @@ -45,6 +45,11 @@ class ProcessInfoPlugin : AndroidFlutterPlugin() { } } + "getRemoteAddressByPort" -> { + val port = call.argument("port") + result.success(processInfoManager.getRemoteAddressByPort(port!!)) + } + else -> { result.notImplemented() } diff --git a/android/app/src/main/kotlin/com/network/proxy/vpn/util/ProcessInfoManager.kt b/android/app/src/main/kotlin/com/network/proxy/vpn/util/ProcessInfoManager.kt index c78e439..2c31d6a 100644 --- a/android/app/src/main/kotlin/com/network/proxy/vpn/util/ProcessInfoManager.kt +++ b/android/app/src/main/kotlin/com/network/proxy/vpn/util/ProcessInfoManager.kt @@ -154,6 +154,17 @@ class ProcessInfoManager private constructor() { return null } + fun getRemoteAddressByPort(localPort: Int): Map? { + val networkInfo = localPortCache.get(localPort) + if (networkInfo != null) { + return mapOf( + "remoteHost" to networkInfo.remoteHost, + "remotePort" to networkInfo.remotePort + ) + } + return null + } + private fun getProcessInfo(uid: Int): ProcessInfo? { var appInfo = appInfoCache.get(uid) if (appInfo != null) return appInfo diff --git a/lib/native/process_info.dart b/lib/native/process_info.dart index 3ce0c29..e111e3f 100644 --- a/lib/native/process_info.dart +++ b/lib/native/process_info.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:proxypin/network/channel/host_port.dart'; import 'package:proxypin/network/util/process_info.dart'; class ProcessInfoPlugin { @@ -14,7 +15,14 @@ class ProcessInfoPlugin { os: Platform.operatingSystem, icon: process['icon'], remoteHost: process['remoteHost'], - remotePost: process['remotePost']); + remotePost: process['remotePort']); + }); + } + + static Future getRemoteAddressByPort(int port) { + return _methodChannel.invokeMethod('getRemoteAddressByPort', {"port": port}).then((process) { + if (process == null) return null; + return HostAndPort.host(process['remoteHost'], process['remotePort']); }); } } diff --git a/lib/network/channel/network.dart b/lib/network/channel/network.dart index be83a4e..f85bd75 100644 --- a/lib/network/channel/network.dart +++ b/lib/network/channel/network.dart @@ -18,6 +18,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; +import 'package:proxypin/native/process_info.dart'; import 'package:proxypin/network/bin/configuration.dart'; import 'package:proxypin/network/channel/channel.dart'; import 'package:proxypin/network/channel/channel_context.dart'; @@ -141,17 +142,24 @@ class Server extends Network { var hostAndPort = channelContext.host; try { String? serviceName = TLS.getDomain(data) ?? hostAndPort?.host; + bool isHttp = true; if (hostAndPort == null) { var domain = serviceName; var port = 443; + if (domain == null) { - var process = await ProcessInfoUtils.getProcessByPort( - channel.remoteSocketAddress, channel.remoteSocketAddress.toString()); - domain = process?.remoteHost; - port = process?.remotePost ?? port; + var remote = await ProcessInfoPlugin.getRemoteAddressByPort(channel.remoteSocketAddress.port); + domain = remote?.host; + port = remote?.port ?? port; serviceName = domain; + + // DNS over HTTPS + if (remote?.port == 853 && TLS.supportProtocols(data)?.contains("http/1.1") == false) { + isHttp = false; + } } + hostAndPort = HostAndPort.host(domain!, port, scheme: HostAndPort.httpsScheme); }