mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[nstool] Encorporate HashWrappedIFile to NcaProcess.
This commit is contained in:
parent
18e4c175df
commit
cd322434c6
2 changed files with 25 additions and 14 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "OffsetAdjustedIFile.h"
|
#include "OffsetAdjustedIFile.h"
|
||||||
#include "AesCtrWrappedIFile.h"
|
#include "AesCtrWrappedIFile.h"
|
||||||
#include "CopiedIFile.h"
|
#include "CopiedIFile.h"
|
||||||
|
#include "HashTreeWrappedIFile.h"
|
||||||
|
|
||||||
std::string kFormatVersionStr[]
|
std::string kFormatVersionStr[]
|
||||||
{
|
{
|
||||||
|
@ -205,10 +206,10 @@ void NcaProcess::generatePartitionConfiguration()
|
||||||
info.reader = nullptr;
|
info.reader = nullptr;
|
||||||
break;
|
break;
|
||||||
case (nx::nca::CRYPT_AESCTR):
|
case (nx::nca::CRYPT_AESCTR):
|
||||||
info.reader = mBodyKeys.aes_ctr.isSet? new AesCtrWrappedIFile(mReader, mBodyKeys.aes_ctr.var, info.aes_ctr) : nullptr;
|
info.reader = mBodyKeys.aes_ctr.isSet? new OffsetAdjustedIFile(new AesCtrWrappedIFile(mReader, mBodyKeys.aes_ctr.var, info.aes_ctr), true, info.offset, info.size) : nullptr;
|
||||||
break;
|
break;
|
||||||
case (nx::nca::CRYPT_NONE):
|
case (nx::nca::CRYPT_NONE):
|
||||||
info.reader = new CopiedIFile(mReader);
|
info.reader = new OffsetAdjustedIFile(mReader, info.offset, info.size);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error.clear();
|
error.clear();
|
||||||
|
@ -220,24 +221,36 @@ void NcaProcess::generatePartitionConfiguration()
|
||||||
switch (info.hash_type)
|
switch (info.hash_type)
|
||||||
{
|
{
|
||||||
case (nx::nca::HASH_NONE):
|
case (nx::nca::HASH_NONE):
|
||||||
info.data_offset = info.offset;
|
|
||||||
info.data_size = info.size;
|
|
||||||
break;
|
break;
|
||||||
case (nx::nca::HASH_HIERARCHICAL_SHA256):
|
case (nx::nca::HASH_HIERARCHICAL_SHA256):
|
||||||
info.hash_tree_meta.importHierarchicalSha256Header(nx::HierarchicalSha256Header(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
|
info.hash_tree_meta.importHierarchicalSha256Header(nx::HierarchicalSha256Header(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
|
||||||
info.data_offset = info.hash_tree_meta.getDataLayer().offset;
|
//info.reader = (info.reader == nullptr) ? nullptr : new OffsetAdjustedIFile(info.reader, true, info.hash_tree_meta.getDataLayer().offset, info.hash_tree_meta.getDataLayer().size);
|
||||||
info.data_size = info.hash_tree_meta.getDataLayer().size;
|
info.reader = (info.reader == nullptr) ? nullptr : new HashTreeWrappedIFile(info.reader, true, info.hash_tree_meta);
|
||||||
break;
|
break;
|
||||||
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
|
case (nx::nca::HASH_HIERARCHICAL_INTERGRITY):
|
||||||
info.hash_tree_meta.importHierarchicalIntergityHeader(nx::HierarchicalIntegrityHeader(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
|
info.hash_tree_meta.importHierarchicalIntergityHeader(nx::HierarchicalIntegrityHeader(fs_header.hash_superblock, nx::nca::kFsHeaderHashSuperblockLen));
|
||||||
info.data_offset = info.hash_tree_meta.getDataLayer().offset;
|
//info.reader = (info.reader == nullptr) ? nullptr : new OffsetAdjustedIFile(info.reader, true, info.hash_tree_meta.getDataLayer().offset, info.hash_tree_meta.getDataLayer().size);
|
||||||
info.data_size = info.hash_tree_meta.getDataLayer().size;
|
info.reader = (info.reader == nullptr) ? nullptr : new HashTreeWrappedIFile(info.reader, true, info.hash_tree_meta);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error.clear();
|
error.clear();
|
||||||
error << "NCA FS Header [" << partition.index << "] HashType(" << info.hash_type << "): UNKNOWN \n";
|
error << "NCA FS Header [" << partition.index << "] HashType(" << info.hash_type << "): UNKNOWN \n";
|
||||||
throw fnd::Exception(kModuleName, error.str());
|
throw fnd::Exception(kModuleName, error.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (info.reader != nullptr)
|
||||||
|
{
|
||||||
|
fnd::MemoryBlob sss;
|
||||||
|
sss.alloc(info.reader->size());
|
||||||
|
info.reader->read(sss.getBytes(), sss.getSize());
|
||||||
|
printf("[%d] START\n", i);
|
||||||
|
fnd::SimpleTextOutput::hxdStyleDump(sss.getBytes(), 0x100);
|
||||||
|
printf("[%d] END\n", i);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +272,7 @@ void NcaProcess::validateNcaSignatures()
|
||||||
if (mPartitions[nx::nca::PARTITION_CODE].reader != nullptr)
|
if (mPartitions[nx::nca::PARTITION_CODE].reader != nullptr)
|
||||||
{
|
{
|
||||||
PfsProcess exefs;
|
PfsProcess exefs;
|
||||||
exefs.setInputFile(mPartitions[nx::nca::PARTITION_CODE].reader, mPartitions[nx::nca::PARTITION_CODE].offset + mPartitions[nx::nca::PARTITION_CODE].data_offset, mPartitions[nx::nca::PARTITION_CODE].data_size);
|
exefs.setInputFile(mPartitions[nx::nca::PARTITION_CODE].reader, 0, mPartitions[nx::nca::PARTITION_CODE].reader->size());
|
||||||
exefs.setCliOutputMode(OUTPUT_MINIMAL);
|
exefs.setCliOutputMode(OUTPUT_MINIMAL);
|
||||||
exefs.process();
|
exefs.process();
|
||||||
|
|
||||||
|
@ -269,7 +282,7 @@ void NcaProcess::validateNcaSignatures()
|
||||||
const nx::PfsHeader::sFile& file = exefs.getPfsHeader().getFileList()[exefs.getPfsHeader().getFileList().getIndexOf(kNpdmExefsPath)];
|
const nx::PfsHeader::sFile& file = exefs.getPfsHeader().getFileList()[exefs.getPfsHeader().getFileList().getIndexOf(kNpdmExefsPath)];
|
||||||
|
|
||||||
NpdmProcess npdm;
|
NpdmProcess npdm;
|
||||||
npdm.setInputFile(mPartitions[nx::nca::PARTITION_CODE].reader, mPartitions[nx::nca::PARTITION_CODE].offset + mPartitions[nx::nca::PARTITION_CODE].data_offset + file.offset, file.size);
|
npdm.setInputFile(mPartitions[nx::nca::PARTITION_CODE].reader, file.offset, file.size);
|
||||||
npdm.setCliOutputMode(OUTPUT_MINIMAL);
|
npdm.setCliOutputMode(OUTPUT_MINIMAL);
|
||||||
npdm.process();
|
npdm.process();
|
||||||
|
|
||||||
|
@ -431,7 +444,7 @@ void NcaProcess::processPartitions()
|
||||||
if (partition.format_type == nx::nca::FORMAT_PFS0)
|
if (partition.format_type == nx::nca::FORMAT_PFS0)
|
||||||
{
|
{
|
||||||
PfsProcess pfs;
|
PfsProcess pfs;
|
||||||
pfs.setInputFile(partition.reader, partition.offset + partition.data_offset, partition.data_size);
|
pfs.setInputFile(partition.reader, 0, partition.reader->size());
|
||||||
pfs.setCliOutputMode(mCliOutputType);
|
pfs.setCliOutputMode(mCliOutputType);
|
||||||
pfs.setListFs(mListFs);
|
pfs.setListFs(mListFs);
|
||||||
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
||||||
|
@ -452,7 +465,7 @@ void NcaProcess::processPartitions()
|
||||||
else if (partition.format_type == nx::nca::FORMAT_ROMFS)
|
else if (partition.format_type == nx::nca::FORMAT_ROMFS)
|
||||||
{
|
{
|
||||||
RomfsProcess romfs;
|
RomfsProcess romfs;
|
||||||
romfs.setInputFile(partition.reader, partition.offset + partition.data_offset, partition.data_size);
|
romfs.setInputFile(partition.reader, 0, partition.reader->size());
|
||||||
romfs.setCliOutputMode(mCliOutputType);
|
romfs.setCliOutputMode(mCliOutputType);
|
||||||
romfs.setListFs(mListFs);
|
romfs.setListFs(mListFs);
|
||||||
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
if (mHdr.getContentType() == nx::nca::TYPE_PROGRAM)
|
||||||
|
|
|
@ -64,8 +64,6 @@ private:
|
||||||
fnd::IFile* reader;
|
fnd::IFile* reader;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t data_offset;
|
|
||||||
size_t data_size;
|
|
||||||
|
|
||||||
// meta data
|
// meta data
|
||||||
nx::nca::FormatType format_type;
|
nx::nca::FormatType format_type;
|
||||||
|
|
Loading…
Reference in a new issue