ui: Correct some uses of ImGui::EndChild()

This commit is contained in:
WerWolv
2021-08-28 14:22:02 +02:00
parent 8dcd5c6e34
commit e9c349fc55
7 changed files with 276 additions and 270 deletions

View File

@@ -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<ImU64, 256> result{ 0 };
std::iota(result.begin(), result.end(), 0);
return result;
}();
ImPlot::PlotBars<ImU64>("##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<RequestSelectionChange>( 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<const char*>("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<ImU64, 256> result{ 0 };
std::iota(result.begin(), result.end(), 0);
return result;
}();
ImPlot::PlotBars<ImU64>("##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<RequestSelectionChange>( 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<const char*>("hex.view.information.encrypted"_lang));
}
}
}
ImGui::EndChild();
}
ImGui::EndChild();
}
ImGui::End();
}