Permalink
Browse files

fixed sierra support when downloading the app from the internet

  • Loading branch information...
Kevin Bradley
Kevin Bradley committed Jan 20, 2017
1 parent 64384fc commit a7a1537d7365098cfadc1c965180241ea9f04e64
Showing with 95 additions and 7 deletions.
  1. +93 −5 main.m
  2. +2 −2 tetherKit.xcodeproj/project.pbxproj
View
98 main.m
@@ -15,15 +15,103 @@
#import <Cocoa/Cocoa.h>
#include <stdio.h>
+#include <dlfcn.h>
+
+/*
+
+ Added some special code to undo App Translocation so we can setuid the helper.
+
+ all praise and credit to these websites and their authors for the solution below.
+
+
+
+ http://lapcatsoftware.com/articles/detect-app-translocation.html
+ https://objective-see.com/blog/blog_0x15.html
+
+ */
+
-int main(int argc, char *argv[])
-{
- //FIXME: COMMENT BACK IN BEFORE RELEASE!!!!
-
+Boolean (*mySecTranslocateIsTranslocatedURL)(CFURLRef path, bool *isTranslocated, CFErrorRef * __nullable error);
+CFURLRef __nullable (*mySecTranslocateCreateOriginalPathForURL)(CFURLRef translocatedPath, CFErrorRef * __nullable error);
+
+bool IsTranslocatedURL(CFURLRef currentURL, CFURLRef *originalURL)
+{
+ if (currentURL == NULL)
+ {
+ return false;
+ }
+
+ // #define NSAppKitVersionNumber10_11 1404
+ if (floor(NSAppKitVersionNumber) <= 1404)
+ {
+ return false;
+ }
+
+ void *handle = dlopen("/System/Library/Frameworks/Security.framework/Security", RTLD_LAZY);
+ if (handle == NULL)
+ {
+ return false;
+ }
+
+ bool isTranslocated = false;
- id pool = [NSAutoreleasePool new];
+ Boolean (*mySecTranslocateIsTranslocatedURL)(CFURLRef path, bool *isTranslocated, CFErrorRef * __nullable error);
+ mySecTranslocateIsTranslocatedURL = dlsym(handle, "SecTranslocateIsTranslocatedURL");
+ if (mySecTranslocateIsTranslocatedURL != NULL)
+ {
+ if (mySecTranslocateIsTranslocatedURL(currentURL, &isTranslocated, NULL))
+ {
+ if (isTranslocated)
+ {
+ if (originalURL != NULL)
+ {
+ CFURLRef __nullable (*mySecTranslocateCreateOriginalPathForURL)(CFURLRef translocatedPath, CFErrorRef * __nullable error);
+ mySecTranslocateCreateOriginalPathForURL = dlsym(handle, "SecTranslocateCreateOriginalPathForURL");
+ if (mySecTranslocateCreateOriginalPathForURL != NULL)
+ {
+ *originalURL = mySecTranslocateCreateOriginalPathForURL((CFURLRef)currentURL, NULL);
+ }
+ else
+ {
+ *originalURL = NULL;
+ }
+ }
+ }
+ }
+ }
+
+ dlclose(handle);
+
+ return isTranslocated;
+}
+
+
+
+int main(int argc, char *argv[])
+{
+ id pool = [NSAutoreleasePool new];
+ NSURL *appPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
+
+ //get original URL
+ NSURL *newPath = nil;
+
+ if (IsTranslocatedURL((CFURLRef) appPath, &newPath) == true)
+ {
+
+ //remove quarantine attributes of original
+
+ [NSTask launchedTaskWithLaunchPath:@"/usr/bin/xattr" arguments:@[@"-cr", (NSURL*)newPath.path]];
+
+ //relaunch original
+
+ // ->use 'open' as allows two instances of app (this instance is exiting)
+ [NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[@"-n", @"-a", newPath.path]];
+ //this instance is done
+ return 0;
+ }
+
NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:LOG_PATH];
freopen([logPath fileSystemRepresentation], "a", stderr);
@@ -762,7 +762,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- CODE_SIGN_IDENTITY = "Developer ID Application: Kevin Bradley (9EUFEA5U7G)";
+ CODE_SIGN_IDENTITY = "Developer ID Application";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
@@ -794,7 +794,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
- CODE_SIGN_IDENTITY = "Developer ID Application: Kevin Bradley (9EUFEA5U7G)";
+ CODE_SIGN_IDENTITY = "Developer ID Application";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_FIX_AND_CONTINUE = NO;

0 comments on commit a7a1537

Please sign in to comment.