fixed bugs

This commit is contained in:
tihmstar 2016-09-22 01:18:31 +02:00
parent 7eb08aafef
commit 4bd6c687a4
3 changed files with 32 additions and 25 deletions

View file

@ -56,7 +56,7 @@ bool futurerestore::init(){
} }
uint64_t futurerestore::getDeviceEcid(){ uint64_t futurerestore::getDeviceEcid(){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
uint64_t ecid; uint64_t ecid;
get_ecid(_client, &ecid); get_ecid(_client, &ecid);
@ -65,7 +65,7 @@ uint64_t futurerestore::getDeviceEcid(){
} }
int futurerestore::getDeviceMode(bool reRequest){ int futurerestore::getDeviceMode(bool reRequest){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
if (!reRequest && _client->mode->index != MODE_UNKNOWN) { if (!reRequest && _client->mode->index != MODE_UNKNOWN) {
return _client->mode->index; return _client->mode->index;
}else{ }else{
@ -76,7 +76,7 @@ int futurerestore::getDeviceMode(bool reRequest){
} }
void futurerestore::putDeviceIntoRecovery(){ void futurerestore::putDeviceIntoRecovery(){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
getDeviceMode(false); getDeviceMode(false);
info("Found device in %s mode\n", _client->mode->string); info("Found device in %s mode\n", _client->mode->string);
@ -100,7 +100,7 @@ void futurerestore::putDeviceIntoRecovery(){
} }
void futurerestore::setAutoboot(bool val){ void futurerestore::setAutoboot(bool val){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
if (getDeviceMode(false) != MODE_RECOVERY){ if (getDeviceMode(false) != MODE_RECOVERY){
reterror(-2, "can't set autoboot, when device isn't in recovery mode\n"); reterror(-2, "can't set autoboot, when device isn't in recovery mode\n");
@ -116,7 +116,7 @@ void futurerestore::setAutoboot(bool val){
} }
bool futurerestore::nonceMatchesApTicket(){ bool futurerestore::nonceMatchesApTicket(){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
if (getDeviceMode(true) != MODE_RECOVERY) reterror(-10, "Device not in recovery mode, can't check apnonce\n"); if (getDeviceMode(true) != MODE_RECOVERY) reterror(-10, "Device not in recovery mode, can't check apnonce\n");
unsigned char* realnonce; unsigned char* realnonce;
@ -127,7 +127,7 @@ bool futurerestore::nonceMatchesApTicket(){
} }
void futurerestore::waitForNonce(const char *nonce){ void futurerestore::waitForNonce(const char *nonce){
if (!_didInit) reterror(-1, "did not init"); if (!_didInit) reterror(-1, "did not init\n");
setAutoboot(false); setAutoboot(false);
unsigned char* realnonce; unsigned char* realnonce;
@ -467,7 +467,7 @@ futurerestore::~futurerestore(){
} }
void futurerestore::loadFirmwareTokens(){ void futurerestore::loadFirmwareTokens(){
if (_firmwareTokens){ if (!_firmwareTokens){
if (!_firmwareJson) _firmwareJson = getFirmwareJson(); if (!_firmwareJson) _firmwareJson = getFirmwareJson();
if (!_firmwareJson) reterror(-6,"[TSSC] could not get firmware.json\n"); if (!_firmwareJson) reterror(-6,"[TSSC] could not get firmware.json\n");
int cnt = parseTokens(_firmwareJson, &_firmwareTokens); int cnt = parseTokens(_firmwareJson, &_firmwareTokens);
@ -476,7 +476,7 @@ void futurerestore::loadFirmwareTokens(){
} }
const char *futurerestore::getConnectedDeviceModel(){ const char *futurerestore::getConnectedDeviceModel(){
if (!_client->device->hardware_model){ if (!_client->device || !_client->device->product_type){
int mode = getDeviceMode(true); int mode = getDeviceMode(true);
if (mode != MODE_NORMAL && mode != MODE_RECOVERY) if (mode != MODE_NORMAL && mode != MODE_RECOVERY)
@ -486,7 +486,7 @@ const char *futurerestore::getConnectedDeviceModel(){
reterror(-2,"ERROR: Unable to discover device model\n"); reterror(-2,"ERROR: Unable to discover device model\n");
} }
return _client->device->hardware_model; return _client->device->product_type;
} }
char *futurerestore::getLatestManifest(){ char *futurerestore::getLatestManifest(){
@ -531,7 +531,7 @@ char *futurerestore::getLatestFirmwareUrl(){
void futurerestore::loadLatestBaseband(){ void futurerestore::loadLatestBaseband(){
char * manifeststr = getLatestManifest(); char * manifeststr = getLatestManifest();
char *pathStr = getPathOfElementInManifest("BasebandFirmware", manifeststr); char *pathStr = getPathOfElementInManifest("BasebandFirmware", manifeststr);
if (!downloadPartialzip(getLatestFirmwareUrl(), pathStr, _basebandPath = BASEBAND_TMP_PATH)) if (downloadPartialzip(getLatestFirmwareUrl(), pathStr, _basebandPath = BASEBAND_TMP_PATH))
reterror(-32, "could not download baseband\n"); reterror(-32, "could not download baseband\n");
saveStringToFile(manifeststr, _basebandManifestPath = BASEBAND_MANIFEST_TMP_PATH); saveStringToFile(manifeststr, _basebandManifestPath = BASEBAND_MANIFEST_TMP_PATH);
} }
@ -539,7 +539,7 @@ void futurerestore::loadLatestBaseband(){
void futurerestore::loadLatestSep(){ void futurerestore::loadLatestSep(){
char * manifeststr = getLatestManifest(); char * manifeststr = getLatestManifest();
char *pathStr = getPathOfElementInManifest("SEP", manifeststr); char *pathStr = getPathOfElementInManifest("SEP", manifeststr);
if (!downloadPartialzip(getLatestFirmwareUrl(), pathStr, _sepPath = SEP_TMP_PATH)) if (downloadPartialzip(getLatestFirmwareUrl(), pathStr, _sepPath = SEP_TMP_PATH))
reterror(-33, "could not download SEP\n"); reterror(-33, "could not download SEP\n");
saveStringToFile(manifeststr, _sepManifestPath = SEP_MANIFEST_TMP_PATH); saveStringToFile(manifeststr, _sepManifestPath = SEP_MANIFEST_TMP_PATH);
} }
@ -552,7 +552,7 @@ inline void futurerestore::saveStringToFile(const char *str, const char *path){
if (!f) reterror(-41,"can't save file at %s\n",path); if (!f) reterror(-41,"can't save file at %s\n",path);
else{ else{
size_t len = strlen(str); size_t len = strlen(str);
size_t wlen = fwrite(str, len, 1, f); size_t wlen = fwrite(str, 1, len, f);
fclose(f); fclose(f);
if (len != wlen) reterror(-42, "saving file failed, wrote=%zu actual=%zu\n",wlen,len); if (len != wlen) reterror(-42, "saving file failed, wrote=%zu actual=%zu\n",wlen,len);
} }
@ -656,11 +656,12 @@ char *futurerestore::getPathOfElementInManifest(const char *element, const char
if (plist_t buildidentities = plist_dict_get_item(buildmanifest._p, "BuildIdentities")) if (plist_t buildidentities = plist_dict_get_item(buildmanifest._p, "BuildIdentities"))
if (plist_t firstIdentitie = plist_array_get_item(buildidentities, 0)) if (plist_t firstIdentitie = plist_array_get_item(buildidentities, 0))
if (plist_t manifest = plist_dict_get_item(firstIdentitie, element)) if (plist_t manifest = plist_dict_get_item(firstIdentitie, "Manifest"))
if (plist_t info = plist_dict_get_item(manifest, "Info")) if (plist_t elem = plist_dict_get_item(manifest, element))
if (plist_t path = plist_dict_get_item(info, "Path")) if (plist_t info = plist_dict_get_item(elem, "Info"))
if (plist_get_string_val(path, &pathStr), pathStr) if (plist_t path = plist_dict_get_item(info, "Path"))
goto noerror; if (plist_get_string_val(path, &pathStr), pathStr)
goto noerror;
reterror(-31, "could not get %s path\n",element); reterror(-31, "could not get %s path\n",element);
noerror: noerror:
return pathStr; return pathStr;

View file

@ -18,15 +18,15 @@ using namespace std;
template <typename T> template <typename T>
class ptr_smart { class ptr_smart {
function<void(T)> _ptr_free; function<void(T)> _ptr_free = NULL;
public: public:
T _p; T _p;
ptr_smart(T p, function<void(T)> ptr_free){static_assert(is_pointer<T>(), "error: this is for pointers only\n"); _p = p;_ptr_free = ptr_free;} ptr_smart(T p, function<void(T)> ptr_free){static_assert(is_pointer<T>(), "error: this is for pointers only\n"); _p = p;_ptr_free = ptr_free;}
ptr_smart(T p){ptr_smart(p,reinterpret_cast<void(*)(T)>(free));} ptr_smart(T p){_p = p;}
ptr_smart(){ptr_smart(NULL,reinterpret_cast<void(*)(T)>(free));} ptr_smart(){_p = NULL;}
T operator=(T p){return _p = p;} T operator=(T p){return _p = p;}
T *operator&(){return &_p;} T *operator&(){return &_p;}
~ptr_smart(){if (_p) _ptr_free(_p);} ~ptr_smart(){if (_p) (_ptr_free) ? _ptr_free(_p) : free((void*)_p);}
}; };
class futurerestore { class futurerestore {

View file

@ -45,6 +45,8 @@ void cmd_help(){
printf(" -m, --sep-manifest PATH\tBuildmanifest for requesting sep ticket\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(" -w, --wait\t\t\tkeep rebooting until nonce matches APTicket\n");
printf(" -u, --update\t\t\tupdate instead of erase install\n"); printf(" -u, --update\t\t\tupdate instead of erase install\n");
printf(" --latest-sep\t\t\tuse latest signed sep instead of manually specifying one(may cause bad restore)\n");
printf(" --latest-baseband\t\t\tse latest signed baseband instead of manually specifying one(may cause bad restore)\n");
printf("\n"); printf("\n");
} }
@ -145,13 +147,17 @@ int main(int argc, const char * argv[]) {
} }
if (flags & FLAG_LATEST_SEP) client.loadLatestSep(); if (flags & FLAG_LATEST_SEP){
else{ info("user specified to use latest signed sep\n");
client.loadLatestSep();
}else{
client.setSepPath(sepPath); client.setSepPath(sepPath);
client.setSepManifestPath(sepManifestPath); client.setSepManifestPath(sepManifestPath);
} }
if (flags & FLAG_LATEST_BASEBAND) client.loadLatestBaseband(); if (flags & FLAG_LATEST_BASEBAND){
else{ info("user specified to use latest signed baseband (WARNING, THIS CAN CAUSE A NON-WORKING RESTORE)\n");
client.loadLatestBaseband();
}else{
client.setBasebandPath(basebandPath); client.setBasebandPath(basebandPath);
client.setBasebandManifestPath(basebandManifestPath); client.setBasebandManifestPath(basebandManifestPath);
} }