73 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include "common.h"
2016-12-16 03:34:49 +01:00
#include "ticket.h"
2016-12-19 13:50:03 +01:00
#include "tmd.h"
#define CIA_HEADER_SIZE sizeof(CiaHeader)
#define CIA_CERT_SIZE 0xA00
#define CIA_META_SIZE sizeof(CiaMeta)
// see: https://www.3dbrew.org/wiki/CIA#Meta
typedef struct {
2017-10-03 01:46:52 +02:00
u8 dependencies[0x180]; // from ExtHeader
u8 reserved0[0x180];
u32 core_version; // 2 normally
u8 reserved1[0xFC];
u8 smdh[0x36C0]; // from ExeFS
} __attribute__((packed)) CiaMeta;
typedef struct {
u32 size_header;
u16 type;
u16 version;
u32 size_cert;
u32 size_ticket;
u32 size_tmd;
u32 size_meta;
u64 size_content;
u8 content_index[0x2000];
} __attribute__((packed)) CiaHeader;
typedef struct {
CiaHeader header;
u8 header_padding[0x40 - (CIA_HEADER_SIZE % 0x40)];
u8 cert[CIA_CERT_SIZE];
2016-11-26 14:25:10 +01:00
// cert is aligned and needs no padding
Ticket ticket;
2016-12-19 13:50:03 +01:00
u8 ticket_padding[0x40 - (TICKET_SIZE % 0x40)];
TitleMetaData tmd;
2016-12-19 13:50:03 +01:00
TmdContentChunk content_list[TMD_MAX_CONTENTS];
} __attribute__((packed)) CiaStub;
typedef struct { // first 0x20 bytes are identical with CIA header
u32 size_header;
u16 type;
u16 version;
u32 size_cert;
u32 size_ticket;
u32 size_tmd;
u32 size_meta;
u64 size_content;
u32 size_content_list;
u64 size_cia;
u32 offset_cert;
u32 offset_ticket;
u32 offset_tmd;
u32 offset_content;
u32 offset_meta;
u32 offset_content_list;
u32 max_contents;
} __attribute__((packed)) CiaInfo;
u32 ValidateCiaHeader(CiaHeader* header);
u32 GetCiaInfo(CiaInfo* info, CiaHeader* header);
2016-12-15 11:46:00 +01:00
u32 FixCiaHeaderForTmd(CiaHeader* header, TitleMetaData* tmd);
u32 BuildCiaCert(u8* ciacert);
2016-12-19 01:33:30 +01:00
u32 BuildCiaMeta(CiaMeta* meta, void* exthdr, void* smdh);
2016-12-15 11:46:00 +01:00
u32 BuildCiaHeader(CiaHeader* header);
u32 DecryptCiaContentSequential(void* data, u32 size, u8* ctr, const u8* titlekey);
u32 EncryptCiaContentSequential(void* data, u32 size, u8* ctr, const u8* titlekey);