/*1* Copyright (c) 2018 naehrwert2* Copyright (c) 2022-2023 CTCaer3*4* This program is free software; you can redistribute it and/or modify it5* under the terms and conditions of the GNU General Public License,6* version 2, as published by the Free Software Foundation.7*8* This program is distributed in the hope it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <http://www.gnu.org/licenses/>.15*/1617#ifndef _PKG1_H_18#define _PKG1_H_1920#include <bdk.h>2122#define PKG1_MAGIC 0x31314B502324#define PK11_SECTION_WB 025#define PK11_SECTION_LD 126#define PK11_SECTION_SM 22728typedef struct _bl_hdr_t210b01_t29{30/* 0x000 */ u8 aes_mac[0x10];31/* 0x010 */ u8 rsa_sig[0x100];32/* 0x110 */ u8 salt[0x20];33/* 0x130 */ u8 sha256[0x20];34/* 0x150 */ u32 version;35/* 0x154 */ u32 size;36/* 0x158 */ u32 load_addr;37/* 0x15C */ u32 entrypoint;38/* 0x160 */ u8 rsvd[0x10];39} bl_hdr_t210b01_t;4041typedef struct _pk1_hdr_t42{43/* 0x00 */ u32 si_sha256; // Secure Init.44/* 0x04 */ u32 sm_sha256; // Secure Monitor.45/* 0x08 */ u32 sl_sha256; // Secure Loader.46/* 0x0C */ u32 unk; // what's this? It's not warmboot.47/* 0x10 */ char timestamp[14];48/* 0x1E */ u8 keygen;49/* 0x1F */ u8 version;50} pk1_hdr_t;5152typedef struct _pkg1_id_t53{54const char *id;55u32 kb;56u32 tsec_off;57u32 pkg11_off;58u32 secmon_base;59u32 warmboot_base;60} pkg1_id_t;6162typedef struct _pk11_hdr_t63{64u32 magic;65u32 wb_size;66u32 wb_off;67u32 pad;68u32 ldr_size;69u32 ldr_off;70u32 sm_size;71u32 sm_off;72} pk11_hdr_t;7374const pkg1_id_t *pkg1_identify(u8 *pkg1, char *build_date);75int pkg1_decrypt(const pkg1_id_t *id, u8 *pkg1);76const u8 *pkg1_unpack(void *wm_dst, void *sm_dst, void *ldr_dst, const pkg1_id_t *id, u8 *pkg1);7778#endif798081