Skip to content

Commit a7a1537

Browse files
author
Kevin Bradley
committed
fixed sierra support when downloading the app from the internet
1 parent 64384fc commit a7a1537

File tree

2 files changed

+95
-7
lines changed

2 files changed

+95
-7
lines changed

main.m

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,103 @@
1515
#import <Cocoa/Cocoa.h>
1616
#include <stdio.h>
1717

18+
#include <dlfcn.h>
19+
20+
/*
21+
22+
Added some special code to undo App Translocation so we can setuid the helper.
23+
24+
all praise and credit to these websites and their authors for the solution below.
25+
26+
27+
28+
http://lapcatsoftware.com/articles/detect-app-translocation.html
29+
https://objective-see.com/blog/blog_0x15.html
30+
31+
*/
32+
1833

19-
int main(int argc, char *argv[])
20-
{
21-
//FIXME: COMMENT BACK IN BEFORE RELEASE!!!!
22-
2334

35+
Boolean (*mySecTranslocateIsTranslocatedURL)(CFURLRef path, bool *isTranslocated, CFErrorRef * __nullable error);
36+
CFURLRef __nullable (*mySecTranslocateCreateOriginalPathForURL)(CFURLRef translocatedPath, CFErrorRef * __nullable error);
37+
38+
bool IsTranslocatedURL(CFURLRef currentURL, CFURLRef *originalURL)
39+
{
40+
if (currentURL == NULL)
41+
{
42+
return false;
43+
}
44+
45+
// #define NSAppKitVersionNumber10_11 1404
46+
if (floor(NSAppKitVersionNumber) <= 1404)
47+
{
48+
return false;
49+
}
50+
51+
void *handle = dlopen("/System/Library/Frameworks/Security.framework/Security", RTLD_LAZY);
52+
if (handle == NULL)
53+
{
54+
return false;
55+
}
56+
57+
bool isTranslocated = false;
2458

25-
id pool = [NSAutoreleasePool new];
59+
Boolean (*mySecTranslocateIsTranslocatedURL)(CFURLRef path, bool *isTranslocated, CFErrorRef * __nullable error);
60+
mySecTranslocateIsTranslocatedURL = dlsym(handle, "SecTranslocateIsTranslocatedURL");
61+
if (mySecTranslocateIsTranslocatedURL != NULL)
62+
{
63+
if (mySecTranslocateIsTranslocatedURL(currentURL, &isTranslocated, NULL))
64+
{
65+
if (isTranslocated)
66+
{
67+
if (originalURL != NULL)
68+
{
69+
CFURLRef __nullable (*mySecTranslocateCreateOriginalPathForURL)(CFURLRef translocatedPath, CFErrorRef * __nullable error);
70+
mySecTranslocateCreateOriginalPathForURL = dlsym(handle, "SecTranslocateCreateOriginalPathForURL");
71+
if (mySecTranslocateCreateOriginalPathForURL != NULL)
72+
{
73+
*originalURL = mySecTranslocateCreateOriginalPathForURL((CFURLRef)currentURL, NULL);
74+
}
75+
else
76+
{
77+
*originalURL = NULL;
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
dlclose(handle);
85+
86+
return isTranslocated;
87+
}
88+
89+
2690

91+
92+
int main(int argc, char *argv[])
93+
{
94+
id pool = [NSAutoreleasePool new];
95+
NSURL *appPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
96+
97+
//get original URL
98+
NSURL *newPath = nil;
99+
100+
if (IsTranslocatedURL((CFURLRef) appPath, &newPath) == true)
101+
{
102+
103+
//remove quarantine attributes of original
104+
105+
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/xattr" arguments:@[@"-cr", (NSURL*)newPath.path]];
106+
107+
//relaunch original
108+
109+
// ->use 'open' as allows two instances of app (this instance is exiting)
110+
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[@"-n", @"-a", newPath.path]];
111+
//this instance is done
112+
return 0;
113+
}
114+
27115

28116
NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:LOG_PATH];
29117
freopen([logPath fileSystemRepresentation], "a", stderr);

tetherKit.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@
762762
isa = XCBuildConfiguration;
763763
buildSettings = {
764764
ALWAYS_SEARCH_USER_PATHS = NO;
765-
CODE_SIGN_IDENTITY = "Developer ID Application: Kevin Bradley (9EUFEA5U7G)";
765+
CODE_SIGN_IDENTITY = "Developer ID Application";
766766
COPY_PHASE_STRIP = NO;
767767
GCC_DYNAMIC_NO_PIC = NO;
768768
GCC_ENABLE_FIX_AND_CONTINUE = YES;
@@ -794,7 +794,7 @@
794794
buildSettings = {
795795
ALWAYS_SEARCH_USER_PATHS = NO;
796796
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
797-
CODE_SIGN_IDENTITY = "Developer ID Application: Kevin Bradley (9EUFEA5U7G)";
797+
CODE_SIGN_IDENTITY = "Developer ID Application";
798798
COPY_PHASE_STRIP = YES;
799799
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
800800
GCC_ENABLE_FIX_AND_CONTINUE = NO;

0 commit comments

Comments
 (0)