-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
202 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <Foundation/Foundation.h> | ||
NSString *jbroot(NSString *path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#import <stdio.h> | ||
#include <sys/types.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
#define JB_ROOT_PREFIX ".jbroot-" | ||
#define JB_RAND_LENGTH (sizeof(uint64_t)*sizeof(char)*2) | ||
|
||
int is_jbrand_value(uint64_t value) | ||
{ | ||
uint8_t check = value>>8 ^ value >> 16 ^ value>>24 ^ value>>32 ^ value>>40 ^ value>>48 ^ value>>56; | ||
return check == (uint8_t)value; | ||
} | ||
|
||
int is_jbroot_name(const char* name) | ||
{ | ||
if(strlen(name) != (sizeof(JB_ROOT_PREFIX)-1+JB_RAND_LENGTH)) | ||
return 0; | ||
|
||
if(strncmp(name, JB_ROOT_PREFIX, sizeof(JB_ROOT_PREFIX)-1) != 0) | ||
return 0; | ||
|
||
char* endp=NULL; | ||
uint64_t value = strtoull(name+sizeof(JB_ROOT_PREFIX)-1, &endp, 16); | ||
if(!endp || *endp!='\0') | ||
return 0; | ||
|
||
if(!is_jbrand_value(value)) | ||
return 0; | ||
|
||
return 1; | ||
} | ||
|
||
uint64_t resolve_jbrand_value(const char* name) | ||
{ | ||
if(strlen(name) != (sizeof(JB_ROOT_PREFIX)-1+JB_RAND_LENGTH)) | ||
return 0; | ||
|
||
if(strncmp(name, JB_ROOT_PREFIX, sizeof(JB_ROOT_PREFIX)-1) != 0) | ||
return 0; | ||
|
||
char* endp=NULL; | ||
uint64_t value = strtoull(name+sizeof(JB_ROOT_PREFIX)-1, &endp, 16); | ||
if(!endp || *endp!='\0') | ||
return 0; | ||
|
||
if(!is_jbrand_value(value)) | ||
return 0; | ||
|
||
return value; | ||
} | ||
|
||
|
||
NSString* find_jbroot() | ||
{ | ||
//jbroot path may change when re-randomize it | ||
NSString * jbroot = nil; | ||
NSArray *subItems = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/var/containers/Bundle/Application/" error:nil]; | ||
for (NSString *subItem in subItems) { | ||
if (is_jbroot_name(subItem.UTF8String)) | ||
{ | ||
NSString* path = [@"/var/containers/Bundle/Application/" stringByAppendingPathComponent:subItem]; | ||
jbroot = path; | ||
break; | ||
} | ||
} | ||
return jbroot; | ||
} | ||
|
||
NSString *jbroot(NSString *path) | ||
{ | ||
NSString* jbroot = find_jbroot(); | ||
return [jbroot stringByAppendingPathComponent:path]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.