Add option "--exit-recovery"

Co-Authored-By: Luke S. <luke@street.dev>
This commit is contained in:
s0uthwest 2019-12-25 11:01:47 -08:00
parent 13a14f7e96
commit c02e9d5876
5 changed files with 29 additions and 25 deletions

1
.gitignore vendored
View file

@ -19,7 +19,6 @@ libtool
ltmain.sh ltmain.sh
m4 m4
missing missing
*/config.h*
*/futurerestore* */futurerestore*
stamp-h1 stamp-h1
xcuserdata xcuserdata

View file

@ -8,6 +8,7 @@ AM_INIT_AUTOMAKE([subdir-objects])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_MACRO_DIRS([m4])
# Versioning.
AC_DEFINE([VERSION_COMMIT_COUNT], "m4_esyscmd([git rev-list --count HEAD | tr -d '\n'])", [Git commit count]) AC_DEFINE([VERSION_COMMIT_COUNT], "m4_esyscmd([git rev-list --count HEAD | tr -d '\n'])", [Git commit count])
AC_DEFINE([VERSION_COMMIT_SHA], "m4_esyscmd([git rev-parse HEAD | tr -d '\n'])", [Git commit sha]) AC_DEFINE([VERSION_COMMIT_SHA], "m4_esyscmd([git rev-parse HEAD | tr -d '\n'])", [Git commit sha])
AC_SUBST([VERSION_COMMIT_COUNT], ["m4_esyscmd([git rev-list --count HEAD | tr -d '\n'])"]) AC_SUBST([VERSION_COMMIT_COUNT], ["m4_esyscmd([git rev-list --count HEAD | tr -d '\n'])"])
@ -17,8 +18,7 @@ AC_SUBST([VERSION_COMMIT_SHA], ["m4_esyscmd([git rev-parse HEAD | tr -d '\n'])"]
AC_PROG_CXX AC_PROG_CXX
AC_PROG_CC AC_PROG_CC
# Check for operating system.
# Check for operating system
AC_MSG_CHECKING([whether we need platform-specific build settings]) AC_MSG_CHECKING([whether we need platform-specific build settings])
case $host_os in case $host_os in
darwin* ) darwin* )
@ -26,13 +26,11 @@ case $host_os in
;; ;;
esac esac
# Checks the flags.
CFLAGS="-DIDEVICERESTORE_NOMAIN=1 -DTSSCHECKER_NOMAIN=1" CFLAGS="-DIDEVICERESTORE_NOMAIN=1 -DTSSCHECKER_NOMAIN=1"
CXXFLAGS+=" -std=c++11" CXXFLAGS+=" -std=c++11"
CFLAGS+=" -std=c11" CFLAGS+=" -std=c11"
AC_DEFUN([AX_UNPRECIOUS], [ AC_DEFUN([AX_UNPRECIOUS], [
m4_define([_AC_PRECIOUS_VARS], m4_bpatsubst(_AC_PRECIOUS_VARS, [$1], [])) m4_define([_AC_PRECIOUS_VARS], m4_bpatsubst(_AC_PRECIOUS_VARS, [$1], []))
]) ])
@ -42,8 +40,7 @@ export CFLAGS
AC_CONFIG_SUBDIRS(external/idevicerestore external/tsschecker) AC_CONFIG_SUBDIRS(external/idevicerestore external/tsschecker)
AC_CONFIG_SRCDIR([futurerestore]) AC_CONFIG_SRCDIR([futurerestore])
# Checks the libraries.
LIBIPATCHER_REQUIRES_STR="libipatcher >= 61" LIBIPATCHER_REQUIRES_STR="libipatcher >= 61"
LIBPLIST_REQUIRES_STR="libplist >= 2.0.0" LIBPLIST_REQUIRES_STR="libplist >= 2.0.0"
LIBZIP_REQUIRES_STR="libzip >= 0.10" LIBZIP_REQUIRES_STR="libzip >= 0.10"
@ -61,7 +58,6 @@ PKG_CHECK_MODULES(libirecovery, $LIBIRECOVERY_REQUIRES_STR)
PKG_CHECK_MODULES(libimg4tool, $IMG4TOOL_REQUIRES_STR) PKG_CHECK_MODULES(libimg4tool, $IMG4TOOL_REQUIRES_STR)
PKG_CHECK_MODULES(libgeneral, $LIBGENERAL_REQUIRES_STR) PKG_CHECK_MODULES(libgeneral, $LIBGENERAL_REQUIRES_STR)
# Optional module libipatcher # Optional module libipatcher
AC_ARG_WITH([libipatcher], AC_ARG_WITH([libipatcher],
[AS_HELP_STRING([--without-libipatcher], [AS_HELP_STRING([--without-libipatcher],
@ -87,7 +83,6 @@ AM_CONDITIONAL([HAVE_LIBIPATCHER],[test "x$do_libipatcher" = "xyes"])
AC_DEFINE(CUSTOM_LOGGING, 1, [required for futurerestore]) AC_DEFINE(CUSTOM_LOGGING, 1, [required for futurerestore])
LT_INIT LT_INIT
AC_OUTPUT([ AC_OUTPUT([
@ -95,7 +90,6 @@ Makefile
futurerestore/Makefile futurerestore/Makefile
]) ])
echo " echo "
Configuration for $PACKAGE $VERSION: Configuration for $PACKAGE $VERSION:
------------------------------------------- -------------------------------------------

View file

@ -178,6 +178,12 @@ void futurerestore::setAutoboot(bool val){
retassure(!recovery_set_autoboot(_client, val),"Setting auto-boot failed?!\n"); retassure(!recovery_set_autoboot(_client, val),"Setting auto-boot failed?!\n");
} }
void futurerestore::exitRecovery() {
setAutoboot(true);
recovery_send_reset(_client);
recovery_client_free(_client);
}
plist_t futurerestore::nonceMatchesApTickets(){ plist_t futurerestore::nonceMatchesApTickets(){
retassure(_didInit, "did not init\n"); retassure(_didInit, "did not init\n");
@ -188,7 +194,6 @@ plist_t futurerestore::nonceMatchesApTickets(){
_rerestoreiOS9 = (info("Detected iOS 9 re-restore, proceeding in DFU mode\n"),true); _rerestoreiOS9 = (info("Detected iOS 9 re-restore, proceeding in DFU mode\n"),true);
} }
unsigned char* realnonce; unsigned char* realnonce;
int realNonceSize = 0; int realNonceSize = 0;
if (_rerestoreiOS9) { if (_rerestoreiOS9) {

View file

@ -63,7 +63,6 @@ class futurerestore {
//methods //methods
void enterPwnRecovery(plist_t build_identity, std::string bootargs = ""); void enterPwnRecovery(plist_t build_identity, std::string bootargs = "");
public: public:
futurerestore(bool isUpdateInstall = false, bool isPwnDfu = false); futurerestore(bool isUpdateInstall = false, bool isPwnDfu = false);
bool init(); bool init();
@ -71,6 +70,7 @@ public:
uint64_t getDeviceEcid(); uint64_t getDeviceEcid();
void putDeviceIntoRecovery(); void putDeviceIntoRecovery();
void setAutoboot(bool val); void setAutoboot(bool val);
void exitRecovery();
void waitForNonce(); void waitForNonce();
void waitForNonce(vector<const char *>nonces, size_t nonceSize); void waitForNonce(vector<const char *>nonces, size_t nonceSize);
void loadAPTickets(const vector<const char *> &apticketPaths); void loadAPTickets(const vector<const char *> &apticketPaths);
@ -93,14 +93,12 @@ public:
void setBasebandPath(const char *basebandPath); void setBasebandPath(const char *basebandPath);
bool isUpdateInstall(){return _isUpdateInstall;}; bool isUpdateInstall(){return _isUpdateInstall;};
plist_t sepManifest(){return _sepbuildmanifest;}; plist_t sepManifest(){return _sepbuildmanifest;};
plist_t basebandManifest(){return _basebandbuildmanifest;}; plist_t basebandManifest(){return _basebandbuildmanifest;};
const char *sepManifestPath(){return _sepbuildmanifestPath;}; const char *sepManifestPath(){return _sepbuildmanifestPath;};
const char *basebandManifestPath(){return _basebandbuildmanifestPath;}; const char *basebandManifestPath(){return _basebandbuildmanifestPath;};
bool is32bit(){return !is_image4_supported(_client);}; bool is32bit(){return !is_image4_supported(_client);};
uint64_t getBasebandGoldCertIDFromDevice(); uint64_t getBasebandGoldCertIDFromDevice();
void doRestore(const char *ipsw); void doRestore(const char *ipsw);
@ -117,7 +115,4 @@ public:
static std::string getGeneratorFromSHSH2(const plist_t shsh2); static std::string getGeneratorFromSHSH2(const plist_t shsh2);
}; };
#endif /* futurerestore_hpp */ #endif /* futurerestore_hpp */

View file

@ -1,4 +1,4 @@
//
// main.cpp // main.cpp
// futurerestore // futurerestore
// //
@ -6,7 +6,6 @@
// Copyright © 2016 tihmstar. All rights reserved. // Copyright © 2016 tihmstar. All rights reserved.
// //
#include <iostream> #include <iostream>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
@ -42,6 +41,7 @@ static struct option longopts[] = {
{ "use-pwndfu", no_argument, NULL, '3' }, { "use-pwndfu", no_argument, NULL, '3' },
{ "just-boot", optional_argument, NULL, '4' }, { "just-boot", optional_argument, NULL, '4' },
#endif #endif
{ "exit-recovery", no_argument, NULL, '5' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -70,9 +70,9 @@ void cmd_help(){
printf(" --use-pwndfu\t\tuse this for restoring devices with odysseus method. Device needs to be in kDFU mode already\n"); 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"); printf(" --just-boot=\"-v\"\t\tuse this to tethered boot the device from kDFU mode. You can optionally set bootargs\n");
#endif #endif
printf(" --exit-recovery\t\tExit recovery mode and quit\n");
printf(" --no-baseband\t\tskip checks and don't flash baseband.\n"); 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(" \t\tWARNING: only use this for device without baseband (eg iPod or some wifi only iPads)\n\n");
printf("\n");
} }
using namespace std; using namespace std;
@ -91,6 +91,7 @@ int main_r(int argc, const char * argv[]) {
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
long flags = 0; long flags = 0;
bool exitRecovery = false;
int isSepManifestSigned = 0; int isSepManifestSigned = 0;
int isBasebandSigned = 0; int isBasebandSigned = 0;
@ -112,8 +113,7 @@ int main_r(int argc, const char * argv[]) {
return -1; return -1;
} }
while ((opt = getopt_long(argc, (char* const *)argv, "ht:b:p:s:m:wud0123", longopts, &optindex)) > 0) {
while ((opt = getopt_long(argc, (char* const *)argv, "ht:b:p:s:m:wud01", longopts, &optindex)) > 0) {
switch (opt) { switch (opt) {
case 't': // long option: "apticket"; can be called as short option case 't': // long option: "apticket"; can be called as short option
apticketPaths.push_back(optarg); apticketPaths.push_back(optarg);
@ -146,7 +146,7 @@ int main_r(int argc, const char * argv[]) {
flags |= FLAG_NO_BASEBAND; flags |= FLAG_NO_BASEBAND;
break; break;
#ifdef HAVE_LIBIPATCHER #ifdef HAVE_LIBIPATCHER
case '3': // long option: "no-baseband"; case '3': // long option: "use-pwndfu";
flags |= FLAG_IS_PWN_DFU; flags |= FLAG_IS_PWN_DFU;
break; break;
case '4': // long option: "just-boot"; case '4': // long option: "just-boot";
@ -154,6 +154,9 @@ int main_r(int argc, const char * argv[]) {
break; break;
break; break;
#endif #endif
case '5': // long option: "exit-recovery";
exitRecovery = true;
break;
case 'd': // long option: "debug"; can be called as short option case 'd': // long option: "debug"; can be called as short option
idevicerestore_debug = 1; idevicerestore_debug = 1;
break; break;
@ -169,6 +172,8 @@ int main_r(int argc, const char * argv[]) {
ipsw = argv[0]; ipsw = argv[0];
}else if (argc == optind && flags & FLAG_WAIT) { }else if (argc == optind && flags & FLAG_WAIT) {
info("User requested to only wait for APNonce to match, but not actually restoring\n"); info("User requested to only wait for APNonce to match, but not actually restoring\n");
}else if (exitRecovery){
info("Exiting recovery mode\n");
}else{ }else{
error("argument parsing failed! agrc=%d optind=%d\n",argc,optind); error("argument parsing failed! agrc=%d optind=%d\n",argc,optind);
if (idevicerestore_debug){ if (idevicerestore_debug){
@ -185,6 +190,12 @@ int main_r(int argc, const char * argv[]) {
printf("futurerestore init done\n"); printf("futurerestore init done\n");
retassure(!bootargs || (flags & FLAG_IS_PWN_DFU),"--just-boot requires --use-pwndfu\n"); retassure(!bootargs || (flags & FLAG_IS_PWN_DFU),"--just-boot requires --use-pwndfu\n");
if (exitRecovery) {
client.exitRecovery();
info("Done\n");
return 0;
}
try { try {
if (apticketPaths.size()) client.loadAPTickets(apticketPaths); if (apticketPaths.size()) client.loadAPTickets(apticketPaths);