From c56694382eb7f545c44f2808949a73a28557d534 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 Jan 2017 21:17:25 -0500 Subject: [PATCH 1/3] Add AppKit prevention guards to modules that shouldn't import it --- Sparkle/SUAppcast.m | 4 ++++ Sparkle/SUAppcastItem.m | 4 ++++ Sparkle/SUBinaryDeltaApply.m | 4 ++++ Sparkle/SUBinaryDeltaCommon.m | 4 ++++ Sparkle/SUBinaryDeltaCreate.m | 4 ++++ Sparkle/SUBinaryDeltaTool.m | 4 ++++ Sparkle/SUBinaryDeltaUnarchiver.m | 4 ++++ Sparkle/SUBundleIcon.m | 4 ++++ Sparkle/SUCodeSigningVerifier.m | 4 ++++ Sparkle/SUConstants.m | 4 ++++ Sparkle/SUDSAVerifier.m | 4 ++++ Sparkle/SUDiskImageUnarchiver.m | 4 ++++ Sparkle/SUFileManager.m | 4 ++++ Sparkle/SUGuidedPackageInstaller.m | 4 ++++ Sparkle/SUHost.m | 4 ++++ Sparkle/SUInstaller.m | 4 ++++ Sparkle/SULog.m | 3 +++ Sparkle/SUOperatingSystem.m | 4 ++++ Sparkle/SUPackageInstaller.m | 4 ++++ Sparkle/SUPipedUnarchiver.m | 4 ++++ Sparkle/SUPlainInstaller.m | 4 ++++ Sparkle/SUStandardVersionComparator.m | 4 ++++ Sparkle/SUSystemProfiler.m | 4 ++++ Sparkle/SUSystemUpdateInfo.m | 4 ++++ Sparkle/SUUnarchiver.m | 4 ++++ Sparkle/SUUnarchiverNotifier.m | 4 ++++ Sparkle/SUUpdatePermissionResponse.m | 4 ++++ Sparkle/SUUpdateValidator.m | 4 ++++ fileop/SUFileOperationConstants.m | 4 ++++ fileop/fileop.m | 4 ++++ 30 files changed, 119 insertions(+) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 70b56f0a..2341222e 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -12,6 +12,10 @@ #import "SULocalizations.h" #import "SUErrors.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface NSXMLElement (SUAppcastExtensions) @property (readonly, copy) NSDictionary *attributesAsDictionary; @end diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 164b5bad..0e1acd92 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -10,6 +10,10 @@ #import "SULog.h" #import "SUConstants.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUAppcastItem () @property (copy, readwrite) NSString *title; @property (copy, readwrite) NSString *dateString; diff --git a/Sparkle/SUBinaryDeltaApply.m b/Sparkle/SUBinaryDeltaApply.m index eac297b4..da6c6f85 100644 --- a/Sparkle/SUBinaryDeltaApply.m +++ b/Sparkle/SUBinaryDeltaApply.m @@ -15,6 +15,10 @@ #include #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath) { NSString *patchFile = temporaryFilename(@"apply-binary-delta"); diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index 5f6ce079..7d2cd316 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -18,6 +18,10 @@ #include #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + int compareFiles(const FTSENT **a, const FTSENT **b) { return strcoll((*a)->fts_name, (*b)->fts_name); diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index 0a8fbc52..00807cf5 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -21,6 +21,10 @@ #include #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + extern int bsdiff(int argc, const char **argv); @interface CreateBinaryDeltaOperation : NSOperation diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index ea83fdd0..2dce1d54 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -20,6 +20,10 @@ #define VERSION_COMMAND @"version" #define VERSION_ALTERNATE_COMMAND @"--version" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + static void printUsage(NSString *programName) { fprintf(stderr, "Usage:\n"); diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index 6dc2a666..aed4a07e 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -13,6 +13,10 @@ #import "SULog.h" #import "SUFileManager.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUBinaryDeltaUnarchiver () @property (nonatomic, copy, readonly) NSString *archivePath; diff --git a/Sparkle/SUBundleIcon.m b/Sparkle/SUBundleIcon.m index a3d86a80..30a831a8 100644 --- a/Sparkle/SUBundleIcon.m +++ b/Sparkle/SUBundleIcon.m @@ -8,6 +8,10 @@ #import "SUBundleIcon.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUBundleIcon + (NSURL *)iconURLForBundle:(NSBundle *)bundle diff --git a/Sparkle/SUCodeSigningVerifier.m b/Sparkle/SUCodeSigningVerifier.m index 1da556f2..7fa84625 100644 --- a/Sparkle/SUCodeSigningVerifier.m +++ b/Sparkle/SUCodeSigningVerifier.m @@ -11,6 +11,10 @@ #import "SUCodeSigningVerifier.h" #import "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUCodeSigningVerifier + (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundleURL matchesSignatureAtBundleURL:(NSURL *)newBundleURL error:(NSError *__autoreleasing *)error diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index f5e73fda..09faeabb 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -13,6 +13,10 @@ #define DEBUG 0 #endif +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + // Define some minimum intervals to avoid DoS-like checking attacks const NSTimeInterval SUMinimumUpdateCheckInterval = DEBUG ? 60 : (60 * 60); const NSTimeInterval SUDefaultUpdateCheckInterval = DEBUG ? 60 : (60 * 60 * 24); diff --git a/Sparkle/SUDSAVerifier.m b/Sparkle/SUDSAVerifier.m index fa5f9934..5542e3cf 100644 --- a/Sparkle/SUDSAVerifier.m +++ b/Sparkle/SUDSAVerifier.m @@ -16,6 +16,10 @@ #import "SULog.h" #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUDSAVerifier { SecKeyRef _secKey; } diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index 60f59780..dfd0c011 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -10,6 +10,10 @@ #import "SUUnarchiverNotifier.h" #import "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUDiskImageUnarchiver () @property (nonatomic, copy, readonly) NSString *archivePath; diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 26369b63..64a1aa66 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -15,6 +15,10 @@ #include #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 308b186c..5093c5e5 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -9,6 +9,10 @@ #import "SUGuidedPackageInstaller.h" #import "SUFileManager.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUGuidedPackageInstaller () @property (nonatomic, readonly, copy) NSString *packagePath; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 8470ae22..0094d669 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -11,6 +11,10 @@ #include // For statfs for isRunningOnReadOnlyVolume #import "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + // This class should not rely on AppKit and should also be process independent // For example, it should not have code that tests writabilty to somewhere on disk, // as that may depend on the privileges of the process owner. Or code that depends on diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 3ef0c5ff..383754fc 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -15,6 +15,10 @@ #import "SULog.h" #import "SUErrors.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUInstaller + (BOOL)isAliasFolderAtPath:(NSString *)path diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 5941aac7..c6519e49 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -13,6 +13,9 @@ #include "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif // ----------------------------------------------------------------------------- // Constants: diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index 4a7d73aa..edaae13a 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -7,6 +7,10 @@ #import "SUOperatingSystem.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000 @interface NSProcessInfo () - (NSOperatingSystemVersion)operatingSystemVersion; diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index 226cde20..15a463d8 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -11,6 +11,10 @@ #import "SUErrors.h" #import "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUPackageInstaller () @property (nonatomic, readonly, copy) NSString *packagePath; diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index b155b408..8b4efb66 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -11,6 +11,10 @@ #import "SULog.h" #import "SUErrors.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUPipedUnarchiver () @property (nonatomic, copy, readonly) NSString *archivePath; diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 586ce47f..7d3ad419 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -14,6 +14,10 @@ #import "SULog.h" #import "SUErrors.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUPlainInstaller () @property (nonatomic, readonly) SUHost *host; diff --git a/Sparkle/SUStandardVersionComparator.m b/Sparkle/SUStandardVersionComparator.m index 7bc68181..fc87e65a 100644 --- a/Sparkle/SUStandardVersionComparator.m +++ b/Sparkle/SUStandardVersionComparator.m @@ -9,6 +9,10 @@ #import "SUVersionComparisonProtocol.h" #import "SUStandardVersionComparator.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUStandardVersionComparator - (instancetype)init diff --git a/Sparkle/SUSystemProfiler.m b/Sparkle/SUSystemProfiler.m index 83a93cee..822da49b 100644 --- a/Sparkle/SUSystemProfiler.m +++ b/Sparkle/SUSystemProfiler.m @@ -14,6 +14,10 @@ #import "SUOperatingSystem.h" #include +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + static NSString *const SUSystemProfilerApplicationNameKey = @"appName"; static NSString *const SUSystemProfilerApplicationVersionKey = @"appVersion"; static NSString *const SUSystemProfilerCPU64bitKey = @"cpu64bit"; diff --git a/Sparkle/SUSystemUpdateInfo.m b/Sparkle/SUSystemUpdateInfo.m index 7ef2dd8f..e06cb747 100644 --- a/Sparkle/SUSystemUpdateInfo.m +++ b/Sparkle/SUSystemUpdateInfo.m @@ -11,6 +11,10 @@ #import "SUConstants.h" #import "SUFileManager.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUSystemUpdateInfo + (BOOL)systemAllowsAutomaticUpdatesForHost:(SUHost *)host diff --git a/Sparkle/SUUnarchiver.m b/Sparkle/SUUnarchiver.m index 7b808814..d91159f9 100644 --- a/Sparkle/SUUnarchiver.m +++ b/Sparkle/SUUnarchiver.m @@ -12,6 +12,10 @@ #import "SUDiskImageUnarchiver.h" #import "SUBinaryDeltaUnarchiver.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUUnarchiver + (nullable id )unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword diff --git a/Sparkle/SUUnarchiverNotifier.m b/Sparkle/SUUnarchiverNotifier.m index 727ac7da..914a08e7 100644 --- a/Sparkle/SUUnarchiverNotifier.m +++ b/Sparkle/SUUnarchiverNotifier.m @@ -10,6 +10,10 @@ #import "SULocalizations.h" #import "SUErrors.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUUnarchiverNotifier () @property (nonatomic, readonly, copy) void (^completionBlock)(NSError * _Nullable); diff --git a/Sparkle/SUUpdatePermissionResponse.m b/Sparkle/SUUpdatePermissionResponse.m index 02c89acd..6636a2f8 100644 --- a/Sparkle/SUUpdatePermissionResponse.m +++ b/Sparkle/SUUpdatePermissionResponse.m @@ -8,6 +8,10 @@ #import "SUUpdatePermissionResponse.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @implementation SUUpdatePermissionResponse @synthesize automaticUpdateChecks = _automaticUpdateChecks; diff --git a/Sparkle/SUUpdateValidator.m b/Sparkle/SUUpdateValidator.m index 164da998..efd8ace3 100644 --- a/Sparkle/SUUpdateValidator.m +++ b/Sparkle/SUUpdateValidator.m @@ -13,6 +13,10 @@ #import "SUHost.h" #import "SULog.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + @interface SUUpdateValidator () @property (nonatomic, readonly) SUHost *host; diff --git a/fileop/SUFileOperationConstants.m b/fileop/SUFileOperationConstants.m index 5ece5917..8a90d30b 100644 --- a/fileop/SUFileOperationConstants.m +++ b/fileop/SUFileOperationConstants.m @@ -8,6 +8,10 @@ #import "SUFileOperationConstants.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + char * const SUFileOpRemoveQuarantineCommand = "xattr-d-apple-quarantine"; char * const SUFileOpCopyCommand = "cp"; char * const SUFileOpMoveCommand = "mv"; diff --git a/fileop/fileop.m b/fileop/fileop.m index 044f2abc..d254439a 100644 --- a/fileop/fileop.m +++ b/fileop/fileop.m @@ -10,6 +10,10 @@ #import "SUFileManager.h" #import "SUFileOperationConstants.h" +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + // If we fail, we exit with a unique status code // We don't try to NSLog because the logs can't be seen anywhere, // and we don't want to log to a file irresponsibly (especially as root), From 135d05b8b8a1463f262b8d7dce4ab4669b828983 Mon Sep 17 00:00:00 2001 From: Zorg Date: Tue, 17 Jan 2017 07:08:29 -0500 Subject: [PATCH 2/3] Add AppKitPrevention header to reduce redundancy. Note this header should be included last in implementation files, which is why I added extra padding. --- Sparkle.xcodeproj/project.pbxproj | 2 ++ Sparkle/AppKitPrevention.h | 16 ++++++++++++++++ Sparkle/SUAppcast.m | 5 ++--- Sparkle/SUAppcastItem.m | 5 ++--- Sparkle/SUBinaryDeltaApply.m | 5 ++--- Sparkle/SUBinaryDeltaCommon.m | 5 ++--- Sparkle/SUBinaryDeltaCreate.m | 5 ++--- Sparkle/SUBinaryDeltaTool.m | 4 +--- Sparkle/SUBinaryDeltaUnarchiver.m | 5 ++--- Sparkle/SUBundleIcon.m | 5 ++--- Sparkle/SUCodeSigningVerifier.m | 5 ++--- Sparkle/SUConstants.m | 4 +--- Sparkle/SUDSAVerifier.m | 5 ++--- Sparkle/SUDiskImageUnarchiver.m | 5 ++--- Sparkle/SUFileManager.m | 5 ++--- Sparkle/SUGuidedPackageInstaller.m | 5 ++--- Sparkle/SUHost.m | 5 ++--- Sparkle/SUInstaller.m | 5 ++--- Sparkle/SULog.m | 5 ++--- Sparkle/SUOperatingSystem.m | 5 ++--- Sparkle/SUPackageInstaller.m | 5 ++--- Sparkle/SUPipedUnarchiver.m | 5 ++--- Sparkle/SUPlainInstaller.m | 5 ++--- Sparkle/SUStandardVersionComparator.m | 5 ++--- Sparkle/SUSystemProfiler.m | 6 ++---- Sparkle/SUSystemUpdateInfo.m | 5 ++--- Sparkle/SUUnarchiver.m | 5 ++--- Sparkle/SUUnarchiverNotifier.m | 5 ++--- Sparkle/SUUpdatePermissionResponse.m | 5 ++--- Sparkle/SUUpdateValidator.m | 5 ++--- fileop/SUFileOperationConstants.m | 5 ++--- fileop/fileop.m | 5 ++--- 32 files changed, 76 insertions(+), 91 deletions(-) create mode 100644 Sparkle/AppKitPrevention.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index e83078b9..a713ac34 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -732,6 +732,7 @@ 7205C4331E12C23C00E370AE /* ConfigGenerateAppcast.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcast.xcconfig; sourceTree = ""; }; 7205C4341E12C66D00E370AE /* ConfigGenerateAppcastRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcastRelease.xcconfig; sourceTree = ""; }; 7205C4351E12CA7000E370AE /* ConfigGenerateAppcastDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigGenerateAppcastDebug.xcconfig; sourceTree = ""; }; + 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitPrevention.h; sourceTree = ""; }; 720B16421C66433D006985FB /* UITests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "UITests-Info.plist"; path = "UITests/UITests-Info.plist"; sourceTree = SOURCE_ROOT; }; 720B16431C66433D006985FB /* SUTestApplicationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SUTestApplicationTest.swift; path = UITests/SUTestApplicationTest.swift; sourceTree = SOURCE_ROOT; }; 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; @@ -1036,6 +1037,7 @@ 1495006D195FBBBD00BC5B5B /* Sparkle */ = { isa = PBXGroup; children = ( + 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */, 61299B3909CB055000B7442F /* Appcast Support */, 55C14BD5136EEFD000649790 /* Autoupdate */, 089C1665FE841158C02AAC07 /* Framework Resources */, diff --git a/Sparkle/AppKitPrevention.h b/Sparkle/AppKitPrevention.h new file mode 100644 index 00000000..875f72a7 --- /dev/null +++ b/Sparkle/AppKitPrevention.h @@ -0,0 +1,16 @@ +// +// AppKitPrevention.h +// Sparkle +// +// Created by Mayur Pawashe on 1/17/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +// #include (not #import) this header to prevent AppKit from being imported +// Note this should be your LAST #include in your implementation file + +// If this error is triggered, you can have Xcode indicate to you which source file including this header caused the issue + +#ifdef _APPKITDEFINES_H +#error This is a core or daemon-safe module and should NOT import AppKit +#endif diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 2341222e..fac2d884 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -12,9 +12,8 @@ #import "SULocalizations.h" #import "SUErrors.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface NSXMLElement (SUAppcastExtensions) @property (readonly, copy) NSDictionary *attributesAsDictionary; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 0e1acd92..26cba3e7 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -10,9 +10,8 @@ #import "SULog.h" #import "SUConstants.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUAppcastItem () @property (copy, readwrite) NSString *title; diff --git a/Sparkle/SUBinaryDeltaApply.m b/Sparkle/SUBinaryDeltaApply.m index da6c6f85..ea93b2be 100644 --- a/Sparkle/SUBinaryDeltaApply.m +++ b/Sparkle/SUBinaryDeltaApply.m @@ -15,9 +15,8 @@ #include #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath) { diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index 7d2cd316..42e9d6c0 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -18,9 +18,8 @@ #include #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" int compareFiles(const FTSENT **a, const FTSENT **b) { diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index 00807cf5..b0dfa3ef 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -21,9 +21,8 @@ #include #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" extern int bsdiff(int argc, const char **argv); diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index 2dce1d54..fae14ed1 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -20,9 +20,7 @@ #define VERSION_COMMAND @"version" #define VERSION_ALTERNATE_COMMAND @"--version" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif +#include "AppKitPrevention.h" static void printUsage(NSString *programName) { diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index aed4a07e..819d8b16 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -13,9 +13,8 @@ #import "SULog.h" #import "SUFileManager.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUBinaryDeltaUnarchiver () diff --git a/Sparkle/SUBundleIcon.m b/Sparkle/SUBundleIcon.m index 30a831a8..84801be2 100644 --- a/Sparkle/SUBundleIcon.m +++ b/Sparkle/SUBundleIcon.m @@ -8,9 +8,8 @@ #import "SUBundleIcon.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUBundleIcon diff --git a/Sparkle/SUCodeSigningVerifier.m b/Sparkle/SUCodeSigningVerifier.m index 7fa84625..85f99a85 100644 --- a/Sparkle/SUCodeSigningVerifier.m +++ b/Sparkle/SUCodeSigningVerifier.m @@ -11,9 +11,8 @@ #import "SUCodeSigningVerifier.h" #import "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUCodeSigningVerifier diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 09faeabb..5e883f6f 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -13,9 +13,7 @@ #define DEBUG 0 #endif -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif +#include "AppKitPrevention.h" // Define some minimum intervals to avoid DoS-like checking attacks const NSTimeInterval SUMinimumUpdateCheckInterval = DEBUG ? 60 : (60 * 60); diff --git a/Sparkle/SUDSAVerifier.m b/Sparkle/SUDSAVerifier.m index 5542e3cf..12434c84 100644 --- a/Sparkle/SUDSAVerifier.m +++ b/Sparkle/SUDSAVerifier.m @@ -16,9 +16,8 @@ #import "SULog.h" #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUDSAVerifier { SecKeyRef _secKey; diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index dfd0c011..3ce85cd1 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -10,9 +10,8 @@ #import "SUUnarchiverNotifier.h" #import "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUDiskImageUnarchiver () diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 64a1aa66..98800e3a 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -15,9 +15,8 @@ #include #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 5093c5e5..cea993a2 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -9,9 +9,8 @@ #import "SUGuidedPackageInstaller.h" #import "SUFileManager.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUGuidedPackageInstaller () diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 0094d669..63fd0380 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -11,9 +11,8 @@ #include // For statfs for isRunningOnReadOnlyVolume #import "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" // This class should not rely on AppKit and should also be process independent // For example, it should not have code that tests writabilty to somewhere on disk, diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 383754fc..98a6c9d5 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -15,9 +15,8 @@ #import "SULog.h" #import "SUErrors.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUInstaller diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index c6519e49..69d136ea 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -13,9 +13,8 @@ #include "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" // ----------------------------------------------------------------------------- // Constants: diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index edaae13a..fada18c3 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -7,9 +7,8 @@ #import "SUOperatingSystem.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000 @interface NSProcessInfo () diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index 15a463d8..15425fe6 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -11,9 +11,8 @@ #import "SUErrors.h" #import "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUPackageInstaller () diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 8b4efb66..178fd5ba 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -11,9 +11,8 @@ #import "SULog.h" #import "SUErrors.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUPipedUnarchiver () diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 7d3ad419..7b86b634 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -14,9 +14,8 @@ #import "SULog.h" #import "SUErrors.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUPlainInstaller () diff --git a/Sparkle/SUStandardVersionComparator.m b/Sparkle/SUStandardVersionComparator.m index fc87e65a..a2958e82 100644 --- a/Sparkle/SUStandardVersionComparator.m +++ b/Sparkle/SUStandardVersionComparator.m @@ -9,9 +9,8 @@ #import "SUVersionComparisonProtocol.h" #import "SUStandardVersionComparator.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUStandardVersionComparator diff --git a/Sparkle/SUSystemProfiler.m b/Sparkle/SUSystemProfiler.m index 822da49b..1d3c085c 100644 --- a/Sparkle/SUSystemProfiler.m +++ b/Sparkle/SUSystemProfiler.m @@ -9,14 +9,12 @@ #import #import "SUSystemProfiler.h" - #import "SUHost.h" #import "SUOperatingSystem.h" #include -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" static NSString *const SUSystemProfilerApplicationNameKey = @"appName"; static NSString *const SUSystemProfilerApplicationVersionKey = @"appVersion"; diff --git a/Sparkle/SUSystemUpdateInfo.m b/Sparkle/SUSystemUpdateInfo.m index e06cb747..78325eae 100644 --- a/Sparkle/SUSystemUpdateInfo.m +++ b/Sparkle/SUSystemUpdateInfo.m @@ -11,9 +11,8 @@ #import "SUConstants.h" #import "SUFileManager.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUSystemUpdateInfo diff --git a/Sparkle/SUUnarchiver.m b/Sparkle/SUUnarchiver.m index d91159f9..9cb33bc6 100644 --- a/Sparkle/SUUnarchiver.m +++ b/Sparkle/SUUnarchiver.m @@ -12,9 +12,8 @@ #import "SUDiskImageUnarchiver.h" #import "SUBinaryDeltaUnarchiver.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUUnarchiver diff --git a/Sparkle/SUUnarchiverNotifier.m b/Sparkle/SUUnarchiverNotifier.m index 914a08e7..643f0eb9 100644 --- a/Sparkle/SUUnarchiverNotifier.m +++ b/Sparkle/SUUnarchiverNotifier.m @@ -10,9 +10,8 @@ #import "SULocalizations.h" #import "SUErrors.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUUnarchiverNotifier () diff --git a/Sparkle/SUUpdatePermissionResponse.m b/Sparkle/SUUpdatePermissionResponse.m index 6636a2f8..203ff151 100644 --- a/Sparkle/SUUpdatePermissionResponse.m +++ b/Sparkle/SUUpdatePermissionResponse.m @@ -8,9 +8,8 @@ #import "SUUpdatePermissionResponse.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @implementation SUUpdatePermissionResponse diff --git a/Sparkle/SUUpdateValidator.m b/Sparkle/SUUpdateValidator.m index efd8ace3..296b5624 100644 --- a/Sparkle/SUUpdateValidator.m +++ b/Sparkle/SUUpdateValidator.m @@ -13,9 +13,8 @@ #import "SUHost.h" #import "SULog.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" @interface SUUpdateValidator () diff --git a/fileop/SUFileOperationConstants.m b/fileop/SUFileOperationConstants.m index 8a90d30b..7476bd6f 100644 --- a/fileop/SUFileOperationConstants.m +++ b/fileop/SUFileOperationConstants.m @@ -8,9 +8,8 @@ #import "SUFileOperationConstants.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" char * const SUFileOpRemoveQuarantineCommand = "xattr-d-apple-quarantine"; char * const SUFileOpCopyCommand = "cp"; diff --git a/fileop/fileop.m b/fileop/fileop.m index d254439a..9bb54411 100644 --- a/fileop/fileop.m +++ b/fileop/fileop.m @@ -10,9 +10,8 @@ #import "SUFileManager.h" #import "SUFileOperationConstants.h" -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif + +#include "AppKitPrevention.h" // If we fail, we exit with a unique status code // We don't try to NSLog because the logs can't be seen anywhere, From 530f3a4a6308c9d91010fc429280afc60afd6ba3 Mon Sep 17 00:00:00 2001 From: Zorg Date: Tue, 17 Jan 2017 07:17:14 -0500 Subject: [PATCH 3/3] Explain why I'm not relying on the compiler to throw linkage errors --- Sparkle/AppKitPrevention.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sparkle/AppKitPrevention.h b/Sparkle/AppKitPrevention.h index 875f72a7..0ede52ff 100644 --- a/Sparkle/AppKitPrevention.h +++ b/Sparkle/AppKitPrevention.h @@ -11,6 +11,10 @@ // If this error is triggered, you can have Xcode indicate to you which source file including this header caused the issue +// One may wonder for certain targets where AppKit is banned completely, why just not link AppKit instead. +// Well, Xcode has thing called auto-linking that I don't trust very much. +// Even after trying to disable the setting, I've had targets able to link to AppKit without AppKit being specified in the list of linked libraries. + #ifdef _APPKITDEFINES_H #error This is a core or daemon-safe module and should NOT import AppKit #endif