Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/nyx/nyx_gui/hos/pkg2.h
3711 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2026 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef _PKG2_H_
19
#define _PKG2_H_
20
21
#include <bdk.h>
22
23
#define PKG2_MAGIC 0x31324B50
24
#define PKG2_SEC_BASE 0x80000000
25
#define PKG2_SEC_KERNEL 0
26
#define PKG2_SEC_INI1 1
27
#define PKG2_SEC_UNUSED 2
28
29
#define INI1_MAGIC 0x31494E49
30
31
//! TODO: Update on kernel change if needed.
32
// Offset of OP + 12 is the INI1 offset. On v2 with dynamic crt0 it's + 16.
33
#define PKG2_NEWKERN_GET_INI1_HEURISTIC 0xD2800015 // MOV X21, #0.
34
#define PKG2_NEWKERN_START 0x800
35
36
extern u32 pkg2_newkern_ini1_start;
37
extern u32 pkg2_newkern_ini1_end;
38
39
typedef struct _pkg2_hdr_t
40
{
41
/* 0x000 */ u8 ctr[0x10];
42
/* 0x010 */ u8 sec_ctr[4][SE_AES_IV_SIZE];
43
/* 0x050 */ u32 magic;
44
/* 0x054 */ u32 base;
45
/* 0x058 */ u32 pad0;
46
/* 0x05C */ u8 pkg2_ver;
47
/* 0x05D */ u8 bl_ver;
48
/* 0x05E */ u16 pad1;
49
/* 0x060 */ u32 sec_size[4];
50
/* 0x070 */ u32 sec_off[4];
51
/* 0x080 */ u8 sec_sha256[4][SE_SHA_256_SIZE];
52
/* 0x100 */ u8 data[];
53
} pkg2_hdr_t;
54
55
typedef struct _pkg2_ini1_t
56
{
57
u32 magic;
58
u32 size;
59
u32 num_procs;
60
u32 pad;
61
} pkg2_ini1_t;
62
63
enum kip_offset_section
64
{
65
KIP_TEXT = 0,
66
KIP_RODATA = 1,
67
KIP_DATA = 2,
68
KIP_BSS = 3,
69
KIP_UNKSEC1 = 4,
70
KIP_UNKSEC2 = 5
71
};
72
73
#define KIP1_NUM_SECTIONS 6
74
75
typedef struct _pkg2_kip1_sec_t
76
{
77
u32 offset;
78
u32 size_decomp;
79
u32 size_comp;
80
u32 attrib;
81
} pkg2_kip1_sec_t;
82
83
typedef struct _pkg2_kip1_t
84
{
85
/* 0x000 */ u32 magic;
86
/* 0x004 */ char name[12];
87
/* 0x010 */ u64 tid;
88
/* 0x018 */ u32 proc_cat;
89
/* 0x01C */ u8 main_thrd_prio;
90
/* 0x01D */ u8 def_cpu_core;
91
/* 0x01E */ u8 res;
92
/* 0x01F */ u8 flags;
93
/* 0x020 */ pkg2_kip1_sec_t sections[KIP1_NUM_SECTIONS];
94
/* 0x080 */ u32 caps[0x20];
95
/* 0x100 */ u8 data[];
96
} pkg2_kip1_t;
97
98
typedef struct _pkg2_kip1_info_t
99
{
100
pkg2_kip1_t *kip1;
101
u32 size;
102
link_t link;
103
} pkg2_kip1_info_t;
104
105
void pkg2_get_newkern_info(u8 *kern_data);
106
u32 pkg2_calc_kip1_size(pkg2_kip1_t *kip1);
107
108
pkg2_hdr_t *pkg2_decrypt(void *data, u8 mkey);
109
110
#endif
111
112