|
@@ -1,6 +1,7 @@
|
|
|
#import "InputPackage.h"
|
|
|
#import "ErrorReturn.h"
|
|
|
#import "HelperClass.h"
|
|
|
+#import "Universalize.h"
|
|
|
|
|
|
@implementation InputPackage
|
|
|
|
|
@@ -234,6 +235,58 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+- (BOOL)fileIsSymbolicLink:(NSString *)file {
|
|
|
+
|
|
|
+ NSString *fileType = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:nil][NSFileType];
|
|
|
+ return ([fileType isEqualToString:NSFileTypeSymbolicLink] || [fileType isEqualToString:NSFileTypeDirectory]);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)flattenIfNecessary:(NSString *)file {
|
|
|
+ if ([self fileIsSymbolicLink:file]){
|
|
|
+ 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];
|
|
|
+ }
|
|
|
+ int uni = [Universalize universalize:file];
|
|
|
+ if (uni == 1){
|
|
|
+ DLog(@"Universalized %@ successfully!", file);
|
|
|
+ [self codesignRetainingSignature:file];
|
|
|
+ } else {
|
|
|
+ DLog(@"Universalize %@ failed or non zero!: %d", file, uni);
|
|
|
+ }
|
|
|
+ // @"sudo lipo -thin arm64 $input.og -output $input";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)codesignRetainingSignature:(NSString *)file {
|
|
|
+
|
|
|
+ NSString *jtp = [HelperClass singleLineReturnForProcess:@"/usr/bin/which jtool"];
|
|
|
+ if (jtp){
|
|
|
+
|
|
|
+ [[NSFileManager defaultManager] 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"]){
|
|
@@ -248,28 +301,34 @@
|
|
|
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];
|
|
|
+ NSString *returnValue = [HelperClass singleLineReturnForProcess:runCommand];
|
|
|
|
|
|
NSLog(@"returnValue: %@", returnValue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)flattenInPath:(NSString *)thePath {
|
|
|
+
|
|
|
+ [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+ NSString *file = [thePath stringByAppendingPathComponent:obj.path];
|
|
|
+ NSLog(@"check sig file: %@", obj.path);
|
|
|
+ [self flattenIfNecessary:file];
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
- (void)validateSignaturesInPath:(NSString *)thePath {
|
|
|
|
|
|
[self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
NSString *file = [thePath stringByAppendingPathComponent:obj.path];
|
|
|
-
|
|
|
NSLog(@"check sig file: %@", file);
|
|
|
[self codesignIfNecessary:file];
|
|
|
-
|
|
|
-
|
|
|
}];
|
|
|
|
|
|
}
|
|
@@ -417,8 +476,8 @@
|
|
|
|
|
|
__block NSInteger markedForDeath = NSNotFound;
|
|
|
[lines enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
-
|
|
|
- // DLog(@"obj: %@", obj);
|
|
|
+
|
|
|
+ // DLog(@"obj: %@", obj);
|
|
|
|
|
|
if ([obj rangeOfString:@"uicache"].location != NSNotFound){
|
|
|
|
|
@@ -434,7 +493,7 @@
|
|
|
}];
|
|
|
|
|
|
if (markedForDeath != NSNotFound){
|
|
|
-
|
|
|
+
|
|
|
[lines removeObjectAtIndex:markedForDeath];
|
|
|
NSString *newString = [lines componentsJoinedByString:@"\n"];
|
|
|
[newString writeToFile:postinst atomically:TRUE];
|
|
@@ -467,6 +526,7 @@
|
|
|
|
|
|
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) {
|
|
|
|