2020-11-11 00:13:09 +01:00
|
|
|
#include "views/view_hashes.hpp"
|
|
|
|
|
2020-11-11 10:47:02 +01:00
|
|
|
#include "providers/provider.hpp"
|
|
|
|
|
2020-11-11 00:13:09 +01:00
|
|
|
#include "utils.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ViewHashes::ViewHashes(prv::Provider* &dataProvider) : View(), m_dataProvider(dataProvider) {
|
2020-11-11 00:13:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewHashes::~ViewHashes() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ViewHashes::createView() {
|
2020-11-11 10:47:02 +01:00
|
|
|
static bool invalidate = false;
|
|
|
|
|
2020-11-11 00:13:09 +01:00
|
|
|
if (!this->m_windowOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ImGui::Begin("Hashing", &this->m_windowOpen)) {
|
|
|
|
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
if (this->m_dataProvider != nullptr && this->m_dataProvider->isAvailable()) {
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 10:47:02 +01:00
|
|
|
ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames,
|
|
|
|
sizeof(HashFunctionNames) / sizeof(const char *));
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::InputInt("Begin", &this->m_hashStart, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::InputInt("End", &this->m_hashEnd, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
if (this->m_hashEnd >= this->m_hashStart) {
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
std::vector<u8> buffer;
|
|
|
|
|
|
|
|
if (invalidate) {
|
|
|
|
buffer = std::vector<u8>(this->m_hashEnd - this->m_hashStart + 1, 0x00);
|
|
|
|
this->m_dataProvider->read(this->m_hashStart, buffer.data(), buffer.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (this->m_currHashFunction) {
|
|
|
|
case 0: // CRC16
|
|
|
|
{
|
|
|
|
static int polynomial = 0, init = 0;
|
|
|
|
|
|
|
|
ImGui::InputInt("Initial Value", &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
ImGui::InputInt("Polynomial", &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
static u16 result = 0;
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
if (invalidate)
|
|
|
|
result = crc16(buffer.data(), buffer.size(), polynomial, init);
|
|
|
|
|
|
|
|
ImGui::LabelText("##nolabel", "%X", result);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // CRC32
|
|
|
|
{
|
|
|
|
static int polynomial = 0, init = 0;
|
|
|
|
|
|
|
|
ImGui::InputInt("Initial Value", &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
ImGui::InputInt("Polynomial", &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
static u32 result = 0;
|
|
|
|
|
|
|
|
if (invalidate)
|
|
|
|
result = crc32(buffer.data(), buffer.size(), polynomial, init);
|
|
|
|
|
|
|
|
ImGui::LabelText("##nolabel", "%X", result);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: // MD5
|
|
|
|
{
|
|
|
|
static std::array<u32, 4> result;
|
|
|
|
|
|
|
|
if (invalidate)
|
|
|
|
result = md5(buffer.data(), buffer.size());
|
|
|
|
|
|
|
|
ImGui::LabelText("##nolabel", "%08X%08X%08X%08X",
|
|
|
|
__builtin_bswap32(result[0]),
|
|
|
|
__builtin_bswap32(result[1]),
|
|
|
|
__builtin_bswap32(result[2]),
|
|
|
|
__builtin_bswap32(result[3]));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-11-11 00:13:09 +01:00
|
|
|
|
|
|
|
}
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
invalidate = false;
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("Hash"))
|
|
|
|
invalidate = true;
|
|
|
|
|
2020-11-11 00:13:09 +01:00
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
2020-11-11 10:47:02 +01:00
|
|
|
ImGui::End();
|
2020-11-11 00:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewHashes::createMenu() {
|
2020-11-11 09:22:55 +01:00
|
|
|
if (ImGui::BeginMenu("View")) {
|
2020-11-11 00:13:09 +01:00
|
|
|
ImGui::MenuItem("Hash View", "", &this->m_windowOpen);
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|