checkbrute/src/brutethread.cpp

40 lines
1.8 KiB
C++

/*****************************************************************************
* checkbrute Checksum Bruteforcing Tool
* Copyright (C) 2020 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include <QTextStream>
#include "brutethread.h"
brutethread::brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), length(length) {}
void brutethread::run()
{
quint64 size = fileContent.size();
for (quint64 seek = 0; seek + length < size; seek++) {
for (checksum *generator : checksum_vector) {
const QByteArray content = fileContent.mid(seek, length);
const QByteArray generatedHash = generator->generateChecksum(content).toHex();
for (const QByteArray &hash : checksums) {
if (generatedHash.left(hash.length()) == hash) {
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
emit matched();
}
}
}
}
}