Skip to content

Commit

Permalink
Add beta support from appledb, cmake shared lib (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptiiiic authored Dec 16, 2022
1 parent eada4cd commit 3b09d63
Showing 5 changed files with 102 additions and 11 deletions.
44 changes: 42 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -41,24 +41,64 @@ endif()
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG")
set(CMAKE_C_STANDARD 17)
add_library(tsschecker
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
add_library(tsschecker STATIC
tsschecker/tsschecker.c
tsschecker/download.c)
add_library(tsschecker_shared SHARED
tsschecker/tsschecker.c
tsschecker/download.c
tsschecker/common.c
tsschecker/tss.c
tsschecker/main.c)
target_include_directories(tsschecker PRIVATE
"${CMAKE_SOURCE_DIR}/dep_root/include/"
tsschecker
external/jssy/jssy)
target_include_directories(tsschecker_shared PRIVATE
"${CMAKE_SOURCE_DIR}/dep_root/include/"
tsschecker
external/jssy/jssy)
target_link_directories(tsschecker PRIVATE
"${CMAKE_SOURCE_DIR}/dep_root/lib/")
target_link_directories(tsschecker_shared PRIVATE
"${CMAKE_SOURCE_DIR}/dep_root/lib/"
.)
if(NOT DEFINED NO_PKGCFG AND NOT "$ENV{NO_PKGCFG}" MATCHES "1")
message("$ENV{NO_PKGCFG}")
find_package(PkgConfig REQUIRED)
pkg_check_modules(DEPS REQUIRED
libplist-2.0
libirecovery-1.0
libfragmentzip)
target_include_directories(tsschecker PRIVATE "${DEPS_INCLUDE_DIRS}")
else()
target_link_libraries(tsschecker_shared PRIVATE
curl
plist-2.0
irecovery-1.0
fragmentzip
usbmuxd-2.0
imobiledevice-glue-1.0
imobiledevice-1.0
z
jssy)
endif()
if("${CMAKE_HOST_SYSTEM_NAME}" MATCHES "Darwin")
target_link_libraries(tsschecker_shared PRIVATE
compression
"-framework CoreFoundation"
"-framework IOKit")
endif()
set_target_properties(tsschecker_shared PROPERTIES OUTPUT_NAME "tsschecker.0")
if(NOT DEFINED VERSION_COMMIT_COUNT)
execute_process(COMMAND git rev-list --count HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE VERSION_COMMIT_COUNT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT DEFINED VERSION_COMMIT_SHA)
execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE VERSION_COMMIT_SHA ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
add_definitions(
-DTSSCHECKER_VERSION_COUNT="${VERSION_COMMIT_COUNT}"
-DTSSCHECKER_VERSION_SHA="${VERSION_COMMIT_SHA}")
add_definitions(-DTSSCHECKER_NOMAIN=1)
project(tsschecker)
add_subdirectory(external)
2 changes: 2 additions & 0 deletions tsschecker/common.c
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@

#include "common.h"

int idevicerestore_debug;

#define MAX_PRINT_LEN 64*1024
#ifndef NO_DEBUG_PLIST
void debug_plist(plist_t plist) {
2 changes: 1 addition & 1 deletion tsschecker/main.c
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
#define FLAG_BUILDMANIFEST (1 << 2)
#define FLAG_LATEST_IOS (1 << 3)

int idevicerestore_debug;
extern int idevicerestore_debug;
#define reterror(code,a ...) {error(a); err = code; goto error;}

static struct option longopts[] = {
63 changes: 55 additions & 8 deletions tsschecker/tsschecker.c
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@

#define FIRMWARE_JSON_URL "https://api.ipsw.me/v2.1/firmwares.json/condensed"
#define FIRMWARE_BETA_JSON_URL "https://api.m1sta.xyz/betas/"
#define FIRMWARE_BETA_JSON_URL2 "https://api.appledb.dev/ios/"
#define FIRMWARE_OTA_JSON_URL "https://api.ipsw.me/v2.1/ota.json/condensed"

/* for KTRR devices this value - 32 */
@@ -69,7 +70,7 @@ static const char *win_pathvars[]={
"\\tsschecker",
"\\ota.json",
"\\firmwares.json",
"\\betas_"
"\\firmwares_betas.json"
};

static const char *win_path_get(enum paths path){
@@ -473,15 +474,38 @@ char *getFirmwareJson(){
return fJson;
}

char *getBetaFirmwareJson2(const char *type, const char *buildid) {
char url[256], path[256];
memset(url, 0, 256);
memset(path, 0, 256);
strcat(url, FIRMWARE_BETA_JSON_URL2);
strcat(url, type);
strcat(url, ";");
strcat(url, buildid);
strcat(url, ".json");
strcat(path, FIRMWARE_BETA_JSON_PATH);
debug("[TSSC] opening %s\n", path);
FILE *f = fopen(path, "rb");
if (!f || nocache){
downloadFile(url, path);
f = fopen(path, "rb");
}
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
char *fJson = calloc(1, fsize + 1);
fread(fJson, fsize, 1, f);
fclose(f);
return fJson;
}

char *getBetaFirmwareJson(const char *device) {
char url[50], path[50];
memset(url, 0, 50);
memset(path, 0, 50);
strcat(url, FIRMWARE_BETA_JSON_URL);
strcat(url, device);
strcat(path, FIRMWARE_BETA_JSON_PATH);
strcat(path, device);
strcat(path, ".json");
debug("[TSSC] opening %s\n", path);
FILE *f = fopen(path, "rb");
if (!f || nocache){
@@ -490,11 +514,15 @@ char *getBetaFirmwareJson(const char *device) {
}
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
char *fJson = calloc(1, fsize + 1);
fread(fJson, fsize, 1, f);
fclose(f);
return fJson;
if(fsize < 1) {
return NULL;
} else {
fseek(f, 0, SEEK_SET);
char *fJson = calloc(1, fsize + 1);
fread(fJson, fsize, 1, f);
fclose(f);
return fJson;
}
}

char *getOtaJson(){
@@ -1547,6 +1575,25 @@ char **getListOfiOSForDevice2(jssytok_t *tokens, const char *device, int isOTA,
return versions;
}

char *getBetaURLForDevice2(jssytok_t *tokens, const char *deviceid) {
if (!tokens)
return error("[TSSC] beta tokens empty\n"),NULL;
jssytok_t *tmp = jssy_dictGetValueForKey(tokens, "devices");
if (!tmp)
return error("[TSSC] beta devices empty\n"),NULL;
tmp = jssy_dictGetValueForKey(tmp, deviceid);
if (!tmp)
return error("[TSSC] beta device not found\n"),NULL;
tmp = jssy_dictGetValueForKey(tmp, "ipsw");
if (!tmp)
return error("[TSSC] beta ipsw not found\n"),NULL;
if (!tmp->size)
return error("[TSSC] beta ipsw name is empty\n"),NULL;
char *url_str = calloc(1, tmp->size + 1);
strncpy(url_str, tmp->value, tmp->size);
return url_str;
}

char *getBetaURLForDevice(jssytok_t *tokens, const char *buildid) {
if (!tokens)
return error("[TSSC] beta tokens empty\n"),NULL;
2 changes: 2 additions & 0 deletions tsschecker/tsschecker.h
Original file line number Diff line number Diff line change
@@ -87,11 +87,13 @@ typedef struct{
int parseHex(const char *nonce, size_t *parsedLen, char *ret, size_t *retSize);

char *getFirmwareJson(void);
char *getBetaFirmwareJson2(const char *type, const char *buildid);
char *getBetaFirmwareJson(const char *device);
char *getOtaJson(void);
long parseTokens(const char *json, jssytok_t **tokens);
char **getListOfiOSForDevice(jssytok_t *tokens, const char *device, int isOTA, int *versionCntt, bool beta);
char **getListOfiOSForDevice2(jssytok_t *tokens, const char *device, int isOTA, int *versionCntt, int buildid, bool beta);
char *getBetaURLForDevice2(jssytok_t *tokens, const char *buildid);
char *getBetaURLForDevice(jssytok_t *tokens, const char *buildid);
int printListOfDevices(jssytok_t *tokens);
int printListOfiOSForDevice(jssytok_t *tokens, char *device, int isOTA);

0 comments on commit 3b09d63

Please sign in to comment.