Last active
October 20, 2021 19:34
-
-
Save esterTion/57df8da3ac5a9471fd86cd7a9c87a7ac to your computer and use it in GitHub Desktop.
AppLink for iOS 9+ (Symlink app/data dir under Documents/App-link)
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
// | |
// applink.m | |
// applink | |
// | |
// Created by esterTion on 2018/3/25. | |
// xcrun -sdk iphoneos clang -framework Foundation -arch arm64 applink.m -o applink | |
// | |
// APT repo: https://repo.estertion.win/ | |
// | |
#import <Foundation/Foundation.h> | |
#import <stdio.h> | |
int main (int argc, const char * argv[]) | |
{ | |
@autoreleasepool | |
{ | |
// create parent folder | |
NSString* appLinkDir = @"/User/Documents/App-link/App"; | |
NSString* dataLinkDir = @"/User/Documents/App-link/Data"; | |
NSFileManager* fileMgr = [NSFileManager defaultManager]; | |
BOOL result = [fileMgr createDirectoryAtPath:appLinkDir | |
withIntermediateDirectories:true | |
attributes:@{NSFileOwnerAccountID:@501,NSFileGroupOwnerAccountID:@501} | |
error:nil]; | |
if (!result) { | |
NSLog(@"Unable to create folder"); | |
return 1; | |
} | |
result = [fileMgr createDirectoryAtPath:dataLinkDir | |
withIntermediateDirectories:true | |
attributes:@{NSFileOwnerAccountID:@501,NSFileGroupOwnerAccountID:@501} | |
error:nil]; | |
if (!result) { | |
NSLog(@"Unable to create folder"); | |
return 1; | |
} | |
//empty old entry | |
for (NSString* file in [fileMgr enumeratorAtPath:appLinkDir]) { | |
[fileMgr removeItemAtPath:[appLinkDir stringByAppendingPathComponent:file] error:nil]; | |
} | |
for (NSString* file in [fileMgr enumeratorAtPath:@"/User/Documents/App-link/Data"]) { | |
[fileMgr removeItemAtPath:[dataLinkDir stringByAppendingPathComponent:file] error:nil]; | |
} | |
//App symlink | |
printf("\nlinking Bundle/Application\n\n"); | |
NSString* appContainerDir = @"/var/containers/Bundle/Application"; | |
NSArray* uuids = [fileMgr contentsOfDirectoryAtPath:appContainerDir error:nil]; | |
for (NSString* uuid in uuids) { | |
NSString* appDir = [appContainerDir stringByAppendingPathComponent:uuid]; | |
NSDictionary* info = [NSDictionary dictionaryWithContentsOfFile:[appDir stringByAppendingPathComponent:@".com.apple.mobile_container_manager.metadata.plist"]]; | |
NSString* id = info[@"MCMMetadataIdentifier"]; | |
[fileMgr createSymbolicLinkAtPath:[appLinkDir stringByAppendingPathComponent:id] withDestinationPath:appDir error:nil]; | |
printf("%s\n", [id cStringUsingEncoding:NSUTF8StringEncoding]); | |
} | |
[fileMgr createFileAtPath:[appLinkDir stringByAppendingPathComponent:@"a"] | |
contents:nil | |
attributes:@{NSFileOwnerAccountID:@501,NSFileGroupOwnerAccountID:@501}]; | |
//Data symlink | |
printf("\nlinking Data/Application\n\n"); | |
NSString* dataContainerDir = @"/var/mobile/Containers/Data/Application"; | |
uuids = [fileMgr contentsOfDirectoryAtPath:dataContainerDir error:nil]; | |
for (NSString* uuid in uuids) { | |
NSString* dataDir = [dataContainerDir stringByAppendingPathComponent:uuid]; | |
NSDictionary* info = [NSDictionary dictionaryWithContentsOfFile:[dataDir stringByAppendingPathComponent:@".com.apple.mobile_container_manager.metadata.plist"]]; | |
NSString* id = info[@"MCMMetadataIdentifier"]; | |
[fileMgr createSymbolicLinkAtPath:[dataLinkDir stringByAppendingPathComponent:id] withDestinationPath:dataDir error:nil]; | |
printf("%s\n", [id cStringUsingEncoding:NSUTF8StringEncoding]); | |
} | |
[fileMgr createFileAtPath:[dataLinkDir stringByAppendingPathComponent:@"a"] | |
contents:nil | |
attributes:@{NSFileOwnerAccountID:@501,NSFileGroupOwnerAccountID:@501}]; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment