]>
Commit | Line | Data |
---|---|---|
551d8fe5 JF |
1 | /* AFC2 - the original definition of "jailbreak" |
2 | * Copyright (C) 2014 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* GNU General Public License, Version 3 {{{ */ | |
6 | /* | |
7 | * Cydia is free software: you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published | |
9 | * by the Free Software Foundation, either version 3 of the License, | |
10 | * or (at your option) any later version. | |
11 | * | |
12 | * Cydia is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with Cydia. If not, see <http://www.gnu.org/licenses/>. | |
19 | **/ | |
20 | /* }}} */ | |
21 | ||
22 | #include <Foundation/Foundation.h> | |
23 | #include <CommonCrypto/CommonDigest.h> | |
24 | #include <zlib.h> | |
25 | ||
26 | #define _failif(test) \ | |
27 | if (test) return @ #test; | |
28 | ||
29 | static NSString *download() { | |
30 | // iPhone3,1 runs armv7: not that it matters, but we don't have an arm64 full update; and as iOS 7 does not support armv6, this one URL covers all users ;P | |
31 | NSString *url(@"http://appldnld.apple.com/iOS7/091-9438.20130918.Lkki8/com_apple_MobileAsset_SoftwareUpdate/7725c7df3d8b6617915ad0d80789fbf4d2b18823.zip"); | |
32 | ||
33 | NSMutableURLRequest *request([NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]); | |
34 | [request setHTTPShouldHandleCookies:NO]; | |
35 | [request setValue:@"bytes=1053518009-1053526335" forHTTPHeaderField:@"Range"]; | |
36 | printf("downloading afcd...\n"); | |
37 | ||
38 | NSHTTPURLResponse *response(nil); | |
39 | ||
40 | NSError *error(nil); | |
41 | NSData *data([NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]); | |
42 | if (error != nil) return [error localizedDescription]; | |
43 | ||
44 | _failif(response == nil); | |
45 | _failif([response statusCode] != 206); | |
46 | ||
47 | _failif(data == nil); | |
48 | _failif([data length] != 0x2087); | |
49 | ||
50 | uint8_t digest[CC_SHA1_DIGEST_LENGTH]; | |
51 | CC_SHA1([data bytes], [data length], digest); | |
52 | _failif(memcmp(digest, (uint8_t[]) {0x7c,0x20,0x8c,0xa7,0x7a,0x2b,0xcb,0x04,0xa9,0x61,0x9b,0x73,0x70,0x5d,0xb3,0x3f,0x36,0x2b,0x1e,0xa5}, sizeof(digest)) != 0); | |
53 | ||
54 | z_stream stream; | |
55 | memset(&stream, 0, sizeof(stream)); | |
56 | ||
57 | stream.next_in = static_cast<Bytef *>(const_cast<void *>([data bytes])); | |
58 | stream.avail_in = [data length]; | |
59 | ||
60 | char buffer[0x5fb0]; | |
61 | stream.next_out = reinterpret_cast<Bytef *>(buffer); | |
62 | stream.avail_out = sizeof(buffer); | |
63 | ||
64 | _failif(inflateInit2(&stream, -15) != Z_OK); | |
65 | _failif(inflate(&stream, Z_SYNC_FLUSH) != Z_STREAM_END); | |
66 | _failif(inflateEnd(&stream) != Z_OK); | |
67 | ||
68 | _failif(stream.avail_in != 0); | |
69 | _failif(stream.avail_out != 0); | |
70 | ||
71 | bool written([[NSData dataWithBytes:buffer length:sizeof(buffer)] writeToFile:@"/usr/libexec/afc2d" atomically:YES]); | |
72 | _failif(!written); | |
73 | return nil; | |
74 | } | |
75 | ||
76 | int main(int argc, const char *argv[]) { | |
77 | if (argc < 2 || ( | |
78 | strcmp(argv[1], "install") != 0 && | |
79 | strcmp(argv[1], "upgrade") != 0 && | |
80 | true)) return 0; | |
81 | ||
82 | NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); | |
83 | ||
83461951 | 84 | if (kCFCoreFoundationVersionNumber >= 800) |
551d8fe5 JF |
85 | if (NSString *error = download()) { |
86 | fprintf(stderr, "error: %s\n", [error UTF8String]); | |
87 | return 1; | |
88 | } | |
89 | ||
0a3e1c15 JF |
90 | if (kCFCoreFoundationVersionNumber < 1000) { |
91 | NSString *path(@"/System/Library/Lockdown/Services.plist"); | |
551d8fe5 | 92 | |
0a3e1c15 JF |
93 | NSMutableDictionary *services([NSMutableDictionary dictionaryWithContentsOfFile:path]); |
94 | if (services == nil) { | |
95 | fprintf(stderr, "cannot read Services.plist\n"); | |
96 | return 1; | |
97 | } | |
98 | ||
99 | [services setObject:@{ | |
100 | @"AllowUnactivatedService": @true, | |
101 | @"Label": @"com.apple.afc2", | |
102 | @"ProgramArguments": @[@"/usr/libexec/afc2d", @"-S", @"-L", @"-d", @"/"], | |
103 | } forKey:@"com.apple.afc2"]; | |
104 | ||
105 | if (![services writeToFile:path atomically:YES]) { | |
106 | fprintf(stderr, "cannot write Services.plist\n"); | |
107 | return 1; | |
108 | } | |
109 | } | |
551d8fe5 | 110 | |
551d8fe5 JF |
111 | system("/bin/launchctl stop com.apple.mobile.lockdown"); |
112 | ||
113 | [pool release]; | |
551d8fe5 JF |
114 | return 0; |
115 | } |