Finally fix iPhone 11 family of devices (#6)

This commit is contained in:
Liam(Cryptic) 2021-02-28 17:02:52 -08:00 committed by GitHub
parent 242163fada
commit 6ccc68162b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 349 additions and 5 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
*.DS_Store
.vscode
*.a
*.o
*.la

View file

@ -1,11 +1,9 @@
# futurerestore
[![CI Building](https://img.shields.io/github/workflow/status/marijuanARM/futurerestore/ci)](https://img.shields.io/github/workflow/status/marijuanARM/futurerestore/ci)
[![CI Building](https://img.shields.io/github/workflow/status/marijuanARM/futurerestore/CI)](https://github.com/marijuanARM/futurerestore/actions?workflow=CI)
_It is a hacked up idevicerestore wrapper, which allows manually specifying SEP and Baseband for restoring._
**THIS HAS NOT YET BEEN TESTED FOR a13 going to 14.3 USE AT YOUR OWN RISK**
Latest compiled version can be found [here](https://github.com/marijuanARM/futurerestore/releases).
__Only use if you are sure what you're doing.__

@ -1 +1 @@
Subproject commit f9cf174ac4fae52ba362d86013b7aa518e0d9846
Subproject commit d7d9996b3910902a56462fa8d9dc5909fcf8f4c9

View file

@ -58,6 +58,7 @@ extern "C"{
#define BASEBAND_MANIFEST_TMP_PATH FUTURERESTORE_TMP_PATH"/basebandManifest.plist"
#define SEP_TMP_PATH FUTURERESTORE_TMP_PATH"/sep.im4p"
#define SEP_MANIFEST_TMP_PATH FUTURERESTORE_TMP_PATH"/sepManifest.plist"
#define FIRMWARES_TMP_PATH FUTURERESTORE_TMP_PATH"/Firmwares/"
#ifdef __APPLE__
# include <CommonCrypto/CommonDigest.h>
@ -1235,6 +1236,320 @@ char *futurerestore::getLatestFirmwareUrl(){
return getLatestManifest(),__latestFirmwareUrl;
}
//https://stackoverflow.com/a/27975357
static void mkdirRecursive(const char *path, mode_t mode) {
char opath[PATH_MAX];
char *p;
size_t len;
strncpy(opath, path, sizeof(opath));
opath[sizeof(opath) - 1] = '\0';
len = strlen(opath);
if (len == 0)
return;
else if (opath[len - 1] == '/')
opath[len - 1] = '\0';
for(p = opath; *p; p++)
if (*p == '/') {
*p = '\0';
if (access(opath, F_OK))
__mkdir(opath, mode);
*p = '/';
}
if (access(opath, F_OK)) /* if path is not terminated with / */
__mkdir(opath, mode);
}
//https://gist.github.com/clalancette/bb5069a09c609e2d33c9858fcc6e170e
static bool is_dir(const std::string& dir)
{
struct stat st;
::stat(dir.c_str(), &st);
return S_ISDIR(st.st_mode);
}
static void walk_directory(const std::string& startdir, const std::string& inputdir, zip_t *zipper)
{
DIR *dp = ::opendir(inputdir.c_str());
if (dp == nullptr) {
throw std::runtime_error("Failed to open input directory: " + std::string(::strerror(errno)));
}
struct dirent *dirp;
while ((dirp = readdir(dp)) != NULL) {
if (dirp->d_name != std::string(".") && dirp->d_name != std::string("..")) {
std::string fullname = inputdir + "/" + dirp->d_name;
if (is_dir(fullname)) {
if (zip_dir_add(zipper, fullname.substr(startdir.length() + 1).c_str(), ZIP_FL_ENC_UTF_8) < 0) {
throw std::runtime_error("Failed to add directory to zip: " + std::string(zip_strerror(zipper)));
}
walk_directory(startdir, fullname, zipper);
} else {
zip_source_t *source = zip_source_file(zipper, fullname.c_str(), 0, 0);
if (source == nullptr) {
throw std::runtime_error("Failed to add file to zip: " + std::string(zip_strerror(zipper)));
}
if (zip_file_add(zipper, fullname.substr(startdir.length() + 1).c_str(), source, ZIP_FL_ENC_UTF_8) < 0) {
zip_source_free(source);
throw std::runtime_error("Failed to add file to zip: " + std::string(zip_strerror(zipper)));
}
}
}
}
::closedir(dp);
}
static void zip_directory(const std::string& inputdir, const std::string& output_filename)
{
int errorp;
zip_t *zipper = zip_open(output_filename.c_str(), ZIP_CREATE | ZIP_EXCL, &errorp);
if (zipper == nullptr) {
zip_error_t ziperror;
zip_error_init_with_code(&ziperror, errorp);
throw std::runtime_error("Failed to open output file " + output_filename + ": " + zip_error_strerror(&ziperror));
}
try {
walk_directory(inputdir, inputdir, zipper);
} catch(...) {
zip_close(zipper);
throw;
}
zip_close(zipper);
}
void futurerestore::downloadLatestRose(){
char * manifeststr = getLatestManifest();
char *roseStr = (elemExists("Rap,RTKitOS", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Rap,RTKitOS", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
if(roseStr) {
info("downloading Rose firmware\n\n");
char roseStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(roseStr1, "%s%s", tmp, roseStr);
std::string rose(roseStr1);
size_t pos = rose.find_last_of('/');
if (pos != std::string::npos) {
rose.erase(pos + 1, rose.length());
mkdirRecursive(rose.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), roseStr, roseStr1), "could not download Rose\n");
}
}
}
void futurerestore::downloadLatestSE(){
char * manifeststr = getLatestManifest();
char *seStr = (elemExists("SE,UpdatePayload", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("SE,UpdatePayload", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
if(seStr) {
info("downloading SE firmware\n\n");
char seStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(seStr1, "%s%s", tmp, seStr);
std::string se(seStr1);
size_t pos = se.find_last_of('/');
if (pos != std::string::npos) {
se.erase(pos, se.length());
mkdirRecursive(se.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), seStr, seStr1), "could not download SE\n");
}
}
}
void futurerestore::downloadLatestSavage(){
char * manifeststr = getLatestManifest();
char *savageB0DevStr = (elemExists("Savage,B0-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B0-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB0DevVTStr = (elemExists("Savage,B0-Dev-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B0-Dev-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB0ProdStr = (elemExists("Savage,B0-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B0-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB0ProdVTStr = (elemExists("Savage,B0-Prod-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B0-Prod-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB2DevStr = (elemExists("Savage,B2-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B2-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB2DevVTStr = (elemExists("Savage,B2-Dev-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B2-Dev-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB2ProdStr = (elemExists("Savage,B2-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B2-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageB2ProdVTStr = (elemExists("Savage,B2-Prod-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,B2-Prod-PatchVT", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageBADevStr = (elemExists("Savage,BA-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,BA-Dev-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *savageBAProdStr = (elemExists("Savage,BA-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("Savage,BA-Prod-Patch", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
if(savageB0DevStr) {
info("downloading Savage,B0-Dev-Patch\n\n");
char savageB0DevStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB0DevStr1, "%s%s", FIRMWARES_TMP_PATH, savageB0DevStr);
std::string savage(savageB0DevStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB0DevStr, savageB0DevStr1), "could not download Savage,B0-Dev-Patch\n");
}
}
if(savageB0DevVTStr) {
info("downloading Savage,B0-Dev-PatchVT\n\n");
char savageB0DevVTStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB0DevVTStr1, "%s%s", FIRMWARES_TMP_PATH, savageB0DevVTStr);
std::string savage(savageB0DevVTStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB0DevVTStr, savageB0DevVTStr1), "could not download Savage,B0-Dev-PatchVT\n");
}
}
if(savageB0ProdStr) {
info("downloading Savage,B0-Prod-Patch\n\n");
char savageB0ProdStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB0ProdStr1, "%s%s", FIRMWARES_TMP_PATH, savageB0ProdStr);
std::string savage(savageB0ProdStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB0ProdStr, savageB0ProdStr1), "could not download Savage,B0-Prod-Patch\n");
}
}
if(savageB0ProdVTStr) {
info("downloading Savage,B0-Prod-PatchVT\n\n");
char savageB0ProdVTStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB0ProdVTStr1, "%s%s", FIRMWARES_TMP_PATH, savageB0ProdVTStr);
std::string savage(savageB0ProdVTStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB0ProdVTStr, savageB0ProdVTStr1), "could not download Savage,B0-Prod-PatchVT\n");
}
}
if(savageB2DevStr) {
info("downloading Savage,B2-Dev-Patch\n\n");
char savageB2DevStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB2DevStr1, "%s%s", FIRMWARES_TMP_PATH, savageB2DevStr);
std::string savage(savageB2DevStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB2DevStr, savageB2DevStr1), "could not download Savage,B2-Dev-Patch\n");
}
}
if(savageB2DevVTStr) {
info("downloading Savage,B2-Dev-PatchV\n\n");
char savageB2DevVTStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB2DevVTStr1, "%s%s", FIRMWARES_TMP_PATH, savageB2DevVTStr);
std::string savage(savageB2DevVTStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB2DevVTStr, savageB2DevVTStr1), "could not download Savage,B2-Dev-PatchV\n");
}
}
if(savageB2ProdStr) {
info("downloading Savage,B2-Prod-Patch\n\n");
char savageB2ProdStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB2ProdStr1, "%s%s", FIRMWARES_TMP_PATH, savageB2ProdStr);
std::string savage(savageB2ProdStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB2ProdStr, savageB2ProdStr1), "could not download Savage,B2-Prod-Patch\n");
}
}
if(savageB2ProdVTStr) {
info("downloading Savage,B2-Prod-PatchVT\n\n");
char savageB2ProdVTStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageB2ProdVTStr1, "%s%s", FIRMWARES_TMP_PATH, savageB2ProdVTStr);
std::string savage(savageB2ProdVTStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageB2ProdVTStr, savageB2ProdVTStr1), "could not download Savage,B2-Prod-PatchVT\n");
}
}
if(savageBADevStr) {
info("downloading Savage,BA-Dev-Patch\n\n");
char savageBADevStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageBADevStr1, "%s%s", FIRMWARES_TMP_PATH, savageBADevStr);
std::string savage(savageBADevStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageBADevStr, savageBADevStr1), "could not download Savage,BA-Dev-Patch\n");
}
}
if(savageBAProdStr) {
info("downloading Savage,BA-Prod-Patch\n\n");
char savageBAProdStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(savageBAProdStr1, "%s%s", FIRMWARES_TMP_PATH, savageBAProdStr);
std::string savage(savageBAProdStr1);
size_t pos = savage.find_last_of('/');
if (pos != std::string::npos) {
savage.erase(pos + 1, savage.length());
mkdirRecursive(savage.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), savageBAProdStr, savageBAProdStr1), "could not download Savage,BA-Prod-Patch\n");
}
}
}
void futurerestore::downloadLatestVeridian(){
char * manifeststr = getLatestManifest();
char *veridianStr = (elemExists("BMU,DigestMap", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("BMU,DigestMap", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
char *veridianFWMStr = (elemExists("BMU,FirmwareMap", manifeststr, getDeviceModelNoCopy(), 0) ? getPathOfElementInManifest("BMU,FirmwareMap", manifeststr, getDeviceModelNoCopy(), 0) : NULL);
if(veridianStr) {
info("downloading Veridian DigestMap\n\n");
char veridianStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(veridianStr1, "%s%s", FIRMWARES_TMP_PATH, veridianStr);
std::string veridian(veridianStr1);
size_t pos = veridian.find_last_of('/');
if (pos != std::string::npos) {
veridian.erase(pos + 1, veridian.length());
mkdirRecursive(veridian.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), veridianStr, veridianStr1), "could not download Veridian DigestMap\n");
}
}
if(veridianFWMStr) {
info("downloading Veridian FirmwareMap\n\n");
char veridianFWMStr1[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(veridianFWMStr1, "%s%s", FIRMWARES_TMP_PATH, veridianFWMStr);
std::string veridian(veridianFWMStr1);
size_t pos = veridian.find_last_of('/');
if (pos != std::string::npos) {
veridian.erase(pos + 1, veridian.length());
mkdirRecursive(veridian.c_str(), 0755);
retassure(!downloadPartialzip(getLatestFirmwareUrl(), veridianFWMStr, veridianFWMStr1), "could not download Veridian FirmwareMap\n");
}
}
}
void futurerestore::downloadLatestFirmwareComponents(){
info("Downloading the latest firmware components...\n");
mkdir(FIRMWARES_TMP_PATH, 0755);
char zip_name[PATH_MAX];
char *tmp = FIRMWARES_TMP_PATH;
sprintf(zip_name, "%s/%s", FUTURERESTORE_TMP_PATH, "Firmwares.ipsw");
unlink(zip_name);
downloadLatestRose();
downloadLatestSE();
downloadLatestSavage();
downloadLatestVeridian();
zip_directory(FIRMWARES_TMP_PATH, zip_name);
struct stat st{0};
retassure(!stat(zip_name, &st), "could not zip Firmwares to ipsw\n");
char *firmware_zip = zip_name;
_client->ipsw2 = strdup(firmware_zip);
info("Finished downloading the latest firmware components!\n");
}
void futurerestore::loadLatestBaseband(){
char * manifeststr = getLatestManifest();
char *pathStr = getPathOfElementInManifest("BasebandFirmware", manifeststr, getDeviceModelNoCopy(), 0);
@ -1423,6 +1738,25 @@ noerror:
return pathStr;
}
bool futurerestore::elemExists(const char *element, const char *manifeststr, const char *model, int isUpdateInstall){
char *pathStr = NULL;
ptr_smart<plist_t> buildmanifest(NULL,plist_free);
plist_from_xml(manifeststr, (uint32_t)strlen(manifeststr), &buildmanifest);
if (plist_t identity = getBuildidentity(buildmanifest._p, model, isUpdateInstall))
if (plist_t manifest = plist_dict_get_item(identity, "Manifest"))
if (plist_t elem = plist_dict_get_item(manifest, element))
if (plist_t info = plist_dict_get_item(elem, "Info"))
if (plist_t path = plist_dict_get_item(info, "Path"))
if (plist_get_string_val(path, &pathStr), pathStr)
goto noerror;
return false;
noerror:
return true;
}
std::string futurerestore::getGeneratorFromSHSH2(const plist_t shsh2){
plist_t pGenerator = NULL;
uint64_t gen = 0;

View file

@ -19,6 +19,11 @@
#include <stdio.h>
#include <functional>
#include <vector>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <zip.h>
#include "idevicerestore.h"
#include <jssy.h>
#include <plist/plist.h>
@ -91,6 +96,11 @@ public:
const char *getDeviceBoardNoCopy();
char *getLatestManifest();
char *getLatestFirmwareUrl();
void downloadLatestRose();
void downloadLatestSE();
void downloadLatestSavage();
void downloadLatestVeridian();
void downloadLatestFirmwareComponents();
void loadLatestBaseband();
void loadLatestSep();
@ -119,6 +129,7 @@ public:
static plist_t loadPlistFromFile(const char *path);
static void saveStringToFile(const char *str, const char *path);
static char *getPathOfElementInManifest(const char *element, const char *manifeststr, const char *model, int isUpdateInstall);
bool elemExists(const char *element, const char *manifeststr, const char *model, int isUpdateInstall);
static std::string getGeneratorFromSHSH2(const plist_t shsh2);
};

View file

@ -257,7 +257,7 @@ int main_r(int argc, const char * argv[]) {
if (!client.is32bit() && !(isSepManifestSigned = isManifestSignedForDevice(client.sepManifestPath(), &devVals, &versVals))){
reterror("SEP firmware doesn't signed\n");
}
client.downloadLatestFirmwareComponents();
if (flags & FLAG_NO_BASEBAND){
printf("\nWARNING: user specified is not to flash a baseband. This can make the restore fail if the device needs a baseband!\n");
printf("if you added this flag by mistake, you can press CTRL-C now to cancel\n");