mirror of
https://github.com/jakcron/nstool
synced 2024-11-15 02:06:40 +00:00
[nstool] Wrapped IFile classes now can optionally specify when constructed if they own their IFile pointer. By default they do not.
This commit is contained in:
parent
446927b53e
commit
1e75262f3f
4 changed files with 43 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue