[nstool] Integrate HashTreeMeta into NcaProcess

This commit is contained in:
jakcron 2018-05-21 21:08:37 +08:00
parent 1f3865c979
commit bd991a25e1
2 changed files with 45 additions and 42 deletions

View file

@ -197,29 +197,6 @@ void NcaProcess::generatePartitionConfiguration()
throw fnd::Exception(kModuleName, error.str()); throw fnd::Exception(kModuleName, error.str());
} }
// filter out unrecognised hash types, and get data offsets
switch (info.hash_type)
{
case (nx::nca::HASH_NONE):
info.data_offset = info.offset;
info.data_size = info.size;
break;
case (nx::nca::HASH_HIERARCHICAL_SHA256):
info.hash_sha256_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen);
info.data_offset = info.hash_sha256_header.getLayerInfo().atBack().offset;
info.data_size = info.hash_sha256_header.getLayerInfo().atBack().size;
break;
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
info.hash_integ_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen);
info.data_offset = info.hash_integ_header.getLayerInfo().atBack().offset;
info.data_size = info.hash_integ_header.getLayerInfo().atBack().size;
break;
default:
error.clear();
error << "NCA FS Header [" << partition.index << "] HashType(" << info.hash_type << "): UNKNOWN \n";
throw fnd::Exception(kModuleName, error.str());
}
// create reader based on encryption type0 // create reader based on encryption type0
switch(info.enc_type) switch(info.enc_type)
{ {
@ -238,6 +215,29 @@ void NcaProcess::generatePartitionConfiguration()
error << "NCA FS Header [" << partition.index << "] EncryptionType(" << info.enc_type << "): UNKNOWN \n"; error << "NCA FS Header [" << partition.index << "] EncryptionType(" << info.enc_type << "): UNKNOWN \n";
throw fnd::Exception(kModuleName, error.str()); throw fnd::Exception(kModuleName, error.str());
} }
// filter out unrecognised hash types, and get data offsets
switch (info.hash_type)
{
case (nx::nca::HASH_NONE):
info.data_offset = info.offset;
info.data_size = info.size;
break;
case (nx::nca::HASH_HIERARCHICAL_SHA256):
info.hash_tree_meta.importHierarchicalSha256Header(nx::HierarchicalSha256Header(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
info.data_offset = info.hash_tree_meta.getDataLayer().offset;
info.data_size = info.hash_tree_meta.getDataLayer().size;
break;
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
info.hash_tree_meta.importHierarchicalIntergityHeader(nx::HierarchicalIntegrityHeader(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
info.data_offset = info.hash_tree_meta.getDataLayer().offset;
info.data_size = info.hash_tree_meta.getDataLayer().size;
break;
default:
error.clear();
error << "NCA FS Header [" << partition.index << "] HashType(" << info.hash_type << "): UNKNOWN \n";
throw fnd::Exception(kModuleName, error.str());
}
} }
} }
@ -367,18 +367,23 @@ void NcaProcess::displayHeader()
} }
if (info.hash_type == nx::nca::HASH_HIERARCHICAL_INTERGRITY) if (info.hash_type == nx::nca::HASH_HIERARCHICAL_INTERGRITY)
{ {
nx::HierarchicalIntegrityHeader& hash_hdr = info.hash_integ_header; HashTreeMeta& hash_hdr = info.hash_tree_meta;
printf(" HierarchicalIntegrity Header:\n"); printf(" HierarchicalIntegrity Header:\n");
//printf(" TypeId: 0x%x\n", hash_hdr.type_id.get()); //printf(" TypeId: 0x%x\n", hash_hdr.type_id.get());
//printf(" MasterHashSize: 0x%x\n", hash_hdr.master_hash_size.get()); //printf(" MasterHashSize: 0x%x\n", hash_hdr.master_hash_size.get());
//printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize()); //printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize());
for (size_t j = 0; j < hash_hdr.getLayerInfo().getSize(); j++) for (size_t j = 0; j < hash_hdr.getHashLayerInfo().getSize(); j++)
{ {
printf(" Layer %d:\n", j); printf(" Hash Layer %d:\n", j);
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getLayerInfo()[j].offset); printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[j].offset);
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getLayerInfo()[j].size); printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[j].size);
printf(" BlockSize: 0x%" PRIx32 "\n", hash_hdr.getLayerInfo()[j].block_size); printf(" BlockSize: 0x%" PRIx32 "\n", hash_hdr.getHashLayerInfo()[j].block_size);
} }
printf(" Data Layer:\n");
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().offset);
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().size);
printf(" BlockSize: 0x%" PRIx32 "\n", hash_hdr.getDataLayer().block_size);
for (size_t j = 0; j < hash_hdr.getMasterHashList().getSize(); j++) for (size_t j = 0; j < hash_hdr.getMasterHashList().getSize(); j++)
{ {
printf(" Master Hash %d: ", j); printf(" Master Hash %d: ", j);
@ -387,18 +392,18 @@ void NcaProcess::displayHeader()
} }
else if (info.hash_type == nx::nca::HASH_HIERARCHICAL_SHA256) else if (info.hash_type == nx::nca::HASH_HIERARCHICAL_SHA256)
{ {
nx::HierarchicalSha256Header& hash_hdr = info.hash_sha256_header; HashTreeMeta& hash_hdr = info.hash_tree_meta;
printf(" HierarchicalSha256 Header:\n"); printf(" HierarchicalSha256 Header:\n");
printf(" Master Hash: "); printf(" Master Hash: ");
fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHash().bytes, sizeof(crypto::sha::sSha256Hash)); fnd::SimpleTextOutput::hexDump(hash_hdr.getMasterHashList()[0].bytes, sizeof(crypto::sha::sSha256Hash));
printf(" HashBlockSize: 0x%x\n", hash_hdr.getHashBlockSize()); printf(" HashBlockSize: 0x%x\n", hash_hdr.getDataLayer().block_size);
//printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize()); //printf(" LayerNum: %d\n", hash_hdr.getLayerInfo().getSize());
for (size_t i = 0; i < hash_hdr.getLayerInfo().getSize(); i++) printf(" Hash Layer:\n");
{ printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[0].offset);
printf(" Layer %d:\n", i); printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getHashLayerInfo()[0].size);
printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getLayerInfo()[i].offset); printf(" Data Layer:\n");
printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getLayerInfo()[i].size); printf(" Offset: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().offset);
} printf(" Size: 0x%" PRIx64 "\n", hash_hdr.getDataLayer().size);
} }
//else //else
//{ //{

View file

@ -3,8 +3,7 @@
#include <fnd/types.h> #include <fnd/types.h>
#include <fnd/SimpleFile.h> #include <fnd/SimpleFile.h>
#include <nx/NcaHeader.h> #include <nx/NcaHeader.h>
#include <nx/HierarchicalSha256Header.h> #include "HashTreeMeta.h"
#include <nx/HierarchicalIntegrityHeader.h>
#include "nstool.h" #include "nstool.h"
@ -72,8 +71,7 @@ private:
nx::nca::FormatType format_type; nx::nca::FormatType format_type;
nx::nca::HashType hash_type; nx::nca::HashType hash_type;
nx::nca::EncryptionType enc_type; nx::nca::EncryptionType enc_type;
nx::HierarchicalSha256Header hash_sha256_header; HashTreeMeta hash_tree_meta;
nx::HierarchicalIntegrityHeader hash_integ_header;
crypto::aes::sAesIvCtr aes_ctr; crypto::aes::sAesIvCtr aes_ctr;
} mPartitions[nx::nca::kPartitionNum]; } mPartitions[nx::nca::kPartitionNum];