mirror of
https://github.com/tihmstar/futurerestore.git
synced 2025-07-07 15:50:32 +00:00
Major code refactor, update idr for a14 fix
This commit is contained in:
parent
06137f3ba4
commit
6406f51650
2
external/idevicerestore
vendored
2
external/idevicerestore
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 6f78f57cd825c84c872af4615da09de59cb8830e
|
Subproject commit b3ac88e2c5c6faeab88eca86bb4ff0f94972d0f7
|
File diff suppressed because it is too large
Load diff
|
@ -19,6 +19,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <array>
|
||||||
|
#include <string>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -50,7 +52,7 @@ public:
|
||||||
|
|
||||||
class futurerestore {
|
class futurerestore {
|
||||||
struct idevicerestore_client_t* _client;
|
struct idevicerestore_client_t* _client;
|
||||||
char *_ibootBuild = NULL;
|
char *_ibootBuild = nullptr;
|
||||||
bool _didInit = false;
|
bool _didInit = false;
|
||||||
vector<plist_t> _aptickets;
|
vector<plist_t> _aptickets;
|
||||||
vector<pair<char *, size_t>>_im4ms;
|
vector<pair<char *, size_t>>_im4ms;
|
||||||
|
@ -62,28 +64,23 @@ class futurerestore {
|
||||||
bool _serial = false;
|
bool _serial = false;
|
||||||
bool _noRestore = false;
|
bool _noRestore = false;
|
||||||
|
|
||||||
char *_firmwareJson = NULL;
|
char *_firmwareJson = nullptr;
|
||||||
jssytok_t *_firmwareTokens = NULL;;
|
jssytok_t *_firmwareTokens = nullptr;;
|
||||||
char *__latestManifest = NULL;
|
char *_latestManifest = nullptr;
|
||||||
char *__latestFirmwareUrl = NULL;
|
char *_latestFirmwareUrl = nullptr;
|
||||||
|
|
||||||
plist_t _sepbuildmanifest = NULL;
|
plist_t _sepbuildmanifest = nullptr;
|
||||||
plist_t _basebandbuildmanifest = NULL;
|
plist_t _basebandbuildmanifest = nullptr;
|
||||||
|
|
||||||
const char *_rosePath = NULL;
|
|
||||||
const char *_sePath = NULL;
|
|
||||||
const char *_savagePath[6];
|
|
||||||
const char *_veridianDGMPath = NULL;
|
|
||||||
const char *_veridianFWMPath = NULL;
|
|
||||||
|
|
||||||
const char *_basebandPath = NULL;
|
std::string _ramdiskPath;
|
||||||
const char *_sepbuildmanifestPath = NULL;
|
std::string _kernelPath;
|
||||||
const char *_basebandbuildmanifestPath = NULL;
|
std::string _sepPath;
|
||||||
const char *_ramdiskPath = NULL;
|
std::string _sepManifestPath;
|
||||||
const char *_kernelPath = NULL;
|
std::string _basebandPath;
|
||||||
|
std::string _basebandManifestPath;
|
||||||
|
|
||||||
const char *_custom_nonce = NULL;
|
const char *_custom_nonce = nullptr;
|
||||||
const char *_boot_args = NULL;
|
const char *_boot_args = nullptr;
|
||||||
|
|
||||||
bool _noCache = false;
|
bool _noCache = false;
|
||||||
bool _skipBlob = false;
|
bool _skipBlob = false;
|
||||||
|
@ -92,8 +89,7 @@ class futurerestore {
|
||||||
bool _rerestoreiOS9 = false;
|
bool _rerestoreiOS9 = false;
|
||||||
//methods
|
//methods
|
||||||
void enterPwnRecovery(plist_t build_identity, std::string bootargs);
|
void enterPwnRecovery(plist_t build_identity, std::string bootargs);
|
||||||
void enterPwnRecovery2(plist_t build_identity, std::string bootargs = "");
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
futurerestore(bool isUpdateInstall = false, bool isPwnDfu = false, bool noIBSS = false, bool setNonce = false, bool serial = false, bool noRestore = false);
|
futurerestore(bool isUpdateInstall = false, bool isPwnDfu = false, bool noIBSS = false, bool setNonce = false, bool serial = false, bool noRestore = false);
|
||||||
bool init();
|
bool init();
|
||||||
|
@ -115,43 +111,44 @@ public:
|
||||||
const char *getDeviceBoardNoCopy();
|
const char *getDeviceBoardNoCopy();
|
||||||
char *getLatestManifest();
|
char *getLatestManifest();
|
||||||
char *getLatestFirmwareUrl();
|
char *getLatestFirmwareUrl();
|
||||||
|
std::string getSepManifestPath(){return _sepManifestPath;}
|
||||||
|
std::string getBasebandManifestPath(){return _basebandManifestPath;}
|
||||||
void downloadLatestRose();
|
void downloadLatestRose();
|
||||||
void downloadLatestSE();
|
void downloadLatestSE();
|
||||||
void downloadLatestSavage();
|
void downloadLatestSavage();
|
||||||
void downloadLatestVeridian();
|
void downloadLatestVeridian();
|
||||||
void downloadLatestFirmwareComponents();
|
void downloadLatestFirmwareComponents();
|
||||||
void loadLatestBaseband();
|
void downloadLatestBaseband();
|
||||||
void loadLatestSep();
|
void downloadLatestSep();
|
||||||
|
|
||||||
void setSepManifestPath(const char *sepManifestPath);
|
void loadSepManifest(std::string sepManifestPath);
|
||||||
void setBasebandManifestPath(const char *basebandManifestPath);
|
void loadBasebandManifest(std::string basebandManifestPath);
|
||||||
void loadRose(const char *rosePath);
|
void loadRose(std::string rosePath);
|
||||||
void loadSE(const char *sePath);
|
void loadSE(std::string sePath);
|
||||||
void loadSavage(const char *savagePath[6]);
|
void loadSavage(std::array<std::string, 6> savagePaths);
|
||||||
void loadVeridian(const char *veridianDGMPath, const char *veridianFWMPath);
|
void loadVeridian(std::string veridianDGMPath, std::string veridianFWMPath);
|
||||||
void loadRamdisk(const char *ramdiskPath);
|
void loadRamdisk(std::string ramdiskPath);
|
||||||
void loadKernel(const char *kernelPath);
|
void loadKernel(std::string kernelPath);
|
||||||
void loadSep(const char *sepPath);
|
void loadSep(std::string sepPath);
|
||||||
void setBasebandPath(const char *basebandPath);
|
void loadBaseband(std::string basebandPath);
|
||||||
void setRamdiskPath(const char *ramdiskPath);
|
|
||||||
void setKernelPath(const char *kernelPath);
|
void setSepPath(std::string sepPath) {_sepPath = sepPath;}
|
||||||
|
void setSepManifestPath(std::string sepManifestPath) {_sepManifestPath = sepManifestPath;}
|
||||||
|
void setRamdiskPath(std::string ramdiskPath) {_ramdiskPath = ramdiskPath;}
|
||||||
|
void setKernelPath(std::string kernelPath) {_kernelPath = kernelPath;}
|
||||||
|
void setBasebandPath(std::string basebandPath) {_basebandPath = basebandPath;}
|
||||||
|
void setBasebandManifestPath(std::string basebandManifestPath) {_basebandManifestPath = basebandManifestPath;}
|
||||||
void setNonce(const char *custom_nonce){_custom_nonce = custom_nonce;};
|
void setNonce(const char *custom_nonce){_custom_nonce = custom_nonce;};
|
||||||
void setBootArgs(const char *boot_args){_boot_args = boot_args;};
|
void setBootArgs(const char *boot_args){_boot_args = boot_args;};
|
||||||
void disableCache(){_noCache = true;};
|
void disableCache(){_noCache = true;};
|
||||||
void skipBlobValidation(){_skipBlob = true;};
|
void skipBlobValidation(){_skipBlob = true;};
|
||||||
bool isUpdateInstall(){return _isUpdateInstall;};
|
|
||||||
|
|
||||||
plist_t sepManifest(){return _sepbuildmanifest;};
|
|
||||||
plist_t basebandManifest(){return _basebandbuildmanifest;};
|
|
||||||
const char *sepManifestPath(){return _sepbuildmanifestPath;};
|
|
||||||
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);
|
||||||
int doJustBoot(const char *ipsw, std::string bootargs = "");
|
|
||||||
|
|
||||||
~futurerestore();
|
~futurerestore();
|
||||||
|
|
||||||
static std::pair<const char *,size_t> getRamdiskHashFromSCAB(const char* scab, size_t scabSize);
|
static std::pair<const char *,size_t> getRamdiskHashFromSCAB(const char* scab, size_t scabSize);
|
||||||
|
@ -160,8 +157,8 @@ public:
|
||||||
static plist_t loadPlistFromFile(const char *path);
|
static plist_t loadPlistFromFile(const char *path);
|
||||||
static void saveStringToFile(const char *str, const char *path);
|
static void saveStringToFile(const char *str, const char *path);
|
||||||
static char *getPathOfElementInManifest(const char *element, const char *manifeststr, const char *boardConfig, int isUpdateInstall);
|
static char *getPathOfElementInManifest(const char *element, const char *manifeststr, const char *boardConfig, int isUpdateInstall);
|
||||||
bool elemExists(const char *element, const char *manifeststr, const char *boardConfig, int isUpdateInstall);
|
static bool elemExists(const char *element, const char *manifeststr, const char *boardConfig, int isUpdateInstall);
|
||||||
static std::string getGeneratorFromSHSH2(const plist_t shsh2);
|
static std::string getGeneratorFromSHSH2(plist_t shsh2);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* futurerestore_hpp */
|
#endif /* futurerestore_hpp */
|
||||||
|
|
|
@ -6,11 +6,7 @@
|
||||||
// Copyright © 2016 tihmstar. All rights reserved.
|
// Copyright © 2016 tihmstar. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <vector>
|
|
||||||
#include "futurerestore.hpp"
|
#include "futurerestore.hpp"
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
|
@ -34,31 +30,31 @@ extern "C"{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{ "apticket", required_argument, NULL, 't' },
|
{ "apticket", required_argument, nullptr, 't' },
|
||||||
{ "baseband", required_argument, NULL, 'b' },
|
{ "baseband", required_argument, nullptr, 'b' },
|
||||||
{ "baseband-manifest", required_argument, NULL, 'p' },
|
{ "baseband-manifest", required_argument, nullptr, 'p' },
|
||||||
{ "sep", required_argument, NULL, 's' },
|
{ "sep", required_argument, nullptr, 's' },
|
||||||
{ "sep-manifest", required_argument, NULL, 'm' },
|
{ "sep-manifest", required_argument, nullptr, 'm' },
|
||||||
{ "wait", no_argument, NULL, 'w' },
|
{ "wait", no_argument, nullptr, 'w' },
|
||||||
{ "update", no_argument, NULL, 'u' },
|
{ "update", no_argument, nullptr, 'u' },
|
||||||
{ "debug", no_argument, NULL, 'd' },
|
{ "debug", no_argument, nullptr, 'd' },
|
||||||
{ "exit-recovery", no_argument, NULL, 'e' },
|
{ "exit-recovery", no_argument, nullptr, 'e' },
|
||||||
{ "latest-sep", no_argument, NULL, '0' },
|
{ "latest-sep", no_argument, nullptr, '0' },
|
||||||
{ "no-restore", no_argument, NULL, 'z' },
|
{ "no-restore", no_argument, nullptr, 'z' },
|
||||||
{ "latest-baseband", no_argument, NULL, '1' },
|
{ "latest-baseband", no_argument, nullptr, '1' },
|
||||||
{ "no-baseband", no_argument, NULL, '2' },
|
{ "no-baseband", no_argument, nullptr, '2' },
|
||||||
#ifdef HAVE_LIBIPATCHER
|
#ifdef HAVE_LIBIPATCHER
|
||||||
{ "use-pwndfu", no_argument, NULL, '3' },
|
{ "use-pwndfu", no_argument, nullptr, '3' },
|
||||||
{ "no-ibss", no_argument, NULL, '4' },
|
{ "no-ibss", no_argument, nullptr, '4' },
|
||||||
{ "rdsk", required_argument, NULL, '5' },
|
{ "rdsk", required_argument, nullptr, '5' },
|
||||||
{ "rkrn", required_argument, NULL, '6' },
|
{ "rkrn", required_argument, nullptr, '6' },
|
||||||
{ "set-nonce", optional_argument, NULL, '7' },
|
{ "set-nonce", optional_argument, nullptr, '7' },
|
||||||
{ "serial", no_argument, NULL, '8' },
|
{ "serial", no_argument, nullptr, '8' },
|
||||||
{ "boot-args", required_argument, NULL, '9' },
|
{ "boot-args", required_argument, nullptr, '9' },
|
||||||
{ "no-cache", no_argument, NULL, 'a' },
|
{ "no-cache", no_argument, nullptr, 'a' },
|
||||||
{ "skip-blob", no_argument, NULL, 'c' },
|
{ "skip-blob", no_argument, nullptr, 'c' },
|
||||||
#endif
|
#endif
|
||||||
{ NULL, 0, NULL, 0 }
|
{ nullptr, 0, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FLAG_WAIT 1 << 0
|
#define FLAG_WAIT 1 << 0
|
||||||
|
@ -136,28 +132,24 @@ int main_r(int argc, const char * argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int optindex = 0;
|
int optindex = 0;
|
||||||
int opt = 0;
|
int opt;
|
||||||
long flags = 0;
|
long flags = 0;
|
||||||
bool exitRecovery = false;
|
bool exitRecovery = false;
|
||||||
bool noRestore = false;
|
|
||||||
|
|
||||||
int isSepManifestSigned = 0;
|
const char *ipsw = nullptr;
|
||||||
int isBasebandSigned = 0;
|
const char *basebandPath = nullptr;
|
||||||
|
const char *basebandManifestPath = nullptr;
|
||||||
const char *ipsw = NULL;
|
const char *sepPath = nullptr;
|
||||||
const char *basebandPath = NULL;
|
const char *sepManifestPath = nullptr;
|
||||||
const char *basebandManifestPath = NULL;
|
const char *bootargs = nullptr;
|
||||||
const char *sepPath = NULL;
|
const char *ramdiskPath = nullptr;
|
||||||
const char *sepManifestPath = NULL;
|
const char *kernelPath = nullptr;
|
||||||
const char *bootargs = NULL;
|
const char *custom_nonce = nullptr;
|
||||||
const char *ramdiskPath = NULL;
|
|
||||||
const char *kernelPath = NULL;
|
|
||||||
const char *custom_nonce = NULL;
|
|
||||||
|
|
||||||
vector<const char*> apticketPaths;
|
vector<const char*> apticketPaths;
|
||||||
|
|
||||||
t_devicevals devVals = {0};
|
t_devicevals devVals = {nullptr};
|
||||||
t_iosVersion versVals = {0};
|
t_iosVersion versVals = {nullptr};
|
||||||
|
|
||||||
if (argc == 1){
|
if (argc == 1){
|
||||||
cmd_help();
|
cmd_help();
|
||||||
|
@ -213,11 +205,11 @@ int main_r(int argc, const char * argv[]) {
|
||||||
break;
|
break;
|
||||||
case '7': // long option: "set-nonce";
|
case '7': // long option: "set-nonce";
|
||||||
flags |= FLAG_SET_NONCE;
|
flags |= FLAG_SET_NONCE;
|
||||||
custom_nonce = (optarg) ? optarg : NULL;
|
custom_nonce = (optarg) ? optarg : nullptr;
|
||||||
if(custom_nonce != NULL) {
|
if(custom_nonce != nullptr) {
|
||||||
uint64_t gen;
|
uint64_t gen;
|
||||||
retassure(strlen(custom_nonce) == 16 || strlen(custom_nonce) == 18,"Incorrect nonce length!\n");
|
retassure(strlen(custom_nonce) == 16 || strlen(custom_nonce) == 18,"Incorrect nonce length!\n");
|
||||||
sscanf(custom_nonce, "0x%16llx",&gen);
|
gen = std::stoul(custom_nonce, nullptr, 16);
|
||||||
retassure(gen, "failed to parse generator. Make sure it is in format 0x%16llx");
|
retassure(gen, "failed to parse generator. Make sure it is in format 0x%16llx");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -226,7 +218,7 @@ int main_r(int argc, const char * argv[]) {
|
||||||
break;
|
break;
|
||||||
case '9': // long option: "boot-args";
|
case '9': // long option: "boot-args";
|
||||||
flags |= FLAG_BOOT_ARGS;
|
flags |= FLAG_BOOT_ARGS;
|
||||||
bootargs = (optarg) ? optarg : NULL;
|
bootargs = (optarg) ? optarg : nullptr;
|
||||||
break;
|
break;
|
||||||
case 'a': // long option: "no-cache";
|
case 'a': // long option: "no-cache";
|
||||||
flags |= FLAG_NO_CACHE;
|
flags |= FLAG_NO_CACHE;
|
||||||
|
@ -251,7 +243,6 @@ int main_r(int argc, const char * argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc-optind == 1) {
|
if (argc-optind == 1) {
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
ipsw = argv[0];
|
ipsw = argv[0];
|
||||||
|
@ -303,10 +294,12 @@ int main_r(int argc, const char * argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (apticketPaths.size()) client.loadAPTickets(apticketPaths);
|
if (!apticketPaths.empty()) {
|
||||||
|
client.loadAPTickets(apticketPaths);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(
|
if (!(
|
||||||
((apticketPaths.size() && ipsw)
|
((!apticketPaths.empty() && ipsw)
|
||||||
&& ((basebandPath && basebandManifestPath) || ((flags & FLAG_LATEST_BASEBAND) || (flags & FLAG_NO_BASEBAND)))
|
&& ((basebandPath && basebandManifestPath) || ((flags & FLAG_LATEST_BASEBAND) || (flags & FLAG_NO_BASEBAND)))
|
||||||
&& ((sepPath && sepManifestPath) || (flags & FLAG_LATEST_SEP) || client.is32bit())
|
&& ((sepPath && sepManifestPath) || (flags & FLAG_LATEST_SEP) || client.is32bit())
|
||||||
) || (ipsw && (flags & FLAG_IS_PWN_DFU))
|
) || (ipsw && (flags & FLAG_IS_PWN_DFU))
|
||||||
|
@ -355,14 +348,14 @@ int main_r(int argc, const char * argv[]) {
|
||||||
|
|
||||||
if (flags & FLAG_LATEST_SEP){
|
if (flags & FLAG_LATEST_SEP){
|
||||||
info("user specified to use latest signed SEP\n");
|
info("user specified to use latest signed SEP\n");
|
||||||
client.loadLatestSep();
|
client.downloadLatestSep();
|
||||||
}else if (!client.is32bit()){
|
}else if (!client.is32bit()){
|
||||||
client.loadSep(sepPath);
|
client.loadSep(sepPath);
|
||||||
client.setSepManifestPath(sepManifestPath);
|
client.loadSepManifest(sepManifestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
versVals.basebandMode = kBasebandModeWithoutBaseband;
|
versVals.basebandMode = kBasebandModeWithoutBaseband;
|
||||||
if (!client.is32bit() && !(isSepManifestSigned = isManifestSignedForDevice(client.sepManifestPath(), &devVals, &versVals, NULL))){
|
if (!client.is32bit() && !(isManifestSignedForDevice(client.getSepManifestPath().c_str(), &devVals, &versVals, nullptr))){
|
||||||
reterror("SEP firmware is NOT being signed!\n");
|
reterror("SEP firmware is NOT being signed!\n");
|
||||||
}
|
}
|
||||||
if (flags & FLAG_NO_BASEBAND){
|
if (flags & FLAG_NO_BASEBAND){
|
||||||
|
@ -379,10 +372,10 @@ int main_r(int argc, const char * argv[]) {
|
||||||
}else{
|
}else{
|
||||||
if (flags & FLAG_LATEST_BASEBAND){
|
if (flags & FLAG_LATEST_BASEBAND){
|
||||||
info("user specified to use latest signed baseband\n");
|
info("user specified to use latest signed baseband\n");
|
||||||
client.loadLatestBaseband();
|
client.downloadLatestBaseband();
|
||||||
}else{
|
}else{
|
||||||
client.setBasebandPath(basebandPath);
|
client.setBasebandPath(basebandPath);
|
||||||
client.setBasebandManifestPath(basebandManifestPath);
|
client.loadBasebandManifest(basebandManifestPath);
|
||||||
printf("Did set SEP+baseband path and firmware\n");
|
printf("Did set SEP+baseband path and firmware\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +383,7 @@ int main_r(int argc, const char * argv[]) {
|
||||||
if (!(devVals.bbgcid = client.getBasebandGoldCertIDFromDevice())){
|
if (!(devVals.bbgcid = client.getBasebandGoldCertIDFromDevice())){
|
||||||
printf("[WARNING] using tsschecker's fallback to get BasebandGoldCertID. This might result in invalid baseband signing status information\n");
|
printf("[WARNING] using tsschecker's fallback to get BasebandGoldCertID. This might result in invalid baseband signing status information\n");
|
||||||
}
|
}
|
||||||
if (!(isBasebandSigned = isManifestSignedForDevice(client.basebandManifestPath(), &devVals, &versVals, NULL))) {
|
if (!(isManifestSignedForDevice(client.getBasebandManifestPath().c_str(), &devVals, &versVals, nullptr))) {
|
||||||
reterror("baseband firmware is NOT being signed!\n");
|
reterror("baseband firmware is NOT being signed!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue