mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-02-10 17:43:03 +00:00
chore: dump fastfile data when xenon t6 fastfile is detected
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user