-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.m
65 lines (52 loc) · 2.07 KB
/
utils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#import "utils.h"
typedef struct __SecTask * SecTaskRef;
extern CFTypeRef SecTaskCopyValueForEntitlement(
SecTaskRef task,
CFStringRef entitlement,
CFErrorRef _Nullable *error
)
__attribute__((weak_import));
extern SecTaskRef SecTaskCreateFromSelf(CFAllocatorRef allocator)
__attribute__((weak_import));
int getEntitlementIntValue(CFStringRef key)
{
if (SecTaskCreateFromSelf == NULL || SecTaskCopyValueForEntitlement == NULL)
return -1;
SecTaskRef sec_task = SecTaskCreateFromSelf(NULL);
if(sec_task == NULL)
return -2;
CFTypeRef entitlementValue = SecTaskCopyValueForEntitlement(sec_task, key, NULL);
CFRelease(sec_task); // release SecTask ref
if(entitlementValue == NULL)
return -3;
int ret = -4;
if(CFGetTypeID(entitlementValue) == CFBooleanGetTypeID())
ret = CFBooleanGetValue((CFBooleanRef)entitlementValue);
CFRelease(entitlementValue);
return ret;
}
BOOL isJITEnabled(BOOL useCSOPS)
{
if(!useCSOPS && getEntitlementIntValue(CFSTR("dynamic-codesigning")) == 1)
return YES;
int flags;
csops(getpid(), 0, &flags, sizeof(flags));
return (flags & CS_DEBUGGED) != 0;
}
BOOL isAppSandboxed()
{
int noConatainer = getEntitlementIntValue(CFSTR("com.apple.private.security.no-container"));
int noSandbox = getEntitlementIntValue(CFSTR("com.apple.private.security.no-sandbox"));
int containerRequired = getEntitlementIntValue(CFSTR("com.apple.private.security.container-required"));
// The app is sandboxed if:
// - "com.apple.private.security.no-container" is false
// - "com.apple.private.security.no-sandbox" is false
// - "com.apple.private.security.container-required" is true
// ref: https://github.com/opa334/TrollStore#unsandboxing
return ( noConatainer == 0 || noSandbox == 0 || containerRequired == 1 );
}
BOOL isTrollStoreEnvironment()
{
NSString *tsPath = [NSString stringWithFormat:@"%@/../_TrollStore", NSBundle.mainBundle.bundlePath];
return (access([tsPath fileSystemRepresentation], F_OK) == 0) ? YES : NO;
}