-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
92 lines (79 loc) · 1.98 KB
/
main.c
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
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (C) 2013 3DSGuy
* Copyright (C) 2015 173210
*
* This file is part of make_cdn_cia.
*
* make_cdn_cia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* make_cdn_cia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with make_cdn_cia. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cia.h"
#include "ctr_endian.h"
#include <errno.h>
#include <unistd.h>
#define VER "1.00"
int main(int argc, char *argv[])
{
TIKCtx tik;
TMDCtx tmd;
FILE *out;
if(argc != 3) {
printf("CTR_Toolkit - CIA Generator for CDN Content\n"
"Version " VER " (C) 2013-2015 3DSGuy, 173210\n\n"
"Usage: %s <CDN Content Dir> <output CIA file>\n",
argv[0]);
return EINVAL;
}
out = fopen(argv[2],"wb");
if (out == NULL) {
perror("CIA: error");
return errno;
}
if (chdir(argv[1])) {
perror("CIA: error");
return errno;
}
tik.fp = fopen("cetk","rb");
if (tik.fp == NULL) {
perror("CETK: error");
return errno;
}
if (processTIK(&tik)) {
fclose(tik.fp);
return errno;
}
tmd.fp = fopen("tmd","rb");
if (tmd.fp == NULL) {
perror("TMD: error");
fclose(out);
fclose(tik.fp);
return errno;
}
if (processTMD(&tmd)) {
fclose(out);
fclose(tik.fp);
fclose(tmd.fp);
return errno;
}
if (tik.titleID != tmd.titleID) {
printf("warning: CETK and TMD Title IDs do not match\n"
" CETK Title ID: 0x%016lluX\n"
" TMD Title ID: 0x%016lluX\n",
be64toh(tik.titleID), be64toh(tmd.titleID));
}
if (writeCIA(&tmd, &tik, out)) {
fclose(out);
fclose(tik.fp);
fclose(tmd.fp);
return errno;
}
return 0;
}