[nstool] Fix XCI partition validation.

This commit is contained in:
jakcron 2018-06-06 21:27:46 +08:00
parent bd2e1dd927
commit b42c551a20
2 changed files with 12 additions and 9 deletions

View file

@ -146,11 +146,11 @@ void PfsProcess::validateHfs()
{
mCache.alloc(file[i].hash_protected_size);
mFile->read(mCache.getBytes(), file[i].offset, file[i].hash_protected_size);
crypto::sha::Sha256(mCache.getBytes(), mCache.getSize(), hash.bytes);
crypto::sha::Sha256(mCache.getBytes(), file[i].hash_protected_size, hash.bytes);
if (hash != file[i].hash)
{
if (mCliOutputType >= OUTPUT_MINIMAL)
printf("[WARNING] HFS0 %s%s%s: FAIL (bad hash)\n", !mMountName.empty()? mMountName.c_str() : "", !mMountName.empty()? "/" : "", file[i].name.c_str());
printf("[WARNING] HFS0 %s%s%s: FAIL (bad hash)\n", !mMountName.empty()? mMountName.c_str() : "", (!mMountName.empty() && mMountName.at(mMountName.length()-1) != '/' )? "/" : "", file[i].name.c_str());
}
}

View file

@ -225,16 +225,13 @@ void XciProcess::validateXciSignature()
void XciProcess::processRootPfs()
{
if (mVerify)
{
if (validateRegionOfFile(mHdr.getPartitionFsAddress(), mHdr.getPartitionFsSize(), mHdr.getPartitionFsHash().bytes) == false)
if (mVerify && validateRegionOfFile(mHdr.getPartitionFsAddress(), mHdr.getPartitionFsSize(), mHdr.getPartitionFsHash().bytes) == false)
{
printf("[WARNING] XCI Root HFS0: FAIL (bad hash)\n");
}
}
mRootPfs.setInputFile(new OffsetAdjustedIFile(mFile, SHARED_IFILE, mHdr.getPartitionFsAddress(), mHdr.getPartitionFsSize()), OWN_IFILE);
mRootPfs.setListFs(mListFs);
mRootPfs.setVerifyMode(mVerify);
mRootPfs.setVerifyMode(false);
mRootPfs.setCliOutputMode(mCliOutputType);
mRootPfs.setMountPointName(kXciMountPointName);
mRootPfs.process();
@ -245,6 +242,12 @@ void XciProcess::processPartitionPfs()
const fnd::List<nx::PfsHeader::sFile>& rootPartitions = mRootPfs.getPfsHeader().getFileList();
for (size_t i = 0; i < rootPartitions.getSize(); i++)
{
// this must be validated here because only the size of the root partiton header is known at verification time
if (mVerify && validateRegionOfFile(mHdr.getPartitionFsAddress() + rootPartitions[i].offset, rootPartitions[i].hash_protected_size, rootPartitions[i].hash.bytes) == false)
{
printf("[WARNING] XCI %s Partition HFS0: FAIL (bad hash)\n", rootPartitions[i].name.c_str());
}
PfsProcess tmp;
tmp.setInputFile(new OffsetAdjustedIFile(mFile, SHARED_IFILE, mHdr.getPartitionFsAddress() + rootPartitions[i].offset, rootPartitions[i].size), OWN_IFILE);
tmp.setListFs(mListFs);