-
Notifications
You must be signed in to change notification settings - Fork 34
/
types.h
179 lines (149 loc) · 2.61 KB
/
types.h
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
Copyright 2010
Sven Peter <[email protected]>
Licensed under the terms of the GNU GPL, version 2
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
#ifndef TYPES_H__
#define TYPES_H__
#include <stdint.h>
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef int64_t s64;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
struct elf_phdr {
u32 p_type;
u64 p_off;
u64 p_vaddr;
u64 p_paddr;
u64 p_filesz;
u64 p_memsz;
u32 p_flags;
u64 p_align;
void *ptr;
};
struct elf_shdr {
u32 sh_name;
u32 sh_type;
u32 sh_flags;
u64 sh_addr;
u64 sh_offset;
u32 sh_size;
u32 sh_link;
u32 sh_info;
u32 sh_addralign;
u32 sh_entsize;
};
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_LOOS 0xfe00
#define ET_HIOS 0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff
struct elf_hdr {
char e_ident[16];
u16 e_type;
u16 e_machine;
u32 e_version;
u64 e_entry;
u64 e_phoff;
u64 e_shoff;
u32 e_flags;
u16 e_ehsize;
u16 e_phentsize;
u16 e_phnum;
u16 e_shentsize;
u16 e_shnum;
u16 e_shtrndx;
};
struct id2name_tbl {
u32 id;
const char *name;
};
struct key {
u8 key[32];
u8 iv[16];
int pub_avail;
int priv_avail;
u8 pub[40];
u8 priv[21];
u32 ctype;
};
struct keylist {
u32 n;
struct key *keys;
struct key *idps;
struct key *klic;
struct key *rif;
struct key *npdrm_const;
struct key *free_klicensee;
};
struct rif {
u8 unk1[0x10]; /* Version, license type and user number */
u8 titleid[0x30]; /* Content ID */
u8 padding[0xC]; /* Padding for randomness */
u32 actDatIndex; /* Key index on act.dat between 0x00 and 0x7F */
u8 key[0x10]; /* Encrypted klicensee */
u64 unk2; /* Timestamp? */
u64 unk3; /* Always 0 */
u8 rs[0x28];
} __attribute__ ((packed));
struct actdat {
u8 unk1[0x10]; /* Version, user number */
u8 keyTable[0x800]; /* Key table */
u8 unk2[0x800];
u8 signature[0x28];
} __attribute__ ((packed));
static inline u8 be8(u8 *p)
{
return *p;
}
static inline u16 be16(u8 *p)
{
u16 a;
a = p[0] << 8;
a |= p[1];
return a;
}
static inline u32 be32(u8 *p)
{
u32 a;
a = p[0] << 24;
a |= p[1] << 16;
a |= p[2] << 8;
a |= p[3] << 0;
return a;
}
static inline u64 be64(u8 *p)
{
u32 a, b;
a = be32(p);
b = be32(p + 4);
return ((u64)a<<32) | b;
}
static inline void wbe16(u8 *p, u16 v)
{
p[0] = v >> 8;
p[1] = v;
}
static inline void wbe32(u8 *p, u32 v)
{
p[0] = v >> 24;
p[1] = v >> 16;
p[2] = v >> 8;
p[3] = v;
}
static inline void wbe64(u8 *p, u64 v)
{
wbe32(p + 4, v);
v >>= 32;
wbe32(p, v);
}
#endif