Browse Source

missed mig timeout, adding the foundation to enable checking for payload and backr00m updates

Kevin Bradley 5 years ago
parent
commit
dd2426f367

+ 2 - 0
Meridian/.gitignore

@@ -0,0 +1,2 @@
+build/*
+*.deb

BIN
Meridian/Meridian/bootstrap/meridian-bootstrap/usr/lib/pspawn_hook.dylib


+ 1 - 1
Meridian/Meridian/build_time

@@ -1 +1 @@
-Sun, 18 Nov 2018 22:15:08 -0700
+Mon, 19 Nov 2018 01:24:01 -0700

+ 2 - 2
Meridian/Meridian/jailbreak.m

@@ -156,7 +156,7 @@ int makeShitHappen(ViewController *view, BOOL kppless) {
         unlink("/Library/LaunchDaemons/._dropbear.plist");
     }
    
-    /*
+    
     
     if (file_exists("/meridian/.bootstrap") == 0) {
         
@@ -164,7 +164,7 @@ int makeShitHappen(ViewController *view, BOOL kppless) {
         
     }
     
-   
+   /*
     
     //take these out later, just so i can update the plists as i tweak the payload
     

+ 17 - 0
Meridian/meridian.xcodeproj/project.pbxproj

@@ -15,6 +15,7 @@
 		320AFA9E20E35D5100859485 /* meridian-bootstrap.tar in Resources */ = {isa = PBXBuildFile; fileRef = 320AFA9D20E35D4200859485 /* meridian-bootstrap.tar */; };
 		3249301C20E41D5400E99767 /* jailbreakd.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3249301A20E41CD300E99767 /* jailbreakd.plist */; };
 		3249301D20E41D5600E99767 /* basebinaries.tar in Resources */ = {isa = PBXBuildFile; fileRef = 3249301B20E41D5200E99767 /* basebinaries.tar */; };
+		32517C2021A28F17008515BB /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 32517C1F21A28F11008515BB /* Reachability.m */; };
 		3252638720E0B140003BD42A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3252638620E0B140003BD42A /* AppDelegate.m */; };
 		3252638A20E0B140003BD42A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3252638920E0B140003BD42A /* ViewController.m */; };
 		3252638D20E0B140003BD42A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3252638B20E0B140003BD42A /* Main.storyboard */; };
@@ -151,6 +152,9 @@
 		320AFA9D20E35D4200859485 /* meridian-bootstrap.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = "meridian-bootstrap.tar"; sourceTree = "<group>"; };
 		3249301A20E41CD300E99767 /* jailbreakd.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = jailbreakd.plist; sourceTree = "<group>"; };
 		3249301B20E41D5200E99767 /* basebinaries.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = basebinaries.tar; sourceTree = "<group>"; };
+		32517C1E21A28F11008515BB /* Reachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
+		32517C1F21A28F11008515BB /* Reachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
+		32517C2121A28FBB008515BB /* meridian.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = meridian.plist; sourceTree = "<group>"; };
 		3252638320E0B140003BD42A /* meridianTV.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = meridianTV.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		3252638520E0B140003BD42A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
 		3252638620E0B140003BD42A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -355,6 +359,16 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
+		32517C1D21A28F11008515BB /* Reachability */ = {
+			isa = PBXGroup;
+			children = (
+				32517C1E21A28F11008515BB /* Reachability.h */,
+				32517C1F21A28F11008515BB /* Reachability.m */,
+			);
+			name = Reachability;
+			path = meridianTV/Reachability;
+			sourceTree = SOURCE_ROOT;
+		};
 		3252638420E0B140003BD42A /* meridianTV */ = {
 			isa = PBXGroup;
 			children = (
@@ -375,6 +389,7 @@
 				3252638620E0B140003BD42A /* AppDelegate.m */,
 				3252638820E0B140003BD42A /* ViewController.h */,
 				3252638920E0B140003BD42A /* ViewController.m */,
+				32517C2121A28FBB008515BB /* meridian.plist */,
 				325263AE20E0B506003BD42A /* patchfinder64.c */,
 				325263AF20E0B506003BD42A /* patchfinder64.h */,
 				3252638B20E0B140003BD42A /* Main.storyboard */,
@@ -388,6 +403,7 @@
 		325263A120E0B2C4003BD42A /* PureLayout */ = {
 			isa = PBXGroup;
 			children = (
+				32517C1D21A28F11008515BB /* Reachability */,
 				325263A220E0B2C4003BD42A /* ALView+PureLayout.h */,
 				325263A320E0B2C4003BD42A /* ALView+PureLayout.m */,
 				325263A420E0B2C4003BD42A /* NSArray+PureLayout.h */,
@@ -934,6 +950,7 @@
 				32DC44EF20EF14B5008FFF9C /* kppremount.m in Sources */,
 				325A25AD20E89556001D1BAD /* fun_objc.m in Sources */,
 				32DC44EC20EF123A008FFF9C /* kppkernel.m in Sources */,
+				32517C2021A28F17008515BB /* Reachability.m in Sources */,
 				320AFA9720E21D0A00859485 /* UIColor+Additions.m in Sources */,
 				325263AC20E0B3E6003BD42A /* NSArray+PureLayout.m in Sources */,
 				3252639220E0B141003BD42A /* main.m in Sources */,

BIN
Meridian/meridian.xcodeproj/project.xcworkspace/xcuserdata/kevinbradley.xcuserdatad/UserInterfaceState.xcuserstate


+ 3 - 3
Meridian/meridian.xcodeproj/xcuserdata/kevinbradley.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -12,12 +12,12 @@
 		<key>amfid.xcscheme</key>
 		<dict>
 			<key>orderHint</key>
-			<integer>1</integer>
+			<integer>2</integer>
 		</dict>
 		<key>jailbreakd.xcscheme</key>
 		<dict>
 			<key>orderHint</key>
-			<integer>2</integer>
+			<integer>3</integer>
 		</dict>
 		<key>meridianTV.xcscheme</key>
 		<dict>
@@ -27,7 +27,7 @@
 		<key>pspawn_hook.xcscheme</key>
 		<dict>
 			<key>orderHint</key>
-			<integer>3</integer>
+			<integer>1</integer>
 		</dict>
 	</dict>
 </dict>

+ 5 - 0
Meridian/meridianTV/ViewController.h

@@ -26,6 +26,11 @@
 
 @interface ViewController : UIViewController
 
+- (void)_updateDateCheck;
+- (NSString *)_lastCheckDate;
+-(BOOL)_shouldCheckUpdate;
+- (void)checkForUpdate;
+
 + (instancetype)currentViewController;
 - (void)removingLiberiOS;
 - (void)removingElectraBeta;

+ 162 - 3
Meridian/meridianTV/ViewController.m

@@ -14,6 +14,7 @@
 #import "PureLayout.h"
 #import "UIColor+Additions.h"
 #import <CoreFoundation/CoreFoundation.h>
+#import "Reachability.h"
 //electra
 
 #import "NSTask.h"
@@ -128,6 +129,164 @@ bool jailbreak_has_run = false;
 
 @implementation ViewController
 
+#define NB [NSBundle mainBundle]
+#define UD [NSUserDefaults standardUserDefaults]
+#define FM [NSFileManager defaultManager]
+#define LAST_UPDATE_CHECK @"lastSelfUpdateCheck"
+
+#define UPDATE_CHECK_FREQUENCY @"updateCheckFrequency"
+#define NOW_STRING        [df stringFromDate:[NSDate date]]
+#define CHECK_FREQ        [UD integerForKey:UPDATE_CHECK_FREQUENCY]
+
+- (void)_updateDateCheck
+{
+    NSDateFormatter *df = [[NSDateFormatter alloc] init];
+    [df setDateFormat:@"MMddyy_HHmmss"];
+    NSString *newDate = [df stringFromDate:[NSDate date]];
+    [UD setObject:newDate forKey:LAST_UPDATE_CHECK];
+}
+- (NSString *)_lastCheckDate
+{
+    return [UD objectForKey:LAST_UPDATE_CHECK];
+}
+
+- (NSString *)updatePlist {
+    
+    return [[ViewController documentsFolder] stringByAppendingPathComponent:@"meridian.plist"];
+    
+}
+
+-(BOOL)_shouldCheckUpdate
+{
+    // return true;
+    
+    if (![FM fileExistsAtPath:[self updatePlist]])
+    {
+        return YES;
+    }
+    
+    NSDateFormatter *df = [[NSDateFormatter alloc] init];
+    [df setDateFormat:@"MMddyy_HHmmss"];
+    NSDate *myDate = [df dateFromString: [self _lastCheckDate]];
+    NSDate *now = [df dateFromString:NOW_STRING];
+    double timeSinceDate = [now timeIntervalSinceDate:myDate];
+    
+    double minutes = (timeSinceDate / 60);
+    
+    NSLog(@"minutes: %g",minutes ); //minutes since check
+    
+    if (minutes > CHECK_FREQ) //FIXME change to higher value!!!
+    {
+        [self _updateDateCheck];
+        return YES;
+        
+    }
+    
+    return NO;
+}
+
++ (NSString *)documentsFolder
+{
+    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    return [paths objectAtIndex:0];
+}
+
+- (NSURL *)remotePathURL { return [NSURL URLWithString:@"https://nitosoft.com/ATV4/backr00m/meridian.plist"]; };
+
+//us.scw.afctwoadd
+
++ (void)validateFile:(NSString *)inputFile withChecksum:(NSString *)checksum completion:(void(^)(BOOL valid))completeBlock
+{
+    //LOG_SELF;
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
+        NSTask *sslTask = [[NSTask alloc] init];
+        NSPipe *sspipe = [[NSPipe alloc] init];
+        NSFileHandle *ssh = [sspipe fileHandleForReading];
+        
+        [sslTask setLaunchPath:@"/usr/bin/openssl"];
+        
+        [sslTask setArguments:[NSArray arrayWithObjects:@"sha1", inputFile, nil]];
+        [sslTask setStandardOutput:sspipe];
+        [sslTask setStandardError:sspipe];
+        [sslTask launch];
+        
+        NSData *outData = [ssh readDataToEndOfFile];
+        
+        [sslTask waitUntilExit];
+        
+        NSString *outputString = [[[NSString alloc] initWithData:outData
+                                                        encoding:NSASCIIStringEncoding]
+                                  stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+        
+        //example outputString: SHA1(~/Documents/Tether/AppleTV2,1_4.3_8F455_Restore.ipsw)= b6a2b0baae79daf95f75044c12946839c662d01d
+        
+        //b6a2b0baae79daf95f75044c12946839c662d01d cleaned up
+        NSString *outputSHA = [[[outputString componentsSeparatedByString:@"="] lastObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+        
+        
+        
+        NSLog(@"sha1: %@ against: %@", outputSHA, checksum);
+        if ([outputSHA isEqualToString:checksum])
+        {
+            sslTask = nil;
+            sspipe = nil;
+            completeBlock(YES);
+        }
+        sslTask = nil;
+        sspipe = nil;
+        completeBlock(NO);
+    });
+   
+}
+
+- (void)checkForUpdate //change update check to look for a typedef int rather than bool, then we can say 0 == update nitotv 1 = update essential 2 = both -1 = none?
+{
+    @autoreleasepool {
+        if ([self _shouldCheckUpdate] == FALSE)
+        {
+            NSLog(@"checked within the last %li minutes!!!", (long)CHECK_FREQ);
+            //return nil;
+            
+            return;
+        }
+        
+        BOOL internetAvailable = [Reachability isInternetReachable];
+        if (internetAvailable == TRUE)
+        {
+            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
+                 NSDictionary *theDict = [NSDictionary dictionaryWithContentsOfURL:[self remotePathURL]];
+                
+                //lastUpdated
+                //bootstrapInfo
+                //meridianToolsInfo
+                //electraToolsInfo
+                
+                //version
+                //link
+                //SHA1
+                
+                NSLog(@"science bro: %@", theDict);
+                
+            });
+            
+           
+            
+//            NSArray *updateArray = [packageManagement basicEssentialUpdatesAvailable];
+//            if ([updateArray count] > 0)
+//            {
+//                [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckForUpdate" object:updateArray userInfo:nil];
+//                //return updateArray;
+//            }
+        }
+    }
+    //return nil;
+    
+}
+
+- (void)checkForUpdatedPayloads {
+    
+    
+}
 
 + (instancetype)currentViewController {
     return currentViewController;
@@ -581,7 +740,7 @@ bool jailbreak_has_run = false;
     
     //if you want to run anything post process on device you can do it here for diagnostic purposes.
     
-    /*
+    
      execprog("/bin/ps", (const char **)&(const char *[]) {
         "/bin/ps",
         "awwwx",
@@ -591,10 +750,10 @@ bool jailbreak_has_run = false;
     execprog("/usr/bin/ls", (const char **)&(const char *[]) {
         "/usr/bin/ls",
         "-alR",
-        "/private/etc",
+        "/usr",
         NULL
     });
-    */
+    
     /*
     execprog("/bin/bash", (const char **)&(const char *[]) {
         "/bin/bash",

BIN
Meridian/meridianTV/bootstrap.tar.gz


+ 35 - 0
Meridian/meridianTV/meridian.plist

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>lastUpdated</key>
+	<date>2018-11-19T06:29:45Z</date>
+	<key>bootstrapInfo</key>
+	<dict>
+		<key>version</key>
+		<integer>4</integer>
+		<key>link</key>
+		<string>https://nitosoft.com/ATV4/backr00m/bootstrap.tar.gz</string>
+		<key>SHA1</key>
+		<string>958b6391eaad64b65798a06dc2dc87d0d625bb9b</string>
+	</dict>
+	<key>meridianToolsInfo</key>
+	<dict>
+		<key>version</key>
+		<integer>4</integer>
+		<key>link</key>
+		<string>https://nitosoft.com/ATV4/backr00m/basebinaries.tar</string>
+		<key>SHA1</key>
+		<string>a3c6d7b3bd193f63693bc2b6261e9d0014447d16</string>
+	</dict>
+	<key>electraToolsInfo</key>
+	<dict>
+		<key>version</key>
+		<integer>4</integer>
+		<key>link</key>
+		<string>https://nitosoft.com/ATV4/backr00m/meridian-bootstrap.tar</string>
+		<key>SHA1</key>
+		<string>2c35ba2f1d91bfd9bb5abf44f804fbc8a7fefced</string>
+	</dict>
+</dict>
+</plist>

BIN
Meridian/pspawn_hook/bin/pspawn_hook.dylib


+ 2 - 2
Meridian/pspawn_hook/mach/jailbreak_daemonUser.c

@@ -231,10 +231,10 @@ mig_external kern_return_t jbd_call
 /* END VOUCHER CODE */
 
 	__BeforeSendRpc(500, "call")
-	msg_result = mach_msg(&InP->Head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE, (mach_msg_size_t)sizeof(Request), (mach_msg_size_t)sizeof(Reply), InP->Head.msgh_reply_port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+	msg_result = mach_msg(&InP->Head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE, (mach_msg_size_t)sizeof(Request), (mach_msg_size_t)sizeof(Reply), InP->Head.msgh_reply_port, 2500, MACH_PORT_NULL);
 	__AfterSendRpc(500, "call")
 	if (msg_result != MACH_MSG_SUCCESS) {
-		__MachMsgErrorWithoutTimeout(msg_result);
+		__MachMsgErrorWithTimeout(msg_result);
 		{ return msg_result; }
 	}