diff --git a/finalize/source/main.c b/finalize/source/main.c index 7066583..8aed4d1 100644 --- a/finalize/source/main.c +++ b/finalize/source/main.c @@ -6,7 +6,7 @@ #include "basetik_bin.h" #define CIFINISH_PATH "/cifinish.bin" -#define REQUIRED_VERSION 1 +#define REQUIRED_VERSION 2 // 0x10 struct finish_db_header { @@ -15,42 +15,36 @@ struct finish_db_header { u32 title_count; }; -// 0x30 +// 0x20 struct finish_db_entry { - u64 title_id; - u8 common_key_index; - bool has_seed; u8 magic[6]; // "TITLE" and a null byte - u8 title_key[0x10]; + bool has_seed; + u64 title_id; u8 seed[0x10]; }; // 0x350 struct ticket_dumb { - u8 unused1[0x1BF]; - u8 title_key[0x10]; - u8 unused2[0xD]; + u8 unused1[0x1DC]; u64 title_id_be; - u8 unused3[0xD]; - u8 common_key_index; - u8 unused4[0x15E]; + u8 unused2[0x16C]; } __attribute__((packed)); // from FBI: // https://github.com/Steveice10/FBI/blob/6e3a28e4b674e0d7a6f234b0419c530b358957db/source/core/http.c#L440-L453 static Result FSUSER_AddSeed(u64 titleId, const void* seed) { - u32 *cmdbuf = getThreadCommandBuffer(); + u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = 0x087A0180; - cmdbuf[1] = (u32) (titleId & 0xFFFFFFFF); - cmdbuf[2] = (u32) (titleId >> 32); - memcpy(&cmdbuf[3], seed, 16); + cmdbuf[0] = 0x087A0180; + cmdbuf[1] = (u32) (titleId & 0xFFFFFFFF); + cmdbuf[2] = (u32) (titleId >> 32); + memcpy(&cmdbuf[3], seed, 16); - Result ret = 0; - if(R_FAILED(ret = svcSendSyncRequest(*fsGetSessionHandle()))) return ret; + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(*fsGetSessionHandle()))) return ret; - ret = cmdbuf[1]; - return ret; + ret = cmdbuf[1]; + return ret; } void finalize_install(void) @@ -82,6 +76,23 @@ void finalize_install(void) return; } + if (header.version != REQUIRED_VERSION) + { + printf("\n%s was created with a different\n", CIFINISH_PATH); + printf(" version of custom-install than this one\n"); + printf(" supports.\n\n"); + printf("Make sure you are using the latest version of\n"); + printf(" custom-install and custom-install-finalize\n"); + printf(" from the repository on GitHub.\n\n"); + printf("When you run the script again, you can use\n"); + printf(" --skip-contents to avoid re-writing the title\n"); + printf(" contents, so only the Title Database and\n"); + printf(" cifinish.bin will be modified.\n\n"); + printf("Expected version %i, got %li\n", REQUIRED_VERSION, header.version); + fclose(fp); + return; + } + entries = calloc(header.title_count, sizeof(struct finish_db_entry)); fread(entries, sizeof(struct finish_db_entry), header.title_count, fp); fclose(fp); @@ -97,8 +108,6 @@ void finalize_install(void) printf("Finalizing %016llx...\n", entries[i].title_id); ticket_buf.title_id_be = __builtin_bswap64(entries[i].title_id); - ticket_buf.common_key_index = entries[i].common_key_index; - memcpy(ticket_buf.title_key, entries[i].title_key, 0x10); res = AM_InstallTicketBegin(&ticketHandle); if (R_FAILED(res)) @@ -148,7 +157,7 @@ int main(int argc, char* argv[]) gfxInitDefault(); consoleInit(GFX_TOP, NULL); - puts("custom-install-finalize v1.0"); + puts("custom-install-finalize v1.1"); finalize_install(); puts("\nPress START or B to exit.");