2020-11-15 00:46:38 +01:00
|
|
|
#include "views/view_tools.hpp"
|
|
|
|
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#include <cstring>
|
2020-11-15 21:31:04 +01:00
|
|
|
#include <regex>
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2020-11-23 16:19:58 +01:00
|
|
|
#include "utils.hpp"
|
|
|
|
|
2020-11-15 00:46:38 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
ViewTools::ViewTools() : View("Tools") {
|
2020-11-15 21:31:04 +01:00
|
|
|
this->m_mangledBuffer = new char[0xF'FFFF];
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2020-11-15 21:31:04 +01:00
|
|
|
std::memset(this->m_mangledBuffer, 0x00, 0xF'FFFF);
|
2020-11-24 02:59:49 +01:00
|
|
|
this->m_demangledName = "< ??? >";
|
2020-11-15 21:31:04 +01:00
|
|
|
|
|
|
|
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);
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewTools::~ViewTools() {
|
|
|
|
delete[] this->m_mangledBuffer;
|
2020-11-15 21:31:04 +01:00
|
|
|
|
|
|
|
delete[] this->m_regexInput;
|
|
|
|
delete[] this->m_regexPattern;
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
|
2020-11-15 02:50:56 +01:00
|
|
|
void ViewTools::drawDemangler() {
|
|
|
|
if (ImGui::CollapsingHeader("Itanium demangler")) {
|
2020-11-15 21:31:04 +01:00
|
|
|
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) {
|
2020-11-24 02:59:49 +01:00
|
|
|
this->m_demangledName = demangleItaniumSymbol(this->m_mangledBuffer);
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 02:59:49 +01:00
|
|
|
ImGui::InputText("Demangled name", this->m_demangledName.data(), this->m_demangledName.size(), ImGuiInputTextFlags_ReadOnly);
|
2020-11-15 21:31:04 +01:00
|
|
|
ImGui::NewLine();
|
2020-11-15 02:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewTools::drawASCIITable() {
|
|
|
|
if (ImGui::CollapsingHeader("ASCII table")) {
|
|
|
|
ImGui::BeginTable("##asciitable", 4);
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
for (u8 tablePart = 0; tablePart < 4; tablePart++) {
|
|
|
|
ImGui::BeginTable("##asciitablepart", this->m_asciiTableShowOctal ? 4 : 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg);
|
|
|
|
ImGui::TableSetupColumn("dec");
|
|
|
|
if (this->m_asciiTableShowOctal)
|
|
|
|
ImGui::TableSetupColumn("oct");
|
|
|
|
ImGui::TableSetupColumn("hex");
|
|
|
|
ImGui::TableSetupColumn("char");
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
u32 rowCount = 0;
|
|
|
|
for (u8 i = 0; i < 0x80 / 4; i++) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("%02d", i + 32 * tablePart);
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2020-11-15 02:50:56 +01:00
|
|
|
if (this->m_asciiTableShowOctal) {
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("0o%02o", i + 32 * tablePart);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("0x%02x", i + 32 * tablePart);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2020-11-23 16:19:58 +01:00
|
|
|
ImGui::Text("%s", makePrintable(i + 32 * tablePart).c_str());
|
2020-11-15 02:50:56 +01:00
|
|
|
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, ((rowCount % 2) == 0) ? 0xFF101010 : 0xFF303030);
|
|
|
|
|
|
|
|
rowCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
}
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
|
|
|
ImGui::Checkbox("Show octal", &this->m_asciiTableShowOctal);
|
2020-11-15 21:31:04 +01:00
|
|
|
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")) {
|
2020-11-24 00:01:44 +01:00
|
|
|
ImGui::SetNextItemWidth(300.0F);
|
2020-11-15 21:31:04 +01:00
|
|
|
ImGui::ColorPicker4("Color Picker", this->m_pickedColor.data(),
|
|
|
|
ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHex);
|
|
|
|
ImGui::NewLine();
|
2020-11-15 02:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewTools::createView() {
|
2020-11-23 23:57:19 +01:00
|
|
|
if (ImGui::Begin("Tools", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2020-11-15 02:50:56 +01:00
|
|
|
this->drawDemangler();
|
|
|
|
this->drawASCIITable();
|
2020-11-15 21:31:04 +01:00
|
|
|
this->drawRegexReplacer();
|
|
|
|
this->drawColorPicker();
|
2020-11-15 00:46:38 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewTools::createMenu() {
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|