refactor: hide implementation of loading steps inside file

This commit is contained in:
Jan 2025-05-02 21:12:48 +01:00
parent 955df98279
commit b92e85dc14
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
31 changed files with 649 additions and 477 deletions

View File

@ -10,6 +10,7 @@
#include "Loading/Steps/StepAddProcessor.h" #include "Loading/Steps/StepAddProcessor.h"
#include "Loading/Steps/StepAllocXBlocks.h" #include "Loading/Steps/StepAllocXBlocks.h"
#include "Loading/Steps/StepLoadZoneContent.h" #include "Loading/Steps/StepLoadZoneContent.h"
#include "Loading/Steps/StepLoadZoneSizes.h"
#include "Loading/Steps/StepSkipBytes.h" #include "Loading/Steps/StepSkipBytes.h"
#include "Utils/ClassUtils.h" #include "Utils/ClassUtils.h"
@ -77,16 +78,15 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
SetupBlock(*zoneLoader); SetupBlock(*zoneLoader);
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE))); zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
// Start of the XFile struct // Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
// Skip size and externalSize fields since they are not interesting for us zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
// Start of the zone content // Start of the zone content
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>( zoneLoader->AddLoadingStep(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
return zoneLoader; return zoneLoader;
} }

View File

@ -15,6 +15,7 @@
#include "Loading/Steps/StepLoadHash.h" #include "Loading/Steps/StepLoadHash.h"
#include "Loading/Steps/StepLoadSignature.h" #include "Loading/Steps/StepLoadSignature.h"
#include "Loading/Steps/StepLoadZoneContent.h" #include "Loading/Steps/StepLoadZoneContent.h"
#include "Loading/Steps/StepLoadZoneSizes.h"
#include "Loading/Steps/StepRemoveProcessor.h" #include "Loading/Steps/StepRemoveProcessor.h"
#include "Loading/Steps/StepSkipBytes.h" #include "Loading/Steps/StepSkipBytes.h"
#include "Loading/Steps/StepVerifyFileName.h" #include "Loading/Steps/StepVerifyFileName.h"
@ -123,38 +124,38 @@ namespace
// If file is signed setup a RSA instance. // If file is signed setup a RSA instance.
auto rsa = SetupRsa(isOfficial); auto rsa = SetupRsa(isOfficial);
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1); auto subHeaderHash = step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get(); auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader.AddLoadingStep(std::move(subHeaderHash)); zoneLoader.AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes)); auto subHeaderHashSignature = step::CreateStepLoadSignature(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get(); auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature)); zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr)); zoneLoader.AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader)); auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader));
auto* subHeaderCapturePtr = subHeaderCapture.get(); auto* subHeaderCapturePtr = subHeaderCapture.get();
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture))); zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(subHeaderCapture)));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName))); zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
auto masterBlockHashes = auto masterBlockHashes =
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>)); step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
auto* masterBlockHashesPtr = masterBlockHashes.get(); auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader.AddLoadingStep(std::move(masterBlockHashes)); zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr)); zoneLoader.AddLoadingStep(step::CreateStepVerifyHash(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr)); zoneLoader.AddLoadingStep(step::CreateStepRemoveProcessor(subHeaderCapturePtr));
// Skip the rest of the first chunk // Skip the rest of the first chunk
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader))); zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>( zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(
processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP, processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE, ZoneConstants::AUTHED_CHUNK_SIZE,
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
@ -185,30 +186,29 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
SetupBlock(*zoneLoader); SetupBlock(*zoneLoader);
// Skip unknown 1 byte field that the game ignores as well // Skip unknown 1 byte field that the game ignores as well
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1)); zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
// Skip timestamp // Skip timestamp
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(8));
// Add steps for loading the auth header which also contain the signature of the zone if it is signed. // Add steps for loading the auth header which also contain the signature of the zone if it is signed.
AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName); AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName);
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE))); zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
if (isIw4x) // IW4x has one extra byte of padding here for protection purposes if (isIw4x) // IW4x has one extra byte of padding here for protection purposes
{ {
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(processor::CreateProcessorIW4xDecryption())); zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorIW4xDecryption()));
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1)); zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
} }
// Start of the XFile struct // Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
// Skip size and externalSize fields since they are not interesting for us zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
// Start of the zone content // Start of the zone content
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>( zoneLoader->AddLoadingStep(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
return zoneLoader; return zoneLoader;
} }

View File

@ -14,6 +14,7 @@
#include "Loading/Steps/StepLoadHash.h" #include "Loading/Steps/StepLoadHash.h"
#include "Loading/Steps/StepLoadSignature.h" #include "Loading/Steps/StepLoadSignature.h"
#include "Loading/Steps/StepLoadZoneContent.h" #include "Loading/Steps/StepLoadZoneContent.h"
#include "Loading/Steps/StepLoadZoneSizes.h"
#include "Loading/Steps/StepRemoveProcessor.h" #include "Loading/Steps/StepRemoveProcessor.h"
#include "Loading/Steps/StepSkipBytes.h" #include "Loading/Steps/StepSkipBytes.h"
#include "Loading/Steps/StepVerifyFileName.h" #include "Loading/Steps/StepVerifyFileName.h"
@ -107,38 +108,38 @@ namespace
// If file is signed setup a RSA instance. // If file is signed setup a RSA instance.
auto rsa = SetupRsa(isOfficial); auto rsa = SetupRsa(isOfficial);
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1); auto subHeaderHash = step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), 1);
auto* subHeaderHashPtr = subHeaderHash.get(); auto* subHeaderHashPtr = subHeaderHash.get();
zoneLoader.AddLoadingStep(std::move(subHeaderHash)); zoneLoader.AddLoadingStep(std::move(subHeaderHash));
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes)); auto subHeaderHashSignature = step::CreateStepLoadSignature(sizeof(DB_AuthSignature::bytes));
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get(); auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature)); zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr)); zoneLoader.AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader)); auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader));
auto* subHeaderCapturePtr = subHeaderCapture.get(); auto* subHeaderCapturePtr = subHeaderCapture.get();
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture))); zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(subHeaderCapture)));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName))); zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
auto masterBlockHashes = auto masterBlockHashes =
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>)); step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
auto* masterBlockHashesPtr = masterBlockHashes.get(); auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader.AddLoadingStep(std::move(masterBlockHashes)); zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr)); zoneLoader.AddLoadingStep(step::CreateStepVerifyHash(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr)); zoneLoader.AddLoadingStep(step::CreateStepRemoveProcessor(subHeaderCapturePtr));
// Skip the rest of the first chunk // Skip the rest of the first chunk
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader))); zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>( zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(
processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP, processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE, ZoneConstants::AUTHED_CHUNK_SIZE,
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
@ -168,24 +169,23 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
SetupBlock(*zoneLoader); SetupBlock(*zoneLoader);
// Skip unknown 1 byte field that the game ignores as well // Skip unknown 1 byte field that the game ignores as well
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1)); zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
// Skip timestamp // Skip timestamp
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(8));
// Add steps for loading the auth header which also contain the signature of the zone if it is signed. // Add steps for loading the auth header which also contain the signature of the zone if it is signed.
AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName); AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName);
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE))); zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
// Start of the XFile struct // Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
// Skip size and externalSize fields since they are not interesting for us zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
// Start of the zone content // Start of the zone content
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>( zoneLoader->AddLoadingStep(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
return zoneLoader; return zoneLoader;
} }

View File

@ -10,6 +10,7 @@
#include "Loading/Steps/StepAddProcessor.h" #include "Loading/Steps/StepAddProcessor.h"
#include "Loading/Steps/StepAllocXBlocks.h" #include "Loading/Steps/StepAllocXBlocks.h"
#include "Loading/Steps/StepLoadZoneContent.h" #include "Loading/Steps/StepLoadZoneContent.h"
#include "Loading/Steps/StepLoadZoneSizes.h"
#include "Loading/Steps/StepSkipBytes.h" #include "Loading/Steps/StepSkipBytes.h"
#include "Utils/ClassUtils.h" #include "Utils/ClassUtils.h"
@ -77,16 +78,15 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
SetupBlock(*zoneLoader); SetupBlock(*zoneLoader);
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE))); zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
// Start of the XFile struct // Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8)); zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
// Skip size and externalSize fields since they are not interesting for us zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
// Start of the zone content // Start of the zone content
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>( zoneLoader->AddLoadingStep(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
return zoneLoader; return zoneLoader;
} }

View File

@ -35,7 +35,7 @@ namespace
for (const auto& languagePrefix : languagePrefixes) for (const auto& languagePrefix : languagePrefixes)
{ {
if (zoneName.compare(0, languagePrefix.m_prefix.length(), languagePrefix.m_prefix) == 0) if (zoneName.starts_with(languagePrefix.m_prefix))
{ {
return languagePrefix.m_language; return languagePrefix.m_language;
} }
@ -128,17 +128,17 @@ namespace
} }
} }
ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader& zoneLoader, std::string& fileName) ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader& zoneLoader, const std::string& fileName)
{ {
// Unsigned zones do not have an auth header // Unsigned zones do not have an auth header
if (!isSecure) if (!isSecure)
return nullptr; return nullptr;
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER)); zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Loading Flags which are always zero zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Loading Flags which are always zero
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, 32)); zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, 32));
auto signatureLoadStep = std::make_unique<StepLoadSignature>(256); auto signatureLoadStep = step::CreateStepLoadSignature(256);
auto* signatureLoadStepPtr = signatureLoadStep.get(); auto* signatureLoadStepPtr = signatureLoadStep.get();
zoneLoader.AddLoadingStep(std::move(signatureLoadStep)); zoneLoader.AddLoadingStep(std::move(signatureLoadStep));
@ -161,7 +161,7 @@ namespace
// Decompress the chunks using zlib // Decompress the chunks using zlib
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>()); xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>());
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(xChunkProcessor))); zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(xChunkProcessor)));
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm // If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
return result; return result;
@ -199,16 +199,16 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName); ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName);
// Start of the XFile struct // Start of the XFile struct
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneSizes>()); zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>()); zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
// Start of the zone content // Start of the zone content
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneContent>( zoneLoader->AddLoadingStep(
std::make_unique<ContentLoader>(*zonePtr), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK)); step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
if (isSecure) if (isSecure)
{ {
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), signatureProvider, signatureDataProvider)); zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
} }
return zoneLoader; return zoneLoader;

View File

@ -2,15 +2,33 @@
#include <cassert> #include <cassert>
StepAddProcessor::StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor) namespace
{
class StepAddProcessor final : public ILoadingStep
{
public:
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
: m_stream_processor(std::move(streamProcessor)) : m_stream_processor(std::move(streamProcessor))
{ {
} }
void StepAddProcessor::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
assert(m_stream_processor != nullptr); assert(m_stream_processor != nullptr);
zoneLoader.AddStreamProcessor(std::move(m_stream_processor)); zoneLoader.AddStreamProcessor(std::move(m_stream_processor));
m_stream_processor = nullptr; m_stream_processor = nullptr;
} }
private:
std::unique_ptr<StreamProcessor> m_stream_processor;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
{
return std::make_unique<StepAddProcessor>(std::move(streamProcessor));
}
} // namespace step

View File

@ -4,13 +4,7 @@
#include <memory> #include <memory>
class StepAddProcessor final : public ILoadingStep namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
std::unique_ptr<StreamProcessor> m_stream_processor;
};

View File

@ -5,10 +5,12 @@
namespace namespace
{ {
constexpr uint64_t MAX_XBLOCK_SIZE = 0x3C000000; constexpr uint64_t MAX_XBLOCK_SIZE = 0x3C000000;
}
void StepAllocXBlocks::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) class StepAllocXBlocks final : public ILoadingStep
{ {
public:
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{
const auto blockCount = static_cast<unsigned>(zoneLoader.m_blocks.size()); const auto blockCount = static_cast<unsigned>(zoneLoader.m_blocks.size());
const auto blockSizes = std::make_unique<xblock_size_t[]>(blockCount); const auto blockSizes = std::make_unique<xblock_size_t[]>(blockCount);
@ -29,4 +31,14 @@ void StepAllocXBlocks::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& strea
{ {
zoneLoader.m_blocks[block]->Alloc(blockSizes[block]); zoneLoader.m_blocks[block]->Alloc(blockSizes[block]);
} }
} }
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepAllocXBlocks()
{
return std::make_unique<StepAllocXBlocks>();
}
} // namespace step

View File

@ -2,8 +2,9 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
class StepAllocXBlocks final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepAllocXBlocks();
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override; }
};

View File

@ -2,13 +2,18 @@
#include <fstream> #include <fstream>
StepDumpData::StepDumpData(const size_t dumpCount) namespace
{
class StepDumpData final : public ILoadingStep
{
public:
explicit StepDumpData(const size_t dumpCount)
: m_dump_count(dumpCount) : m_dump_count(dumpCount)
{ {
} }
void StepDumpData::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
uint8_t tempBuffer[128]; uint8_t tempBuffer[128];
auto dumpedBytes = 0uz; auto dumpedBytes = 0uz;
@ -37,4 +42,17 @@ void StepDumpData::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream)
} }
tempFile.close(); tempFile.close();
} }
private:
size_t m_dump_count;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount)
{
return std::make_unique<StepDumpData>(dumpCount);
}
} // namespace step

View File

@ -2,13 +2,9 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
class StepDumpData final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount);
explicit StepDumpData(size_t dumpCount); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
size_t m_dump_count;
};

View File

@ -4,23 +4,26 @@
#include <cassert> #include <cassert>
StepLoadHash::StepLoadHash(const size_t hashSize, const unsigned hashCount) namespace
{
class StepLoadHash final : public step::IStepLoadHash
{
public:
StepLoadHash(const size_t hashSize, const unsigned hashCount)
: m_hash_size(hashSize), : m_hash_size(hashSize),
m_hash_count(hashCount), m_hash_count(hashCount),
m_hashes(std::make_unique<uint8_t[]>(hashSize * hashCount)) m_hashes(std::make_unique<uint8_t[]>(hashSize * hashCount))
{ {
} }
StepLoadHash::~StepLoadHash() = default; void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{
void StepLoadHash::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream)
{
if (stream.Load(m_hashes.get(), m_hash_size * m_hash_count) != m_hash_size * m_hash_count) if (stream.Load(m_hashes.get(), m_hash_size * m_hash_count) != m_hash_size * m_hash_count)
throw UnexpectedEndOfFileException(); throw UnexpectedEndOfFileException();
} }
void StepLoadHash::GetHash(const unsigned hashIndex, const uint8_t** pHash, size_t* pSize) void GetHash(const unsigned hashIndex, const uint8_t** pHash, size_t* pSize) override
{ {
assert(pHash != nullptr); assert(pHash != nullptr);
assert(pSize != nullptr); assert(pSize != nullptr);
assert(hashIndex < m_hash_count); assert(hashIndex < m_hash_count);
@ -29,13 +32,28 @@ void StepLoadHash::GetHash(const unsigned hashIndex, const uint8_t** pHash, size
*pHash = &m_hashes[m_hash_size * hashIndex]; *pHash = &m_hashes[m_hash_size * hashIndex];
*pSize = m_hash_size; *pSize = m_hash_size;
} }
void StepLoadHash::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override
{ {
assert(pCapturedData != nullptr); assert(pCapturedData != nullptr);
assert(pSize != nullptr); assert(pSize != nullptr);
*pCapturedData = m_hashes.get(); *pCapturedData = m_hashes.get();
*pSize = m_hash_size * m_hash_count; *pSize = m_hash_size * m_hash_count;
} }
private:
size_t m_hash_size;
unsigned m_hash_count;
std::unique_ptr<uint8_t[]> m_hashes;
};
} // namespace
namespace step
{
std::unique_ptr<IStepLoadHash> CreateStepLoadHash(const size_t hashSize, const unsigned hashCount)
{
return std::make_unique<StepLoadHash>(hashSize, hashCount);
}
} // namespace step

View File

@ -4,26 +4,13 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
#include "Utils/ICapturedDataProvider.h" #include "Utils/ICapturedDataProvider.h"
#include <cstdint>
#include <memory> #include <memory>
class StepLoadHash final : public ILoadingStep, public IHashProvider, public ICapturedDataProvider namespace step
{ {
public: class IStepLoadHash : public ILoadingStep, public IHashProvider, public ICapturedDataProvider
StepLoadHash(size_t hashSize, unsigned hashCount); {
~StepLoadHash() override; };
StepLoadHash(const StepLoadHash& other) = delete; std::unique_ptr<IStepLoadHash> CreateStepLoadHash(size_t hashSize, unsigned hashCount);
StepLoadHash(StepLoadHash&& other) noexcept = default; } // namespace step
StepLoadHash& operator=(const StepLoadHash& other) = delete;
StepLoadHash& operator=(StepLoadHash&& other) noexcept = delete;
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
void GetHash(unsigned hashIndex, const uint8_t** pHash, size_t* pSize) override;
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
private:
const size_t m_hash_size;
const unsigned m_hash_count;
std::unique_ptr<uint8_t[]> m_hashes;
};

View File

@ -4,20 +4,25 @@
#include <cassert> #include <cassert>
StepLoadSignature::StepLoadSignature(const size_t signatureSize) namespace
{
class StepLoadSignature final : public step::IStepLoadSignature
{
public:
explicit StepLoadSignature(const size_t signatureSize)
: m_signature(std::make_unique<uint8_t[]>(signatureSize)), : m_signature(std::make_unique<uint8_t[]>(signatureSize)),
m_signature_size(signatureSize) m_signature_size(signatureSize)
{ {
} }
void StepLoadSignature::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
if (stream.Load(m_signature.get(), m_signature_size) != m_signature_size) if (stream.Load(m_signature.get(), m_signature_size) != m_signature_size)
throw UnexpectedEndOfFileException(); throw UnexpectedEndOfFileException();
} }
void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize) void GetSignature(const uint8_t** pSignature, size_t* pSize) override
{ {
assert(pSignature != nullptr); assert(pSignature != nullptr);
assert(pSize != nullptr); assert(pSize != nullptr);
@ -25,4 +30,18 @@ void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize)
*pSignature = m_signature.get(); *pSignature = m_signature.get();
*pSize = m_signature_size; *pSize = m_signature_size;
} }
private:
std::unique_ptr<uint8_t[]> m_signature;
size_t m_signature_size;
};
} // namespace
namespace step
{
std::unique_ptr<IStepLoadSignature> CreateStepLoadSignature(const size_t signatureSize)
{
return std::make_unique<StepLoadSignature>(signatureSize);
}
} // namespace step

View File

@ -5,15 +5,11 @@
#include <memory> #include <memory>
class StepLoadSignature final : public ILoadingStep, public ISignatureProvider namespace step
{ {
public: class IStepLoadSignature : public ILoadingStep, public ISignatureProvider
explicit StepLoadSignature(size_t signatureSize); {
};
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override; std::unique_ptr<IStepLoadSignature> CreateStepLoadSignature(size_t signatureSize);
void GetSignature(const uint8_t** pSignature, size_t* pSize) override; } // namespace step
private:
std::unique_ptr<uint8_t[]> m_signature;
size_t m_signature_size;
};

View File

@ -2,20 +2,37 @@
#include "Zone/Stream/ZoneInputStream.h" #include "Zone/Stream/ZoneInputStream.h"
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, namespace
Zone* zone, {
const int offsetBlockBitCount, class StepLoadZoneContent final : public ILoadingStep
const block_t insertBlock) {
public:
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
: m_content_loader(std::move(entryPoint)), : m_content_loader(std::move(entryPoint)),
m_zone(zone),
m_offset_block_bit_count(offsetBlockBitCount), m_offset_block_bit_count(offsetBlockBitCount),
m_insert_block(insertBlock) m_insert_block(insertBlock)
{ {
} }
void StepLoadZoneContent::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
const auto inputStream = ZoneInputStream::Create(zoneLoader.m_blocks, stream, m_offset_block_bit_count, m_insert_block); const auto inputStream = ZoneInputStream::Create(zoneLoader.m_blocks, stream, m_offset_block_bit_count, m_insert_block);
m_content_loader->Load(*inputStream); m_content_loader->Load(*inputStream);
} }
private:
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
int m_offset_block_bit_count;
block_t m_insert_block;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep>
CreateStepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
{
return std::make_unique<StepLoadZoneContent>(std::move(entryPoint), offsetBlockBitCount, insertBlock);
}
} // namespace step

View File

@ -5,16 +5,8 @@
#include <memory> #include <memory>
class StepLoadZoneContent final : public ILoadingStep namespace step
{ {
public: std::unique_ptr<ILoadingStep>
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock); CreateStepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, int offsetBlockBitCount, block_t insertBlock);
}
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
Zone* m_zone;
int m_offset_block_bit_count;
block_t m_insert_block;
};

View File

@ -1,23 +1,42 @@
#include "StepLoadZoneSizes.h" #include "StepLoadZoneSizes.h"
StepLoadZoneSizes::StepLoadZoneSizes() namespace
{
class StepLoadZoneSizes final : public step::IStepLoadZoneSizes
{
public:
StepLoadZoneSizes()
: m_size(0), : m_size(0),
m_external_size(0) m_external_size(0)
{ {
} }
void StepLoadZoneSizes::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
stream.Load(&m_size, sizeof(m_size)); stream.Load(&m_size, sizeof(m_size));
stream.Load(&m_external_size, sizeof(m_external_size)); stream.Load(&m_external_size, sizeof(m_external_size));
} }
size_t StepLoadZoneSizes::GetSize() const [[nodiscard]] uint32_t GetSize() const override
{ {
return m_size; return m_size;
} }
size_t StepLoadZoneSizes::GetExternalSize() const [[nodiscard]] uint32_t GetExternalSize() const override
{ {
return m_external_size; return m_external_size;
} }
private:
uint32_t m_size;
uint32_t m_external_size;
};
} // namespace
namespace step
{
std::unique_ptr<IStepLoadZoneSizes> CreateStepLoadZoneSizes()
{
return std::make_unique<StepLoadZoneSizes>();
}
} // namespace step

View File

@ -2,19 +2,16 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
#include <cstddef> #include <memory>
class StepLoadZoneSizes final : public ILoadingStep namespace step
{ {
public: class IStepLoadZoneSizes : public ILoadingStep
StepLoadZoneSizes(); {
public:
[[nodiscard]] virtual uint32_t GetSize() const = 0;
[[nodiscard]] virtual uint32_t GetExternalSize() const = 0;
};
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override; std::unique_ptr<IStepLoadZoneSizes> CreateStepLoadZoneSizes();
} // namespace step
[[nodiscard]] size_t GetSize() const;
[[nodiscard]] size_t GetExternalSize() const;
private:
size_t m_size;
size_t m_external_size;
};

View File

@ -2,14 +2,32 @@
#include <cassert> #include <cassert>
StepRemoveProcessor::StepRemoveProcessor(StreamProcessor* streamProcessor) namespace
{
class StepRemoveProcessor final : public ILoadingStep
{
public:
explicit StepRemoveProcessor(const StreamProcessor* streamProcessor)
: m_stream_processor(streamProcessor) : m_stream_processor(streamProcessor)
{ {
} }
void StepRemoveProcessor::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
assert(m_stream_processor != nullptr); assert(m_stream_processor != nullptr);
zoneLoader.RemoveStreamProcessor(m_stream_processor); zoneLoader.RemoveStreamProcessor(m_stream_processor);
} }
private:
const StreamProcessor* m_stream_processor;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepRemoveProcessor(const StreamProcessor* streamProcessor)
{
return std::make_unique<StepRemoveProcessor>(streamProcessor);
}
} // namespace step

View File

@ -1,14 +1,11 @@
#pragma once #pragma once
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
#include "Loading/StreamProcessor.h"
class StepRemoveProcessor final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepRemoveProcessor(const StreamProcessor* streamProcessor);
explicit StepRemoveProcessor(StreamProcessor* streamProcessor); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
StreamProcessor* m_stream_processor;
};

View File

@ -1,12 +1,17 @@
#include "StepSkipBytes.h" #include "StepSkipBytes.h"
StepSkipBytes::StepSkipBytes(const size_t skipCount) namespace
{
class StepSkipBytes final : public ILoadingStep
{
public:
explicit StepSkipBytes(const size_t skipCount)
: m_skip_count(skipCount) : m_skip_count(skipCount)
{ {
} }
void StepSkipBytes::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
uint8_t tempBuffer[128]; uint8_t tempBuffer[128];
auto skippedBytes = 0uz; auto skippedBytes = 0uz;
@ -27,4 +32,17 @@ void StepSkipBytes::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream)
skippedBytes += toSkip; skippedBytes += toSkip;
} }
} }
private:
size_t m_skip_count;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepSkipBytes(size_t skipCount)
{
return std::make_unique<StepSkipBytes>(skipCount);
}
} // namespace step

View File

@ -2,13 +2,9 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
class StepSkipBytes final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepSkipBytes(size_t skipCount);
explicit StepSkipBytes(size_t skipCount); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
size_t m_skip_count;
};

View File

@ -4,16 +4,21 @@
#include <sstream> #include <sstream>
StepVerifyFileName::StepVerifyFileName(std::string fileName, const size_t fileNameBufferSize) namespace
{
class StepVerifyFileName final : public ILoadingStep
{
public:
StepVerifyFileName(std::string fileName, const size_t fileNameBufferSize)
: m_expected_file_name(std::move(fileName)), : m_expected_file_name(std::move(fileName)),
m_file_name_buffer_size(fileNameBufferSize) m_file_name_buffer_size(fileNameBufferSize)
{ {
if (m_expected_file_name.length() > (m_file_name_buffer_size - 1)) if (m_expected_file_name.length() > (m_file_name_buffer_size - 1))
m_expected_file_name.erase(m_file_name_buffer_size - 1); m_expected_file_name.erase(m_file_name_buffer_size - 1);
} }
void StepVerifyFileName::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
std::stringstream originalFilenameStream; std::stringstream originalFilenameStream;
unsigned bufferOffset = 0; unsigned bufferOffset = 0;
char c; char c;
@ -42,4 +47,18 @@ void StepVerifyFileName::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& str
if (originalFileName != m_expected_file_name) if (originalFileName != m_expected_file_name)
throw InvalidFileNameException(m_expected_file_name, originalFileName); throw InvalidFileNameException(m_expected_file_name, originalFileName);
} }
private:
std::string m_expected_file_name;
size_t m_file_name_buffer_size;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepVerifyFileName(std::string fileName, const size_t fileNameBufferSize)
{
return std::make_unique<StepVerifyFileName>(std::move(fileName), fileNameBufferSize);
}
} // namespace step

View File

@ -2,14 +2,10 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
class StepVerifyFileName final : public ILoadingStep #include <memory>
#include <string>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepVerifyFileName(std::string fileName, size_t fileNameBufferSize);
explicit StepVerifyFileName(std::string fileName, size_t fileNameBufferSize); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
std::string m_expected_file_name;
size_t m_file_name_buffer_size;
};

View File

@ -2,10 +2,14 @@
#include "Loading/Exception/InvalidHashException.h" #include "Loading/Exception/InvalidHashException.h"
#include <cstring>
#include <memory> #include <memory>
StepVerifyHash::StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction, namespace
{
class StepVerifyHash final : public ILoadingStep
{
public:
StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
const unsigned hashIndex, const unsigned hashIndex,
IHashProvider* hashProvider, IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider) ICapturedDataProvider* dataProvider)
@ -13,11 +17,11 @@ StepVerifyHash::StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hash
m_hash_index(hashIndex), m_hash_index(hashIndex),
m_hash_provider(hashProvider), m_hash_provider(hashProvider),
m_data_provider(dataProvider) m_data_provider(dataProvider)
{ {
} }
void StepVerifyHash::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
const uint8_t* dataToHash = nullptr; const uint8_t* dataToHash = nullptr;
size_t dataToHashSize = 0; size_t dataToHashSize = 0;
m_data_provider->GetCapturedData(&dataToHash, &dataToHashSize); m_data_provider->GetCapturedData(&dataToHash, &dataToHashSize);
@ -36,4 +40,23 @@ void StepVerifyHash::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream)
if (std::memcmp(hashData, hashMemory.get(), m_hash_function->GetHashSize()) != 0) if (std::memcmp(hashData, hashMemory.get(), m_hash_function->GetHashSize()) != 0)
throw InvalidHashException(); throw InvalidHashException();
} }
private:
std::unique_ptr<cryptography::IHashFunction> m_hash_function;
unsigned m_hash_index;
IHashProvider* m_hash_provider;
ICapturedDataProvider* m_data_provider;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
unsigned hashIndex,
IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider)
{
return std::make_unique<StepVerifyHash>(std::move(hashFunction), hashIndex, hashProvider, dataProvider);
}
} // namespace step

View File

@ -7,19 +7,10 @@
#include <memory> #include <memory>
class StepVerifyHash final : public ILoadingStep namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
unsigned hashIndex, unsigned hashIndex,
IHashProvider* hashProvider, IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider); ICapturedDataProvider* dataProvider);
}
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
std::unique_ptr<cryptography::IHashFunction> m_hash_function;
unsigned m_hash_index;
IHashProvider* m_hash_provider;
ICapturedDataProvider* m_data_provider;
};

View File

@ -4,14 +4,19 @@
#include <cstring> #include <cstring>
StepVerifyMagic::StepVerifyMagic(const char* magic) namespace
{ {
m_magic = magic; class StepVerifyMagic final : public ILoadingStep
m_magic_len = strlen(m_magic); {
} public:
explicit StepVerifyMagic(const char* magic)
: m_magic(magic),
m_magic_len(strlen(m_magic))
{
}
void StepVerifyMagic::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
char currentCharacter; char currentCharacter;
for (unsigned i = 0; i < m_magic_len; i++) for (unsigned i = 0; i < m_magic_len; i++)
@ -21,4 +26,18 @@ void StepVerifyMagic::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream
if (currentCharacter != m_magic[i]) if (currentCharacter != m_magic[i])
throw InvalidMagicException(m_magic); throw InvalidMagicException(m_magic);
} }
} }
private:
const char* m_magic;
size_t m_magic_len;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepVerifyMagic(const char* magic)
{
return std::make_unique<StepVerifyMagic>(magic);
}
} // namespace step

View File

@ -2,14 +2,9 @@
#include "Loading/ILoadingStep.h" #include "Loading/ILoadingStep.h"
class StepVerifyMagic final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepVerifyMagic(const char* magic);
explicit StepVerifyMagic(const char* magic); }
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
const char* m_magic;
size_t m_magic_len;
};

View File

@ -4,17 +4,22 @@
#include <cassert> #include <cassert>
StepVerifySignature::StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm, namespace
{
class StepVerifySignature final : public ILoadingStep
{
public:
StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider, ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider) ICapturedDataProvider* signatureDataProvider)
: m_algorithm(std::move(signatureAlgorithm)), : m_algorithm(std::move(signatureAlgorithm)),
m_signature_provider(signatureProvider), m_signature_provider(signatureProvider),
m_signature_data_provider(signatureDataProvider) m_signature_data_provider(signatureDataProvider)
{ {
} }
void StepVerifySignature::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{ {
assert(m_algorithm != nullptr); assert(m_algorithm != nullptr);
assert(m_signature_provider != nullptr); assert(m_signature_provider != nullptr);
assert(m_signature_data_provider != nullptr); assert(m_signature_data_provider != nullptr);
@ -31,4 +36,21 @@ void StepVerifySignature::PerformStep(ZoneLoader& zoneLoader, ILoadingStream& st
{ {
throw InvalidSignatureException(); throw InvalidSignatureException();
} }
} }
private:
std::unique_ptr<cryptography::IPublicKeyAlgorithm> m_algorithm;
ISignatureProvider* m_signature_provider;
ICapturedDataProvider* m_signature_data_provider;
};
} // namespace
namespace step
{
std::unique_ptr<ILoadingStep> CreateStepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider)
{
return std::make_unique<StepVerifySignature>(std::move(signatureAlgorithm), signatureProvider, signatureDataProvider);
}
} // namespace step

View File

@ -5,17 +5,11 @@
#include "Loading/ISignatureProvider.h" #include "Loading/ISignatureProvider.h"
#include "Utils/ICapturedDataProvider.h" #include "Utils/ICapturedDataProvider.h"
class StepVerifySignature final : public ILoadingStep #include <memory>
namespace step
{ {
public: std::unique_ptr<ILoadingStep> CreateStepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider, ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider); ICapturedDataProvider* signatureDataProvider);
}
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override;
private:
std::unique_ptr<cryptography::IPublicKeyAlgorithm> m_algorithm;
ISignatureProvider* m_signature_provider;
ICapturedDataProvider* m_signature_data_provider;
};