mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
Added regex replacer and color picker to tools window
This commit is contained in:
@@ -4,11 +4,9 @@
|
||||
|
||||
#include "imgui.h"
|
||||
#include "views/view.hpp"
|
||||
#include "views/pattern_data.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <cstdio>
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace hex {
|
||||
|
||||
@@ -30,8 +28,17 @@ namespace hex {
|
||||
|
||||
bool m_asciiTableShowOctal = false;
|
||||
|
||||
char *m_regexInput = nullptr;
|
||||
char *m_regexPattern = nullptr;
|
||||
char *m_replacePattern = nullptr;
|
||||
std::string m_regexOutput;
|
||||
|
||||
std::array<float, 4> m_pickedColor;
|
||||
|
||||
void drawDemangler();
|
||||
void drawASCIITable();
|
||||
void drawRegexReplacer();
|
||||
void drawColorPicker();
|
||||
};
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace hex {
|
||||
};
|
||||
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(450, 300), ImVec2(2000, 1000));
|
||||
if (ImGui::BeginPopupModal("PatternLanguage", &this->m_patternHelpWindowOpen)) {
|
||||
if (ImGui::BeginPopupModal("Pattern Language Cheat Sheet", &this->m_patternHelpWindowOpen)) {
|
||||
ImGui::Text("ImHex Pattern Language Cheat Sheet");
|
||||
ImGui::Separator();
|
||||
ImGui::NewLine();
|
||||
|
||||
@@ -2,20 +2,31 @@
|
||||
|
||||
#include <cxxabi.h>
|
||||
#include <cstring>
|
||||
#include <regex>
|
||||
|
||||
namespace hex {
|
||||
|
||||
ViewTools::ViewTools() {
|
||||
this->m_mangledBuffer = new char[0xFF'FFFF];
|
||||
this->m_mangledBuffer = new char[0xF'FFFF];
|
||||
this->m_demangledName = static_cast<char*>(malloc(8));
|
||||
|
||||
std::memset(this->m_mangledBuffer, 0xFF'FFFF, 0x00);
|
||||
std::memset(this->m_mangledBuffer, 0x00, 0xF'FFFF);
|
||||
strcpy(this->m_demangledName, "< ??? >");
|
||||
|
||||
this->m_regexInput = new char[0xF'FFFF];
|
||||
this->m_regexPattern = new char[0xF'FFFF];
|
||||
this->m_replacePattern = new char[0xF'FFFF];
|
||||
std::memset(this->m_regexInput, 0x00, 0xF'FFFF);
|
||||
std::memset(this->m_regexPattern, 0x00, 0xF'FFFF);
|
||||
std::memset(this->m_replacePattern, 0x00, 0xF'FFFF);
|
||||
}
|
||||
|
||||
ViewTools::~ViewTools() {
|
||||
delete[] this->m_mangledBuffer;
|
||||
free(this->m_demangledName);
|
||||
|
||||
delete[] this->m_regexInput;
|
||||
delete[] this->m_regexPattern;
|
||||
}
|
||||
|
||||
static std::string toASCIITableString(char c) {
|
||||
@@ -60,7 +71,7 @@ namespace hex {
|
||||
|
||||
void ViewTools::drawDemangler() {
|
||||
if (ImGui::CollapsingHeader("Itanium demangler")) {
|
||||
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xFF'FFFF)) {
|
||||
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) {
|
||||
size_t length = 0;
|
||||
int status = 0;
|
||||
|
||||
@@ -76,6 +87,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
ImGui::InputText("Demangled name", this->m_demangledName, strlen(this->m_demangledName), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +140,36 @@ namespace hex {
|
||||
ImGui::EndTable();
|
||||
|
||||
ImGui::Checkbox("Show octal", &this->m_asciiTableShowOctal);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawRegexReplacer() {
|
||||
if (ImGui::CollapsingHeader("Regex replacer")) {
|
||||
bool shouldInvalidate;
|
||||
|
||||
shouldInvalidate = ImGui::InputText("Regex pattern", this->m_regexPattern, 0xF'FFFF);
|
||||
shouldInvalidate = ImGui::InputText("Replace pattern", this->m_replacePattern, 0xF'FFFF) || shouldInvalidate;
|
||||
shouldInvalidate = ImGui::InputTextMultiline("Input", this->m_regexInput, 0xF'FFFF) || shouldInvalidate;
|
||||
|
||||
if (shouldInvalidate) {
|
||||
try {
|
||||
this->m_regexOutput = std::regex_replace(this->m_regexInput, std::regex(this->m_regexPattern), this->m_replacePattern);
|
||||
} catch (std::regex_error&) {}
|
||||
}
|
||||
|
||||
ImGui::InputTextMultiline("Output", this->m_regexOutput.data(), this->m_regexOutput.size(), ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::NewLine();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawColorPicker() {
|
||||
if (ImGui::CollapsingHeader("Color picker")) {
|
||||
ImGui::ColorPicker4("Color Picker", this->m_pickedColor.data(),
|
||||
ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHex);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +181,8 @@ namespace hex {
|
||||
|
||||
this->drawDemangler();
|
||||
this->drawASCIITable();
|
||||
this->drawRegexReplacer();
|
||||
this->drawColorPicker();
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
Reference in New Issue
Block a user