mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-18 16:37:48 +00:00
feat: dump iw3 xbox signed fastfile data
This commit is contained in:
@@ -6,12 +6,22 @@
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Game/IW3/ZoneConstantsIW3.h"
|
||||
#include "Loading/Processor/ProcessorAuthedBlocks.h"
|
||||
#include "Loading/Processor/ProcessorCaptureData.h"
|
||||
#include "Loading/Processor/ProcessorInflate.h"
|
||||
#include "Loading/Steps/StepAddProcessor.h"
|
||||
#include "Loading/Steps/StepAllocXBlocks.h"
|
||||
#include "Loading/Steps/StepDumpData.h"
|
||||
#include "Loading/Steps/StepLoadHash.h"
|
||||
#include "Loading/Steps/StepLoadSignature.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Loading/Steps/StepVerifyFileName.h"
|
||||
#include "Loading/Steps/StepVerifyHash.h"
|
||||
#include "Loading/Steps/StepVerifyMagic.h"
|
||||
#include "Loading/Steps/StepVerifySignature.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/Endianness.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
@@ -42,6 +52,77 @@ namespace
|
||||
|
||||
#undef XBLOCK_DEF
|
||||
}
|
||||
|
||||
std::unique_ptr<cryptography::IPublicKeyAlgorithm> SetupRsa(const bool isOfficial)
|
||||
{
|
||||
if (isOfficial)
|
||||
{
|
||||
auto rsa = cryptography::CreateRsa(cryptography::HashingAlgorithm::RSA_HASH_SHA256, cryptography::RsaPaddingMode::RSA_PADDING_PSS);
|
||||
|
||||
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
|
||||
{
|
||||
con::error("Invalid public key for signature checking");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rsa;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
|
||||
// TODO: Load custom RSA key here
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void AddAuthHeaderSteps(const ZoneLoaderInspectionResult& inspectResult, ZoneLoader& zoneLoader, const std::string& fileName)
|
||||
{
|
||||
// Unsigned zones do not have an auth header
|
||||
if (!inspectResult.m_is_signed)
|
||||
return;
|
||||
|
||||
// If file is signed setup a RSA instance.
|
||||
auto rsa = SetupRsa(inspectResult.m_is_official);
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto subHeaderHash = step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), 1);
|
||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHash));
|
||||
|
||||
auto subHeaderHashSignature = step::CreateStepLoadSignature(sizeof(DB_AuthSignature::bytes));
|
||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
|
||||
auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader));
|
||||
auto* subHeaderCapturePtr = subHeaderCapture.get();
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(subHeaderCapture)));
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto masterBlockHashes =
|
||||
step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyHash(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepRemoveProcessor(subHeaderCapturePtr));
|
||||
|
||||
// Skip the rest of the first chunk
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(
|
||||
processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||
ZoneConstants::AUTHED_CHUNK_SIZE,
|
||||
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
|
||||
cryptography::CreateSha256(),
|
||||
masterBlockHashesPtr)));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::optional<ZoneLoaderInspectionResult> ZoneLoaderFactory::InspectZoneHeader(const ZoneHeader& header) const
|
||||
@@ -70,11 +151,23 @@ std::optional<ZoneLoaderInspectionResult> ZoneLoaderFactory::InspectZoneHeader(c
|
||||
.m_endianness = GameEndianness::BE,
|
||||
.m_word_size = GameWordSize::ARCH_32,
|
||||
.m_platform = GamePlatform::XBOX,
|
||||
.m_is_official = false,
|
||||
.m_is_official = true,
|
||||
.m_is_signed = false,
|
||||
.m_is_encrypted = false,
|
||||
};
|
||||
}
|
||||
if (!memcmp(header.m_magic, ZoneConstants::MAGIC_SIGNED, std::char_traits<char>::length(ZoneConstants::MAGIC_SIGNED)))
|
||||
{
|
||||
return ZoneLoaderInspectionResult{
|
||||
.m_game_id = GameId::IW3,
|
||||
.m_endianness = GameEndianness::BE,
|
||||
.m_word_size = GameWordSize::ARCH_32,
|
||||
.m_platform = GamePlatform::XBOX,
|
||||
.m_is_official = true,
|
||||
.m_is_signed = true,
|
||||
.m_is_encrypted = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
@@ -99,6 +192,9 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(const ZoneH
|
||||
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||
AddAuthHeaderSteps(*inspectResult, *zoneLoader, fileName);
|
||||
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
if (inspectResult->m_endianness == GameEndianness::LE)
|
||||
|
||||
Reference in New Issue
Block a user