diff --git a/programs/nstool/source/AesCtrWrappedIFile.cpp b/programs/nstool/source/AesCtrWrappedIFile.cpp index 79d966f..134ded9 100644 --- a/programs/nstool/source/AesCtrWrappedIFile.cpp +++ b/programs/nstool/source/AesCtrWrappedIFile.cpp @@ -1,6 +1,7 @@ #include "AesCtrWrappedIFile.h" AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr) : + mOwnIFile(false), mFile(file), mKey(key), mBaseCtr(ctr) @@ -8,6 +9,23 @@ AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, const crypto::aes::sAes mScratch.alloc(kAesCtrScratchAllocSize); } +AesCtrWrappedIFile::AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr) : + mOwnIFile(ownIfile), + mFile(file), + mKey(key), + mBaseCtr(ctr) +{ + mScratch.alloc(kAesCtrScratchAllocSize); +} + +AesCtrWrappedIFile::~AesCtrWrappedIFile() +{ + if (mOwnIFile) + { + delete mFile; + } +} + size_t AesCtrWrappedIFile::size() { return mFile->size(); diff --git a/programs/nstool/source/AesCtrWrappedIFile.h b/programs/nstool/source/AesCtrWrappedIFile.h index f2a001c..3eaaaad 100644 --- a/programs/nstool/source/AesCtrWrappedIFile.h +++ b/programs/nstool/source/AesCtrWrappedIFile.h @@ -6,6 +6,8 @@ class AesCtrWrappedIFile : public fnd::IFile { public: AesCtrWrappedIFile(fnd::IFile* file, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr); + AesCtrWrappedIFile(fnd::IFile* file, bool ownIfile, const crypto::aes::sAes128Key& key, const crypto::aes::sAesIvCtr& ctr); + ~AesCtrWrappedIFile(); size_t size(); void seek(size_t offset); @@ -18,6 +20,7 @@ private: static const size_t kAesCtrScratchSize = 0x1000000; static const size_t kAesCtrScratchAllocSize = kAesCtrScratchSize + crypto::aes::kAesBlockSize; + bool mOwnIFile; fnd::IFile* mFile; crypto::aes::sAes128Key mKey; crypto::aes::sAesIvCtr mBaseCtr, mCurrentCtr; diff --git a/programs/nstool/source/OffsetAdjustedIFile.cpp b/programs/nstool/source/OffsetAdjustedIFile.cpp index e9f7231..d2fb0cf 100644 --- a/programs/nstool/source/OffsetAdjustedIFile.cpp +++ b/programs/nstool/source/OffsetAdjustedIFile.cpp @@ -1,6 +1,7 @@ #include "OffsetAdjustedIFile.h" OffsetAdjustedIFile::OffsetAdjustedIFile(fnd::IFile* file, size_t offset, size_t size) : + mOwnIFile(false), mFile(file), mBaseOffset(offset), mCurrentOffset(0), @@ -9,6 +10,24 @@ OffsetAdjustedIFile::OffsetAdjustedIFile(fnd::IFile* file, size_t offset, size_t } +OffsetAdjustedIFile::OffsetAdjustedIFile(fnd::IFile* file, bool ownIFile, size_t offset, size_t size) : + mOwnIFile(ownIFile), + mFile(file), + mBaseOffset(offset), + mCurrentOffset(0), + mSize(size) +{ + +} + +OffsetAdjustedIFile::~OffsetAdjustedIFile() +{ + if (mOwnIFile) + { + delete mFile; + } +} + size_t OffsetAdjustedIFile::size() { return mSize; diff --git a/programs/nstool/source/OffsetAdjustedIFile.h b/programs/nstool/source/OffsetAdjustedIFile.h index 5b60dcf..b1c1e09 100644 --- a/programs/nstool/source/OffsetAdjustedIFile.h +++ b/programs/nstool/source/OffsetAdjustedIFile.h @@ -4,6 +4,8 @@ class OffsetAdjustedIFile : public fnd::IFile { public: OffsetAdjustedIFile(fnd::IFile* file, size_t offset, size_t size); + OffsetAdjustedIFile(fnd::IFile* file, bool ownIFile, size_t offset, size_t size); + ~OffsetAdjustedIFile(); size_t size(); void seek(size_t offset); @@ -12,6 +14,7 @@ public: void write(const byte_t* out, size_t len); void write(const byte_t* out, size_t offset, size_t len); private: + bool mOwnIFile; fnd::IFile* mFile; size_t mBaseOffset, mCurrentOffset; size_t mSize;