Refactor: Update FastFile::Open to use consistent filename parsing.

This commit is contained in:
njohnson 2025-09-15 18:49:54 -04:00
parent ea1a829957
commit 754c563515
9 changed files with 10 additions and 72 deletions

View File

@ -120,7 +120,7 @@ void AutoTest_COD10_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD10";

View File

@ -120,7 +120,7 @@ void AutoTest_COD11_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD11";

View File

@ -238,7 +238,7 @@ void AutoTest_COD12_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD12";

View File

@ -143,7 +143,7 @@ void AutoTest_COD2_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD2";

View File

@ -126,7 +126,7 @@ void AutoTest_COD5_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD5";

View File

@ -146,7 +146,7 @@ void AutoTest_COD6_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD6";

View File

@ -67,45 +67,6 @@ void AutoTest_COD7_360::testDecompression() {
QByteArray fileName(32, Qt::Uninitialized);
fastFileStream.readRawData(fileName.data(), 32);
// Build the IV table from the fileName.
QByteArray ivTable = Encryption::InitIVTable(fileName);
// Skip the RSA signature (256 bytes).
QByteArray rsaSignature(256, Qt::Uninitialized);
fastFileStream.readRawData(rsaSignature.data(), 256);
// Now the stream should be positioned at 0x13C, where sections begin.
int sectionIndex = 0;
while (true) {
qint32 sectionSize = 0;
fastFileStream >> sectionSize;
if (sectionSize == 0)
break;
// Read the section data.
QByteArray sectionData;
sectionData.resize(sectionSize);
fastFileStream.readRawData(sectionData.data(), sectionSize);
// Compute the IV for this section.
QByteArray iv = Encryption::GetIV(ivTable, sectionIndex);
// Decrypt the section using Salsa20.
QByteArray decData = Encryption::salsa20DecryptSection(sectionData, key, iv);
// Compute SHA1 hash of the decrypted data.
QByteArray sectionHash = QCryptographicHash::hash(decData, QCryptographicHash::Sha1);
// Update the IV table based on the section hash.
Encryption::UpdateIVTable(ivTable, sectionIndex, sectionHash);
// Build a compressed data buffer by prepending the two-byte zlib header.
decompressedData.append(Compression::DecompressDeflate(decData));
sectionIndex++;
}
const QByteArray testZoneData = decompressedData;
// Verify the decompressed data via its embedded zone size.
@ -149,7 +110,7 @@ void AutoTest_COD7_360::testCompression() {
zoneFile.close();
QByteArray compressedData;
QByteArray key = QByteArray::fromHex("1ac1d12d527c59b40eca619120ff8217ccff09cd16896f81b829c7f52793405d");
//QByteArray key = QByteArray::fromHex("1ac1d12d527c59b40eca619120ff8217ccff09cd16896f81b829c7f52793405d");
// Read the original fastfile header to recover metadata (filename, IV table, etc.)
QString ffPath = zoneFilePath;
@ -163,40 +124,17 @@ void AutoTest_COD7_360::testCompression() {
originalFF.read(fileName.data(), 32);
originalFF.close();
QByteArray ivTable = Encryption::InitIVTable(fileName);
// Rebuild sections from zone data
QDataStream zoneStream(zoneData);
zoneStream.setByteOrder(QDataStream::BigEndian);
quint32 zoneSize;
zoneStream >> zoneSize;
QByteArray remainingData = zoneData.mid(4); // exclude size field
const int chunkSize = 0x40000; // 256KB max section size
//QByteArray remainingData = zoneData.mid(4); // exclude size field
QDataStream fastFileStreamOut(&compressedData, QIODevice::WriteOnly);
fastFileStreamOut.setByteOrder(QDataStream::BigEndian);
int sectionIndex = 0;
int offset = 0;
while (offset < remainingData.size()) {
int sectionLen = qMin(chunkSize, remainingData.size() - offset);
QByteArray chunk = remainingData.mid(offset, sectionLen);
QByteArray deflated = Compression::CompressDeflate(chunk);
QByteArray iv = Encryption::GetIV(ivTable, sectionIndex);
QByteArray encrypted = Encryption::salsa20DecryptSection(deflated, key, iv);
QByteArray sha1 = QCryptographicHash::hash(chunk, QCryptographicHash::Sha1);
Encryption::UpdateIVTable(ivTable, sectionIndex, sha1);
fastFileStreamOut << static_cast<qint32>(encrypted.size());
fastFileStreamOut.writeRawData(encrypted.constData(), encrypted.size());
offset += sectionLen;
sectionIndex++;
}
// Write 0 section size terminator
fastFileStreamOut << static_cast<qint32>(0);

View File

@ -139,7 +139,7 @@ void AutoTest_COD8_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD8";

View File

@ -120,7 +120,7 @@ void AutoTest_COD9_360::testFactory() {
const QString testName = "Factory ingest: " + fastFilePath;
FastFile* fastFile = FastFileFactory::Create(fastFilePath);
FastFile* fastFile = FastFile::Open(fastFilePath);
const QString game = fastFile->GetGame();
bool correctGame = game == "COD9";