63 lines
2.1 KiB
C++
63 lines
2.1 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 "checksum_lib.h"
|
|
#include <iostream>
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc) : hash32Func(hash32Func)
|
|
{
|
|
p_formatName = QString::fromUtf8(formatFunc());
|
|
p_checksumSize = hashSzFunc();
|
|
p_funcBit = 32;
|
|
}
|
|
|
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
|
|
{
|
|
p_formatName = QString::fromUtf8(formatFunc());
|
|
p_checksumSize = hashSzFunc();
|
|
p_funcBit = 64;
|
|
}
|
|
|
|
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
|
{
|
|
const size_t size = data.size();
|
|
unsigned char *udata = new unsigned char[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);
|
|
free(udata);
|
|
return QByteArray::number((quint64)hash, 16);
|
|
}
|
|
}
|
|
|
|
const QString checksum_lib::formatName()
|
|
{
|
|
return p_formatName;
|
|
}
|
|
|
|
int checksum_lib::checksumSize()
|
|
{
|
|
return p_checksumSize;
|
|
}
|