[nstool] Formatting changes.

This commit is contained in:
jakcron 2018-05-21 20:49:28 +08:00
parent 1e75262f3f
commit e4b86ab566
2 changed files with 28 additions and 28 deletions

View file

@ -167,6 +167,13 @@ void NcaProcess::generatePartitionConfiguration()
} }
if (fs_header.version.get() != nx::nca::kDefaultFsHeaderVersion)
{
error.clear();
error << "NCA FS Header [" << partition.index << "] Version(" << fs_header.version.get() << "): UNSUPPORTED\n";
throw fnd::Exception(kModuleName, error.str());
}
// setup AES-CTR // setup AES-CTR
nx::NcaUtils::getNcaPartitionAesCtr(&fs_header, info.aes_ctr.iv); nx::NcaUtils::getNcaPartitionAesCtr(&fs_header, info.aes_ctr.iv);
@ -174,7 +181,6 @@ void NcaProcess::generatePartitionConfiguration()
info.reader = nullptr; info.reader = nullptr;
info.offset = partition.offset; info.offset = partition.offset;
info.size = partition.size; info.size = partition.size;
info.version = fs_header.version.get();
info.format_type = (nx::nca::FormatType)fs_header.format_type; info.format_type = (nx::nca::FormatType)fs_header.format_type;
info.hash_type = (nx::nca::HashType)fs_header.hash_type; info.hash_type = (nx::nca::HashType)fs_header.hash_type;
info.enc_type = (nx::nca::EncryptionType)fs_header.encryption_type; info.enc_type = (nx::nca::EncryptionType)fs_header.encryption_type;
@ -186,7 +192,9 @@ void NcaProcess::generatePartitionConfiguration()
case (nx::nca::FORMAT_ROMFS): case (nx::nca::FORMAT_ROMFS):
break; break;
default: default:
continue; error.clear();
error << "NCA FS Header [" << partition.index << "] FormatType(" << info.format_type << "): UNKNOWN \n";
throw fnd::Exception(kModuleName, error.str());
} }
// filter out unrecognised hash types, and get data offsets // filter out unrecognised hash types, and get data offsets
@ -197,21 +205,23 @@ void NcaProcess::generatePartitionConfiguration()
info.data_size = info.size; info.data_size = info.size;
break; break;
case (nx::nca::HASH_HIERARCHICAL_SHA256): case (nx::nca::HASH_HIERARCHICAL_SHA256):
info.hierarchicalsha256_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen); info.hash_sha256_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen);
info.data_offset = info.hierarchicalsha256_header.getLayerInfo().atBack().offset; info.data_offset = info.hash_sha256_header.getLayerInfo().atBack().offset;
info.data_size = info.hierarchicalsha256_header.getLayerInfo().atBack().size; info.data_size = info.hash_sha256_header.getLayerInfo().atBack().size;
break; break;
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY): case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
info.hierarchicalintergrity_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen); info.hash_integ_header.importBinary(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen);
info.data_offset = info.hierarchicalintergrity_header.getLayerInfo().atBack().offset; info.data_offset = info.hash_integ_header.getLayerInfo().atBack().offset;
info.data_size = info.hierarchicalintergrity_header.getLayerInfo().atBack().size; info.data_size = info.hash_integ_header.getLayerInfo().atBack().size;
break; break;
default: default:
continue; 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(fs_header.encryption_type) switch(info.enc_type)
{ {
case (nx::nca::CRYPT_AESXTS): case (nx::nca::CRYPT_AESXTS):
case (nx::nca::CRYPT_AESCTREX): case (nx::nca::CRYPT_AESCTREX):
@ -225,17 +235,12 @@ void NcaProcess::generatePartitionConfiguration()
break; break;
default: default:
error.clear(); error.clear();
error << "NCA FS Header [" << partition.index << "] EncryptionType(" << fs_header.encryption_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());
} }
} }
} }
void NcaProcess::validatePartitionHash()
{
}
void NcaProcess::validateNcaSignatures() void NcaProcess::validateNcaSignatures()
{ {
// validate signature[0] // validate signature[0]
@ -350,9 +355,6 @@ void NcaProcess::displayHeader()
printf(" %lu:\n", i); printf(" %lu:\n", i);
printf(" Offset: 0x%" PRIx64 "\n", info.offset); printf(" Offset: 0x%" PRIx64 "\n", info.offset);
printf(" Size: 0x%" PRIx64 "\n", info.size); printf(" Size: 0x%" PRIx64 "\n", info.size);
printf(" FsHeader:\n");
printf(" Version: 0x%d\n", info.version);
printf(" Format Type: %s\n", kFormatTypeStr[info.format_type].c_str()); printf(" Format Type: %s\n", kFormatTypeStr[info.format_type].c_str());
printf(" Hash Type: %s\n", kHashTypeStr[info.hash_type].c_str()); printf(" Hash Type: %s\n", kHashTypeStr[info.hash_type].c_str());
printf(" Enc. Type: %s\n", kEncryptionTypeStr[info.enc_type].c_str()); printf(" Enc. Type: %s\n", kEncryptionTypeStr[info.enc_type].c_str());
@ -365,7 +367,7 @@ 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.hierarchicalintergrity_header; nx::HierarchicalIntegrityHeader& hash_hdr = info.hash_integ_header;
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());
@ -385,7 +387,7 @@ 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.hierarchicalsha256_header; nx::HierarchicalSha256Header& hash_hdr = info.hash_sha256_header;
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.getMasterHash().bytes, sizeof(crypto::sha::sSha256Hash));

View file

@ -69,18 +69,16 @@ private:
size_t data_size; size_t data_size;
// meta data // meta data
uint16_t version;
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 hierarchicalsha256_header; nx::HierarchicalSha256Header hash_sha256_header;
nx::HierarchicalIntegrityHeader hierarchicalintergrity_header; nx::HierarchicalIntegrityHeader hash_integ_header;
crypto::aes::sAesIvCtr aes_ctr; crypto::aes::sAesIvCtr aes_ctr;
} mPartitions[nx::nca::kPartitionNum]; } mPartitions[nx::nca::kPartitionNum];
void generateNcaBodyEncryptionKeys(); void generateNcaBodyEncryptionKeys();
void generatePartitionConfiguration(); void generatePartitionConfiguration();
void validatePartitionHash();
void validateNcaSignatures(); void validateNcaSignatures();
void displayHeader(); void displayHeader();
void processPartitions(); void processPartitions();