Improved InitializationThread::selfTest() function: It will now verify the hashes of *all* tools (it still is called in DEBUG builds only).

This commit is contained in:
LoRd_MuldeR 2013-10-20 19:12:55 +02:00
parent be9cf25645
commit 8a3094653c
3 changed files with 35 additions and 8 deletions

View File

@ -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);

View File

@ -24,6 +24,7 @@
#include <QString>
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;

View File

@ -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");
}