big update

lots cleaned, added cia to cci conv, it
's called a block, separated reading from building, improved ncch keyx
stuff, and basic verbose for keys, elf checking and romfs
This commit is contained in:
applestash
2014-08-26 00:34:28 +10:00
parent c6e98ca578
commit 9c548197c1
66 changed files with 2970 additions and 2551 deletions
+92 -7
View File
@@ -1,6 +1,6 @@
#include "lib.h"
#include "cia.h"
#include "tmd.h"
#include "cia_build.h"
#include "tmd_build.h"
// Private Prototypes
int SetupTMDBuffer(buffer_struct *tik);
@@ -85,11 +85,96 @@ int SetupTMDContentRecord(u8 *content_record, cia_settings *ciaset)
{
for(int i = 0; i < ciaset->content.count; i++){
tmd_content_chunk *ptr = (tmd_content_chunk*)(content_record+sizeof(tmd_content_chunk)*i);
u32_to_u8(ptr->contentID,ciaset->content.id[i],BE);
u16_to_u8(ptr->contentIndex,ciaset->content.index[i],BE);
u16_to_u8(ptr->contentFlags,ciaset->content.flags[i],BE);
u64_to_u8(ptr->contentSize,ciaset->content.size[i],BE);
memcpy(ptr->contentHash,ciaset->content.hash[i],0x20);
u32_to_u8(ptr->id,ciaset->content.id[i],BE);
u16_to_u8(ptr->index,ciaset->content.index[i],BE);
u16_to_u8(ptr->flags,ciaset->content.flags[i],BE);
u64_to_u8(ptr->size,ciaset->content.size[i],BE);
memcpy(ptr->hash,ciaset->content.hash[i],0x20);
}
return 0;
}
tmd_hdr *GetTmdHdr(u8 *tmd)
{
u32 sigType = u8_to_u32(tmd,BE);
switch(sigType){
case(RSA_4096_SHA1):
case(RSA_4096_SHA256):
return (tmd_hdr*)(tmd+0x240);
case(RSA_2048_SHA1):
case(RSA_2048_SHA256):
return (tmd_hdr*)(tmd+0x140);
case(ECC_SHA1):
case(ECC_SHA256):
return (tmd_hdr*)(tmd+0x7C);
}
return NULL;
}
tmd_content_chunk* GetTmdContentInfo(u8 *tmd)
{
tmd_hdr *hdr = GetTmdHdr(tmd);
if(!hdr)
return NULL;
return (tmd_content_chunk*)((u8*)hdr + sizeof(tmd_hdr) + (sizeof(tmd_content_info_record)*64));
}
u64 GetTmdTitleId(tmd_hdr *hdr)
{
return u8_to_u64(hdr->titleID,BE);
}
u32 GetTmdSaveSize(tmd_hdr *hdr)
{
return u8_to_u32(hdr->savedataSize,BE);
}
u16 GetTmdContentCount(tmd_hdr *hdr)
{
return u8_to_u16(hdr->contentCount,BE);
}
u16 GetTmdVersion(tmd_hdr *hdr)
{
return u8_to_u16(hdr->titleVersion,BE);
}
u32 GetTmdContentId(tmd_content_chunk info)
{
return u8_to_u32(info.id,BE);
}
u16 GetTmdContentIndex(tmd_content_chunk info)
{
return u8_to_u16(info.index,BE);
}
u16 GetTmdContentFlags(tmd_content_chunk info)
{
return u8_to_u16(info.flags,BE);
}
u64 GetTmdContentSize(tmd_content_chunk info)
{
return u8_to_u64(info.size,BE);
}
u8* GetTmdContentHash(tmd_content_chunk *info)
{
return (u8*)info->hash;
}
bool IsTmdContentEncrypted(tmd_content_chunk info)
{
return (GetTmdContentFlags(info) & content_Encrypted) == content_Encrypted;
}
bool ValidateTmdContent(u8 *data, tmd_content_chunk info)
{
u8 hash[32];
ctr_sha(data,GetTmdContentSize(info),hash,CTR_SHA_256);
return memcmp(hash,GetTmdContentHash(&info),32) == 0;
}