DiscIO: Move some raw pointers over to unique_ptr

This commit is contained in:
Lioncash 2014-08-31 09:34:58 -04:00
parent ea7eee1f58
commit 4cb46879bc
9 changed files with 40 additions and 48 deletions

View File

@ -6,6 +6,7 @@
#include <cinttypes>
#include <cstddef>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
@ -275,9 +276,9 @@ bool ParsePartitionData(SPartition& _rPartition)
// Ready some stuff
m_Disc = CreateVolumeFromFilename(m_Filename, _rPartition.GroupNumber, _rPartition.Number);
IFileSystem *FileSystem = CreateFileSystem(m_Disc);
std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(m_Disc));
if (!FileSystem)
if (!filesystem)
{
ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", _rPartition.GroupNumber, _rPartition.Number);
ParsedOK = false;
@ -285,7 +286,7 @@ bool ParsePartitionData(SPartition& _rPartition)
else
{
std::vector<const SFileInfo *> Files;
size_t numFiles = FileSystem->GetFileList(Files);
size_t numFiles = filesystem->GetFileList(Files);
// Mark things as used which are not in the filesystem
// Header, Header Information, Apploader
@ -330,8 +331,6 @@ bool ParsePartitionData(SPartition& _rPartition)
}
}
delete FileSystem;
// Swap back
delete m_Disc;
m_Disc = OldVolume;

View File

@ -5,6 +5,7 @@
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <memory>
#include <string>
#include "Common/Common.h"
@ -22,13 +23,12 @@ CARCFile::CARCFile(const std::string& _rFilename)
: m_pBuffer(nullptr)
, m_Initialized(false)
{
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rFilename.c_str());
if (pReader != nullptr)
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(_rFilename));
if (reader != nullptr)
{
u64 FileSize = pReader->GetDataSize();
u64 FileSize = reader->GetDataSize();
m_pBuffer = new u8[(u32)FileSize];
pReader->Read(0, FileSize, m_pBuffer);
delete pReader;
reader->Read(0, FileSize, m_pBuffer);
m_Initialized = ParseBuffer();
}
@ -38,13 +38,12 @@ CARCFile::CARCFile(const std::string& _rFilename, u32 offset)
: m_pBuffer(nullptr)
, m_Initialized(false)
{
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rFilename.c_str());
if (pReader != nullptr)
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(_rFilename));
if (reader != nullptr)
{
u64 FileSize = pReader->GetDataSize() - offset;
u64 FileSize = reader->GetDataSize() - offset;
m_pBuffer = new u8[(u32)FileSize];
pReader->Read(offset, FileSize, m_pBuffer);
delete pReader;
reader->Read(offset, FileSize, m_pBuffer);
m_Initialized = ParseBuffer();
}

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
@ -21,8 +22,6 @@ CVolumeGC::CVolumeGC(IBlobReader* _pReader)
CVolumeGC::~CVolumeGC()
{
delete m_pReader;
m_pReader = nullptr; // I don't think this makes any difference, but anyway
}
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include <string>
#include <vector>
@ -41,7 +42,7 @@ public:
static StringDecoder GetStringDecoder(ECountry country);
private:
IBlobReader* m_pReader;
std::unique_ptr<IBlobReader> m_pReader;
};
} // namespace

View File

@ -41,7 +41,6 @@ CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
CVolumeWAD::~CVolumeWAD()
{
delete m_pReader;
}
bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include <string>
#include <vector>
@ -37,7 +38,7 @@ public:
u64 GetRawSize() const override;
private:
IBlobReader* m_pReader;
std::unique_ptr<IBlobReader> m_pReader;
u32 OpeningBnrOffset, hdr_size, cert_size, tick_size, tmd_size, data_size;
u8 m_Country;
};

View File

@ -21,25 +21,21 @@ namespace DiscIO
CVolumeWiiCrypted::CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset,
const unsigned char* _pVolumeKey)
: m_pReader(_pReader),
m_AES_ctx(new aes_context),
m_pBuffer(nullptr),
m_VolumeOffset(_VolumeOffset),
dataOffset(0x20000),
m_LastDecryptedBlockOffset(-1)
{
m_AES_ctx = new aes_context;
aes_setkey_dec(m_AES_ctx, _pVolumeKey, 128);
aes_setkey_dec(m_AES_ctx.get(), _pVolumeKey, 128);
m_pBuffer = new u8[0x8000];
}
CVolumeWiiCrypted::~CVolumeWiiCrypted()
{
delete m_pReader; // is this really our responsibility?
m_pReader = nullptr;
delete[] m_pBuffer;
m_pBuffer = nullptr;
delete m_AES_ctx;
m_AES_ctx = nullptr;
}
bool CVolumeWiiCrypted::RAWRead( u64 _Offset, u64 _Length, u8* _pBuffer ) const
@ -78,7 +74,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer) const
if (m_LastDecryptedBlockOffset != Block)
{
memcpy(IV, m_pBuffer + 0x3d0, 16);
aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x7C00, IV, m_pBuffer + 0x400, m_LastDecryptedBlock);
aes_crypt_cbc(m_AES_ctx.get(), AES_DECRYPT, 0x7C00, IV, m_pBuffer + 0x400, m_LastDecryptedBlock);
m_LastDecryptedBlockOffset = Block;
}
@ -261,7 +257,7 @@ bool CVolumeWiiCrypted::CheckIntegrity() const
NOTICE_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read metadata", clusterID);
return false;
}
aes_crypt_cbc(m_AES_ctx, AES_DECRYPT, 0x400, IV, clusterMDCrypted, clusterMD);
aes_crypt_cbc(m_AES_ctx.get(), AES_DECRYPT, 0x400, IV, clusterMDCrypted, clusterMD);
// Some clusters have invalid data and metadata because they aren't

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <polarssl/aes.h>
@ -40,10 +41,10 @@ public:
bool CheckIntegrity() const override;
private:
IBlobReader* m_pReader;
std::unique_ptr<IBlobReader> m_pReader;
std::unique_ptr<aes_context> m_AES_ctx;
u8* m_pBuffer;
aes_context* m_AES_ctx;
u64 m_VolumeOffset;
u64 dataOffset;

View File

@ -4,6 +4,7 @@
#include <cstddef>
#include <memory>
#include <string>
#include "Common/Common.h"
@ -32,18 +33,16 @@ private:
DiscIO::IBlobReader& m_rReader;
};
WiiWAD::WiiWAD(const std::string& _rName)
WiiWAD::WiiWAD(const std::string& name)
{
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rName);
if (pReader == nullptr || File::IsDirectory(_rName))
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(name));
if (reader == nullptr || File::IsDirectory(name))
{
m_Valid = false;
if (pReader) delete pReader;
return;
}
m_Valid = ParseWAD(*pReader);
delete pReader;
m_Valid = ParseWAD(*reader);
}
WiiWAD::~WiiWAD()
@ -118,30 +117,28 @@ bool WiiWAD::ParseWAD(DiscIO::IBlobReader& _rReader)
return true;
}
bool WiiWAD::IsWiiWAD(const std::string& _rName)
bool WiiWAD::IsWiiWAD(const std::string& name)
{
DiscIO::IBlobReader* pReader = DiscIO::CreateBlobReader(_rName);
if (pReader == nullptr)
std::unique_ptr<IBlobReader> blob_reader(DiscIO::CreateBlobReader(name));
if (blob_reader == nullptr)
return false;
CBlobBigEndianReader Reader(*pReader);
bool Result = false;
CBlobBigEndianReader big_endian_reader(*blob_reader);
bool result = false;
// check for wii wad
if (Reader.Read32(0x00) == 0x20)
if (big_endian_reader.Read32(0x00) == 0x20)
{
u32 WADTYpe = Reader.Read32(0x04);
switch (WADTYpe)
u32 wad_type = big_endian_reader.Read32(0x04);
switch (wad_type)
{
case 0x49730000:
case 0x69620000:
Result = true;
result = true;
}
}
delete pReader;
return Result;
return result;
}