parent
391c8acfe4
commit
87d0aae608
@ -31,7 +31,7 @@ namespace hex::plugin::builtin {
|
||||
TaskHolder m_disassemblerTask;
|
||||
|
||||
u64 m_baseAddress = 0;
|
||||
ui::SelectedRegion m_range = ui::SelectedRegion::EntireData;
|
||||
ui::RegionType m_range = ui::RegionType::EntireData;
|
||||
Region m_codeRegion = { 0, 0 };
|
||||
|
||||
Architecture m_architecture = Architecture::ARM;
|
||||
|
@ -33,7 +33,8 @@ namespace hex::plugin::builtin {
|
||||
};
|
||||
|
||||
struct SearchSettings {
|
||||
ui::SelectedRegion range = ui::SelectedRegion::EntireData;
|
||||
ui::RegionType range = ui::RegionType::EntireData;
|
||||
Region region = { 0, 0 };
|
||||
|
||||
enum class Mode : int {
|
||||
Strings,
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <hex/api/task.hpp>
|
||||
|
||||
#include "content/helpers/diagrams.hpp"
|
||||
#include <ui/widgets.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
@ -34,6 +35,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
TaskHolder m_analyzerTask;
|
||||
|
||||
Region m_analysisRegion = { 0, 0 };
|
||||
Region m_analyzedRegion = { 0, 0 };
|
||||
|
||||
std::string m_dataDescription;
|
||||
@ -47,10 +49,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
void analyze();
|
||||
|
||||
// User controlled input (referenced by ImgGui)
|
||||
int m_inputChunkSize = 0;
|
||||
u64 m_inputStartAddress = 0;
|
||||
u64 m_inputEndAddress = 0;
|
||||
ui::RegionType m_selectionType = ui::RegionType::EntireData;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,20 +9,46 @@ namespace hex::prv { class Provider; }
|
||||
namespace hex::plugin::builtin::ui {
|
||||
|
||||
|
||||
enum class SelectedRegion : int {
|
||||
enum class RegionType : int {
|
||||
EntireData,
|
||||
Selection
|
||||
Selection,
|
||||
Region
|
||||
};
|
||||
|
||||
inline void regionSelectionPicker(SelectedRegion *region, bool showHeader = true, bool firstEntry = false) {
|
||||
inline void regionSelectionPicker(Region *region, prv::Provider *provider, RegionType *type, bool showHeader = true, bool firstEntry = false) {
|
||||
if (showHeader)
|
||||
ImGui::Header("hex.builtin.common.range"_lang, firstEntry);
|
||||
|
||||
if (ImGui::RadioButton("hex.builtin.common.range.entire_data"_lang, *region == SelectedRegion::EntireData))
|
||||
*region = SelectedRegion::EntireData;
|
||||
if (ImGui::RadioButton("hex.builtin.common.range.selection"_lang, *region == SelectedRegion::Selection))
|
||||
*region = SelectedRegion::Selection;
|
||||
if (ImGui::RadioButton("hex.builtin.common.range.entire_data"_lang, *type == RegionType::EntireData)) {
|
||||
*region = { provider->getBaseAddress(), provider->getActualSize() };
|
||||
*type = RegionType::EntireData;
|
||||
}
|
||||
if (ImGui::RadioButton("hex.builtin.common.range.selection"_lang, *type == RegionType::Selection)) {
|
||||
*region = ImHexApi::HexEditor::getSelection().value_or(ImHexApi::HexEditor::ProviderRegion { { 0, 1 }, provider });
|
||||
*type = RegionType::Selection;
|
||||
}
|
||||
if (ImGui::RadioButton("hex.builtin.common.region"_lang, *type == RegionType::Region)) {
|
||||
*type = RegionType::Region;
|
||||
}
|
||||
|
||||
if (*type == RegionType::Region) {
|
||||
ImGui::SameLine();
|
||||
|
||||
const auto width = ImGui::GetContentRegionAvail().x / 2 - ImGui::CalcTextSize(" - ").x / 2 - ImGui::GetStyle().FramePadding.x * 4;
|
||||
u64 start = region->getStartAddress(), end = region->getEndAddress();
|
||||
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputHexadecimal("##start", &start);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(" - ");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputHexadecimal("##end", &end);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
*region = { start, (end - start) + 1 };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -92,21 +92,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::InputHexadecimal("hex.builtin.view.disassembler.base"_lang, &this->m_baseAddress, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
|
||||
ui::regionSelectionPicker(&this->m_range);
|
||||
switch (this->m_range) {
|
||||
case ui::SelectedRegion::Selection: {
|
||||
auto region = ImHexApi::HexEditor::getSelection();
|
||||
if (region.has_value()) {
|
||||
this->m_codeRegion = region.value();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ui::SelectedRegion::EntireData: {
|
||||
auto base = provider->getBaseAddress();
|
||||
this->m_codeRegion = { base, base + provider->getActualSize() - 1 };
|
||||
}
|
||||
break;
|
||||
}
|
||||
ui::regionSelectionPicker(&this->m_codeRegion, provider, &this->m_range);
|
||||
|
||||
|
||||
if (ImGui::IsItemEdited()) {
|
||||
// Force execution of Region Selection Event
|
||||
|
@ -486,14 +486,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void ViewFind::runSearch() {
|
||||
Region searchRegion = [this]{
|
||||
if (this->m_searchSettings.range == ui::SelectedRegion::EntireData || !ImHexApi::HexEditor::isSelectionValid()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
return Region { provider->getBaseAddress(), provider->getActualSize() };
|
||||
} else {
|
||||
return ImHexApi::HexEditor::getSelection()->getRegion();
|
||||
}
|
||||
}();
|
||||
Region searchRegion = this->m_searchSettings.region;
|
||||
|
||||
this->m_searchTask = TaskManager::createTask("hex.builtin.view.find.searching", searchRegion.getSize(), [this, settings = this->m_searchSettings, searchRegion](auto &task) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
@ -596,7 +589,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImGui::BeginDisabled(this->m_searchTask.isRunning());
|
||||
{
|
||||
ui::regionSelectionPicker(&this->m_searchSettings.range, true, true);
|
||||
ui::regionSelectionPicker(&this->m_searchSettings.region, provider, &this->m_searchSettings.range, true, true);
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/magic.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
@ -69,21 +68,14 @@ namespace hex::plugin::builtin {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if ((this->m_inputChunkSize <= 0)
|
||||
|| (this->m_inputStartAddress >= this->m_inputEndAddress)
|
||||
|| ((size_t) this->m_inputEndAddress > provider->getActualSize())) {
|
||||
|| (this->m_analyzedRegion.getStartAddress() >= this->m_analyzedRegion.getEndAddress())
|
||||
|| (this->m_analyzedRegion.getEndAddress() > provider->getActualSize())) {
|
||||
// Invalid parameters, set default one
|
||||
this->m_inputChunkSize = 256;
|
||||
this->m_inputStartAddress = 0;
|
||||
this->m_inputEndAddress = provider->getActualSize();
|
||||
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getActualSize() };
|
||||
}
|
||||
|
||||
task.setMaxValue(this->m_inputEndAddress - this->m_inputStartAddress);
|
||||
|
||||
// Modify the analyzed region
|
||||
this->m_analyzedRegion = {
|
||||
provider->getBaseAddress() + this->m_inputStartAddress,
|
||||
size_t(this->m_inputEndAddress - this->m_inputStartAddress)
|
||||
};
|
||||
task.setMaxValue(this->m_analyzedRegion.getSize());
|
||||
|
||||
{
|
||||
magic::compile();
|
||||
@ -102,17 +94,18 @@ namespace hex::plugin::builtin {
|
||||
// Setup / start each analysis
|
||||
|
||||
this->m_byteDistribution.reset();
|
||||
this->m_digram.reset(this->m_inputEndAddress - this->m_inputStartAddress);
|
||||
this->m_layeredDistribution.reset(this->m_inputEndAddress - this->m_inputStartAddress);
|
||||
this->m_byteTypesDistribution.reset(this->m_inputStartAddress, this->m_inputEndAddress,
|
||||
provider->getBaseAddress(), provider->getActualSize());
|
||||
this->m_chunkBasedEntropy.reset(this->m_inputChunkSize, this->m_inputStartAddress, this->m_inputEndAddress,
|
||||
this->m_digram.reset(this->m_analysisRegion.getSize());
|
||||
this->m_layeredDistribution.reset(this->m_analysisRegion.getSize());
|
||||
this->m_byteTypesDistribution.reset(this->m_analysisRegion.getStartAddress(), this->m_analysisRegion.getEndAddress(), provider->getBaseAddress(), provider->getActualSize());
|
||||
this->m_chunkBasedEntropy.reset(this->m_inputChunkSize, this->m_analysisRegion.getStartAddress(), this->m_analysisRegion.getEndAddress(),
|
||||
provider->getBaseAddress(), provider->getActualSize());
|
||||
|
||||
// Create a handle to the file
|
||||
auto reader = prv::ProviderReader(provider);
|
||||
reader.seek(provider->getBaseAddress() + this->m_inputStartAddress);
|
||||
reader.setEndAddress(provider->getBaseAddress() + this->m_inputEndAddress);
|
||||
reader.seek(this->m_analysisRegion.getStartAddress());
|
||||
reader.setEndAddress(this->m_analysisRegion.getEndAddress());
|
||||
|
||||
this->m_analyzedRegion = this->m_analysisRegion;
|
||||
|
||||
u64 count = 0;
|
||||
|
||||
@ -128,7 +121,7 @@ namespace hex::plugin::builtin {
|
||||
task.update(count);
|
||||
}
|
||||
|
||||
this->m_averageEntropy = this->m_chunkBasedEntropy.calculateEntropy(this->m_byteDistribution.get(), this->m_inputEndAddress - this->m_inputStartAddress);
|
||||
this->m_averageEntropy = this->m_chunkBasedEntropy.calculateEntropy(this->m_byteDistribution.get(), this->m_analyzedRegion.getSize());
|
||||
this->m_highestBlockEntropy = this->m_chunkBasedEntropy.getHighestEntropyBlockValue();
|
||||
this->m_highestBlockEntropyAddress = this->m_chunkBasedEntropy.getHighestEntropyBlockAddress();
|
||||
this->m_lowestBlockEntropy = this->m_chunkBasedEntropy.getLowestEntropyBlockValue();
|
||||
@ -150,11 +143,7 @@ namespace hex::plugin::builtin {
|
||||
{
|
||||
ImGui::Header("hex.builtin.common.settings"_lang, true);
|
||||
|
||||
const u64 min = 0;
|
||||
const u64 max = provider->getActualSize();
|
||||
ImGui::SliderScalar("hex.builtin.common.begin"_lang, ImGuiDataType_U64, &this->m_inputStartAddress, &min, &max, "0x%02llX", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::SliderScalar("hex.builtin.common.end"_lang, ImGuiDataType_U64, &this->m_inputEndAddress, &min, &max, "0x%02llX", ImGuiSliderFlags_AlwaysClamp);
|
||||
|
||||
ui::regionSelectionPicker(&this->m_analysisRegion, provider, &this->m_selectionType, false);
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::InputInt("hex.builtin.view.information.block_size"_lang, &this->m_inputChunkSize, ImGuiInputTextFlags_CharsDecimal);
|
||||
|
Loading…
x
Reference in New Issue
Block a user