forked from luigoalma/ctrcdnfetch
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTMD.hpp
More file actions
98 lines (84 loc) · 2.15 KB
/
TMD.hpp
File metadata and controls
98 lines (84 loc) · 2.15 KB
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
93
94
95
96
97
98
#ifndef __TMD_HPP__
#define __TMD_HPP__
#include "Endian.hpp"
#include "types.h"
namespace NintendoData
{
class TMD
{
public:
enum SignatureType : u32
{
RSA_4096_SHA1 = 0x10000,
RSA_2048_SHA1,
ECDSA_SHA1,
RSA_4096_SHA256,
RSA_2048_SHA256,
ECDSA_SHA256
};
struct __attribute__((__packed__)) Header
{
char Issuer[64];
u8 Version;
u8 CaCrlVersion;
u8 SignerCrlVersion;
u8 Reserved1;
u64 SystemVersion;
u64 TitleID;
u32 TitleType;
u16 GroupID;
u32 SaveDataSize;
u32 SRLPrivateSaveDataSize;
u32 Reserved2;
u8 SRLFlag;
u8 Reserved3[0x31];
u32 AccessRights;
u16 TitleVersion;
u16 ContentCount;
u16 BootContent;
u16 Padding;
u8 SHA256ContentInfoDigest[0x20];
};
struct __attribute__((__packed__)) ContentInfoRecords
{
u16 IndexOffset;
u16 CommandCount;
u8 SHA256ContentRecords[0x20];
};
struct __attribute__((__packed__)) ContentChunkRecords
{
u32 ContentId;
u16 ContentIndex;
u16 ContentType;
u64 ContentSize;
u8 SHA256[0x20];
u32 GetContentId() const noexcept { return Endian::Be(ContentId); }
u16 GetContentIndex() const noexcept { return Endian::Be(ContentIndex); }
u16 GetContentType() const noexcept { return Endian::Be(ContentType); }
u64 GetContentSize() const noexcept { return Endian::Be(ContentSize); }
};
private:
u8 *rawtmd;
struct Header *header;
struct ContentInfoRecords *inforecords;
struct ContentChunkRecords *chunkrecords;
public:
u16 GetContentCount() const noexcept { return Endian::Be(header->ContentCount); }
u16 GetTitleVersion() const noexcept { return Endian::Be(header->TitleVersion); }
const struct ContentInfoRecords& InfoRecord(const int index) const
{
if (index < 0 || index > 64) throw
std::out_of_range("TMDs only have 64 info records. Excepted range from 0 to 63.");
return inforecords[index];
}
struct ContentChunkRecords& ChunkRecord(const int index)
{
if (index < 0 || index > GetContentCount())
throw std::out_of_range("TMD doesn't have that many content records.");
return chunkrecords[index];
}
TMD(const void *ptr, size_t ptrlen);
~TMD() noexcept;
};
}
#endif