123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #import "InputPackage.h"
- #import "ErrorReturn.h"
- #import "HelperClass.h"
- @implementation InputPackage
- - (NSString*) description {
-
- NSString *orig = [super description];
- NSMutableDictionary *details = [NSMutableDictionary new];
- NSArray *props = [self properties];
- [props enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- NSString *cv = [self valueForKey:obj];
- if (cv){
- details[obj] = cv;
- }
-
- }];
- return [NSString stringWithFormat:@"%@ = %@", orig, details];
-
- }
- - (NSString *)listfile {
-
- __block NSMutableArray *outFiles = [NSMutableArray new];
- [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- if ([obj.fileType isEqualToString:@"link"]){ //does this need to handle things differently?
- [outFiles addObject:obj.path];
- } else {
- [outFiles addObject:obj.path];
- }
- }];
- return [outFiles componentsJoinedByString:@"\n"];
-
- }
- - (void)repackageInCurrentDirectoryWithArch:(NSString *)newArch {
- NSString *fakeRoot = [[HelperClass returnForProcess:@"/usr/bin/which fakeroot"] componentsJoinedByString:@"\n"];
- NSString *pwd = [[HelperClass returnForProcess:@"/bin/pwd"] componentsJoinedByString:@"\n"];
- 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"];
- [FM createDirectoryAtPath:tmpPath withIntermediateDirectories:TRUE attributes:nil error:nil];
- DLog(@"\nExtracting package contents for processing...\n");
- [HelperClass returnForProcess:[NSString stringWithFormat:@"/usr/local/bin/dpkg -x %@ %@", self.path, tmpPath]];
- [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]];
-
-
- if (newArch != nil) {
-
- NSString *controlPath = [debian stringByAppendingPathComponent:@"control"];
-
- NSMutableString *controlFile = [[NSMutableString alloc] initWithContentsOfFile:controlPath encoding:NSUTF8StringEncoding error:nil];
- //@"appletvos-arm64"
- [controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:newArch options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
-
- [controlFile writeToFile:controlPath atomically:TRUE];
- }
-
- //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"];
- //__block NSMutableArray *_overwriteArray = [NSMutableArray new];
- [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- if (obj.type == BSPackageFileTypeFile || obj.type == BSPackageFileTypeDirectory){
-
-
- NSString *fullPath = [tmpPath stringByAppendingPathComponent:obj.path];
-
- if ([ignoreFiles containsObject:obj.path.lastPathComponent]){
-
- DLog(@"in ignore file list, purge");
- [FM removeItemAtPath:fullPath error:nil];
-
- }
-
- NSArray *pathComponents = [obj.path pathComponents];
- if ([pathComponents count] > 1)
- {
-
- NSString *rootPath = [pathComponents objectAtIndex:1];
- DLog(@"\n Checking root path: %@ for file %@\n", rootPath, obj.path);
- if ([forbiddenRoots containsObject:rootPath])
- {
- DLog(@"\n [ERROR] package file: '%@' would overwrite symbolic link at '%@'\n\n", obj.path, rootPath);
- NSString *privateDir = [tmpPath stringByAppendingPathComponent:@"private"];
- 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];
- NSString *newPath = [privateDir stringByAppendingPathComponent:rootPath];
- DLog(@"\n [INFO] Moving %@ to %@...", badPath, newPath);
- [FM moveItemAtPath:badPath 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"];
-
-
- //return er;
- }
- - (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]){
-
- //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)
- {
- NSString *rootPath = [pathComponents objectAtIndex:1];
- 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
|