32 bit hash function introduced
This commit is contained in:
parent
d115b6fc8b
commit
11ae78cc2f
3 changed files with 33 additions and 5 deletions
|
@ -21,10 +21,18 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc) : hash32Func(hash32Func)
|
||||||
|
{
|
||||||
|
p_formatName = QString::fromUtf8(formatFunc());
|
||||||
|
p_checksumSize = hashSzFunc();
|
||||||
|
p_funcBit = 64;
|
||||||
|
}
|
||||||
|
|
||||||
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
|
||||||
{
|
{
|
||||||
p_formatName = QString::fromUtf8(formatFunc());
|
p_formatName = QString::fromUtf8(formatFunc());
|
||||||
p_checksumSize = hashSzFunc();
|
p_checksumSize = hashSzFunc();
|
||||||
|
p_funcBit = 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
||||||
|
@ -32,9 +40,16 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
||||||
const size_t size = data.size();
|
const size_t size = data.size();
|
||||||
unsigned char *udata = new unsigned char[size];
|
unsigned char *udata = new unsigned char[size];
|
||||||
std::memcpy(udata, data.constData(), size);
|
std::memcpy(udata, data.constData(), size);
|
||||||
|
if (p_funcBit == 32) {
|
||||||
|
const u_int32_t hash = hash32Func(udata, size);
|
||||||
|
free(udata);
|
||||||
|
return QByteArray::number((quint32)hash, 16);
|
||||||
|
}
|
||||||
|
else {
|
||||||
const u_int64_t hash = hash64Func(udata, size);
|
const u_int64_t hash = hash64Func(udata, size);
|
||||||
free(udata);
|
free(udata);
|
||||||
return QByteArray::number((quint64)hash, 16);
|
return QByteArray::number((quint64)hash, 16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString checksum_lib::formatName()
|
const QString checksum_lib::formatName()
|
||||||
|
|
|
@ -24,21 +24,25 @@
|
||||||
typedef int (*PluginHashSzFunction)();
|
typedef int (*PluginHashSzFunction)();
|
||||||
typedef const char* (*PluginFormatFunction)();
|
typedef const char* (*PluginFormatFunction)();
|
||||||
typedef const char* (*PluginVersionFunction)();
|
typedef const char* (*PluginVersionFunction)();
|
||||||
|
typedef u_int32_t (*PluginHash32Function)(unsigned char*, size_t);
|
||||||
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
|
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
|
||||||
|
|
||||||
class checksum_lib : public checksum
|
class checksum_lib : public checksum
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc);
|
||||||
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
|
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
|
||||||
QByteArray generateChecksum(const QByteArray &data);
|
QByteArray generateChecksum(const QByteArray &data);
|
||||||
const QString formatName();
|
const QString formatName();
|
||||||
int checksumSize();
|
int checksumSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PluginHash32Function hash32Func;
|
||||||
PluginHash64Function hash64Func;
|
PluginHash64Function hash64Func;
|
||||||
QString p_formatName;
|
QString p_formatName;
|
||||||
int p_checksumSize;
|
int p_checksumSize;
|
||||||
|
int p_funcBit;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHECKSUM_LIB_H
|
#endif // CHECKSUM_LIB_H
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -36,7 +36,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
a.setApplicationName("checkbrute");
|
a.setApplicationName("checkbrute");
|
||||||
a.setApplicationVersion("0.2.1");
|
a.setApplicationVersion("0.3");
|
||||||
|
|
||||||
QCommandLineParser commandLineParser;
|
QCommandLineParser commandLineParser;
|
||||||
commandLineParser.addHelpOption();
|
commandLineParser.addHelpOption();
|
||||||
|
@ -111,11 +111,20 @@ int main(int argc, char *argv[])
|
||||||
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
|
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
|
||||||
QLibrary plugin(filePath);
|
QLibrary plugin(filePath);
|
||||||
if (plugin.load()) {
|
if (plugin.load()) {
|
||||||
|
PluginHash32Function hash32Func = (PluginHash32Function)plugin.resolve("checkbrute_hash32");
|
||||||
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
|
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
|
||||||
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
|
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
|
||||||
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
|
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
|
||||||
PluginVersionFunction versionFunc = (PluginVersionFunction)plugin.resolve("checkbrute_version");
|
PluginVersionFunction versionFunc = (PluginVersionFunction)plugin.resolve("checkbrute_version");
|
||||||
if (formatFunc && hash64Func && hashSzFunc) {
|
if (formatFunc && hash32Func && hashSzFunc) {
|
||||||
|
QString version = "undefined";
|
||||||
|
const char *format = formatFunc();
|
||||||
|
if (versionFunc)
|
||||||
|
version = QString::fromUtf8(versionFunc());
|
||||||
|
checksum_map[format] = new checksum_lib(formatFunc, hash32Func, hashSzFunc);
|
||||||
|
QTextStream(stderr) << "INFO: " << format << " plugin " << fileName << " loaded" << Qt::endl;
|
||||||
|
}
|
||||||
|
else if (formatFunc && hash64Func && hashSzFunc) {
|
||||||
QString version = "undefined";
|
QString version = "undefined";
|
||||||
const char *format = formatFunc();
|
const char *format = formatFunc();
|
||||||
if (versionFunc)
|
if (versionFunc)
|
||||||
|
|
Loading…
Reference in a new issue