Skip to content

Commit

Permalink
fixed sierra support when downloading the app from the internet
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Bradley committed Jan 20, 2017
1 parent 64384fc commit a7a1537
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
98 changes: 93 additions & 5 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tetherKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a7a1537

Please sign in to comment.