diff --git a/src/detection/wm/wm_apple.m b/src/detection/wm/wm_apple.m index 2036cfd12..a1421107d 100644 --- a/src/detection/wm/wm_apple.m +++ b/src/detection/wm/wm_apple.m @@ -5,6 +5,7 @@ #include "common/stringUtils.h" #include +#include #import const char* ffDetectWMPlugin(FFstrbuf* pluginName) @@ -20,9 +21,10 @@ const char* ffDetectWMPlugin(FFstrbuf* pluginName) for(size_t i = 0; i < length / sizeof(struct kinfo_proc); i++) { - if (processes[i].kp_eproc.e_ppid != 1) continue; + const struct kinfo_proc* proc = &processes[i]; + if (proc->kp_eproc.e_ppid != 1) continue; - const char* comm = processes[i].kp_proc.p_comm; + const char* comm = proc->kp_proc.p_comm; if( !ffStrEqualsIgnCase(comm, "spectacle") && @@ -34,6 +36,37 @@ const char* ffDetectWMPlugin(FFstrbuf* pluginName) !ffStrEqualsIgnCase(comm, "rectangle") ) continue; + char buf[PROC_PIDPATHINFO_MAXSIZE]; + int length = proc_pidpath(proc->kp_proc.p_pid, buf, ARRAY_SIZE(buf)); + if (length > 0) + { + char* lastSlash = strrchr(buf, '/'); + if (lastSlash) + { + *lastSlash = '\0'; + if (ffStrEndsWith(buf, ".app/Contents/MacOS")) + { + lastSlash -= strlen("MacOS"); + strcpy(lastSlash, "Info.plist"); // X.app/Contents/Info.plist + NSError* error; + NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:@(buf)] + error:&error]; + if (dict) + { + ffStrbufSetS(pluginName, [dict[@"CFBundleName"] UTF8String]); + NSString* version = dict[@"CFBundleShortVersionString"]; + if (version) + { + ffStrbufAppendC(pluginName, ' '); + ffStrbufAppendS(pluginName, version.UTF8String); + } + + break; + } + } + } + } + ffStrbufAppendS(pluginName, comm); pluginName->chars[0] = (char) toupper(pluginName->chars[0]); break; @@ -50,11 +83,11 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE if (ffStrbufEqualS(wmName, "WindowServer")) { NSError* error; - NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"file:///System/Library/PrivateFrameworks/SkyLight.framework/Resources/version.plist"] + NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:@"/System/Library/PrivateFrameworks/SkyLight.framework/Resources/version.plist" isDirectory:NO] error:&error]; if (!dict) { - dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"file:///System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/version.plist"] + dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:@"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/version.plist" isDirectory:NO] error:&error]; }