From 4bb405a5e48e0a145518f320324dce5847b1e844 Mon Sep 17 00:00:00 2001
From: Patrick Wardle <code@objective-see.com>
Date: Sat, 19 Nov 2022 11:25:15 -1000
Subject: [PATCH] replaced deprecated APIs

---
 Application/Application/AVMonitor.m           |  5 +-
 Application/Application/AboutWindow.xib       |  6 +-
 Application/Application/UpdateWindow.xib      |  6 +-
 Installer/Source/AboutWindow.xib              |  6 +-
 Installer/Source/ConfigureWindowController.m  | 64 ++++++++++++++-----
 .../Source/ConfigureWindowController.xib      |  2 +-
 Shared/Utilities.m                            | 12 ++--
 Shared/patrons.txt                            |  2 +-
 8 files changed, 67 insertions(+), 36 deletions(-)

diff --git a/Application/Application/AVMonitor.m b/Application/Application/AVMonitor.m
index 8c9e078..c8f65de 100644
--- a/Application/Application/AVMonitor.m
+++ b/Application/Application/AVMonitor.m
@@ -852,10 +852,11 @@ bail:
         goto bail;
     }
     
-    //ignore leak warning
+    //ignore warning
     #pragma clang diagnostic push
+    #pragma clang diagnostic ignored "-Wpointer-to-int-cast"
     #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
-    
+
     //grab connection ID
     objectID = (UInt32)[device performSelector:methodSelector withObject:nil];
     
diff --git a/Application/Application/AboutWindow.xib b/Application/Application/AboutWindow.xib
index 54f3aea..6929566 100644
--- a/Application/Application/AboutWindow.xib
+++ b/Application/Application/AboutWindow.xib
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -16,7 +16,7 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
+            <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
             <rect key="contentRect" x="196" y="240" width="486" height="301"/>
             <rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
             <view key="contentView" id="se5-gp-TjO">
diff --git a/Application/Application/UpdateWindow.xib b/Application/Application/UpdateWindow.xib
index b6233b8..7775905 100644
--- a/Application/Application/UpdateWindow.xib
+++ b/Application/Application/UpdateWindow.xib
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -18,7 +18,7 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
+            <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
             <rect key="contentRect" x="196" y="240" width="422" height="133"/>
             <rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
             <view key="contentView" id="se5-gp-TjO">
diff --git a/Installer/Source/AboutWindow.xib b/Installer/Source/AboutWindow.xib
index 860d94a..ce4af51 100644
--- a/Installer/Source/AboutWindow.xib
+++ b/Installer/Source/AboutWindow.xib
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -17,7 +17,7 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
+            <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
             <rect key="contentRect" x="196" y="240" width="486" height="301"/>
             <rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
             <view key="contentView" id="se5-gp-TjO">
diff --git a/Installer/Source/ConfigureWindowController.m b/Installer/Source/ConfigureWindowController.m
index 948801a..396b80a 100644
--- a/Installer/Source/ConfigureWindowController.m
+++ b/Installer/Source/ConfigureWindowController.m
@@ -161,10 +161,10 @@ extern os_log_t logHandle;
     
     //app path
     NSURL* appPath = nil;
-    
-    //error
-    NSError* error = nil;
 
+    //app config
+    NSWorkspaceOpenConfiguration* configuration = nil;
+    
     //grab tag
     action = ((NSButton*)sender).tag;
     
@@ -235,21 +235,47 @@ extern os_log_t logHandle;
                 //init app path
                 appPath = [NSURL fileURLWithPath:[@"/Applications" stringByAppendingPathComponent:APP_NAME]];
                 
-                //dbg msg
-                os_log_debug(logHandle, "now launching: %{public}@", appPath);
+                //alloc configuration
+                configuration = [[NSWorkspaceOpenConfiguration alloc] init];
                 
+                //set args
+                configuration.arguments = @[INITIAL_LAUNCH];
+                
+                //unset recent
+                configuration.addsToRecentItems = NO;
+                
+                //dbg msg
+                os_log_debug(logHandle, "now launching: %{public}@", appPath.path);
+                                
                 //launch it
-                if(nil == [[NSWorkspace sharedWorkspace] launchApplicationAtURL:appPath options:0 configuration:@{NSWorkspaceLaunchConfigurationArguments:@[INITIAL_LAUNCH]} error:&error])
+                [NSWorkspace.sharedWorkspace openApplicationAtURL:appPath configuration:configuration completionHandler:^(NSRunningApplication * _Nullable application, NSError * _Nullable error)
                 {
-                    //err msg
-                    os_log_error(logHandle, "ERROR: failed to launch %{public}@ (error: %{public}@)", appPath, error);
-                }
+                    #pragma unused(application)
+                    
+                    //error?
+                    if(nil != error)
+                    {
+                        //err msg
+                        os_log_error(logHandle, "ERROR: failed to launch %{public}@ (error: %{public}@)", appPath, error);
+                    }
+                    
+                    //close window
+                    // triggers cleanup logic
+                    dispatch_sync(dispatch_get_main_queue(),
+                    ^{
+                        [self.window close];
+                    });
+                    
+                }];
             }
-            
-            //close window
-            // triggers cleanup logic
-            [self.window close];
-            
+           
+            else
+            {
+                //close window
+                // triggers cleanup logic
+                [self.window close];
+            }
+           
             break;
         }
         
@@ -300,7 +326,7 @@ extern os_log_t logHandle;
     
     //open URL
     // invokes user's default browser
-    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:ERRORS_URL]];
+    [NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:ERRORS_URL]];
     
     return;
 }
@@ -561,8 +587,12 @@ bail:
         //exit on main thread
         dispatch_async(dispatch_get_main_queue(),
         ^{
-           //exit
-           [NSApp terminate:self];
+            
+            //dbg msg
+            os_log_debug(logHandle, "%{public}@ exiting...", [NSProcessInfo.processInfo.arguments.firstObject lastPathComponent]);
+            
+            //exit
+            [NSApp terminate:self];
         });
     });
 
diff --git a/Installer/Source/ConfigureWindowController.xib b/Installer/Source/ConfigureWindowController.xib
index 7b36326..928e1d5 100644
--- a/Installer/Source/ConfigureWindowController.xib
+++ b/Installer/Source/ConfigureWindowController.xib
@@ -21,7 +21,7 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
+            <windowStyleMask key="styleMask" titled="YES" closable="YES"/>
             <rect key="contentRect" x="196" y="240" width="523" height="237"/>
             <rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
             <view key="contentView" id="se5-gp-TjO">
diff --git a/Shared/Utilities.m b/Shared/Utilities.m
index 35bfd50..3b403ed 100644
--- a/Shared/Utilities.m
+++ b/Shared/Utilities.m
@@ -24,6 +24,7 @@
 #import <Foundation/Foundation.h>
 #import <CommonCrypto/CommonDigest.h>
 #import <SystemConfiguration/SystemConfiguration.h>
+#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
 
 /* GLOBALS */
 
@@ -888,8 +889,8 @@ NSImage* getIconForProcess(NSString* path)
     if(YES != [NSFileManager.defaultManager fileExistsAtPath:path])
     {
         //set icon to system 'application' icon
-        icon = [NSWorkspace.sharedWorkspace iconForFileType: NSFileTypeForHFSTypeCode(kGenericApplicationIcon)];
-        
+        icon = [NSWorkspace.sharedWorkspace iconForContentType:[UTType typeWithFilenameExtension:@"app"]];
+                
         //set size to 64 @2x
         [icon setSize:NSMakeSize(128, 128)];
    
@@ -946,8 +947,8 @@ NSImage* getIconForProcess(NSString* path)
         if(nil == documentIcon)
         {
             //load
-            documentIcon = [[NSWorkspace sharedWorkspace] iconForFileType:
-                            NSFileTypeForHFSTypeCode(kGenericDocumentIcon)];
+            documentIcon = [NSWorkspace.sharedWorkspace iconForContentType:[UTType typeWithFilenameExtension:@"txt"]];
+            
         }
         
         //if 'iconForFile' method doesn't find and icon, it returns the system 'document' icon
@@ -955,8 +956,7 @@ NSImage* getIconForProcess(NSString* path)
         if(YES == [icon isEqual:documentIcon])
         {
             //set icon to system 'application' icon
-            icon = [[NSWorkspace sharedWorkspace]
-                    iconForFileType: NSFileTypeForHFSTypeCode(kGenericApplicationIcon)];
+            icon = [NSWorkspace.sharedWorkspace iconForContentType:[UTType typeWithFilenameExtension:@"app"]];
         }
         
         //'iconForFileType' returns small icons
diff --git a/Shared/patrons.txt b/Shared/patrons.txt
index 2cc729c..90189fa 100644
--- a/Shared/patrons.txt
+++ b/Shared/patrons.txt
@@ -2,4 +2,4 @@ Patrons (2^6+):
 Jan Koum, Nick, Shain Singh, Christian Blümlein, Rocky Zadok, Cane Juice, M S
 
 Friends of Objective-See:
-Kandji, Jamf, Mosyle, CleanMyMac X, Kolide, Fleet, Palo Alto Networks, SmugMug, Guardian Mobile Firewall, iVerify, Halo Privacy
+Kandji, Jamf, Mosyle, CleanMyMac X, Kolide, Fleet, Palo Alto Networks, Sophos, SmugMug, Guardian Mobile Firewall, iVerify, Halo Privacy