Various fixes and improvements
This commit is contained in:
parent
df06dd49c5
commit
460d5a9386
@ -37,8 +37,8 @@ namespace hex {
|
||||
|
||||
std::map<u64, u32> m_highlightedBytes;
|
||||
|
||||
char m_searchStringBuffer[0xFFFF] = { 0 };
|
||||
char m_searchHexBuffer[0xFFFF] = { 0 };
|
||||
std::vector<char> m_searchStringBuffer;
|
||||
std::vector<char> m_searchHexBuffer;
|
||||
SearchFunction m_searchFunction = nullptr;
|
||||
std::vector<std::pair<u64, u64>> *m_lastSearchBuffer;
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace hex {
|
||||
|
||||
std::vector<FoundString> m_foundStrings;
|
||||
int m_minimumLength = 5;
|
||||
char *m_filter;
|
||||
std::vector<char> m_filter;
|
||||
|
||||
std::string m_selectedString;
|
||||
std::string m_demangledName;
|
||||
|
@ -122,21 +122,21 @@ namespace hex {
|
||||
}
|
||||
|
||||
std::string toEngineeringString(double value) {
|
||||
constexpr std::array prefixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
|
||||
constexpr std::array Suffixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
|
||||
|
||||
int8_t prefixIndex = 6;
|
||||
int8_t suffixIndex = 6;
|
||||
|
||||
while (prefixIndex != 0 && prefixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
|
||||
while (suffixIndex != 0 && suffixIndex != 12 && (value >= 1000 || value < 1) && value != 0) {
|
||||
if (value >= 1000) {
|
||||
value /= 1000;
|
||||
prefixIndex++;
|
||||
suffixIndex++;
|
||||
} else if (value < 1) {
|
||||
value *= 1000;
|
||||
prefixIndex--;
|
||||
suffixIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
return std::to_string(value).substr(0, 5) + prefixes[prefixIndex];
|
||||
return std::to_string(value).substr(0, 5) + Suffixes[suffixIndex];
|
||||
}
|
||||
|
||||
std::vector<u8> readFile(std::string_view path) {
|
||||
|
@ -40,7 +40,6 @@ namespace hex {
|
||||
}
|
||||
|
||||
void View::drawCommonInterfaces() {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10));
|
||||
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
|
||||
ImGui::NewLine();
|
||||
@ -50,7 +49,6 @@ namespace hex {
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (SharedData::fileBrowser.showFileDialog(SharedData::fileBrowserTitle, SharedData::fileBrowserDialogMode, ImVec2(0, 0), SharedData::fileBrowserValidExtensions)) {
|
||||
SharedData::fileBrowserCallback(SharedData::fileBrowser.selected_path);
|
||||
@ -61,7 +59,7 @@ namespace hex {
|
||||
void View::showErrorPopup(std::string_view errorMessage) {
|
||||
SharedData::errorPopupMessage = errorMessage;
|
||||
|
||||
ImGui::OpenPopup("Error");
|
||||
View::doLater([] { ImGui::OpenPopup("Error"); });
|
||||
}
|
||||
|
||||
bool View::hasViewMenuItemEntry() {
|
||||
|
@ -19,6 +19,9 @@ namespace hex {
|
||||
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData)
|
||||
: View("hex.view.hexeditor.title"_lang), m_patternData(patternData) {
|
||||
|
||||
this->m_searchStringBuffer.resize(0xFFF, 0x00);
|
||||
this->m_searchHexBuffer.resize(0xFFF, 0x00);
|
||||
|
||||
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (!provider->isAvailable() || !provider->isReadable())
|
||||
@ -952,13 +955,13 @@ R"(
|
||||
if (ImGui::BeginPopupContextVoid("hex.view.hexeditor.menu.file.search"_lang)) {
|
||||
ImGui::TextUnformatted("hex.view.hexeditor.menu.file.search"_lang);
|
||||
if (ImGui::BeginTabBar("searchTabs")) {
|
||||
char *currBuffer;
|
||||
std::vector<char> *currBuffer = nullptr;
|
||||
if (ImGui::BeginTabItem("hex.view.hexeditor.search.string"_lang)) {
|
||||
this->m_searchFunction = findString;
|
||||
this->m_lastSearchBuffer = &this->m_lastStringSearch;
|
||||
currBuffer = this->m_searchStringBuffer;
|
||||
currBuffer = &this->m_searchStringBuffer;
|
||||
|
||||
ImGui::InputText("##nolabel", currBuffer, 0xFFFF, ImGuiInputTextFlags_CallbackCompletion,
|
||||
ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(), ImGuiInputTextFlags_CallbackCompletion,
|
||||
InputCallback, this);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
@ -966,16 +969,17 @@ R"(
|
||||
if (ImGui::BeginTabItem("hex.view.hexeditor.search.hex"_lang)) {
|
||||
this->m_searchFunction = findHex;
|
||||
this->m_lastSearchBuffer = &this->m_lastHexSearch;
|
||||
currBuffer = this->m_searchHexBuffer;
|
||||
currBuffer = &this->m_searchHexBuffer;
|
||||
|
||||
ImGui::InputText("##nolabel", currBuffer, 0xFFFF,
|
||||
ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(),
|
||||
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CallbackCompletion,
|
||||
InputCallback, this);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (currBuffer != nullptr) {
|
||||
if (ImGui::Button("hex.view.hexeditor.search.find"_lang))
|
||||
Find(currBuffer);
|
||||
Find(currBuffer->data());
|
||||
|
||||
if (this->m_lastSearchBuffer->size() > 0) {
|
||||
if ((ImGui::Button("hex.view.hexeditor.search.find_next"_lang)))
|
||||
@ -986,6 +990,7 @@ R"(
|
||||
if ((ImGui::Button("hex.view.hexeditor.search.find_prev"_lang)))
|
||||
FindPrevious();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
@ -16,13 +16,11 @@ namespace hex {
|
||||
this->m_foundStrings.clear();
|
||||
});
|
||||
|
||||
this->m_filter = new char[0xFFFF];
|
||||
std::memset(this->m_filter, 0x00, 0xFFFF);
|
||||
this->m_filter.resize(0xFFFF, 0x00);
|
||||
}
|
||||
|
||||
ViewStrings::~ViewStrings() {
|
||||
View::unsubscribeEvent(Events::DataChanged);
|
||||
delete[] this->m_filter;
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +87,7 @@ namespace hex {
|
||||
if (ImGui::InputInt("hex.view.strings.min_length"_lang, &this->m_minimumLength, 1, 0))
|
||||
this->m_shouldInvalidate = true;
|
||||
|
||||
ImGui::InputText("hex.view.strings.filter"_lang, this->m_filter, 0xFFFF);
|
||||
ImGui::InputText("hex.view.strings.filter"_lang, this->m_filter.data(), this->m_filter.size());
|
||||
if (ImGui::Button("hex.view.strings.extract"_lang))
|
||||
this->m_shouldInvalidate = true;
|
||||
|
||||
@ -109,17 +107,17 @@ namespace hex {
|
||||
if (sortSpecs->SpecsDirty) {
|
||||
std::sort(this->m_foundStrings.begin(), this->m_foundStrings.end(),
|
||||
[&sortSpecs](FoundString &left, FoundString &right) -> bool {
|
||||
if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.offset"_lang)) {
|
||||
if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("offset")) {
|
||||
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
|
||||
return left.offset > right.offset;
|
||||
else
|
||||
return left.offset < right.offset;
|
||||
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.size"_lang)) {
|
||||
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("size")) {
|
||||
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
|
||||
return left.size > right.size;
|
||||
else
|
||||
return left.size < right.size;
|
||||
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.string"_lang)) {
|
||||
} else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("string")) {
|
||||
if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending)
|
||||
return left.string > right.string;
|
||||
else
|
||||
@ -141,8 +139,8 @@ namespace hex {
|
||||
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
auto &foundString = this->m_foundStrings[i];
|
||||
|
||||
if (strlen(this->m_filter) != 0 &&
|
||||
foundString.string.find(this->m_filter) == std::string::npos)
|
||||
if (strlen(this->m_filter.data()) != 0 &&
|
||||
foundString.string.find(this->m_filter.data()) == std::string::npos)
|
||||
continue;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
@ -172,7 +170,7 @@ namespace hex {
|
||||
|
||||
if (ImGui::BeginPopup("hex.view.strings.demangle.title"_lang)) {
|
||||
if (ImGui::BeginChild("##scrolling", ImVec2(500, 150))) {
|
||||
ImGui::Text("hex.view.strings.demangle.title"_lang);
|
||||
ImGui::TextUnformatted("hex.view.strings.demangle.title"_lang);
|
||||
ImGui::Separator();
|
||||
ImGui::TextWrapped("%s", this->m_demangledName.c_str());
|
||||
ImGui::EndChild();
|
||||
|
Loading…
Reference in New Issue
Block a user