1
0
mirror of synced 2025-02-14 09:32:35 +01:00
ImHex/include/views/view_hashes.hpp
RADICS Áron a6b8597f5a
Fix CRC and hash calculations (#321)
* Fix CRC calculation, add more CRC parameters

Use the Boost CRC module to calculate the CRC values.
Add options for final xor value, reflectIn and reflectOut.
Fixes #320

* Cleanup Hash view combo box, add CRC8

* Use offset/size consistently

* Cleanup: unify processing data by chunks

* Change CRC algorithm back, drop boost dependency

This is mostly the original algorithm, with a few fixes and small
additions (support for reflect In / Out, final XOR value).

* Use size_t for file read size consistently
2021-10-26 17:21:48 +02:00

43 lines
1.2 KiB
C++

#pragma once
#include <hex/views/view.hpp>
#include <array>
#include <utility>
#include <cstdio>
namespace hex {
namespace prv { class Provider; }
class ViewHashes : public View {
public:
explicit ViewHashes();
~ViewHashes() override;
void drawContent() override;
void drawMenu() override;
private:
enum class HashFunctions { Crc8, Crc16, Crc32, Md5, Sha1, Sha224, Sha256, Sha384, Sha512 };
bool m_shouldInvalidate = true;
int m_currHashFunction = 0;
u64 m_hashRegion[2] = { 0 };
bool m_shouldMatchSelection = false;
static constexpr std::array hashFunctionNames {
std::pair{HashFunctions::Crc8, "CRC8"},
std::pair{HashFunctions::Crc16, "CRC16"},
std::pair{HashFunctions::Crc32, "CRC32"},
std::pair{HashFunctions::Md5, "MD5"},
std::pair{HashFunctions::Sha1, "SHA-1"},
std::pair{HashFunctions::Sha224, "SHA-224"},
std::pair{HashFunctions::Sha256, "SHA-256"},
std::pair{HashFunctions::Sha384, "SHA-384"},
std::pair{HashFunctions::Sha512, "SHA-512"},
};
};
}