// main.cpp // futurerestore // // Created by tihmstar on 14.09.16. // Copyright © 2016 tihmstar. All rights reserved. // #include #include #include #include #include #include #include "futurerestore.hpp" #ifdef HAVE_LIBIPATCHER #include #endif extern "C"{ #include "tsschecker.h" }; static struct option longopts[] = { { "apticket", required_argument, NULL, 't' }, { "baseband", required_argument, NULL, 'b' }, { "baseband-manifest", required_argument, NULL, 'p' }, { "sep", required_argument, NULL, 's' }, { "sep-manifest", required_argument, NULL, 'm' }, { "wait", no_argument, NULL, 'w' }, { "update", no_argument, NULL, 'u' }, { "debug", no_argument, NULL, 'd' }, { "latest-sep", no_argument, NULL, '0' }, { "latest-baseband", no_argument, NULL, '1' }, { "no-baseband", no_argument, NULL, '2' }, #ifdef HAVE_LIBIPATCHER { "use-pwndfu", no_argument, NULL, '3' }, { "just-boot", optional_argument, NULL, '4' }, #endif { NULL, 0, NULL, 0 } }; #define FLAG_WAIT 1 << 0 #define FLAG_UPDATE 1 << 1 #define FLAG_LATEST_SEP 1 << 2 #define FLAG_LATEST_BASEBAND 1 << 3 #define FLAG_NO_BASEBAND 1 << 4 #define FLAG_IS_PWN_DFU 1 << 5 void cmd_help(){ printf("Usage: futurerestore [OPTIONS] IPSW\n"); printf("Allows restoring nonmatching iOS/Sep/Baseband\n\n"); printf(" -t, --apticket PATH\t\tApticket used for restoring\n"); printf(" -b, --baseband PATH\t\tBaseband to be flashed\n"); printf(" -p, --baseband-manifest PATH\tBuildmanifest for requesting baseband ticket\n"); printf(" -s, --sep PATH\t\tSep to be flashed\n"); printf(" -m, --sep-manifest PATH\tBuildmanifest for requesting sep ticket\n"); printf(" -w, --wait\t\t\tkeep rebooting until nonce matches APTicket\n"); printf(" -u, --update\t\t\tupdate instead of erase install\n"); printf(" --latest-sep\t\tuse latest signed sep instead of manually specifying one(may cause bad restore)\n"); printf(" --latest-baseband\t\tuse latest signed baseband instead of manually specifying one(may cause bad restore)\n"); #ifdef HAVE_LIBIPATCHER printf(" --use-pwndfu\t\tuse this for restoring devices with odysseus method. Device needs to be in kDFU mode already\n"); printf(" --just-boot=\"-v\"\t\tuse this to tethered boot the device from kDFU mode. You can optionally set bootargs\n"); #endif printf(" --no-baseband\t\tskip checks and don't flash baseband.\n"); printf(" \t\tWARNING: only use this for device without baseband (eg iPod or some wifi only iPads)\n"); printf("\n"); } using namespace std; using namespace tihmstar; int main_r(int argc, const char * argv[]) { int err=0; int res = -1; printf("Version: " VERSION_COMMIT_SHA " - " VERSION_COMMIT_COUNT "\n"); #ifdef HAVE_LIBIPATCHER printf("%s\n",libipatcher::version().c_str()); printf("Odysseus Support: yes\n"); printf("Odysseus 64bit support: %s\n",(libipatcher::has64bitSupport() ? "yes" : "no")); #else printf("Odysseus Support: no\n"); #endif int optindex = 0; int opt = 0; long flags = 0; int isSepManifestSigned = 0; int isBasebandSigned = 0; const char *ipsw = NULL; const char *basebandPath = NULL; const char *basebandManifestPath = NULL; const char *sepPath = NULL; const char *sepManifestPath = NULL; const char *bootargs = NULL; vector apticketPaths; t_devicevals devVals = {0}; t_iosVersion versVals = {0}; if (argc == 1){ cmd_help(); return -1; } while ((opt = getopt_long(argc, (char* const *)argv, "ht:b:p:s:m:wud01", longopts, &optindex)) > 0) { switch (opt) { case 't': // long option: "apticket"; can be called as short option apticketPaths.push_back(optarg); break; case 'b': // long option: "baseband"; can be called as short option basebandPath = optarg; break; case 'p': // long option: "baseband-plist"; can be called as short option basebandManifestPath = optarg; break; case 's': // long option: "sep"; can be called as short option sepPath = optarg; break; case 'm': // long option: "sep-manifest"; can be called as short option sepManifestPath = optarg; break; case 'w': // long option: "wait"; can be called as short option flags |= FLAG_WAIT; break; case 'u': // long option: "update"; can be called as short option flags |= FLAG_UPDATE; break; case '0': // long option: "latest-sep"; flags |= FLAG_LATEST_SEP; break; case '1': // long option: "latest-baseband"; flags |= FLAG_LATEST_BASEBAND; break; case '2': // long option: "no-baseband"; flags |= FLAG_NO_BASEBAND; break; #ifdef HAVE_LIBIPATCHER case '3': // long option: "no-baseband"; flags |= FLAG_IS_PWN_DFU; break; case '4': // long option: "just-boot"; bootargs = (optarg) ? optarg : ""; break; break; #endif case 'd': // long option: "debug"; can be called as short option idevicerestore_debug = 1; break; default: cmd_help(); return -1; } } if (argc-optind == 1) { argc -= optind; argv += optind; ipsw = argv[0]; }else if (argc == optind && flags & FLAG_WAIT) { info("User requested to only wait for APNonce to match, but not actually restoring\n"); }else{ error("argument parsing failed! agrc=%d optind=%d\n",argc,optind); if (idevicerestore_debug){ for (int i=0; i