diff --git a/src/LockedFile.cpp b/src/LockedFile.cpp index 09f6b5c9..394b94b3 100644 --- a/src/LockedFile.cpp +++ b/src/LockedFile.cpp @@ -54,7 +54,7 @@ static const char *g_blnk = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdea static const char *g_seed = "c375d83b4388329408dfcbb4d9a065b6e06d28272f25ef299c70b506e26600af79fd2f866ae24602daf38f25c9d4b7e1"; static const char *g_salt = "ee9f7bdabc170763d2200a7e3030045aafe380011aefc1730e547e9244c62308aac42a976feeca224ba553de0c4bb883"; -static QByteArray fileHash(QFile &file) +QByteArray LockedFile::fileHash(QFile &file) { QByteArray hash = QByteArray::fromHex(g_blnk); diff --git a/src/LockedFile.h b/src/LockedFile.h index 4485bd88..e0c46f95 100644 --- a/src/LockedFile.h +++ b/src/LockedFile.h @@ -24,6 +24,7 @@ #include class QResource; +class QFile; class LockedFile { @@ -35,6 +36,7 @@ public: const QString &filePath(); static void selfTest(); + static QByteArray fileHash(QFile &file); private: QString m_filePath; diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 3ae66285..859f7eb0 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -771,8 +771,11 @@ void InitializationThread::initQAac(void) void InitializationThread::selfTest(void) { + static const unsigned int expcetedCount = 27; const unsigned int cpu[4] = {CPU_TYPE_X86_GEN, CPU_TYPE_X86_SSE, CPU_TYPE_X64_GEN, CPU_TYPE_X64_SSE}; + LockedFile::selfTest(); + for(size_t k = 0; k < 4; k++) { qDebug("[TEST]"); @@ -784,21 +787,43 @@ void InitializationThread::selfTest(void) PRINT_CPU_TYPE(CPU_TYPE_X64_SSE); break; default: THROW("CPU support undefined!"); } - int n = 0; - for(int i = 0; i < INT_MAX; i++) + unsigned int n = 0; + for(int i = 0; true; i++) { - if(!g_lamexp_tools[i].pcName && !g_lamexp_tools[i].pcHash && !g_lamexp_tools[i].uiVersion) + if(!(g_lamexp_tools[i].pcName || g_lamexp_tools[i].pcHash || g_lamexp_tools[i].uiVersion)) { break; } - if(g_lamexp_tools[i].uiCpuType & cpu[k]) + else if(g_lamexp_tools[i].pcName && g_lamexp_tools[i].pcHash && g_lamexp_tools[i].uiVersion) { - qDebug("%02i -> %s", ++n, g_lamexp_tools[i].pcName); + const QString toolName = QString::fromLatin1(g_lamexp_tools[i].pcName); + const QByteArray expectedHash = QByteArray(g_lamexp_tools[i].pcHash); + if(g_lamexp_tools[i].uiCpuType & cpu[k]) + { + qDebug("%02i -> %s", ++n, toolName.toUtf8().constData()); + QFile resource(QString(":/tools/%1").arg(toolName)); + if(!resource.open(QIODevice::ReadOnly)) + { + qFatal("The resource for \"%s\" could not be opened!", toolName.toUtf8().constData()); + break; + } + QByteArray hash = LockedFile::fileHash(resource); + if(hash.isNull() || _stricmp(hash.constData(), expectedHash.constData())) + { + qFatal("Hash check for tool \"%s\" has failed!", toolName.toUtf8().constData()); + break; + } + resource.close(); + } + } + else + { + qFatal("Inconsistent checksum data detected. Take care!"); } } - if(n != 27) + if(n != expcetedCount) { - qFatal("Tool count mismatch !!!"); + qFatal("Tool count mismatch for CPU type %u !!!", cpu[4]); } qDebug("Done.\n"); }