Skip to content

Commit

Permalink
Merge the iOS16 branch into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTheMann15 authored Oct 7, 2022
2 parents ea4d7b1 + 3427ed2 commit b981d16
Show file tree
Hide file tree
Showing 9 changed files with 1,815 additions and 1,716 deletions.
4 changes: 2 additions & 2 deletions tsschecker/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ libjssy_a_SOURCES = $(top_srcdir)/external/jssy/jssy/jssy.c

if NOMAIN
noinst_LTLIBRARIES = libtsschecker.la
libtsschecker_la_SOURCES = tsschecker.c tss.c download.c
libtsschecker_la_SOURCES = tsschecker.c tss.c download.c common.c
libtsschecker_la_CFLAGS = $(AM_CFLAGS)
libtsschecker_la_LIBADD = $(AM_LDFLAGS) libjssy.a
else
bin_PROGRAMS = tsschecker
tsschecker_CFLAGS = $(AM_CFLAGS)
tsschecker_LDADD = $(AM_LDFLAGS) libjssy.a

tsschecker_SOURCES = tsschecker.c tss.c download.c main.c
tsschecker_SOURCES = tsschecker.c tss.c download.c common.c main.c
endif

tsschecker_LDFLAGS = $(AM_LDFLAGS)
3 changes: 3 additions & 0 deletions tsschecker/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifndef all_h
#define all_h

#define TSSCHECKER_VERSION_MAJOR "0"
#define TSSCHECKER_VERSION_PATCH "0"

#ifdef DEBUG // this is for developing with Xcode
#define TSSCHECKER_BUILD_TYPE "DEBUG"
#define TSSCHECKER_VERSION_SHA "Build: " __DATE__ " " __TIME__ ""
Expand Down
205 changes: 205 additions & 0 deletions tsschecker/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/*
* common.c
* Misc functions used in idevicerestore
*
* Copyright (c) 2012-2019 Nikias Bassen. All Rights Reserved.
* Copyright (c) 2012 Martin Szulecki. All Rights Reserved.
* Copyright (c) 2010 Joshua Hill. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "common.h"

#define MAX_PRINT_LEN 64*1024
#ifndef NO_DEBUG_PLIST
void debug_plist(plist_t plist) {
uint32_t size = 0;
char* data = NULL;
if(plist_to_xml(plist, &data, &size) != PLIST_ERR_SUCCESS) {
error("Failed to convert plist data to xml!\n");
return;
}
if (size <= MAX_PRINT_LEN)
info("%s:printing %i bytes plist:\n%s", __FILE__, size, data);
else
info("%s:supressed printing %i bytes plist...\n", __FILE__, size);
free(data);
}
#endif

#define GET_RAND(min, max) ((rand() % (max - min)) + min)

char *generate_guid(void)
{
char *guid = (char *) malloc(sizeof(char) * 37);
const char *chars = "ABCDEF0123456789";
srand(time(NULL));
int i = 0;

for (i = 0; i < 36; i++) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
guid[i] = '-';
continue;
} else {
guid[i] = chars[GET_RAND(0, 16)];
}
}
guid[36] = '\0';
return guid;
}

uint64_t _plist_dict_get_uint(plist_t dict, const char *key)
{
uint64_t uintval = 0;
char *strval = NULL;
uint64_t strsz = 0;
plist_t node = plist_dict_get_item(dict, key);
if (!node) {
return uintval;
}
switch (plist_get_node_type(node)) {
case PLIST_UINT:
plist_get_uint_val(node, &uintval);
break;
case PLIST_STRING:
plist_get_string_val(node, &strval);
if (strval) {
uintval = strtoull(strval, NULL, 0);
free(strval);
}
break;
case PLIST_DATA:
plist_get_data_val(node, &strval, &strsz);
if (strval) {
if (strsz == 8) {
uintval = le64toh(*(uint64_t*)strval);
} else if (strsz == 4) {
uintval = le32toh(*(uint32_t*)strval);
} else if (strsz == 2) {
uintval = le16toh(*(uint16_t*)strval);
} else if (strsz == 1) {
uintval = strval[0];
} else {
error("%s: ERROR: invalid size " FMT_qu " for data to integer conversion\n", __func__, strsz);
}
free(strval);
}
break;
default:
break;
}
return uintval;
}

uint8_t _plist_dict_get_bool(plist_t dict, const char *key)
{
uint8_t bval = 0;
uint64_t uintval = 0;
char *strval = NULL;
uint64_t strsz = 0;
plist_t node = plist_dict_get_item(dict, key);
if (!node) {
return 0;
}
switch (plist_get_node_type(node)) {
case PLIST_BOOLEAN:
plist_get_bool_val(node, &bval);
break;
case PLIST_UINT:
plist_get_uint_val(node, &uintval);
bval = (uint8_t)uintval;
break;
case PLIST_STRING:
plist_get_string_val(node, &strval);
if (strval) {
if (strcmp(strval, "true")) {
bval = 1;
} else if (strcmp(strval, "false")) {
bval = 0;
}
free(strval);
}
break;
case PLIST_DATA:
plist_get_data_val(node, &strval, &strsz);
if (strval) {
if (strsz == 1) {
bval = strval[0];
} else {
error("%s: ERROR: invalid size " FMT_qu " for data to boolean conversion\n", __func__, strsz);
}
free(strval);
}
break;
default:
break;
}
return bval;
}

int _plist_dict_copy_uint(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key)
{
if (plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key) == NULL) {
return -1;
}
uint64_t u64val = _plist_dict_get_uint(source_dict, (alt_source_key) ? alt_source_key : key);
plist_dict_set_item(target_dict, key, plist_new_uint(u64val));
return 0;
}

int _plist_dict_copy_bool(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key)
{
if (plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key) == NULL) {
return -1;
}
uint64_t bval = _plist_dict_get_bool(source_dict, (alt_source_key) ? alt_source_key : key);
plist_dict_set_item(target_dict, key, plist_new_bool(bval));
return 0;
}

int _plist_dict_copy_data(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key)
{
plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key);
if (!PLIST_IS_DATA(node)) {
return -1;
}
plist_dict_set_item(target_dict, key, plist_copy(node));
return 0;
}

int _plist_dict_copy_string(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key)
{
plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key);
if (!PLIST_IS_STRING(node)) {
return -1;
}
plist_dict_set_item(target_dict, key, plist_copy(node));
return 0;
}

int _plist_dict_copy_item(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key)
{
plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key);
if (!node) {
return -1;
}
plist_dict_set_item(target_dict, key, plist_copy(node));
return 0;
}
70 changes: 70 additions & 0 deletions tsschecker/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* common.h
* Misc functions used in idevicerestore
*
* Copyright (c) 2012-2019 Nikias Bassen. All Rights Reserved.
* Copyright (c) 2012 Martin Szulecki. All Rights Reserved.
* Copyright (c) 2010 Joshua Hill. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef IDEVICERESTORE_COMMON_H
#define IDEVICERESTORE_COMMON_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <libfragmentzip/libfragmentzip.h>
#include <stdint.h>
#include <string.h>
#include <plist/plist.h>
#include "debug.h"
#include "endianness.h"

#define USER_AGENT_STRING "InetURL/1.0"
#ifdef WIN32
#include <windows.h>
#define __mkdir(path, mode) mkdir(path)
#define FMT_qu "%I64u"
#ifndef sleep
#define sleep(x) Sleep(x*1000)
#endif
#else
#include <sys/stat.h>
#define __mkdir(path, mode) mkdir(path, mode)
#define FMT_qu "%llu"
#endif

void debug_plist(plist_t plist);
char *generate_guid(void);
uint8_t _plist_dict_get_bool(plist_t dict, const char *key);
uint64_t _plist_dict_get_uint(plist_t dict, const char *key);
int _plist_dict_copy_uint(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key);
int _plist_dict_copy_bool(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key);
int _plist_dict_copy_data(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key);
int _plist_dict_copy_string(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key);
int _plist_dict_copy_item(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions tsschecker/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
}

int downloadFile(const char *url, const char *dstPath){
info("[DOWN] downloading file %s\n",url);
info("[DOWN] Downloading file: %s\n",url);
CURL *mcurl = curl_easy_init();

FILE *dfile = fopen(dstPath, "wb");
Expand All @@ -30,7 +30,7 @@ int downloadFile(const char *url, const char *dstPath){
curl_easy_cleanup(mcurl);
fclose(dfile);
if (res != CURLE_OK){
error("failed to download file from=%s to=%s CURLcode=%d\n",url,dstPath,res);
error("Failed to download file from: %s to=%s CURLcode=%d\n[TSSC] BuildManifest.plist not directly available, using fallback method...\n",url,dstPath,res);
return res;
}
return 0;
Expand Down
Loading

0 comments on commit b981d16

Please sign in to comment.