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-28 21:55:52 +01:00
|
|
|
#include "helpers/crypto.hpp"
|
2020-11-11 00:13:09 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2020-11-28 21:55:52 +01:00
|
|
|
#include "helpers/utils.hpp"
|
2020-11-19 11:37:16 +01:00
|
|
|
|
2020-11-11 00:13:09 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
ViewHashes::ViewHashes() : View("Hashes") {
|
2020-11-17 13:58:50 +01:00
|
|
|
View::subscribeEvent(Events::DataChanged, [this](const void*){
|
2020-11-12 09:38:52 +01:00
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
});
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
View::subscribeEvent(Events::RegionSelected, [this](const void *userData) {
|
|
|
|
Region region = *static_cast<const Region*>(userData);
|
|
|
|
|
|
|
|
if (this->m_shouldMatchSelection) {
|
|
|
|
this->m_hashRegion[0] = region.address;
|
|
|
|
this->m_hashRegion[1] = region.address + region.size - 1;
|
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
}
|
|
|
|
});
|
2020-11-11 00:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewHashes::~ViewHashes() {
|
2020-11-12 09:38:52 +01:00
|
|
|
View::unsubscribeEvent(Events::DataChanged);
|
2020-11-28 15:53:11 +01:00
|
|
|
View::unsubscribeEvent(Events::RegionSelected);
|
2020-11-11 00:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 12:00:50 +01:00
|
|
|
static void formatBigHexInt(auto dataArray, char *buffer, size_t bufferSize) {
|
|
|
|
for (int i = 0; i < dataArray.size(); i++)
|
2020-11-22 15:32:37 +01:00
|
|
|
snprintf(buffer + 8 * i, bufferSize - 8 * i, "%08X", hex::changeEndianess(dataArray[i], std::endian::big));
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewHashes::drawContent() {
|
2020-11-23 23:57:19 +01:00
|
|
|
if (ImGui::Begin("Hashing", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2020-11-11 00:13:09 +01:00
|
|
|
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
|
|
|
|
|
2021-01-12 23:28:41 +01:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 15:39:06 +01:00
|
|
|
if (provider != nullptr && provider->isAvailable()) {
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-28 15:53:11 +01:00
|
|
|
ImGui::TextUnformatted("Region");
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::Separator();
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-28 15:53:11 +01:00
|
|
|
ImGui::InputScalarN("##nolabel", ImGuiDataType_U64, this->m_hashRegion, 2, nullptr, nullptr, "%08X", ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-28 15:53:11 +01:00
|
|
|
ImGui::Checkbox("Match selection", &this->m_shouldMatchSelection);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::NewLine();
|
2020-11-28 15:53:11 +01:00
|
|
|
ImGui::TextUnformatted("Settings");
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::Separator();
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-28 15:53:11 +01:00
|
|
|
if (ImGui::Combo("Hash Function", &this->m_currHashFunction, HashFunctionNames,sizeof(HashFunctionNames) / sizeof(const char *)))
|
|
|
|
this->m_shouldInvalidate = true;
|
|
|
|
|
2020-12-27 15:39:06 +01:00
|
|
|
size_t dataSize = provider->getSize();
|
2020-11-28 15:53:11 +01:00
|
|
|
if (this->m_hashRegion[1] >= dataSize)
|
|
|
|
this->m_hashRegion[1] = dataSize - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (this->m_hashRegion[1] >= this->m_hashRegion[0]) {
|
2020-11-11 00:13:09 +01:00
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
switch (this->m_currHashFunction) {
|
|
|
|
case 0: // CRC16
|
|
|
|
{
|
2020-11-27 09:09:59 +01:00
|
|
|
static int polynomial = 0, init = 0;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
ImGui::InputInt("Initial Value", &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::InputInt("Polynomial", &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
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-12 09:38:52 +01:00
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = crc16(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init);
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-12 12:00:50 +01:00
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
snprintf(buffer, sizeof(buffer), "%04X", result);
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-11 09:18:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // CRC32
|
|
|
|
{
|
2020-11-27 09:09:59 +01:00
|
|
|
static int polynomial = 0, init = 0;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
ImGui::InputInt("Initial Value", &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
|
|
|
|
2020-11-11 09:18:35 +01:00
|
|
|
ImGui::InputInt("Polynomial", &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-12 09:38:52 +01:00
|
|
|
if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
static u32 result = 0;
|
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = crc32(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init);
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-12 12:00:50 +01:00
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
snprintf(buffer, sizeof(buffer), "%08X", result);
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-11 09:18:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-11-12 12:00:50 +01:00
|
|
|
case 2: // MD4
|
2020-11-11 09:18:35 +01:00
|
|
|
{
|
|
|
|
static std::array<u32, 4> result;
|
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = md4(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: // MD5
|
|
|
|
{
|
|
|
|
static std::array<u32, 4> result = { 0 };
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = md5(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: // SHA-1
|
|
|
|
{
|
|
|
|
static std::array<u32, 5> result = { 0 };
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = sha1(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: // SHA-224
|
|
|
|
{
|
|
|
|
static std::array<u32, 7> result = { 0 };
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = sha224(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: // SHA-256
|
|
|
|
{
|
|
|
|
static std::array<u32, 8> result;
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = sha256(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7: // SHA-384
|
|
|
|
{
|
|
|
|
static std::array<u32, 12> result;
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = sha384(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-12 12:00:50 +01:00
|
|
|
|
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-12 12:00:50 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8: // SHA-512
|
|
|
|
{
|
|
|
|
static std::array<u32, 16> result;
|
|
|
|
|
|
|
|
if (this->m_shouldInvalidate)
|
2020-12-27 15:39:06 +01:00
|
|
|
result = sha512(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1);
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-12 12:00:50 +01:00
|
|
|
char buffer[sizeof(result) * 2 + 1];
|
|
|
|
formatBigHexInt(result, buffer, sizeof(buffer));
|
2020-11-28 15:53:11 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("Result");
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly);
|
2020-11-11 09:18:35 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-11-11 00:13:09 +01:00
|
|
|
|
|
|
|
}
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2020-11-12 09:38:52 +01:00
|
|
|
this->m_shouldInvalidate = false;
|
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
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewHashes::drawMenu() {
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2020-11-11 00:13:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|