diff --git a/source/views/view_disassembler.cpp b/source/views/view_disassembler.cpp index 8b88f0806..f654ccc03 100644 --- a/source/views/view_disassembler.cpp +++ b/source/views/view_disassembler.cpp @@ -244,8 +244,8 @@ namespace hex { break; } + ImGui::EndChild(); } - ImGui::EndChild(); ImGui::Disabled([this] { if (ImGui::Button("hex.view.disassembler.disassemble"_lang)) diff --git a/source/views/view_hashes.cpp b/source/views/view_hashes.cpp index eb9d2282e..ae3e99cad 100644 --- a/source/views/view_hashes.cpp +++ b/source/views/view_hashes.cpp @@ -37,192 +37,194 @@ namespace hex { void ViewHashes::drawContent() { if (ImGui::Begin(View::toWindowName("hex.view.hashes.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { - ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); - - auto provider = SharedData::currentProvider; - if (provider != nullptr && provider->isAvailable()) { - - ImGui::TextUnformatted("hex.common.region"_lang); - ImGui::Separator(); - - ImGui::InputScalarN("##nolabel", ImGuiDataType_U64, this->m_hashRegion, 2, nullptr, nullptr, "%08X", ImGuiInputTextFlags_CharsHexadecimal); - if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; - - ImGui::Checkbox("hex.common.match_selection"_lang, &this->m_shouldMatchSelection); - if (ImGui::IsItemEdited()) { - // Force execution of Region Selection Event - EventManager::post(Region{ 0, 0 }); - this->m_shouldInvalidate = true; - } - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.settings"_lang); - ImGui::Separator(); - - if (ImGui::Combo("hex.view.hashes.function"_lang, &this->m_currHashFunction, HashFunctionNames,sizeof(HashFunctionNames) / sizeof(const char *))) - this->m_shouldInvalidate = true; - - size_t dataSize = provider->getSize(); - if (this->m_hashRegion[1] >= provider->getBaseAddress() + dataSize) - this->m_hashRegion[1] = provider->getBaseAddress() + dataSize; + if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) { - if (this->m_hashRegion[1] >= this->m_hashRegion[0]) { + auto provider = SharedData::currentProvider; + if (provider != nullptr && provider->isAvailable()) { - switch (this->m_currHashFunction) { - case 0: // CRC16 - { - static int polynomial = 0x8005, init = 0x0000; + ImGui::TextUnformatted("hex.common.region"_lang); + ImGui::Separator(); - ImGui::InputInt("hex.view.hashes.iv"_lang, &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); - if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; + ImGui::InputScalarN("##nolabel", ImGuiDataType_U64, this->m_hashRegion, 2, nullptr, nullptr, "%08X", ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; - ImGui::InputInt("hex.view.hashes.poly"_lang, &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); - if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; - - ImGui::NewLine(); - - static u16 result = 0; - - if (this->m_shouldInvalidate) - result = crypt::crc16(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init); - - char buffer[sizeof(result) * 2 + 1]; - snprintf(buffer, sizeof(buffer), "%04X", result); - - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 1: // CRC32 - { - static int polynomial = 0x04C11DB7, init = 0xFFFFFFFF; - - ImGui::InputInt("hex.view.hashes.iv"_lang, &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); - if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; - - ImGui::InputInt("hex.view.hashes.poly"_lang, &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); - if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; - - ImGui::NewLine(); - - static u32 result = 0; - - if (this->m_shouldInvalidate) - result = crypt::crc32(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init); - - char buffer[sizeof(result) * 2 + 1]; - snprintf(buffer, sizeof(buffer), "%08X", result); - - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 2: // MD5 - { - static std::array result = { 0 }; - - if (this->m_shouldInvalidate) - result = crypt::md5(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 3: // SHA-1 - { - static std::array result = { 0 }; - - if (this->m_shouldInvalidate) - result = crypt::sha1(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 4: // SHA-224 - { - static std::array result = { 0 }; - - if (this->m_shouldInvalidate) - result = crypt::sha224(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 5: // SHA-256 - { - static std::array result; - - if (this->m_shouldInvalidate) - result = crypt::sha256(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 6: // SHA-384 - { - static std::array result; - - if (this->m_shouldInvalidate) - result = crypt::sha384(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; - case 7: // SHA-512 - { - static std::array result; - - if (this->m_shouldInvalidate) - result = crypt::sha512(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); - - char buffer[sizeof(result) * 2 + 1]; - formatBigHexInt(result, buffer, sizeof(buffer)); - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.hashes.result"_lang); - ImGui::Separator(); - ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); - } - break; + ImGui::Checkbox("hex.common.match_selection"_lang, &this->m_shouldMatchSelection); + if (ImGui::IsItemEdited()) { + // Force execution of Region Selection Event + EventManager::post(Region{ 0, 0 }); + this->m_shouldInvalidate = true; } - } + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.settings"_lang); + ImGui::Separator(); - this->m_shouldInvalidate = false; + if (ImGui::Combo("hex.view.hashes.function"_lang, &this->m_currHashFunction, HashFunctionNames,sizeof(HashFunctionNames) / sizeof(const char *))) + this->m_shouldInvalidate = true; + + size_t dataSize = provider->getSize(); + if (this->m_hashRegion[1] >= provider->getBaseAddress() + dataSize) + this->m_hashRegion[1] = provider->getBaseAddress() + dataSize; + + + if (this->m_hashRegion[1] >= this->m_hashRegion[0]) { + + switch (this->m_currHashFunction) { + case 0: // CRC16 + { + static int polynomial = 0x8005, init = 0x0000; + + ImGui::InputInt("hex.view.hashes.iv"_lang, &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; + + ImGui::InputInt("hex.view.hashes.poly"_lang, &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; + + ImGui::NewLine(); + + static u16 result = 0; + + if (this->m_shouldInvalidate) + result = crypt::crc16(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init); + + char buffer[sizeof(result) * 2 + 1]; + snprintf(buffer, sizeof(buffer), "%04X", result); + + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 1: // CRC32 + { + static int polynomial = 0x04C11DB7, init = 0xFFFFFFFF; + + ImGui::InputInt("hex.view.hashes.iv"_lang, &init, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; + + ImGui::InputInt("hex.view.hashes.poly"_lang, &polynomial, 0, 0, ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::IsItemEdited()) this->m_shouldInvalidate = true; + + ImGui::NewLine(); + + static u32 result = 0; + + if (this->m_shouldInvalidate) + result = crypt::crc32(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1, polynomial, init); + + char buffer[sizeof(result) * 2 + 1]; + snprintf(buffer, sizeof(buffer), "%08X", result); + + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 2: // MD5 + { + static std::array result = { 0 }; + + if (this->m_shouldInvalidate) + result = crypt::md5(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 3: // SHA-1 + { + static std::array result = { 0 }; + + if (this->m_shouldInvalidate) + result = crypt::sha1(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 4: // SHA-224 + { + static std::array result = { 0 }; + + if (this->m_shouldInvalidate) + result = crypt::sha224(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 5: // SHA-256 + { + static std::array result; + + if (this->m_shouldInvalidate) + result = crypt::sha256(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 6: // SHA-384 + { + static std::array result; + + if (this->m_shouldInvalidate) + result = crypt::sha384(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + case 7: // SHA-512 + { + static std::array result; + + if (this->m_shouldInvalidate) + result = crypt::sha512(provider, this->m_hashRegion[0], this->m_hashRegion[1] - this->m_hashRegion[0] + 1); + + char buffer[sizeof(result) * 2 + 1]; + formatBigHexInt(result, buffer, sizeof(buffer)); + + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.hashes.result"_lang); + ImGui::Separator(); + ImGui::InputText("##nolabel", buffer, ImGuiInputTextFlags_ReadOnly); + } + break; + } + + } + + this->m_shouldInvalidate = false; + } + ImGui::EndChild(); } - ImGui::EndChild(); } ImGui::End(); } diff --git a/source/views/view_help.cpp b/source/views/view_help.cpp index ce995efb3..0ca9dfdd9 100644 --- a/source/views/view_help.cpp +++ b/source/views/view_help.cpp @@ -38,11 +38,11 @@ namespace hex { static void drawCodeSegment(const std::string &id, const std::string &code) { ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.2F, 0.2F, 0.2F, 0.3F)); - ImGui::BeginChild(id.c_str(), ImVec2(-1, ImGui::CalcTextSize(code.c_str()).y)); + if (ImGui::BeginChild(id.c_str(), ImVec2(-1, ImGui::CalcTextSize(code.c_str()).y))) { + ImGui::Text("%s", code.c_str()); + ImGui::EndChild(); + } - ImGui::Text("%s", code.c_str()); - - ImGui::EndChild(); ImGui::NewLine(); ImGui::PopStyleColor(); }; diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index f6e6a820e..a64b4539e 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -565,8 +565,8 @@ namespace hex { return true; } + ON_SCOPE_EXIT { ImGui::End(); }; if (ImGui::Begin(View::toWindowName("hex.view.hexeditor.name").c_str())) { - ON_SCOPE_EXIT { ImGui::End(); }; if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) { if (ctrl && keys['Z']) { diff --git a/source/views/view_information.cpp b/source/views/view_information.cpp index 8923b4653..d74e99b60 100644 --- a/source/views/view_information.cpp +++ b/source/views/view_information.cpp @@ -140,107 +140,109 @@ namespace hex { void ViewInformation::drawContent() { if (ImGui::Begin(View::toWindowName("hex.view.information.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { - ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); + if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) { - auto provider = SharedData::currentProvider; - if (provider != nullptr && provider->isReadable()) { - ImGui::TextUnformatted("hex.view.information.control"_lang); - ImGui::Separator(); - ImGui::Disabled([this] { - if (ImGui::Button("hex.view.information.analyze"_lang)) - this->analyze(); - }, this->m_analyzing); - - if (this->m_analyzing) { - ImGui::SameLine(); - ImGui::TextSpinner("hex.view.information.analyzing"_lang); - } - - if (this->m_dataValid) { - - ImGui::NewLine(); - ImGui::TextUnformatted("hex.view.information.region"_lang); + auto provider = SharedData::currentProvider; + if (provider != nullptr && provider->isReadable()) { + ImGui::TextUnformatted("hex.view.information.control"_lang); ImGui::Separator(); - for (auto &[name, value] : (SharedData::currentProvider)->getDataInformation()) { - ImGui::LabelText(name.c_str(), "%s", value.c_str()); + ImGui::Disabled([this] { + if (ImGui::Button("hex.view.information.analyze"_lang)) + this->analyze(); + }, this->m_analyzing); + + if (this->m_analyzing) { + ImGui::SameLine(); + ImGui::TextSpinner("hex.view.information.analyzing"_lang); } - ImGui::LabelText("hex.view.information.region"_lang, "0x%llx - 0x%llx", this->m_analyzedRegion.first, this->m_analyzedRegion.second); + if (this->m_dataValid) { - ImGui::NewLine(); - - if (!this->m_fileDescription.empty() || !this->m_mimeType.empty()) { - ImGui::TextUnformatted("hex.view.information.magic"_lang); + ImGui::NewLine(); + ImGui::TextUnformatted("hex.view.information.region"_lang); ImGui::Separator(); - } - if (!this->m_fileDescription.empty()) { - ImGui::TextUnformatted("hex.view.information.description"_lang); - ImGui::TextWrapped("%s", this->m_fileDescription.c_str()); - ImGui::NewLine(); - } - - if (!this->m_mimeType.empty()) { - ImGui::TextUnformatted("hex.view.information.mime"_lang); - ImGui::TextWrapped("%s", this->m_mimeType.c_str()); - ImGui::NewLine(); - } - - ImGui::TextUnformatted("hex.view.information.info_analysis"_lang); - ImGui::Separator(); - - ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetColorU32(ImGuiCol_WindowBg)); - - ImGui::TextUnformatted("hex.view.information.distribution"_lang); - ImPlot::SetNextPlotLimits(0, 256, 0, float(*std::max_element(this->m_valueCounts.begin(), this->m_valueCounts.end())) * 1.1F, ImGuiCond_Always); - if (ImPlot::BeginPlot("##distribution", "Address", "Count", ImVec2(-1,0), ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock)) { - static auto x = []{ - std::array result{ 0 }; - std::iota(result.begin(), result.end(), 0); - return result; - }(); - - - ImPlot::PlotBars("##bytes", x.data(), this->m_valueCounts.data(), x.size(), 0.67); - - ImPlot::EndPlot(); - } - - ImGui::NewLine(); - - ImGui::TextUnformatted("hex.view.information.entropy"_lang); - - ImPlot::SetNextPlotLimits(0, this->m_blockEntropy.size(), -0.1, 1.1, ImGuiCond_Always); - if (ImPlot::BeginPlot("##entropy", "Address", "Entropy", ImVec2(-1,0), ImPlotFlags_CanvasOnly, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_Lock)) { - ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size()); - - if (ImPlot::DragLineX("Position", &this->m_entropyHandlePosition, false)) { - u64 address = u64(this->m_entropyHandlePosition * this->m_blockSize) + provider->getBaseAddress(); - address = std::min(address, provider->getBaseAddress() + provider->getSize() - 1); - EventManager::post( Region{ address, 1 }); + for (auto &[name, value] : (SharedData::currentProvider)->getDataInformation()) { + ImGui::LabelText(name.c_str(), "%s", value.c_str()); } - ImPlot::EndPlot(); - } + ImGui::LabelText("hex.view.information.region"_lang, "0x%llx - 0x%llx", this->m_analyzedRegion.first, this->m_analyzedRegion.second); - ImGui::PopStyleColor(); - - ImGui::NewLine(); - - ImGui::LabelText("hex.view.information.block_size"_lang, "%s", hex::format("hex.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize).c_str()); - ImGui::LabelText("hex.view.information.file_entropy"_lang, "%.8f", this->m_averageEntropy); - ImGui::LabelText("hex.view.information.highest_entropy"_lang, "%.8f", this->m_highestBlockEntropy); - - if (this->m_averageEntropy > 0.83 && this->m_highestBlockEntropy > 0.9) { ImGui::NewLine(); - ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "%s", static_cast("hex.view.information.encrypted"_lang)); - } + if (!this->m_fileDescription.empty() || !this->m_mimeType.empty()) { + ImGui::TextUnformatted("hex.view.information.magic"_lang); + ImGui::Separator(); + } + + if (!this->m_fileDescription.empty()) { + ImGui::TextUnformatted("hex.view.information.description"_lang); + ImGui::TextWrapped("%s", this->m_fileDescription.c_str()); + ImGui::NewLine(); + } + + if (!this->m_mimeType.empty()) { + ImGui::TextUnformatted("hex.view.information.mime"_lang); + ImGui::TextWrapped("%s", this->m_mimeType.c_str()); + ImGui::NewLine(); + } + + ImGui::TextUnformatted("hex.view.information.info_analysis"_lang); + ImGui::Separator(); + + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImGui::GetColorU32(ImGuiCol_WindowBg)); + + ImGui::TextUnformatted("hex.view.information.distribution"_lang); + ImPlot::SetNextPlotLimits(0, 256, 0, float(*std::max_element(this->m_valueCounts.begin(), this->m_valueCounts.end())) * 1.1F, ImGuiCond_Always); + if (ImPlot::BeginPlot("##distribution", "Address", "Count", ImVec2(-1,0), ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock)) { + static auto x = []{ + std::array result{ 0 }; + std::iota(result.begin(), result.end(), 0); + return result; + }(); + + + ImPlot::PlotBars("##bytes", x.data(), this->m_valueCounts.data(), x.size(), 0.67); + + ImPlot::EndPlot(); + } + + ImGui::NewLine(); + + ImGui::TextUnformatted("hex.view.information.entropy"_lang); + + ImPlot::SetNextPlotLimits(0, this->m_blockEntropy.size(), -0.1, 1.1, ImGuiCond_Always); + if (ImPlot::BeginPlot("##entropy", "Address", "Entropy", ImVec2(-1,0), ImPlotFlags_CanvasOnly, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_Lock)) { + ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size()); + + if (ImPlot::DragLineX("Position", &this->m_entropyHandlePosition, false)) { + u64 address = u64(this->m_entropyHandlePosition * this->m_blockSize) + provider->getBaseAddress(); + address = std::min(address, provider->getBaseAddress() + provider->getSize() - 1); + EventManager::post( Region{ address, 1 }); + } + + ImPlot::EndPlot(); + } + + ImGui::PopStyleColor(); + + ImGui::NewLine(); + + ImGui::LabelText("hex.view.information.block_size"_lang, "%s", hex::format("hex.view.information.block_size.desc"_lang, this->m_blockEntropy.size(), this->m_blockSize).c_str()); + ImGui::LabelText("hex.view.information.file_entropy"_lang, "%.8f", this->m_averageEntropy); + ImGui::LabelText("hex.view.information.highest_entropy"_lang, "%.8f", this->m_highestBlockEntropy); + + if (this->m_averageEntropy > 0.83 && this->m_highestBlockEntropy > 0.9) { + ImGui::NewLine(); + ImGui::TextColored(ImVec4(0.92F, 0.25F, 0.2F, 1.0F), "%s", static_cast("hex.view.information.encrypted"_lang)); + } + + } } + ImGui::EndChild(); } - ImGui::EndChild(); } ImGui::End(); } diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 218d89ac4..21b5a2c24 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -257,8 +257,9 @@ namespace hex { ImGui::PopStyleColor(); } + + ImGui::EndChild(); } - ImGui::EndChild(); ImGui::PopStyleColor(1); ImGui::Disabled([this]{ diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index c00aaa7ab..e803c3fff 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -186,10 +186,11 @@ namespace hex { ImGui::TextUnformatted("hex.view.strings.demangle.title"_lang); ImGui::Separator(); ImGui::TextWrapped("%s", this->m_demangledName.c_str()); - ImGui::EndChild(); ImGui::NewLine(); if (ImGui::Button("hex.view.strings.demangle.copy"_lang)) ImGui::SetClipboardText(this->m_demangledName.c_str()); + + ImGui::EndChild(); } ImGui::EndPopup(); }