From dcbfae7f726ba1079fb299aa3541b242d5cd012a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 1 Aug 2024 16:04:37 +0800 Subject: [PATCH] Wifi (macOS): use private property to fetch ssid --- src/detection/wifi/wifi_apple.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/detection/wifi/wifi_apple.m b/src/detection/wifi/wifi_apple.m index 28edee5eb..55085fda1 100644 --- a/src/detection/wifi/wifi_apple.m +++ b/src/detection/wifi/wifi_apple.m @@ -6,21 +6,17 @@ struct Apple80211; // https://code.google.com/archive/p/iphone-wireless/wikis/Apple80211.wiki // 0 is successful; < 0 is failure -int Apple80211Open(struct Apple80211 **handle) __attribute__((weak_import)); -int Apple80211BindToInterface(struct Apple80211 *handle, CFStringRef interface) __attribute__((weak_import)); int Apple80211GetInfoCopy(struct Apple80211 *handle, CFDictionaryRef *info) __attribute__((weak_import)); -int Apple80211Close(struct Apple80211 *handle) __attribute__((weak_import)); -static NSDictionary* getWifiInfoByApple80211(NSString* ifName) +@interface CWInterface() +@property (readonly) struct Apple80211* device; +@end + +static NSDictionary* getWifiInfoByApple80211(CWInterface* inf) { - if (!Apple80211Open || !Apple80211BindToInterface || !Apple80211GetInfoCopy || !Apple80211Close) return NULL; - - struct Apple80211* handle = NULL; - if (Apple80211Open(&handle) < 0) return NULL; - if (Apple80211BindToInterface(handle, (__bridge CFStringRef)ifName) < 0) return NULL; - CFDictionaryRef result; - if (Apple80211GetInfoCopy(handle, &result) < 0) return NULL; - Apple80211Close(handle); + if (!Apple80211GetInfoCopy) return NULL; + CFDictionaryRef result = NULL; + if (Apple80211GetInfoCopy(inf.device, &result) < 0) return NULL; return CFBridgingRelease(result); } @@ -57,14 +53,14 @@ const char* ffDetectWifi(FFlist* result) if (inf.ssid) // https://developer.apple.com/forums/thread/732431 ffStrbufAppendS(&item->conn.ssid, inf.ssid.UTF8String); - else if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) + else if (apple || (apple = getWifiInfoByApple80211(inf))) ffStrbufAppendS(&item->conn.ssid, [[apple valueForKey:@"SSID_STR"] UTF8String]); else ffStrbufSetStatic(&item->conn.ssid, ""); // https://developer.apple.com/forums/thread/732431 if (inf.bssid) ffStrbufAppendS(&item->conn.bssid, inf.bssid.UTF8String); - else if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) + else if (apple || (apple = getWifiInfoByApple80211(inf))) ffStrbufAppendS(&item->conn.bssid, [[apple valueForKey:@"BSSID"] UTF8String]); switch(inf.activePHYMode) @@ -152,7 +148,7 @@ const char* ffDetectWifi(FFlist* result) break; case kCWSecurityUnknown: // Sonoma... - if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) + if (apple || (apple = getWifiInfoByApple80211(inf))) { NSDictionary* authType = [apple valueForKey:@"AUTH_TYPE"]; if (authType)