Skip to content

Commit

Permalink
add save as bplist
Browse files Browse the repository at this point in the history
  • Loading branch information
1Conan committed Nov 22, 2021
1 parent 7446832 commit 9e7762e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions tsschecker/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static struct option longopts[] = {
{ "raw", required_argument, NULL, 10 },
{ "bbsnum", required_argument, NULL, 11 },
{ "server-url", required_argument, NULL, 12 },
{ "bplist", no_argument, NULL, 13 },
{ "generator", required_argument, NULL, 'g' },
{ NULL, 0, NULL, 0 }
};
Expand All @@ -85,6 +86,7 @@ void cmd_help(){
printf(" --sepnonce NONCE\t\tmanually specify SEP Nonce instead of using random ones (not required for saving blobs)\n");
printf(" --bbsnum SNUM\t\tmanually specify BbSNUM in HEX to save valid BBTickets (not required for saving blobs)\n\n");
printf(" --save-path PATH\t\tspecify output path for saving shsh blobs\n");
printf(" --bplist\t\t\tsave shsh blob as binary plist (used with --save)\n");
printf(" --server-url URL\t\tmanually specify TSS server url\n");
printf(" --beta\t\t\trequest tickets for a beta instead of normal release (use with -o)\n");
printf(" --list-devices\t\tlist all known devices\n");
Expand Down Expand Up @@ -157,6 +159,7 @@ int main(int argc, const char * argv[]) {
dbglog = 1;
idevicerestore_debug = 0;
save_shshblobs = 0;
save_bplist = 0;
int optindex = 0;
int opt = 0;
long flags = 0;
Expand Down Expand Up @@ -284,6 +287,9 @@ int main(int argc, const char * argv[]) {
case 12: // only long option: "server-url"
serverUrl = optarg;
break;
case 13: // only long option: "bplist"
save_bplist = 1;
break;
default:
cmd_help();
return -1;
Expand Down
21 changes: 12 additions & 9 deletions tsschecker/tsschecker.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int print_tss_request = 0;
int print_tss_response = 0;
int nocache = 0;
int save_shshblobs = 0;
int save_bplist = 0;
const char *shshSavePath = "."DIRECTORY_DELIMITER_STR;

// iPhone & iPod touch (1st generations) do not use SHSH or APTicket.
Expand Down Expand Up @@ -1028,15 +1029,20 @@ int isManifestBufSignedForDevice(char *buildManifestBuffer, t_devicevals *devVal
plist_get_uint_val(pecid, &devVals->ecid);
char *cecid = ecid_to_string(devVals->ecid);

uint32_t size = 0;
char* data = NULL;
if (*devVals->generator)
plist_dict_set_item(apticket, "generator", plist_new_string(devVals->generator));
if (apticket2)
plist_dict_set_item(apticket, "updateInstall", apticket2);
if (apticket3)
plist_dict_set_item(apticket, "noNonce", apticket3);
plist_to_xml(apticket, &data, &size);

uint32_t size = 0;
char* data = NULL;

if (save_bplist)
plist_to_bin(apticket, &data, &size);
else
plist_to_xml(apticket, &data, &size);

char *apnonce = "";
size_t apnonceLen = 0;
Expand All @@ -1056,22 +1062,19 @@ int isManifestBufSignedForDevice(char *buildManifestBuffer, t_devicevals *devVal
snprintf(tmpDevicename, tmpDeviceNameSize, "%s", devVals->deviceModel);
if (devVals->deviceBoard) snprintf(tmpDevicename+strlen(tmpDevicename), tmpDeviceNameSize-strlen(tmpDevicename), "_%s",devVals->deviceBoard);

size_t fnamelen = strlen(shshSavePath) + 1 + strlen(cecid) + tmpDeviceNameSize + strlen(cpvers) + strlen(cbuild) + strlen(DIRECTORY_DELIMITER_STR"___-.shsh2") + 1;
size_t fnamelen = strlen(shshSavePath) + 1 + strlen(cecid) + tmpDeviceNameSize + strlen(cpvers) + strlen(cbuild) + strlen(DIRECTORY_DELIMITER_STR"___-.bshsh2") + 1;
fnamelen += devVals->parsedApnonceLen*2;

char *fname = malloc(fnamelen);
memset(fname, 0, fnamelen);
size_t prePathLen= strlen(shshSavePath);
if (shshSavePath[prePathLen-1] == DIRECTORY_DELIMITER_CHR) prePathLen--;
strncpy(fname, shshSavePath, prePathLen);

snprintf(fname+prePathLen, fnamelen, DIRECTORY_DELIMITER_STR"%s_%s_%s-%s_%s.shsh%s",cecid,tmpDevicename,cpvers,cbuild, apnonce, (*devVals->generator || apticket2) ? "2" : "");


snprintf(fname+prePathLen, fnamelen, DIRECTORY_DELIMITER_STR"%s_%s_%s-%s_%s.%Sshsh%s",cecid,tmpDevicename,cpvers,cbuild, apnonce, save_bplist ? "b" : "", (*devVals->generator || apticket2) ? "2" : "");
FILE *shshfile = fopen(fname, "wb");
if (!shshfile) error("[Error] can't save shsh at %s\n",fname);
else{
fwrite(data, strlen(data), 1, shshfile);
fwrite(data, size, 1, shshfile);
fclose(shshfile);
info("Saved shsh blobs!\n");
}
Expand Down
1 change: 1 addition & 0 deletions tsschecker/tsschecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern int dbglog;
extern int print_tss_response;
extern int nocache;
extern int save_shshblobs;
extern int save_bplist;
extern const char *shshSavePath;

struct bbdevice{
Expand Down

0 comments on commit 9e7762e

Please sign in to comment.