forked from SciresM/hactool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.h
98 lines (82 loc) · 2.39 KB
/
packages.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
#ifndef HACTOOL_PACKAGES_H
#define HACTOOL_PACKAGES_H
#include "types.h"
#include "utils.h"
#include "settings.h"
#include "kip.h"
#define MAGIC_PK11 0x31314B50
#define MAGIC_PK21 0x31324B50
typedef struct {
unsigned char build_hash[0x10];
unsigned char build_date[0x10];
unsigned char stage1[0x3FC0];
uint32_t pk11_size;
unsigned char _0x3FE4[0xC];
unsigned char ctr[0x10];
} pk11_stage1_t;
typedef struct {
uint32_t magic;
uint32_t warmboot_size;
uint32_t _0x8;
uint32_t _0xC;
uint32_t nx_bootloader_size;
uint32_t _0x14;
uint32_t secmon_size;
uint32_t _0x1C;
unsigned char data[];
} pk11_t;
typedef struct {
FILE *file;
hactool_ctx_t *tool_ctx;
int is_pilot;
unsigned int key_rev;
pk11_stage1_t stage1;
pk11_t *pk11;
} pk11_ctx_t;
static inline unsigned char *pk11_get_warmboot_bin(pk11_ctx_t *ctx) {
return ctx->is_pilot ? &ctx->pk11->data[ctx->pk11->secmon_size + ctx->pk11->nx_bootloader_size] : &ctx->pk11->data[0];
}
static inline unsigned char *pk11_get_secmon(pk11_ctx_t *ctx) {
return ctx->is_pilot ? &ctx->pk11->data[0] : &ctx->pk11->data[ctx->pk11->warmboot_size + ctx->pk11->nx_bootloader_size];
}
static inline unsigned char *pk11_get_nx_bootloader(pk11_ctx_t *ctx) {
return ctx->is_pilot ? &ctx->pk11->data[ctx->pk11->secmon_size] : &ctx->pk11->data[ctx->pk11->warmboot_size];
}
void pk11_process(pk11_ctx_t *ctx);
void pk11_print(pk11_ctx_t *ctx);
void pk11_save(pk11_ctx_t *ctx);
/* Package2 */
#pragma pack(push, 1)
typedef struct {
unsigned char signature[0x100];
union {
unsigned char ctr[0x10];
uint32_t ctr_dwords[0x4];
};
unsigned char section_ctrs[4][0x10];
uint32_t magic;
uint32_t base_offset;
uint32_t _0x58;
uint8_t version_max; /* Must be > TZ value. */
uint8_t version_min; /* Must be < TZ value. */
uint16_t _0x5E;
uint32_t section_sizes[4];
uint32_t section_offsets[4];
unsigned char section_hashes[4][0x20];
} pk21_header_t;
#pragma pack(pop)
typedef struct {
FILE *file;
hactool_ctx_t *tool_ctx;
unsigned int key_rev;
uint32_t package_size;
validity_t signature_validity;
validity_t section_validities[4];
unsigned char *sections;
pk21_header_t header;
ini1_ctx_t ini1_ctx;
} pk21_ctx_t;
void pk21_process(pk21_ctx_t *ctx);
void pk21_print(pk21_ctx_t *ctx);
void pk21_save(pk21_ctx_t *ctx);
#endif