1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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;
}
|