[nstool] Changed handling of shared IFile derrivatives. Always a pointer

This commit is contained in:
jakcron 2018-05-11 21:20:28 +08:00
parent 90bbbede60
commit 8e360332e5
15 changed files with 37 additions and 38 deletions

View file

@ -1,6 +1,6 @@
#include "AesCtrWrappedIFile.h"
AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile& file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr) :
AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr) :
mFile(file),
mKey(key),
mBaseCtr(ctr)
@ -10,12 +10,12 @@ AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile& file, const crypto::aes::sAes
size_t AesCtrWrappedIFile::size()
{
return mFile.size();
return mFile->size();
}
void AesCtrWrappedIFile::seek(size_t offset)
{
mFile.seek(offset);
mFile->seek(offset);
crypto::aes::AesIncrementCounter(mBaseCtr.iv, offset>>4, mCurrentCtr.iv);
mBlockOffset = offset & 0xf;
}
@ -24,7 +24,7 @@ void AesCtrWrappedIFile::read(byte_t* out, size_t len)
{
for (size_t i = 0; i < (len / kAesCtrScratchSize); i++)
{
mFile.read(mScratch.getBytes() + mBlockOffset, kAesCtrScratchSize);
mFile->read(mScratch.getBytes() + mBlockOffset, kAesCtrScratchSize);
crypto::aes::AesCtr(mScratch.getBytes(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.getBytes());
memcpy(out + (i * kAesCtrScratchSize), mScratch.getBytes() + mBlockOffset, kAesCtrScratchSize);
}
@ -33,7 +33,7 @@ void AesCtrWrappedIFile::read(byte_t* out, size_t len)
{
size_t read_len = len % kAesCtrScratchSize;
size_t read_pos = ((len / kAesCtrScratchSize) * kAesCtrScratchSize);
mFile.read(mScratch.getBytes() + mBlockOffset, read_len);
mFile->read(mScratch.getBytes() + mBlockOffset, read_len);
crypto::aes::AesCtr(mScratch.getBytes(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.getBytes());
memcpy(out + read_pos, mScratch.getBytes() + mBlockOffset, read_len);
}
@ -51,7 +51,7 @@ void AesCtrWrappedIFile::write(const byte_t* out, size_t len)
{
memcpy(mScratch.getBytes() + mBlockOffset, out + (i * kAesCtrScratchSize), kAesCtrScratchSize);
crypto::aes::AesCtr(mScratch.getBytes(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.getBytes());
mFile.write(mScratch.getBytes() + mBlockOffset, kAesCtrScratchSize);
mFile->write(mScratch.getBytes() + mBlockOffset, kAesCtrScratchSize);
}
if (len % kAesCtrScratchSize)
@ -60,7 +60,7 @@ void AesCtrWrappedIFile::write(const byte_t* out, size_t len)
size_t write_pos = ((len / kAesCtrScratchSize) * kAesCtrScratchSize);
memcpy(mScratch.getBytes() + mBlockOffset, out + write_pos, write_len);
crypto::aes::AesCtr(mScratch.getBytes(), kAesCtrScratchAllocSize, mKey.key, mCurrentCtr.iv, mScratch.getBytes());
mFile.write(mScratch.getBytes() + mBlockOffset, write_len);
mFile->write(mScratch.getBytes() + mBlockOffset, write_len);
}
}

View file

@ -5,7 +5,7 @@
class AesCtrWrappedIFile : public fnd::IFile
{
public:
AesCtrWrappedIFile(fnd::IFile& file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr);
AesCtrWrappedIFile(fnd::IFile* file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr);
size_t size();
void seek(size_t offset);
@ -18,7 +18,7 @@ private:
static const size_t kAesCtrScratchSize = 0x1000000;
static const size_t kAesCtrScratchAllocSize = kAesCtrScratchSize + crypto::aes::kAesBlockSize;
fnd::IFile& mFile;
fnd::IFile* mFile;
crypto::aes::sAes128Key mKey;
crypto::aes::sAesIvCtr mBaseCtr, mCurrentCtr;
size_t mBlockOffset;

View file

@ -249,7 +249,7 @@ void NcaProcess::processPartitions()
// create reader
fnd::IFile* partitionReader = nullptr;
AesCtrWrappedIFile aesCtrFile = AesCtrWrappedIFile(*mReader, mBodyKeys.aes_ctr.var, ctr);
AesCtrWrappedIFile aesCtrFile = AesCtrWrappedIFile(mReader, mBodyKeys.aes_ctr.var, ctr);
switch(fs_header.encryption_type)
{
case (nx::nca::CRYPT_AESXTS):
@ -290,7 +290,7 @@ void NcaProcess::processPartitions()
if (fs_header.format_type == nx::nca::FORMAT_PFS0)
{
PfsProcess pfs;
pfs.setInputFile(*partitionReader);
pfs.setInputFile(partitionReader);
pfs.setInputFileOffset(partition.offset + data_offset);
pfs.setCliOutputMode(mCliOutputType);
pfs.setListFs(mListFs);
@ -301,7 +301,7 @@ void NcaProcess::processPartitions()
else if (fs_header.format_type == nx::nca::FORMAT_ROMFS)
{
RomfsProcess romfs;
romfs.setInputFile(*partitionReader);
romfs.setInputFile(partitionReader);
romfs.setInputFileOffset(partition.offset + data_offset);
romfs.setCliOutputMode(mCliOutputType);
romfs.setListFs(mListFs);

View file

@ -59,7 +59,6 @@ private:
} mBodyKeys;
void displayHeader();
void generateNcaBodyEncryptionKeys();

View file

@ -665,9 +665,9 @@ void NpdmProcess::process()
}
}
void NpdmProcess::setInputFile(fnd::IFile& reader)
void NpdmProcess::setInputFile(fnd::IFile* reader)
{
mReader = &reader;
mReader = reader;
}
void NpdmProcess::setInputFileOffset(size_t offset)

View file

@ -13,7 +13,7 @@ public:
void process();
void setInputFile(fnd::IFile& reader);
void setInputFile(fnd::IFile* reader);
void setInputFileOffset(size_t offset);
void setKeyset(const sKeyset* keyset);
void setCliOutputMode(CliOutputType type);

View file

@ -1,6 +1,6 @@
#include "OffsetAdjustedIFile.h"
OffsetAdjustedIFile::OffsetAdjustedIFile(fnd::IFile& file, size_t offset, size_t size) :
OffsetAdjustedIFile::OffsetAdjustedIFile(fnd::IFile* file, size_t offset, size_t size) :
mFile(file),
mBaseOffset(offset),
mCurrentOffset(0),
@ -17,13 +17,13 @@ size_t OffsetAdjustedIFile::size()
void OffsetAdjustedIFile::seek(size_t offset)
{
mCurrentOffset = offset;
mFile.seek(offset + mBaseOffset);
mFile->seek(offset + mBaseOffset);
}
void OffsetAdjustedIFile::read(byte_t* out, size_t len)
{
seek(mCurrentOffset);
mFile.read(out, len);
mFile->read(out, len);
}
void OffsetAdjustedIFile::read(byte_t* out, size_t offset, size_t len)
@ -35,7 +35,7 @@ void OffsetAdjustedIFile::read(byte_t* out, size_t offset, size_t len)
void OffsetAdjustedIFile::write(const byte_t* out, size_t len)
{
seek(mCurrentOffset);
mFile.write(out, len);
mFile->write(out, len);
}
void OffsetAdjustedIFile::write(const byte_t* out, size_t offset, size_t len)

View file

@ -3,7 +3,7 @@
class OffsetAdjustedIFile : public fnd::IFile
{
public:
OffsetAdjustedIFile(fnd::IFile& file, size_t offset, size_t size);
OffsetAdjustedIFile(fnd::IFile* file, size_t offset, size_t size);
size_t size();
void seek(size_t offset);
@ -12,7 +12,7 @@ public:
void write(const byte_t* out, size_t len);
void write(const byte_t* out, size_t offset, size_t len);
private:
fnd::IFile& mFile;
fnd::IFile* mFile;
size_t mBaseOffset, mCurrentOffset;
size_t mSize;
};

View file

@ -139,9 +139,9 @@ void PfsProcess::process()
extractFs();
}
void PfsProcess::setInputFile(fnd::IFile& reader)
void PfsProcess::setInputFile(fnd::IFile* reader)
{
mReader = &reader;
mReader = reader;
}
void PfsProcess::setInputFileOffset(size_t offset)

View file

@ -14,7 +14,7 @@ public:
void process();
// generic
void setInputFile(fnd::IFile& reader);
void setInputFile(fnd::IFile* reader);
void setInputFileOffset(size_t offset);
void setKeyset(const sKeyset* keyset);
void setCliOutputMode(CliOutputType type);

View file

@ -256,9 +256,9 @@ void RomfsProcess::process()
extractFs();
}
void RomfsProcess::setInputFile(fnd::IFile& reader)
void RomfsProcess::setInputFile(fnd::IFile* reader)
{
mReader = &reader;
mReader = reader;
}
void RomfsProcess::setInputFileOffset(size_t offset)

View file

@ -93,7 +93,7 @@ public:
void process();
// generic
void setInputFile(fnd::IFile& reader);
void setInputFile(fnd::IFile* reader);
void setInputFileOffset(size_t offset);
void setKeyset(const sKeyset* keyset);
void setCliOutputMode(CliOutputType type);

View file

@ -141,7 +141,7 @@ void XciProcess::processRootPfs()
printf("[WARNING] XCI Root HFS0: FAIL (bad hash)\n");
}
}
mRootPfs.setInputFile(*mReader);
mRootPfs.setInputFile(mReader);
mRootPfs.setInputFileOffset(mOffset + mHdr.getPartitionFsAddress());
mRootPfs.setListFs(mListFs);
mRootPfs.setVerifyMode(mVerify);
@ -156,7 +156,7 @@ void XciProcess::processPartitionPfs()
for (size_t i = 0; i < rootPartitions.getSize(); i++)
{
PfsProcess tmp;
tmp.setInputFile(*mReader);
tmp.setInputFile(mReader);
tmp.setInputFileOffset(mOffset + mHdr.getPartitionFsAddress() + rootPartitions[i].offset);
tmp.setListFs(mListFs);
tmp.setVerifyMode(mVerify);
@ -227,9 +227,9 @@ void XciProcess::process()
processPartitionPfs();
}
void XciProcess::setInputFile(fnd::IFile& reader)
void XciProcess::setInputFile(fnd::IFile* reader)
{
mReader = &reader;
mReader = reader;
}
void XciProcess::setInputFileOffset(size_t offset)

View file

@ -17,7 +17,7 @@ public:
void process();
// generic
void setInputFile(fnd::IFile& reader);
void setInputFile(fnd::IFile* reader);
void setInputFileOffset(size_t offset);
void setKeyset(const sKeyset* keyset);
void setCliOutputMode(CliOutputType type);

View file

@ -21,7 +21,7 @@ int main(int argc, char** argv)
{
XciProcess xci;
xci.setInputFile(inputFile);
xci.setInputFile(&inputFile);
xci.setKeyset(&user_set.getKeyset());
xci.setCliOutputMode(user_set.getCliOutputType());
@ -41,7 +41,7 @@ int main(int argc, char** argv)
{
PfsProcess pfs;
pfs.setInputFile(inputFile);
pfs.setInputFile(&inputFile);
pfs.setKeyset(&user_set.getKeyset());
pfs.setCliOutputMode(user_set.getCliOutputType());
pfs.setVerifyMode(user_set.isVerifyFile());
@ -56,7 +56,7 @@ int main(int argc, char** argv)
{
RomfsProcess romfs;
romfs.setInputFile(inputFile);
romfs.setInputFile(&inputFile);
romfs.setKeyset(&user_set.getKeyset());
romfs.setCliOutputMode(user_set.getCliOutputType());
romfs.setVerifyMode(user_set.isVerifyFile());
@ -93,7 +93,7 @@ int main(int argc, char** argv)
{
NpdmProcess npdm;
npdm.setInputFile(inputFile);
npdm.setInputFile(&inputFile);
npdm.setKeyset(&user_set.getKeyset());
npdm.setCliOutputMode(user_set.getCliOutputType());
npdm.setVerifyMode(user_set.isVerifyFile());