From 551d8fe51ab02c3142ff42c577758841e7996972 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 24 Jun 2014 19:51:01 -0700 Subject: [PATCH] Apparently, AFC2 is no longer possible on iOS 7.1. --- .gitignore | 2 + afc2d | 2 + control.in | 15 ++++++++ extrainst.mm | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ make.sh | 15 ++++++++ postrm.mm | 43 +++++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 .gitignore create mode 100755 afc2d create mode 100644 control.in create mode 100644 extrainst.mm create mode 100755 make.sh create mode 100644 postrm.mm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..000de66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.deb +_ diff --git a/afc2d b/afc2d new file mode 100755 index 0000000..2d6fcfd --- /dev/null +++ b/afc2d @@ -0,0 +1,2 @@ +#!/bin/bash +exec /usr/libexec/afcd "$@" diff --git a/control.in b/control.in new file mode 100644 index 0000000..e707f2d --- /dev/null +++ b/control.in @@ -0,0 +1,15 @@ +Package: com.saurik.afc2d +Priority: optional +Section: System +Maintainer: Jay Freeman (saurik) +Architecture: iphoneos-arm +Version: ${ver} +Pre-Depends: dpkg (>= 1.14.25-8) +Conflicts: us.scw.afctwoadd, net.angelxwind.afc2ios70, afc2.25pp, afc2.25pp7, afc2.91, app.taig.afc2 +Replaces: us.scw.afctwoadd, net.angelxwind.afc2ios70, afc2.25pp, afc2.25pp7, afc2.91, app.taig.afc2 +Provides: us.scw.afctwoadd, net.angelxwind.afc2ios70, afc2.25pp, afc2.25pp7, afc2.91, app.taig.afc2 +Description: allow full file-system access over USB +Name: Apple File Conduit "2" +Author: Jay Freeman (saurik) +Depiction: http://cydia.saurik.com/info/com.saurik.afc2d/ +Tag: purpose::daemon, role::enduser diff --git a/extrainst.mm b/extrainst.mm new file mode 100644 index 0000000..e0a4efe --- /dev/null +++ b/extrainst.mm @@ -0,0 +1,105 @@ +/* AFC2 - the original definition of "jailbreak" + * Copyright (C) 2014 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see . +**/ +/* }}} */ + +#include +#include +#include + +#define _failif(test) \ + if (test) return @ #test; + +static NSString *download() { + // 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 + NSString *url(@"http://appldnld.apple.com/iOS7/091-9438.20130918.Lkki8/com_apple_MobileAsset_SoftwareUpdate/7725c7df3d8b6617915ad0d80789fbf4d2b18823.zip"); + + NSMutableURLRequest *request([NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]); + [request setHTTPShouldHandleCookies:NO]; + [request setValue:@"bytes=1053518009-1053526335" forHTTPHeaderField:@"Range"]; + printf("downloading afcd...\n"); + + NSHTTPURLResponse *response(nil); + + NSError *error(nil); + NSData *data([NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]); + if (error != nil) return [error localizedDescription]; + + _failif(response == nil); + _failif([response statusCode] != 206); + + _failif(data == nil); + _failif([data length] != 0x2087); + + uint8_t digest[CC_SHA1_DIGEST_LENGTH]; + CC_SHA1([data bytes], [data length], digest); + _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); + + z_stream stream; + memset(&stream, 0, sizeof(stream)); + + stream.next_in = static_cast(const_cast([data bytes])); + stream.avail_in = [data length]; + + char buffer[0x5fb0]; + stream.next_out = reinterpret_cast(buffer); + stream.avail_out = sizeof(buffer); + + _failif(inflateInit2(&stream, -15) != Z_OK); + _failif(inflate(&stream, Z_SYNC_FLUSH) != Z_STREAM_END); + _failif(inflateEnd(&stream) != Z_OK); + + _failif(stream.avail_in != 0); + _failif(stream.avail_out != 0); + + bool written([[NSData dataWithBytes:buffer length:sizeof(buffer)] writeToFile:@"/usr/libexec/afc2d" atomically:YES]); + _failif(!written); + return nil; +} + +int main(int argc, const char *argv[]) { + if (argc < 2 || ( + strcmp(argv[1], "install") != 0 && + strcmp(argv[1], "upgrade") != 0 && + true)) return 0; + + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + + if (kCFCoreFoundationVersionNumber >= 847.24) + if (NSString *error = download()) { + fprintf(stderr, "error: %s\n", [error UTF8String]); + return 1; + } + + NSString *path(@"/System/Library/Lockdown/Services.plist"); + NSMutableDictionary *services([NSMutableDictionary dictionaryWithContentsOfFile:path]); + + [services setObject:@{ + @"AllowUnactivatedService": @true, + @"Label": @"com.apple.afc2", + @"ProgramArguments": @[@"/usr/libexec/afc2d", @"-S", @"-L", @"-d", @"/"], + } forKey:@"com.apple.afc2"]; + + [services writeToFile:path atomically:YES]; + system("/bin/launchctl stop com.apple.mobile.lockdown"); + + [pool release]; + + return 0; +} diff --git a/make.sh b/make.sh new file mode 100755 index 0000000..56519ef --- /dev/null +++ b/make.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e +ver=$(git describe --tags --match="v*" "${flags[@]}" | sed -e 's@-\([^-]*\)-\([^-]*\)$@+\1.\2@;s@^v@@;s@%@~@g') +sudo rm -rf _ +mkdir -p _/DEBIAN +cycc -i2.0 -o_/DEBIAN/extrainst_ -- extrainst.mm -lz -framework Foundation +cycc -i2.0 -o_/DEBIAN/postrm -- postrm.mm -lz -framework Foundation +sed -e 's/\${ver}/'"${ver}"'/' control.in >_/DEBIAN/control +mkdir -p _/usr/libexec +cp -a afc2d _/usr/libexec +deb=com.saurik.afc2d_${ver}_iphoneos-arm.deb +sudo chown -R root:wheel _ +sudo dpkg-deb -b _ "${deb}" +#sudo rm -rf _ +ln -sf com.saurik.afc2d.deb "${deb}" diff --git a/postrm.mm b/postrm.mm new file mode 100644 index 0000000..d3b1332 --- /dev/null +++ b/postrm.mm @@ -0,0 +1,43 @@ +/* AFC2 - the original definition of "jailbreak" + * Copyright (C) 2014 Jay Freeman (saurik) +*/ + +/* GNU General Public License, Version 3 {{{ */ +/* + * Cydia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Cydia is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cydia. If not, see . +**/ +/* }}} */ + +#include + +int main(int argc, const char *argv[]) { + if (argc < 2 || ( + strcmp(argv[1], "abort-install") != 0 && + strcmp(argv[1], "remove") != 0 && + true)) return 0; + + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + + NSString *path(@"/System/Library/Lockdown/Services.plist"); + NSMutableDictionary *services([NSMutableDictionary dictionaryWithContentsOfFile:path]); + + [services removeObjectForKey:@"com.apple.afc2"]; + + [services writeToFile:path atomically:YES]; + system("/bin/launchctl stop com.apple.mobile.lockdown"); + + [pool release]; + + return 0; +} -- 2.47.2