From e025f28cdcc22b8d91a0f1f0900e79bc2483447c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 12 Sep 2025 14:28:01 +0800 Subject: [PATCH] Wifi (macOS): removes wdutil-based Wi-Fi detection code Let's stop this hide and seek game. --- src/detection/wifi/wifi_apple.m | 190 +------------------------------- 1 file changed, 1 insertion(+), 189 deletions(-) diff --git a/src/detection/wifi/wifi_apple.m b/src/detection/wifi/wifi_apple.m index 02521294f..de2a6ff3a 100644 --- a/src/detection/wifi/wifi_apple.m +++ b/src/detection/wifi/wifi_apple.m @@ -52,184 +52,7 @@ static bool getWifiInfoByIpconfig(FFstrbuf* ipconfig, const char* prefix, FFstrb return true; } -static const char* detectByWdutil(FFlist* result) -{ - FF_STRBUF_AUTO_DESTROY wdutil = ffStrbufCreate(); - - if (geteuid() != 0) - return "wdutil requires root privileges to run"; - - bool ok = ffProcessAppendStdOut(&wdutil, (char* const[]) { - "/usr/bin/wdutil", - "info", - NULL - }) == NULL; - if (!ok) return "Failed to run wdutil info command"; - - // ... - // ———————————————————————————————————————————————————————————————————— - // WIFI - // ———————————————————————————————————————————————————————————————————— - // - // ———————————————————————————————————————————————————————————————————— - // ... - - { - // Remove unrelated lines - uint32_t start = ffStrbufFirstIndexS(&wdutil, "\nWIFI\n"); - if (start >= wdutil.length) - return "wdutil info command did not return WIFI section (1)"; - - start += 6; // Skip "\nWIFI\n" - start = ffStrbufNextIndexC(&wdutil, start, '\n'); - if (start >= wdutil.length) - return "wdutil info command did not return WIFI section (2)"; - start++; - - uint32_t end = ffStrbufNextIndexS(&wdutil, start, "\n——————————"); - - ffStrbufSubstr(&wdutil, start, end); - } - - - // `wdutil info ` returns a string like this: - // MAC Address : xx:xx:xx:xx:xx:xx (hw=xx:xx:xx:xx:xx:xx) - // Interface Name : en0 - // Power : On [On] - // Op Mode : STA - // SSID : XXX-XXX - // BSSID : xx:xx:xx:xx:xx:xx - // RSSI : -58 dBm - // CCA : 29 % - // Noise : -96 dBm - // Tx Rate : 173.0 Mbps - // Security : WPA2 Enterprise - // 802.1X Mode : User - // 802.1X Supplicant : Authenticated - // PHY Mode : 11ac - // MCS Index : 8 - // Guard Interval : 400 - // NSS : 2 - // Channel : 5g165/20 - // Country Code : CN - // Scan Cache Count : 28 - // NetworkServiceID : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - // IPv4 Config Method : DHCP - // IPv4 Address : xx.xx.xx.xx - // IPv4 Router : xx.xx.xx.x - // IPv6 Config Method : Automatic - // IPv6 Address : xxxx:xxxx:xxxx:xxxx:xxxx:xxxx - // IPv6 Router : None - // DNS : xxx.xxx.xxx.xxx - // : xxx.xxx.xxx.xxx - // BTC Mode : Off - // Desense : - // Chain Ack : [] - // BTC Profile 2.4GHz : Disabled - // BTC Profile 5GHz : Disabled - // Sniffer Supported : YES - // Supports 6e : No - // Supported Channels : 2g1/20,2g2/20,2g3/20,2g4/20,2g5/20,2g6/20,2g7/20,2g8/20,2g9/20,2g10/20,2g11/20,2g12/20,2g13/20,5g36/20,5g40/20,5g44/20,5g48/20,5g52/20,5g56/20,5g60/20,5g64/20,5g149/20,5g153/20,5g157/20,5g161/20,5g165/20,5g36/40,5g40/40,5g44/40,5g48/40,5g52/40,5g56/40,5g60/40,5g64/40,5g149/40,5g153/40,5g157/40,5g161/40,5g36/80,5g40/80,5g44/80,5g48/80,5g52/80,5g56/80,5g60/80,5g64/80,5g149/80,5g153/80,5g157/80,5g161/80 - - FFWifiResult* item = (FFWifiResult*) ffListAdd(result); - ffStrbufInit(&item->inf.description); - ffStrbufInit(&item->inf.status); - ffStrbufInit(&item->conn.status); - ffStrbufInit(&item->conn.ssid); - ffStrbufInit(&item->conn.bssid); - ffStrbufInit(&item->conn.protocol); - ffStrbufInit(&item->conn.security); - item->conn.signalQuality = -DBL_MAX; - item->conn.rxRate = -DBL_MAX; - item->conn.txRate = -DBL_MAX; - item->conn.channel = 0; - item->conn.frequency = 0; - - char* line = NULL; - size_t len = 0; - while (ffStrbufGetline(&line, &len, &wdutil)) - { - const char* key = line + 4; // Skip " " - const char* value = key + strlen("MAC Address : "); - switch (key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3]) - { - case 'Inte': // Interface Name - ffStrbufAppendS(&item->inf.description, value); - break; - case 'Powe': // Power - if (ffStrStartsWith(value, "On ")) - ffStrbufSetStatic(&item->inf.status, "Power On"); - else - ffStrbufSetStatic(&item->inf.status, "Power Off"); - break; - case 'SSID': // SSID - ffStrbufAppendS(&item->conn.ssid, value); - break; - case 'BSSI': // BSSID - if (ffStrEquals(value, "None") && ffStrbufEqualS(&item->conn.ssid, "None")) - { - ffStrbufSetStatic(&item->conn.status, "Inactive"); - ffStrbufClear(&item->conn.ssid); // None - return NULL; - } - ffStrbufSetStatic(&item->conn.status, "Active"); - ffStrbufAppendS(&item->conn.bssid, value); - break; - case 'RSSI': // RSSI - item->conn.signalQuality = rssiToSignalQuality((int) strtol(value, NULL, 10)); - break; - case 'Tx R': // Tx Rate - item->conn.txRate = strtod(value, NULL); - break; - case 'Secu': // Security - if (ffStrEquals(value, "None")) - ffStrbufSetStatic(&item->conn.security, "Insecure"); - else - ffStrbufAppendS(&item->conn.security, value); - break; - case 'PHY ': // PHY Mode - if (ffStrEquals(value, "None")) - ffStrbufSetStatic(&item->conn.protocol, "none"); - else if (ffStrEquals(value, "11a")) - ffStrbufSetStatic(&item->conn.protocol, "802.11a"); - else if (ffStrEquals(value, "11b")) - ffStrbufSetStatic(&item->conn.protocol, "802.11b"); - else if (ffStrEquals(value, "11g")) - ffStrbufSetStatic(&item->conn.protocol, "802.11g"); - else if (ffStrEquals(value, "11n")) - ffStrbufSetStatic(&item->conn.protocol, "802.11n (Wi-Fi 4)"); - else if (ffStrEquals(value, "11ac")) - ffStrbufSetStatic(&item->conn.protocol, "802.11ac (Wi-Fi 5)"); - else if (ffStrEquals(value, "11ax")) - ffStrbufSetStatic(&item->conn.protocol, "802.11ax (Wi-Fi 6)"); - else if (ffStrEquals(value, "11be")) - ffStrbufSetStatic(&item->conn.protocol, "802.11be (Wi-Fi 7)"); - else - ffStrbufAppendS(&item->conn.protocol, value); - break; - case 'Chan': // Channel - { - int band, channel; - if (sscanf(value, "%dg%d", &band, &channel) == 2) - { - item->conn.channel = (uint16_t) channel; - switch (band) - { - case 2: item->conn.frequency = 2400; break; - case 5: item->conn.frequency = 5400; break; - case 6: item->conn.frequency = 6400; break; - default: item->conn.frequency = 0; break; - } - } - break; - } - } - } - - return NULL; -} - -static const char* detectByCoreWlan(FFlist* result) +const char* ffDetectWifi(FFlist* result) { NSArray* interfaces = CWWiFiClient.sharedWiFiClient.interfaces; if (!interfaces) @@ -382,14 +205,3 @@ static const char* detectByCoreWlan(FFlist* result) return NULL; } - -const char* ffDetectWifi(FFlist* result) -{ - if (@available(macOS 15.6, *)) - { - if (detectByWdutil(result) == NULL) - return NULL; - } - - return detectByCoreWlan(result); -}