diff options
Diffstat (limited to 'patcher.c')
-rw-r--r-- | patcher.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/patcher.c b/patcher.c new file mode 100644 index 0000000..30e4620 --- /dev/null +++ b/patcher.c @@ -0,0 +1,80 @@ +/** + * patcher.c + */ + +#include <string.h> +#include <stdlib.h> + +#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; +} + |