2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-23 16:56:39 +00:00

chore: dump fastfile data when xenon t6 fastfile is detected

This commit is contained in:
Jan Laupetin
2025-08-19 13:22:39 +02:00
parent facb95f1cb
commit 802b0f244a
19 changed files with 226 additions and 152 deletions

View File

@@ -12,21 +12,25 @@ namespace T6
ZoneConstants() = default;
public:
static constexpr const char* MAGIC_SIGNED_TREYARCH = "TAff0100";
static constexpr const char* MAGIC_SIGNED_OAT = "ABff0100";
static constexpr const char* MAGIC_SIGNED_PC_TREYARCH = "TAff0100";
static constexpr const char* MAGIC_SIGNED_XENON_TREYARCH = "TAffx100";
static constexpr const char* MAGIC_SIGNED_PC_OAT = "ABff0100";
static constexpr const char* MAGIC_UNSIGNED = "TAffu100";
static constexpr const char* MAGIC_UNSIGNED_SERVER = "TAsvu100";
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_OAT) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_PC_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_XENON_TREYARCH) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_SIGNED_PC_OAT) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED) == sizeof(ZoneHeader::m_magic));
static_assert(std::char_traits<char>::length(MAGIC_UNSIGNED_SERVER) == sizeof(ZoneHeader::m_magic));
static constexpr int ZONE_VERSION = 147;
static constexpr int STREAM_COUNT = 4;
static constexpr int XCHUNK_SIZE = 0x8000;
static constexpr int XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr int VANILLA_BUFFER_SIZE = 0x80000;
static constexpr unsigned ZONE_VERSION_PC = 147;
static constexpr unsigned ZONE_VERSION_XENON = 146;
static constexpr unsigned STREAM_COUNT = 4;
static constexpr unsigned XCHUNK_SIZE = 0x8000;
static constexpr unsigned XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr unsigned VANILLA_BUFFER_SIZE = 0x80000;
static constexpr unsigned OFFSET_BLOCK_BIT_COUNT = 3u;
static constexpr block_t INSERT_BLOCK = XFILE_BLOCK_VIRTUAL;
@@ -34,10 +38,14 @@ namespace T6
static constexpr size_t FILE_SUFFIX_ZERO_ALIGN = 0x40;
static constexpr const char* MAGIC_AUTH_HEADER = "PHEEBs71";
inline static const uint8_t SALSA20_KEY_TREYARCH[]{
inline static const uint8_t SALSA20_KEY_TREYARCH_PC[]{
0x64, 0x1D, 0x8A, 0x2F, 0xE3, 0x1D, 0x3A, 0xA6, 0x36, 0x22, 0xBB, 0xC9, 0xCE, 0x85, 0x87, 0x22,
0x9D, 0x42, 0xB0, 0xF8, 0xED, 0x9B, 0x92, 0x41, 0x30, 0xBF, 0x88, 0xB6, 0x5E, 0xDC, 0x50, 0xBE,
};
inline static const uint8_t SALSA20_KEY_TREYARCH_XENON[]{
0x0E, 0x50, 0xF4, 0x9F, 0x41, 0x23, 0x17, 0x09, 0x60, 0x38, 0x66, 0x56, 0x22, 0xDD, 0x09, 0x13,
0x32, 0xA2, 0x09, 0xBA, 0x0A, 0x05, 0xA0, 0x0E, 0x13, 0x77, 0xCE, 0xDB, 0x0A, 0x3C, 0xB1, 0xD3,
};
inline static const uint8_t RSA_PUBLIC_KEY_TREYARCH[]{
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc7, 0x9d, 0x33, 0xe0, 0x75, 0xaf, 0xef, 0x08, 0x08, 0x2b, 0x89, 0xd9, 0x3b, 0xf3,

View File

@@ -2,24 +2,16 @@
#include <cassert>
AbstractSalsa20Processor::AbstractSalsa20Processor(const int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
AbstractSalsa20Processor::AbstractSalsa20Processor(const unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, const unsigned keySize)
: m_stream_count(streamCount),
m_stream_contexts(std::make_unique<StreamContext[]>(streamCount)),
m_stream_block_indices(std::make_unique<unsigned int[]>(streamCount))
m_stream_contexts(streamCount),
m_block_hashes(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE),
m_stream_block_indices(streamCount)
{
m_block_hashes = std::make_unique<uint8_t[]>(BLOCK_HASHES_COUNT * streamCount * SHA1_HASH_SIZE);
InitStreams(zoneName, salsa20Key, keySize);
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const int streamNumber) const
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize) const
void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, const size_t keySize)
{
// Original buffer must have been 32 bytes because the zoneName can at most be 31 characters be long before being cut off
const auto zoneNameLength = std::min(zoneName.length(), 31uz);
@@ -29,14 +21,14 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
assert(blockHashBufferSize % 4 == 0);
size_t zoneNameOffset = 0;
for (size_t i = 0; i < blockHashBufferSize; i += 4)
for (auto i = 0uz; i < blockHashBufferSize; i += 4)
{
*reinterpret_cast<uint32_t*>(&m_block_hashes[i]) = 0x1010101 * zoneName[zoneNameOffset++];
memset(&m_block_hashes[i], zoneName[zoneNameOffset++], 4u);
zoneNameOffset %= zoneNameLength;
}
for (auto stream = 0; stream < m_stream_count; stream++)
for (auto stream = 0u; stream < m_stream_count; stream++)
{
m_stream_block_indices[stream] = 0;
@@ -45,11 +37,19 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
}
}
uint8_t* AbstractSalsa20Processor::GetHashBlock(const unsigned streamNumber)
{
const auto blockIndexOffset = m_stream_block_indices[streamNumber] * m_stream_count * SHA1_HASH_SIZE;
const auto streamOffset = static_cast<size_t>(streamNumber) * SHA1_HASH_SIZE;
return &m_block_hashes[blockIndexOffset + streamOffset];
}
void AbstractSalsa20Processor::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
{
assert(pCapturedData != nullptr);
assert(pSize != nullptr);
*pCapturedData = m_block_hashes.get();
*pCapturedData = m_block_hashes.data();
*pSize = BLOCK_HASHES_COUNT * m_stream_count * SHA1_HASH_SIZE;
}

View File

@@ -1,40 +1,22 @@
#pragma once
#include "Cryptography.h"
#include "Utils/ClassUtils.h"
#include "Utils/ICapturedDataProvider.h"
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
class Salsa20StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
class AbstractSalsa20Processor : public ICapturedDataProvider
{
protected:
static constexpr int BLOCK_HASHES_COUNT = 200;
static constexpr int SHA1_HASH_SIZE = 20;
static constexpr int SALSA20_IV_SIZE = 8;
class StreamContext
{
public:
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
int m_stream_count;
std::unique_ptr<StreamContext[]> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][HASH_SIZE]
std::unique_ptr<uint8_t[]> m_block_hashes;
std::unique_ptr<unsigned int[]> m_stream_block_indices;
AbstractSalsa20Processor(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
_NODISCARD uint8_t* GetHashBlock(int streamNumber) const;
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize) const;
public:
virtual ~AbstractSalsa20Processor() = default;
AbstractSalsa20Processor(const AbstractSalsa20Processor& other) = delete;
@@ -43,4 +25,21 @@ public:
AbstractSalsa20Processor& operator=(AbstractSalsa20Processor&& other) noexcept = default;
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
protected:
static constexpr auto BLOCK_HASHES_COUNT = 200u;
static constexpr auto SHA1_HASH_SIZE = 20u;
static constexpr auto SALSA20_IV_SIZE = 8u;
AbstractSalsa20Processor(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, unsigned keySize);
void InitStreams(const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
[[nodiscard]] uint8_t* GetHashBlock(unsigned streamNumber);
unsigned m_stream_count;
std::vector<Salsa20StreamContext> m_stream_contexts;
// m_block_hashes[BLOCK_HASHES_COUNT][numStreams][SHA1_HASH_SIZE]
std::vector<uint8_t> m_block_hashes;
std::vector<unsigned int> m_stream_block_indices;
};

View File

@@ -6,6 +6,12 @@
class IXChunkProcessor
{
public:
IXChunkProcessor() = default;
virtual ~IXChunkProcessor() = default;
virtual size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
IXChunkProcessor(const IXChunkProcessor& other) = default;
IXChunkProcessor(IXChunkProcessor&& other) noexcept = default;
IXChunkProcessor& operator=(const IXChunkProcessor& other) = default;
IXChunkProcessor& operator=(IXChunkProcessor&& other) noexcept = default;
virtual size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) = 0;
};

View File

@@ -6,7 +6,7 @@
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorDeflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorDeflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorDeflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -2,10 +2,12 @@
#include "XChunkException.h"
#include <format>
#include <iostream>
#include <zlib.h>
#include <zutil.h>
size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
size_t XChunkProcessorInflate::Process(unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
z_stream stream{};
stream.zalloc = Z_NULL;
@@ -23,7 +25,10 @@ size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, c
ret = inflate(&stream, Z_FULL_FLUSH);
if (ret != Z_STREAM_END)
throw XChunkException("Zone has invalid or unsupported compression. Inflate failed");
{
std::cerr << std::format("inflate of stream failed with error code {}: {}\n", streamNumber, ret, stream.msg);
throw XChunkException(std::format("Zone has invalid or unsupported compression: {}", stream.msg));
}
const size_t outputSize = stream.total_out;

View File

@@ -4,5 +4,5 @@
class XChunkProcessorInflate final : public IXChunkProcessor
{
public:
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -4,9 +4,11 @@
#include "Cryptography.h"
#include <cassert>
#include <format>
#include <iostream>
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int streamCount,
std::string& zoneName,
XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
: AbstractSalsa20Processor(streamCount, zoneName, salsa20Key, keySize)
@@ -14,9 +16,9 @@ XChunkProcessorSalsa20Decryption::XChunkProcessorSalsa20Decryption(const int str
}
size_t XChunkProcessorSalsa20Decryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);

View File

@@ -7,7 +7,7 @@
class XChunkProcessorSalsa20Decryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Decryption(int streamCount, std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Decryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};

View File

@@ -2,7 +2,7 @@
#include <cassert>
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int streamCount,
XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const unsigned streamCount,
const std::string& zoneName,
const uint8_t* salsa20Key,
const size_t keySize)
@@ -11,14 +11,14 @@ XChunkProcessorSalsa20Encryption::XChunkProcessorSalsa20Encryption(const int str
}
size_t XChunkProcessorSalsa20Encryption::Process(
const int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
const unsigned streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
{
assert(streamNumber >= 0 && streamNumber < m_stream_count);
assert(streamNumber < m_stream_count);
assert(input != nullptr);
assert(output != nullptr);
assert(inputLength <= outputBufferSize);
auto& streamContext = m_stream_contexts[streamNumber];
const auto& streamContext = m_stream_contexts[streamNumber];
// Hash not yet encrypted XChunk
uint8_t blockSha1Hash[SHA1_HASH_SIZE];

View File

@@ -8,7 +8,7 @@
class XChunkProcessorSalsa20Encryption final : public IXChunkProcessor, public AbstractSalsa20Processor
{
public:
XChunkProcessorSalsa20Encryption(int streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
XChunkProcessorSalsa20Encryption(unsigned streamCount, const std::string& zoneName, const uint8_t* salsa20Key, size_t keySize);
size_t Process(int streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
size_t Process(unsigned streamNumber, const uint8_t* input, size_t inputLength, uint8_t* output, size_t outputBufferSize) override;
};