|
@@ -98,10 +98,9 @@
|
|
|
|
|
|
NSString *pwd = [[HelperClass returnForProcess:@"/bin/pwd"] componentsJoinedByString:@"\n"];
|
|
|
|
|
|
- NSFileManager *man = [NSFileManager defaultManager];
|
|
|
NSString *tmpPath = [pwd stringByAppendingPathComponent:self.packageName];
|
|
|
NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
|
|
|
- [man createDirectoryAtPath:tmpPath withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
+ [FM createDirectoryAtPath:tmpPath withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
DLog(@"\nExtracting deb for processing...\n");
|
|
|
[HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", self.path, tmpPath]];
|
|
|
|
|
@@ -133,7 +132,7 @@
|
|
|
|
|
|
//[outputs writeToFile:md5s atomically:TRUE encoding:NSASCIIStringEncoding error:nil];
|
|
|
*/
|
|
|
- [man createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
+ [FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
|
|
|
DLog(@"\nExtracting DEBIAN files for processing...\n");
|
|
|
|
|
@@ -144,23 +143,20 @@
|
|
|
|
|
|
__block NSString *postInstFile = nil;
|
|
|
|
|
|
- NSArray *files = [man contentsOfDirectoryAtPath:debian error:nil];
|
|
|
+ NSArray *files = [FM contentsOfDirectoryAtPath:debian error:nil];
|
|
|
[files enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
|
|
NSString *fullPath = [debian stringByAppendingPathComponent:obj];
|
|
|
if (![obj isEqualToString:@"control"]){
|
|
|
-
|
|
|
if ([obj isEqualToString:@"postinst"]){
|
|
|
-
|
|
|
postInstFile = fullPath;
|
|
|
-
|
|
|
}
|
|
|
DLog(@"Copying file... %@\n\n", fullPath);
|
|
|
NSString *fileName = [NSString stringWithFormat:@"%@.%@", self.packageName, obj];
|
|
|
NSString *newPath = [bootstrapPath stringByAppendingPathComponent:@"Library/dpkg/info"];
|
|
|
newPath = [newPath stringByAppendingPathComponent:fileName];
|
|
|
//DLog(@"newPath: %@", newPath);
|
|
|
- [man copyItemAtPath:fullPath toPath:newPath error:nil];
|
|
|
+ [FM copyItemAtPath:fullPath toPath:newPath error:nil];
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -179,66 +175,38 @@
|
|
|
NSMutableString *statusContents = [[NSMutableString alloc] initWithContentsOfFile:statusFile encoding:NSASCIIStringEncoding error:nil];
|
|
|
|
|
|
if (model) { //we found the package model, just replace the old string with our new one
|
|
|
-
|
|
|
-
|
|
|
DLog(@"Updating status file for new package version...\n\n");
|
|
|
|
|
|
[statusContents replaceOccurrencesOfString:model.rawString withString:controlFile options:NSLiteralSearch range:NSMakeRange(0, [statusContents length])];
|
|
|
-
|
|
|
//[statusContents writeToFileWithoutAttributes:statusFile];
|
|
|
[statusContents writeToFile:statusFile atomically:TRUE encoding:NSASCIIStringEncoding error:nil];
|
|
|
-
|
|
|
-
|
|
|
} else {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
DLog(@"Updating status file for new package...\n\n");
|
|
|
|
|
|
//DLog(@"down here??: -%@-\n", controlFile);
|
|
|
-
|
|
|
[statusContents appendFormat:@"%@\n", controlFile];
|
|
|
-
|
|
|
//DLog(@"\nnew status file: %@\n", statusContents);
|
|
|
-
|
|
|
//[statusContents writeToFileWithoutAttributes:statusFile];
|
|
|
-
|
|
|
[statusContents writeToFile:statusFile atomically:TRUE encoding:NSASCIIStringEncoding error:nil];
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}];
|
|
|
|
|
|
//finally actually install the package onto the bootstrap
|
|
|
|
|
|
DLog(@"Extracting package onto bootstrap folder...\n");
|
|
|
-
|
|
|
[HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", self.path, bootstrapPath]];
|
|
|
-
|
|
|
if (postInstFile) {
|
|
|
-
|
|
|
DLog(@"\n [WARNING] We found a postinst file, will not run this due to potential unexpected consequences in your run environment! Displaying contents so you can determine if any additional steps are necessary. Contents will be delimited by a line -----\n");
|
|
|
-
|
|
|
DLog(@"\n%@ Contents:\n\n---------------------\n\n%@\n\n---------------------\n\n", postInstFile, [NSString stringWithContentsOfFile:postInstFile encoding:NSASCIIStringEncoding error:nil]);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
[FM removeItemAtPath:tmpPath error:nil];
|
|
|
-
|
|
|
DLog(@"Done!\n\n");
|
|
|
return 0;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- (BOOL)fileIsSymbolicLink:(NSString *)file {
|
|
|
-
|
|
|
- NSString *fileType = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:nil][NSFileType];
|
|
|
+ NSString *fileType = [FM attributesOfItemAtPath:file error:nil][NSFileType];
|
|
|
return ([fileType isEqualToString:NSFileTypeSymbolicLink] || [fileType isEqualToString:NSFileTypeDirectory]);
|
|
|
}
|
|
|
|
|
@@ -247,15 +215,13 @@
|
|
|
DLog(@"skipping symbolic link: %@", file);
|
|
|
return;
|
|
|
}
|
|
|
- NSFileManager *man = [NSFileManager defaultManager];
|
|
|
NSString *fat = [HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"/usr/bin/lipo -info %@",file]];
|
|
|
if ([fat containsString:@"Architectures"]){
|
|
|
NSString *newFile = [file stringByAppendingPathExtension:@"thin"];
|
|
|
[HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"/usr/bin/lipo -thin arm64 %@ -output %@",file, newFile]];
|
|
|
- if ([man fileExistsAtPath:newFile]){
|
|
|
-
|
|
|
- [man removeItemAtPath:file error:nil];
|
|
|
- [man moveItemAtPath:newFile toPath:file error:nil];
|
|
|
+ if ([FM fileExistsAtPath:newFile]){
|
|
|
+ [FM removeItemAtPath:file error:nil];
|
|
|
+ [FM moveItemAtPath:newFile toPath:file error:nil];
|
|
|
}
|
|
|
int uni = [Universalize universalize:file];
|
|
|
if (uni == 1){
|
|
@@ -268,47 +234,33 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//FIXME: change to ldid
|
|
|
- (void)codesignRetainingSignature:(NSString *)file {
|
|
|
-
|
|
|
NSString *jtp = [HelperClass singleLineReturnForProcess:@"/usr/bin/which jtool"];
|
|
|
if (jtp){
|
|
|
-
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:@"/tmp/ent.plist" error:nil];
|
|
|
+ [FM removeItemAtPath:@"/tmp/ent.plist" error:nil];
|
|
|
[HelperClass singleLineReturnForProcess:[NSString stringWithFormat:@"%@ %@ --ent > /tmp/ent.plist", jtp, file]];
|
|
|
NSString *ents = [HelperClass singleLineReturnForProcess:@"/bin/cat /tmp/ent.plist"];
|
|
|
DLog(@"ents: %@", ents);
|
|
|
NSString *runCommand = [NSString stringWithFormat:@"%@ --sign platform %@ --ent /tmp/ent.plist --inplace", jtp, file];
|
|
|
-
|
|
|
DLog(@"running codesign command: %@", runCommand);
|
|
|
-
|
|
|
NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
|
|
|
-
|
|
|
DLog(@"returnValue: %@", returnValue);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- (void)codesignIfNecessary:(NSString *)file {
|
|
|
-
|
|
|
if (![[[file pathExtension] lowercaseString] isEqualToString:@"dylib"]){
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
NSString *jtp = [HelperClass singleLineReturnForProcess:@"/usr/bin/which jtool"];
|
|
|
if (jtp){
|
|
|
-
|
|
|
NSString *proc = [[HelperClass arrayReturnForTask:jtp withArguments:@[@"--sig", file]] componentsJoinedByString:@"\n"];
|
|
|
-
|
|
|
NSLog(@"proc: %@", proc);
|
|
|
-
|
|
|
if ([proc containsString:@"No Code Signing blob detected in this file"]){
|
|
|
-
|
|
|
NSString *runCommand = [NSString stringWithFormat:@"%@ --sign platform %@ --inplace", jtp, file];
|
|
|
-
|
|
|
NSLog(@"running codesign command: %@", runCommand);
|
|
|
-
|
|
|
NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
|
|
|
-
|
|
|
NSLog(@"returnValue: %@", returnValue);
|
|
|
}
|
|
|
}
|
|
@@ -356,10 +308,7 @@
|
|
|
[FM createDirectoryAtPath:debian withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
DLog(@"\nExtracting DEBIAN files for processing...\n");
|
|
|
[HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -e %@ %@", self.path, debian]];
|
|
|
-
|
|
|
-
|
|
|
NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
|
|
|
-
|
|
|
NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSASCIIStringEncoding error:nil];
|
|
|
//@"appletvos-arm64"
|
|
|
[controlFile replaceOccurrencesOfString:self.version withString:[self.version nextVersionNumber] options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
|
|
@@ -376,12 +325,9 @@
|
|
|
|
|
|
//__block NSMutableArray *_overwriteArray = [NSMutableArray new];
|
|
|
[self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
if (obj.type == BSPackageFileTypeFile || obj.type == BSPackageFileTypeDirectory){
|
|
|
-
|
|
|
//DLog(@"processing path: %@", obj.path);
|
|
|
if ([obj.path isEqualToString:@"/private/var/mobile/Applications/"]){
|
|
|
-
|
|
|
NSString *badPath = [tmpPath stringByAppendingPathComponent:obj.path];
|
|
|
NSString *newPath = [tmpPath stringByAppendingPathComponent:@"Applications"];
|
|
|
DLog(@"\n [INFO] Moving %@ to %@...", badPath, newPath);
|
|
@@ -391,12 +337,9 @@
|
|
|
}
|
|
|
|
|
|
NSString *fullPath = [tmpPath stringByAppendingPathComponent:obj.path];
|
|
|
-
|
|
|
if ([ignoreFiles containsObject:obj.path.lastPathComponent]){
|
|
|
-
|
|
|
DLog(@"in ignore file list, purge");
|
|
|
[FM removeItemAtPath:fullPath error:nil];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (self.appendedPrefix.length > 0 && [obj.path properPathComponents].count == 1) {
|
|
@@ -444,9 +387,7 @@
|
|
|
NSString *pwd = [HelperClass singleLineReturnForProcess:@"/bin/pwd"];
|
|
|
DLog(@"\nProcessing file: %@\n", self.path);
|
|
|
InputPackage *output = self;
|
|
|
-
|
|
|
DLog(@"\nFound package: '%@' at version: '%@'...\n", output.packageName, output.version );
|
|
|
-
|
|
|
NSString *tmpPath = [pwd stringByAppendingPathComponent:output.packageName];
|
|
|
NSString *debian = [tmpPath stringByAppendingPathComponent:@"DEBIAN"];
|
|
|
NSString *newRoot = nil;
|
|
@@ -463,25 +404,17 @@
|
|
|
[HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -e %@ %@", self.path, debian]];
|
|
|
|
|
|
//clean up any calls to uicache
|
|
|
-
|
|
|
NSString *postinst = [debian stringByAppendingPathComponent:@"postinst"];
|
|
|
-
|
|
|
//DLog(@"post inst: %@", postinst);
|
|
|
-
|
|
|
if ([FM fileExistsAtPath:postinst]){
|
|
|
NSString *postinstSource = [NSString stringWithContentsOfFile:postinst encoding:NSUTF8StringEncoding error:nil];
|
|
|
if (postinstSource.length > 0){
|
|
|
if ([postinstSource rangeOfString:@"uicache"].location != NSNotFound){
|
|
|
-
|
|
|
NSMutableArray *lines = [[postinstSource componentsSeparatedByString:@"\n"] mutableCopy];
|
|
|
-
|
|
|
//DLog(@"lines: %@", lines);
|
|
|
-
|
|
|
__block NSInteger markedForDeath = NSNotFound;
|
|
|
[lines enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
// DLog(@"obj: %@", obj);
|
|
|
-
|
|
|
if ([obj rangeOfString:@"uicache"].location != NSNotFound){
|
|
|
|
|
|
if ([obj rangeOfString:@"echo"].location == NSNotFound){
|
|
@@ -490,35 +423,23 @@
|
|
|
markedForDeath = idx;
|
|
|
}
|
|
|
*stop = TRUE;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}];
|
|
|
-
|
|
|
if (markedForDeath != NSNotFound){
|
|
|
-
|
|
|
[lines removeObjectAtIndex:markedForDeath];
|
|
|
NSString *newString = [lines componentsJoinedByString:@"\n"];
|
|
|
[newString writeToFile:postinst atomically:TRUE];
|
|
|
#pragma clang diagnostic pop
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
if (newArch != nil) {
|
|
|
-
|
|
|
NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
|
|
|
NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSASCIIStringEncoding error:nil];
|
|
|
//@"appletvos-arm64"
|
|
|
-
|
|
|
//this is hacky but should be fine, only one of the two should exist so only one will get overwritten.
|
|
|
-
|
|
|
[controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:newArch options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
|
|
|
-
|
|
|
[controlFile replaceOccurrencesOfString:@"darwin-arm64" withString:newArch options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
|
|
|
|
|
|
#pragma clang diagnostic push
|
|
@@ -528,15 +449,12 @@
|
|
|
}
|
|
|
|
|
|
//at this point we have the files extracted, time to determine what needs to be changed
|
|
|
-
|
|
|
NSArray *ignoreFiles = @[@".fauxsu", @".DS_Store"];
|
|
|
NSArray *forbiddenRoots = @[@"etc", @"var", @"tmp"];
|
|
|
[self flattenInPath:tmpPath];
|
|
|
//__block NSMutableArray *_overwriteArray = [NSMutableArray new];
|
|
|
[self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
if (obj.type == BSPackageFileTypeFile || obj.type == BSPackageFileTypeDirectory){
|
|
|
-
|
|
|
//DLog(@"processing path: %@", obj.path);
|
|
|
if ([obj.path isEqualToString:@"/private/var/mobile/Applications/"]){
|
|
|
|
|
@@ -547,34 +465,26 @@
|
|
|
[FM removeItemAtPath:[tmpPath stringByAppendingPathComponent:@"private"] error:nil];
|
|
|
*stop = TRUE;
|
|
|
}
|
|
|
-
|
|
|
NSString *fullPath = [tmpPath stringByAppendingPathComponent:obj.path];
|
|
|
-
|
|
|
- if ([ignoreFiles containsObject:obj.path.lastPathComponent]){
|
|
|
-
|
|
|
+ if ([ignoreFiles containsObject:obj.path.lastPathComponent]) {
|
|
|
DLog(@"in ignore file list, purge");
|
|
|
[FM removeItemAtPath:fullPath error:nil];
|
|
|
-
|
|
|
}
|
|
|
if (self.appendedPrefix.length > 0) {
|
|
|
- if (![obj.path containsString:self.appendedPrefix]){
|
|
|
+ if (![obj.path containsString:self.appendedPrefix]) {
|
|
|
DLog(@"[INFO] %@ doesnt have the prefix!", obj.path);
|
|
|
[moveRoot addObject:obj.path];
|
|
|
}
|
|
|
}
|
|
|
NSArray *pathComponents = [obj.path pathComponents];
|
|
|
- if ([pathComponents count] > 1)
|
|
|
- {
|
|
|
-
|
|
|
+ if ([pathComponents count] > 1) {
|
|
|
NSString *rootPath = [pathComponents objectAtIndex:1];
|
|
|
//DLog(@"\n Checking root path: %@ for file %@\n", rootPath, obj.path);
|
|
|
- if ([forbiddenRoots containsObject:rootPath])
|
|
|
- {
|
|
|
+ if ([forbiddenRoots containsObject:rootPath]) {
|
|
|
DLog(@"\n [WARNING] package file: '%@' would overwrite symbolic link at '%@'\n", obj.path, rootPath);
|
|
|
NSString *privateDir = [tmpPath stringByAppendingPathComponent:@"private"];
|
|
|
- if (![FM fileExistsAtPath:privateDir]){
|
|
|
+ if (![FM fileExistsAtPath:privateDir]) {
|
|
|
[FM createDirectoryAtPath:privateDir withIntermediateDirectories:TRUE attributes:nil error:nil];
|
|
|
-
|
|
|
}
|
|
|
//take <package_name>/[rootPath] (could be etc, var, tmp) and move to <package_name>/private/[rootPath]
|
|
|
NSString *badPath = [tmpPath stringByAppendingPathComponent:rootPath];
|
|
@@ -592,67 +502,42 @@
|
|
|
[FM moveItemAtPath:oldPath toPath:newPath error:nil];
|
|
|
}];
|
|
|
NSString *depArchiveInfo = [NSString stringWithFormat:@"/usr/local/bin/dpkg -b %@", self.packageName];
|
|
|
-
|
|
|
if (fakeRoot) {
|
|
|
-
|
|
|
depArchiveInfo = [NSString stringWithFormat:@"%@ /usr/local/bin/dpkg -b %@", fakeRoot, self.packageName];
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
[[HelperClass returnForProcess:depArchiveInfo] componentsJoinedByString:@"\n"];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
DLog(@"\nDone!\n\n");
|
|
|
-
|
|
|
- //return er;
|
|
|
}
|
|
|
|
|
|
-- (ErrorReturn *)errorReturnForBootstrap:(NSString *)bootstrapPath
|
|
|
-{
|
|
|
+- (ErrorReturn *)errorReturnForBootstrap:(NSString *)bootstrapPath {
|
|
|
NSArray *ignoreFiles = @[@".fauxsu", @".DS_Store"];
|
|
|
NSArray *forbiddenRoots = @[@"etc", @"var", @"tmp"];
|
|
|
- NSFileManager *man = [NSFileManager defaultManager];
|
|
|
__block NSInteger returnValue = 0; //0 = good to go 1 = over write warning, 2 = no go
|
|
|
__block NSMutableArray *_overwriteArray = [NSMutableArray new];
|
|
|
[self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
if ([obj.fileType isEqualToString:@"file"]){
|
|
|
-
|
|
|
NSString *fullPath = [bootstrapPath stringByAppendingPathComponent:obj.path];
|
|
|
- if ([man fileExistsAtPath:fullPath] && ![ignoreFiles containsObject:obj.basename]){
|
|
|
-
|
|
|
+ if ([FM fileExistsAtPath:fullPath] && ![ignoreFiles containsObject:obj.basename]){
|
|
|
//DLog(@"[WARNING] overwriting a file that already exists and isn't DS_Store or .fauxsu: %@", fullPath);
|
|
|
[_overwriteArray addObject:obj.path];
|
|
|
//*stop = TRUE;//return FALSE;
|
|
|
returnValue = 1;
|
|
|
}
|
|
|
-
|
|
|
NSArray *pathComponents = [obj.path pathComponents];
|
|
|
- if ([pathComponents count] > 1)
|
|
|
- {
|
|
|
+ if ([pathComponents count] > 1) {
|
|
|
NSString *rootPath = [pathComponents objectAtIndex:1];
|
|
|
- if ([forbiddenRoots containsObject:rootPath])
|
|
|
- {
|
|
|
+ if ([forbiddenRoots containsObject:rootPath]) {
|
|
|
DLog(@"\n [ERROR] package file: '%@' would overwrite symbolic link at '%@'! Exiting!\n\n", obj.path, rootPath);
|
|
|
*stop = TRUE;
|
|
|
returnValue = 2;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}];
|
|
|
-
|
|
|
ErrorReturn *er = [ErrorReturn new];
|
|
|
er.returnStatus = returnValue;
|
|
|
er.overwriteFiles = _overwriteArray;
|
|
|
-
|
|
|
return er;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@end
|