/** * patcher.c */ #include #include #include "crypto.h" #include "patcher.h" #include "wii_tmd.h" int trucha_sign_ticket(u8 *ticket, u32 ticket_len) { u8 sha1[20]; u16 i; for(i=0; i<65535; i++) { memcpy(ticket+OFFSET_BF, &i, sizeof(u16)); sha(ticket+0x140, ticket_len-0x140, sha1); if (sha1[0] == 0x00) break; } if (i == 65535) return 0; else return 1; } int change_region_code(FILE *f, u32 tmd_len) { u8 *tmd; u8 region; char input[10]; fseek(f, OFFSET_TMD, SEEK_SET); tmd = (u8*)malloc(tmd_len); if (tmd == NULL) { fprintf(stderr, "mem error\n"); return 0; } fread((u8*)tmd, tmd_len, 1, f); dump_tmd_raw((u8*)tmd); region = tmd[OFFSET_REGION]; int i; do { printf("Region is set to %s\n",region_names[region]); printf("New region: \n"); for(i=0; i<4; i++) printf("%d- %s\n",i, region_names[i]); printf("Enter your new choice:"); fflush(stdout); fgets(input, 9, stdin); region = atoi(input); if (region > 4) region = 0x04; printf("New region is set to %s, do you agree? (y/n) ",region_names[region]); fflush(stdout); fgets(input, 9, stdin); } while(input[0] != 'y'); tmd[OFFSET_REGION] = region; printf("\tSigning...\n"); if (trucha_sign_ticket(tmd, tmd_len) == 0) { fprintf(stderr, "Error signing TMD\n"); return 0; } printf("\tdone.\n\n"); printf("Writing changes... \n"); fseek(f, OFFSET_TMD, SEEK_SET); fwrite((u8*)tmd, tmd_len, 1, f); free(tmd); return 1; }