2020-11-10 20:31:04 +00:00
|
|
|
#include "views/view_hexeditor.hpp"
|
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/providers/provider.hpp>
|
2021-01-20 19:16:24 +00:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-02-03 10:54:41 +00:00
|
|
|
#include <hex/helpers/crypto.hpp>
|
2020-11-11 08:18:35 +00:00
|
|
|
|
2020-11-11 13:42:01 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2021-02-03 10:54:41 +00:00
|
|
|
#include "providers/file_provider.hpp"
|
2020-11-28 20:55:52 +00:00
|
|
|
#include "helpers/patches.hpp"
|
2020-11-29 23:03:12 +00:00
|
|
|
#include "helpers/project_file_handler.hpp"
|
2020-12-01 01:21:40 +00:00
|
|
|
#include "helpers/loader_script_handler.hpp"
|
2020-11-24 01:00:22 +00:00
|
|
|
|
|
|
|
#undef __STRICT_ANSI__
|
|
|
|
#include <cstdio>
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
namespace hex {
|
|
|
|
|
2021-01-20 19:16:24 +00:00
|
|
|
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData)
|
2021-02-11 22:09:45 +00:00
|
|
|
: View("hex.view.hexeditor.title"_lang), m_patternData(patternData) {
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
this->m_searchStringBuffer.resize(0xFFF, 0x00);
|
|
|
|
this->m_searchHexBuffer.resize(0xFFF, 0x00);
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
if (!provider->isAvailable() || !provider->isReadable())
|
2020-11-10 20:31:04 +00:00
|
|
|
return 0x00;
|
|
|
|
|
|
|
|
ImU8 byte;
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(off, &byte, sizeof(ImU8));
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2021-01-30 21:39:06 +00:00
|
|
|
for (auto &overlay : SharedData::currentProvider->getOverlays()) {
|
|
|
|
auto overlayAddress = overlay->getAddress();
|
|
|
|
if (off >= overlayAddress && off < overlayAddress + overlay->getSize())
|
|
|
|
byte = overlay->getData()[off - overlayAddress];
|
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
return byte;
|
|
|
|
};
|
|
|
|
|
|
|
|
this->m_memoryEditor.WriteFn = [](ImU8 *data, size_t off, ImU8 d) -> void {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
if (!provider->isAvailable() || !provider->isWritable())
|
2020-11-10 20:31:04 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->write(off, &d, sizeof(ImU8));
|
|
|
|
View::postEvent(Events::DataChanged);
|
2020-11-29 23:03:12 +00:00
|
|
|
ProjectFile::markDirty();
|
2020-11-10 20:31:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this->m_memoryEditor.HighlightFn = [](const ImU8 *data, size_t off, bool next) -> bool {
|
|
|
|
ViewHexEditor *_this = (ViewHexEditor *) data;
|
|
|
|
|
2021-01-03 01:37:37 +00:00
|
|
|
std::optional<u32> currColor, prevColor;
|
2021-01-13 13:11:23 +00:00
|
|
|
|
2021-02-17 13:57:32 +00:00
|
|
|
off += SharedData::currentProvider->getBaseAddress();
|
|
|
|
|
2021-01-20 19:16:24 +00:00
|
|
|
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
|
2021-01-13 13:11:23 +00:00
|
|
|
if (off >= region.address && off < (region.address + region.size))
|
2021-01-20 17:10:40 +00:00
|
|
|
currColor = (color & 0x00FFFFFF) | 0x80000000;
|
2021-01-13 13:11:23 +00:00
|
|
|
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
|
2021-01-20 17:10:40 +00:00
|
|
|
prevColor = (color & 0x00FFFFFF) | 0x80000000;
|
2021-01-13 13:11:23 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 17:10:40 +00:00
|
|
|
if (_this->m_highlightedBytes.contains(off)) {
|
|
|
|
auto color = (_this->m_highlightedBytes[off] & 0x00FFFFFF) | 0x80000000;
|
|
|
|
currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color;
|
|
|
|
}
|
|
|
|
if (_this->m_highlightedBytes.contains(off - 1)) {
|
|
|
|
auto color = (_this->m_highlightedBytes[off - 1] & 0x00FFFFFF) | 0x80000000;
|
|
|
|
prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, prevColor.value()) : color;
|
|
|
|
}
|
2021-01-03 01:37:37 +00:00
|
|
|
|
|
|
|
if (next && prevColor != currColor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-20 17:10:40 +00:00
|
|
|
if (currColor.has_value() && (currColor.value() & 0x00FFFFFF) != 0x00) {
|
|
|
|
_this->m_memoryEditor.HighlightColor = (currColor.value() & 0x00FFFFFF) | 0x40000000;
|
2021-01-03 01:37:37 +00:00
|
|
|
return true;
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 21:34:56 +00:00
|
|
|
_this->m_memoryEditor.HighlightColor = 0x60C08080;
|
2020-11-10 20:31:04 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-11-17 12:58:50 +00:00
|
|
|
|
2021-02-17 13:57:32 +00:00
|
|
|
this->m_memoryEditor.HoverFn = [](const ImU8 *data, size_t off) {
|
2021-01-13 15:45:31 +00:00
|
|
|
bool tooltipShown = false;
|
|
|
|
|
2021-02-17 13:57:32 +00:00
|
|
|
off += SharedData::currentProvider->getBaseAddress();
|
|
|
|
|
2021-01-20 19:16:24 +00:00
|
|
|
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
|
2021-02-17 13:57:32 +00:00
|
|
|
if (off >= region.address && off < (region.address + region.size)) {
|
2021-01-13 15:45:31 +00:00
|
|
|
if (!tooltipShown) {
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
tooltipShown = true;
|
|
|
|
}
|
|
|
|
ImGui::ColorButton(name.data(), ImColor(color).Value);
|
|
|
|
ImGui::SameLine(0, 10);
|
|
|
|
ImGui::TextUnformatted(name.data());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tooltipShown)
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
};
|
|
|
|
|
2021-02-14 00:11:55 +00:00
|
|
|
this->m_memoryEditor.DecodeFn = [](const ImU8 *data, size_t addr) -> MemoryEditor::DecodeData {
|
|
|
|
ViewHexEditor *_this = (ViewHexEditor *) data;
|
|
|
|
|
|
|
|
if (_this->m_currEncodingFile.getLongestSequence() == 0)
|
|
|
|
return { ".", 1, 0xFFFF8000 };
|
|
|
|
|
|
|
|
auto &provider = SharedData::currentProvider;
|
|
|
|
size_t size = std::min<size_t>(_this->m_currEncodingFile.getLongestSequence(), provider->getActualSize() - addr);
|
|
|
|
|
|
|
|
std::vector<u8> buffer(size);
|
|
|
|
provider->read(addr, buffer.data(), size);
|
|
|
|
|
|
|
|
auto [decoded, advance] = _this->m_currEncodingFile.getEncodingFor(buffer);
|
|
|
|
|
|
|
|
ImColor color;
|
|
|
|
if (decoded.length() == 1 && std::isalnum(decoded[0])) color = 0xFFFF8000;
|
|
|
|
else if (decoded.length() == 1 && advance == 1) color = 0xFF0000FF;
|
|
|
|
else if (decoded.length() > 1 && advance == 1) color = 0xFF00FFFF;
|
|
|
|
else if (advance > 1) color = 0xFFFFFFFF;
|
|
|
|
else color = 0xFFFF8000;
|
|
|
|
|
|
|
|
return { std::string(decoded), advance, color };
|
|
|
|
};
|
|
|
|
|
2021-01-21 09:53:12 +00:00
|
|
|
View::subscribeEvent(Events::FileDropped, [this](auto userData) {
|
|
|
|
auto filePath = std::any_cast<const char*>(userData);
|
2020-11-17 12:58:50 +00:00
|
|
|
|
|
|
|
if (filePath != nullptr)
|
|
|
|
this->openFile(filePath);
|
|
|
|
});
|
2020-11-23 12:10:14 +00:00
|
|
|
|
2021-01-21 09:53:12 +00:00
|
|
|
View::subscribeEvent(Events::SelectionChangeRequest, [this](auto userData) {
|
|
|
|
const Region ®ion = std::any_cast<Region>(userData);
|
2020-11-23 12:10:14 +00:00
|
|
|
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
auto page = provider->getPageOfAddress(region.address);
|
2020-11-23 12:10:14 +00:00
|
|
|
if (!page.has_value())
|
|
|
|
return;
|
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->setCurrentPage(page.value());
|
2020-11-23 12:10:14 +00:00
|
|
|
this->m_memoryEditor.GotoAddr = region.address;
|
|
|
|
this->m_memoryEditor.DataPreviewAddr = region.address;
|
|
|
|
this->m_memoryEditor.DataPreviewAddrEnd = region.address + region.size - 1;
|
2021-01-21 09:53:12 +00:00
|
|
|
View::postEvent(Events::RegionSelected, region);
|
2020-11-23 12:10:14 +00:00
|
|
|
});
|
2020-11-29 23:03:12 +00:00
|
|
|
|
2021-01-21 09:53:12 +00:00
|
|
|
View::subscribeEvent(Events::ProjectFileLoad, [this](auto) {
|
2020-11-29 23:03:12 +00:00
|
|
|
this->openFile(ProjectFile::getFilePath());
|
|
|
|
});
|
|
|
|
|
2021-01-21 09:53:12 +00:00
|
|
|
View::subscribeEvent(Events::WindowClosing, [this](auto userData) {
|
|
|
|
auto window = std::any_cast<GLFWwindow*>(userData);
|
2020-11-29 23:03:12 +00:00
|
|
|
|
|
|
|
if (ProjectFile::hasUnsavedChanges()) {
|
|
|
|
glfwSetWindowShouldClose(window, GLFW_FALSE);
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([] { ImGui::OpenPopup("hex.view.hexeditor.save_changes"_lang); });
|
2020-11-29 23:03:12 +00:00
|
|
|
}
|
|
|
|
});
|
2021-01-03 01:37:37 +00:00
|
|
|
|
2021-01-21 09:53:12 +00:00
|
|
|
View::subscribeEvent(Events::PatternChanged, [this](auto) {
|
2021-01-27 13:26:24 +00:00
|
|
|
this->m_highlightedBytes.clear();
|
2021-01-03 01:37:37 +00:00
|
|
|
|
2021-01-27 13:26:24 +00:00
|
|
|
for (const auto &pattern : this->m_patternData)
|
|
|
|
this->m_highlightedBytes.merge(pattern->getHighlightedAddresses());
|
|
|
|
});
|
|
|
|
|
|
|
|
View::subscribeEvent(Events::OpenWindow, [this](auto name) {
|
|
|
|
if (std::any_cast<const char*>(name) == std::string("Open File")) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-27 13:26:24 +00:00
|
|
|
this->openFile(path);
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
2021-01-30 22:02:03 +00:00
|
|
|
} else if (std::any_cast<const char*>(name) == std::string("Open Project")) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.open_project"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".hexproj", [this](auto path) {
|
2021-01-30 22:02:03 +00:00
|
|
|
ProjectFile::load(path);
|
|
|
|
View::postEvent(Events::ProjectFileLoad);
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
2021-01-27 13:26:24 +00:00
|
|
|
}
|
2021-01-03 01:37:37 +00:00
|
|
|
});
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
ViewHexEditor::~ViewHexEditor() {
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
void ViewHexEditor::drawContent() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
|
|
|
size_t dataSize = (provider == nullptr || !provider->isReadable()) ? 0x00 : provider->getSize();
|
2020-11-12 08:38:52 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
this->m_memoryEditor.DrawWindow("hex.view.hexeditor.title"_lang, &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress());
|
2020-11-12 08:38:52 +00:00
|
|
|
|
|
|
|
if (dataSize != 0x00) {
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::Begin("hex.view.hexeditor.title"_lang)) {
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-01-30 21:39:06 +00:00
|
|
|
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::OpenPopup("hex.menu.edit"_lang);
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopup("hex.menu.edit"_lang)) {
|
2021-01-10 22:59:36 +00:00
|
|
|
this->drawEditPopup();
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-01-10 22:59:36 +00:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::SameLine();
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::Text("hex.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount());
|
2021-01-10 22:59:36 +00:00
|
|
|
ImGui::SameLine();
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-01-10 22:59:36 +00:00
|
|
|
if (ImGui::ArrowButton("prevPage", ImGuiDir_Left)) {
|
|
|
|
provider->setCurrentPage(provider->getCurrentPage() - 1);
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-01-10 22:59:36 +00:00
|
|
|
Region dataPreview = { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 };
|
2021-01-21 09:53:12 +00:00
|
|
|
View::postEvent(Events::RegionSelected, dataPreview);
|
2021-01-10 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::ArrowButton("nextPage", ImGuiDir_Right)) {
|
|
|
|
provider->setCurrentPage(provider->getCurrentPage() + 1);
|
2020-11-22 18:43:35 +00:00
|
|
|
|
2021-01-10 22:59:36 +00:00
|
|
|
Region dataPreview = { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 };
|
2021-01-21 09:53:12 +00:00
|
|
|
View::postEvent(Events::RegionSelected, dataPreview);
|
2021-01-10 22:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-22 18:43:35 +00:00
|
|
|
ImGui::End();
|
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
this->drawSearchPopup();
|
|
|
|
this->drawGotoPopup();
|
|
|
|
}
|
2021-02-07 13:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void save() {
|
|
|
|
auto provider = SharedData::currentProvider;
|
|
|
|
for (const auto &[address, value] : provider->getPatches())
|
|
|
|
provider->writeRaw(address, &value, sizeof(u8));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void saveAs() {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.save_as"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [](auto path) {
|
2021-02-07 13:29:13 +00:00
|
|
|
FILE *file = fopen(path.c_str(), "wb");
|
|
|
|
|
|
|
|
if (file != nullptr) {
|
|
|
|
std::vector<u8> buffer(0xFF'FFFF, 0x00);
|
|
|
|
size_t bufferSize = buffer.size();
|
|
|
|
|
|
|
|
fseek(file, 0, SEEK_SET);
|
2020-11-12 08:38:52 +00:00
|
|
|
|
2021-02-07 13:29:13 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
|
|
|
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
|
|
|
|
if (bufferSize > provider->getActualSize() - offset)
|
|
|
|
bufferSize = provider->getActualSize() - offset;
|
|
|
|
|
|
|
|
provider->read(offset, buffer.data(), bufferSize);
|
|
|
|
fwrite(buffer.data(), 1, bufferSize, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewHexEditor::drawAlwaysVisible() {
|
|
|
|
auto provider = SharedData::currentProvider;
|
2020-11-24 01:59:49 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopupModal("hex.view.hexeditor.save_changes.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
2020-11-29 23:03:12 +00:00
|
|
|
ImGui::NewLine();
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::TextUnformatted("hex.view.hexeditor.save_changes.desc"_lang);
|
2020-12-11 13:24:42 +00:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-02-01 18:03:45 +00:00
|
|
|
confirmButtons("Yes", "No", [] { View::postEvent(Events::CloseImHex); }, [] { ImGui::CloseCurrentPopup(); });
|
2021-01-14 16:01:44 +00:00
|
|
|
|
|
|
|
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
2020-11-29 23:03:12 +00:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopupModal("hex.view.hexeditor.script.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
2020-12-11 13:24:42 +00:00
|
|
|
ImGui::SetCursorPosX(10);
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::TextWrapped("hex.view.hexeditor.script.desc"_lang);
|
2020-12-01 01:21:40 +00:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::InputText("##nolabel", this->m_loaderScriptScriptPath.data(), this->m_loaderScriptScriptPath.length(), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::SameLine();
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::Button("hex.view.hexeditor.script.script"_lang)) {
|
|
|
|
View::openFileBrowser("hex.view.hexeditor.script.script.title"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".py", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
this->m_loaderScriptScriptPath = path;
|
|
|
|
});
|
|
|
|
}
|
2020-12-01 01:21:40 +00:00
|
|
|
ImGui::InputText("##nolabel", this->m_loaderScriptFilePath.data(), this->m_loaderScriptFilePath.length(), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::SameLine();
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::Button("hex.view.hexeditor.script.file"_lang)) {
|
|
|
|
View::openFileBrowser("hex.view.hexeditor.script.file.title"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
this->m_loaderScriptFilePath = path;
|
|
|
|
});
|
|
|
|
}
|
2021-01-14 16:01:44 +00:00
|
|
|
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
|
|
|
ImGui::CloseCurrentPopup();
|
2020-12-01 01:21:40 +00:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
confirmButtons("hex.common.load"_lang, "hex.common.cancel"_lang,
|
2021-02-07 13:29:13 +00:00
|
|
|
[this, &provider] {
|
|
|
|
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
|
|
|
|
this->openFile(this->m_loaderScriptFilePath);
|
|
|
|
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
|
|
|
|
LoaderScript::setDataProvider(provider);
|
|
|
|
LoaderScript::processFile(this->m_loaderScriptScriptPath);
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[] {
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
2020-12-11 13:24:42 +00:00
|
|
|
);
|
|
|
|
|
2020-12-01 01:21:40 +00:00
|
|
|
ImGui::EndPopup();
|
2020-12-11 13:24:42 +00:00
|
|
|
|
2020-12-01 01:21:40 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopupModal("hex.view.hexeditor.menu.edit.set_base"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
|
ImGui::InputText("hex.common.address"_lang, this->m_baseAddressBuffer, 16, ImGuiInputTextFlags_CharsHexadecimal);
|
2021-01-11 12:50:04 +00:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
confirmButtons("hex.common.set"_lang, "hex.common.cancel"_lang,
|
2021-02-07 13:29:13 +00:00
|
|
|
[this, &provider]{
|
|
|
|
provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16));
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}, []{
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
});
|
2021-01-11 12:50:04 +00:00
|
|
|
|
2021-01-14 16:01:44 +00:00
|
|
|
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
2021-01-11 12:50:04 +00:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2021-01-26 23:44:10 +00:00
|
|
|
}
|
2021-01-11 12:50:04 +00:00
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
void ViewHexEditor::drawMenu() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-11-24 01:00:22 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginMenu("hex.menu.file"_lang)) {
|
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) {
|
2021-01-26 23:44:10 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
this->openFile(path);
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
2020-11-24 01:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, provider != nullptr && provider->isWritable())) {
|
2021-01-26 23:44:10 +00:00
|
|
|
save();
|
2020-11-27 12:45:56 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_as"_lang, "CTRL + SHIFT + S", false, provider != nullptr && provider->isWritable())) {
|
2021-01-26 23:44:10 +00:00
|
|
|
saveAs();
|
2020-11-27 12:45:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 23:03:12 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.open_project"_lang, "")) {
|
|
|
|
View::openFileBrowser("hex.view.hexeditor.menu.file.open_project"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".hexproj", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
ProjectFile::load(path);
|
|
|
|
View::postEvent(Events::ProjectFileLoad);
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
2020-11-29 23:03:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_project"_lang, "", false, provider != nullptr && provider->isWritable())) {
|
2020-11-29 23:03:12 +00:00
|
|
|
View::postEvent(Events::ProjectFileStore);
|
|
|
|
|
2021-01-26 23:44:10 +00:00
|
|
|
if (ProjectFile::getProjectFilePath() == "") {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.save_project"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".hexproj", [](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
ProjectFile::store(path);
|
|
|
|
});
|
|
|
|
}
|
2020-11-29 23:03:12 +00:00
|
|
|
else
|
|
|
|
ProjectFile::store();
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:11:55 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.load_encoding_file"_lang)) {
|
|
|
|
View::openFileBrowser("hex.view.hexeditor.load_enconding_file"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
|
|
|
this->m_currEncodingFile = EncodingFile(EncodingFile::Type::Thingy, path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-29 23:03:12 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginMenu("hex.view.hexeditor.menu.file.import"_lang)) {
|
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.import.base64"_lang)) {
|
2021-01-26 23:44:10 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.menu.file.import.base64"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
std::vector<u8> base64;
|
|
|
|
this->loadFromFile(path, base64);
|
|
|
|
|
|
|
|
if (!base64.empty()) {
|
2021-02-02 22:11:23 +00:00
|
|
|
this->m_dataToSave = crypt::decode64(base64);
|
2021-01-26 23:44:10 +00:00
|
|
|
|
|
|
|
if (this->m_dataToSave.empty())
|
2021-02-11 22:09:45 +00:00
|
|
|
View::showErrorPopup("hex.view.hexeditor.base64.import_error"_lang);
|
2021-01-26 23:44:10 +00:00
|
|
|
else
|
2021-02-11 22:09:45 +00:00
|
|
|
ImGui::OpenPopup("hex.view.hexeditor.save_data"_lang);
|
2021-01-26 23:44:10 +00:00
|
|
|
this->getWindowOpenState() = true;
|
2021-02-11 22:09:45 +00:00
|
|
|
} else View::showErrorPopup("hex.view.hexeditor.file_open_error"_lang);
|
2021-01-26 23:44:10 +00:00
|
|
|
});
|
2020-11-24 01:00:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 14:09:36 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.import.ips"_lang)) {
|
2021-01-26 23:44:10 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
auto patchData = hex::readFile(path);
|
|
|
|
auto patch = hex::loadIPSPatch(patchData);
|
|
|
|
|
|
|
|
for (auto &[address, value] : patch) {
|
|
|
|
SharedData::currentProvider->write(address, &value, 1);
|
|
|
|
}
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-11-29 14:09:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.import.ips32"_lang)) {
|
|
|
|
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
auto patchData = hex::readFile(path);
|
|
|
|
auto patch = hex::loadIPS32Patch(patchData);
|
|
|
|
|
|
|
|
for (auto &[address, value] : patch) {
|
|
|
|
SharedData::currentProvider->write(address, &value, 1);
|
|
|
|
}
|
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
});
|
2020-11-29 14:09:36 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.import.script"_lang)) {
|
2020-12-01 01:21:40 +00:00
|
|
|
this->m_loaderScriptFilePath.clear();
|
|
|
|
this->m_loaderScriptScriptPath.clear();
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.script.title"_lang); });
|
2020-12-01 01:21:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 01:00:22 +00:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginMenu("hex.view.hexeditor.menu.file.export"_lang, provider != nullptr && provider->isWritable())) {
|
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.export.ips"_lang)) {
|
2020-12-27 14:39:06 +00:00
|
|
|
Patches patches = provider->getPatches();
|
2020-11-27 08:09:48 +00:00
|
|
|
if (!patches.contains(0x00454F45) && patches.contains(0x00454F46)) {
|
|
|
|
u8 value = 0;
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(0x00454F45, &value, sizeof(u8));
|
2020-11-27 08:09:48 +00:00
|
|
|
patches[0x00454F45] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_dataToSave = generateIPSPatch(patches);
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.menu.file.export.title"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
this->saveToFile(path, this->m_dataToSave);
|
|
|
|
});
|
2020-11-27 08:09:48 +00:00
|
|
|
}
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.export.ips32"_lang)) {
|
2020-12-27 14:39:06 +00:00
|
|
|
Patches patches = provider->getPatches();
|
2020-11-27 08:09:48 +00:00
|
|
|
if (!patches.contains(0x00454F45) && patches.contains(0x45454F46)) {
|
|
|
|
u8 value = 0;
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(0x45454F45, &value, sizeof(u8));
|
2020-11-27 08:09:48 +00:00
|
|
|
patches[0x45454F45] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_dataToSave = generateIPS32Patch(patches);
|
2021-02-11 22:09:45 +00:00
|
|
|
View::openFileBrowser("hex.view.hexeditor.menu.file.export.title"_lang, imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [this](auto path) {
|
2021-01-26 23:44:10 +00:00
|
|
|
this->saveToFile(path, this->m_dataToSave);
|
|
|
|
});
|
2020-11-27 08:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2020-11-27 12:45:56 +00:00
|
|
|
|
|
|
|
|
2020-11-24 01:00:22 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.search"_lang, "CTRL + F")) {
|
2020-11-29 00:17:54 +00:00
|
|
|
this->getWindowOpenState() = true;
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.search"_lang); });
|
2020-11-24 01:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.goto"_lang, "CTRL + G")) {
|
2020-11-29 00:17:54 +00:00
|
|
|
this->getWindowOpenState() = true;
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.goto"_lang); });
|
2020-11-24 01:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginMenu("hex.menu.edit"_lang)) {
|
2021-01-10 22:59:36 +00:00
|
|
|
this->drawEditPopup();
|
2020-11-24 01:00:22 +00:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewHexEditor::handleShortcut(int key, int mods) {
|
2020-11-27 12:45:56 +00:00
|
|
|
if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_S) {
|
2021-01-26 23:44:10 +00:00
|
|
|
save();
|
2020-11-27 12:45:56 +00:00
|
|
|
return true;
|
2020-11-29 23:03:12 +00:00
|
|
|
} else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == GLFW_KEY_S) {
|
2021-01-26 23:44:10 +00:00
|
|
|
saveAs();
|
2020-11-27 12:45:56 +00:00
|
|
|
return true;
|
|
|
|
} else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_F) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.search"_lang); });
|
2020-11-24 01:00:22 +00:00
|
|
|
return true;
|
|
|
|
} else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_G) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.goto"_lang); });
|
2020-11-24 01:00:22 +00:00
|
|
|
return true;
|
|
|
|
} else if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_O) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.open_file"_lang); });
|
2020-11-24 01:00:22 +00:00
|
|
|
return true;
|
|
|
|
} else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_ALT) && key == GLFW_KEY_C) {
|
|
|
|
this->copyBytes();
|
|
|
|
return true;
|
|
|
|
} else if (mods == (GLFW_MOD_CONTROL | GLFW_MOD_SHIFT) && key == GLFW_KEY_C) {
|
|
|
|
this->copyString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-11-12 08:38:52 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 01:00:22 +00:00
|
|
|
|
2020-11-17 12:58:50 +00:00
|
|
|
void ViewHexEditor::openFile(std::string path) {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto& provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
|
|
|
if (provider != nullptr)
|
|
|
|
delete provider;
|
2020-11-17 12:58:50 +00:00
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
provider = new prv::FileProvider(path);
|
2021-01-30 23:05:07 +00:00
|
|
|
if (!provider->isWritable()) {
|
|
|
|
this->m_memoryEditor.ReadOnly = true;
|
2021-02-11 22:09:45 +00:00
|
|
|
View::showErrorPopup("hex.view.hexeditor.error.read_only"_lang);
|
2021-01-30 23:05:07 +00:00
|
|
|
} else {
|
|
|
|
this->m_memoryEditor.ReadOnly = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!provider->isAvailable()) {
|
2021-02-11 22:09:45 +00:00
|
|
|
View::showErrorPopup("hex.view.hexeditor.error.open"_lang);
|
2021-02-14 00:11:55 +00:00
|
|
|
delete provider;
|
|
|
|
provider = nullptr;
|
|
|
|
|
2021-01-30 23:05:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-29 23:03:12 +00:00
|
|
|
|
2021-01-30 23:05:07 +00:00
|
|
|
ProjectFile::setFilePath(path);
|
2020-11-29 23:03:12 +00:00
|
|
|
|
2020-12-05 21:10:03 +00:00
|
|
|
this->getWindowOpenState() = true;
|
|
|
|
|
2021-02-01 18:03:45 +00:00
|
|
|
View::postEvent(Events::FileLoaded, path);
|
2020-11-17 12:58:50 +00:00
|
|
|
View::postEvent(Events::DataChanged);
|
2021-01-08 16:38:43 +00:00
|
|
|
View::postEvent(Events::PatternChanged);
|
2020-11-17 12:58:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 01:00:22 +00:00
|
|
|
bool ViewHexEditor::saveToFile(std::string path, const std::vector<u8>& data) {
|
|
|
|
FILE *file = fopen(path.c_str(), "wb");
|
|
|
|
|
|
|
|
if (file == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fwrite(data.data(), 1, data.size(), file);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewHexEditor::loadFromFile(std::string path, std::vector<u8>& data) {
|
|
|
|
FILE *file = fopen(path.c_str(), "rb");
|
|
|
|
|
|
|
|
if (file == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
|
|
size_t size = ftello64(file);
|
|
|
|
rewind(file);
|
|
|
|
|
|
|
|
data.resize(size);
|
|
|
|
fread(data.data(), 1, data.size(), file);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-15 23:07:42 +00:00
|
|
|
void ViewHexEditor::copyBytes() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-17 01:36:12 +00:00
|
|
|
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
size_t copySize = (end - start) + 1;
|
2020-11-15 23:07:42 +00:00
|
|
|
|
|
|
|
std::vector<u8> buffer(copySize, 0x00);
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(start, buffer.data(), buffer.size());
|
2020-11-15 23:07:42 +00:00
|
|
|
|
|
|
|
std::string str;
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("%02X ", byte);
|
2020-11-15 23:07:42 +00:00
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
ImGui::SetClipboardText(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewHexEditor::copyString() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-17 01:36:12 +00:00
|
|
|
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
size_t copySize = (end - start) + 1;
|
2020-11-15 23:07:42 +00:00
|
|
|
|
2020-11-23 02:00:46 +00:00
|
|
|
std::string buffer(copySize, 0x00);
|
2020-11-15 23:07:42 +00:00
|
|
|
buffer.reserve(copySize + 1);
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(start, buffer.data(), copySize);
|
2020-11-15 23:07:42 +00:00
|
|
|
|
|
|
|
ImGui::SetClipboardText(buffer.c_str());
|
|
|
|
}
|
|
|
|
|
2020-11-20 10:57:14 +00:00
|
|
|
void ViewHexEditor::copyLanguageArray(Language language) {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-20 10:57:14 +00:00
|
|
|
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
size_t copySize = (end - start) + 1;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(copySize, 0x00);
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(start, buffer.data(), buffer.size());
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
std::string str;
|
|
|
|
switch (language) {
|
|
|
|
case Language::C:
|
|
|
|
str += "const unsigned char data[" + std::to_string(buffer.size()) + "] = { ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " };";
|
|
|
|
break;
|
|
|
|
case Language::Cpp:
|
2020-11-20 10:58:40 +00:00
|
|
|
str += "constexpr std::array<unsigned char, " + std::to_string(buffer.size()) + "> data = { ";
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " };";
|
|
|
|
break;
|
|
|
|
case Language::Java:
|
|
|
|
str += "final byte[] data = { ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " };";
|
|
|
|
break;
|
|
|
|
case Language::CSharp:
|
|
|
|
str += "const byte[] data = { ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " };";
|
|
|
|
break;
|
|
|
|
case Language::Rust:
|
|
|
|
str += "let data: [u8, " + std::to_string(buffer.size()) + "] = [ ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " ];";
|
|
|
|
break;
|
|
|
|
case Language::Python:
|
|
|
|
str += "data = bytes([ ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " ]);";
|
|
|
|
break;
|
|
|
|
case Language::JavaScript:
|
|
|
|
str += "const data = new Uint8Array([ ";
|
|
|
|
|
|
|
|
for (const auto &byte : buffer)
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("0x%02X, ", byte);
|
2020-11-20 10:57:14 +00:00
|
|
|
|
|
|
|
// Remove trailing comma
|
|
|
|
str.pop_back();
|
|
|
|
str.pop_back();
|
|
|
|
|
|
|
|
str += " ]);";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetClipboardText(str.c_str());
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:25:55 +00:00
|
|
|
void ViewHexEditor::copyHexView() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-20 12:25:55 +00:00
|
|
|
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
size_t copySize = (end - start) + 1;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(copySize, 0x00);
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(start, buffer.data(), buffer.size());
|
2020-11-20 12:25:55 +00:00
|
|
|
|
|
|
|
std::string str = "Hex View 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
for (u32 col = start >> 4; col <= (end >> 4); col++) {
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("%08lX ", col << 4);
|
2020-11-20 12:25:55 +00:00
|
|
|
for (u64 i = 0 ; i < 16; i++) {
|
|
|
|
|
|
|
|
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
|
|
|
str += " ";
|
|
|
|
else
|
2020-11-20 14:15:43 +00:00
|
|
|
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
|
2020-11-20 12:25:55 +00:00
|
|
|
|
|
|
|
if ((i & 0xF) == 0x7)
|
|
|
|
str += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
str += " ";
|
|
|
|
|
|
|
|
for (u64 i = 0 ; i < 16; i++) {
|
|
|
|
|
|
|
|
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
|
|
|
str += " ";
|
|
|
|
else {
|
|
|
|
u8 c = buffer[((col << 4) - start) + i];
|
|
|
|
char displayChar = (c < 32 || c >= 128) ? '.' : c;
|
|
|
|
str += hex::format("%c", displayChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::SetClipboardText(str.c_str());
|
|
|
|
}
|
|
|
|
|
2020-11-20 14:15:43 +00:00
|
|
|
void ViewHexEditor::copyHexViewHTML() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2020-11-20 14:15:43 +00:00
|
|
|
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
size_t copySize = (end - start) + 1;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(copySize, 0x00);
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->read(start, buffer.data(), buffer.size());
|
2020-11-20 14:15:43 +00:00
|
|
|
|
|
|
|
std::string str =
|
|
|
|
R"(
|
|
|
|
<div>
|
|
|
|
<style type="text/css">
|
|
|
|
.offsetheader { color:#0000A0; line-height:200% }
|
|
|
|
.offsetcolumn { color:#0000A0 }
|
|
|
|
.hexcolumn { color:#000000 }
|
|
|
|
.textcolumn { color:#000000 }
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<code>
|
|
|
|
<span class="offsetheader">Hex View  00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F</span><br/>
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
|
|
for (u32 col = start >> 4; col <= (end >> 4); col++) {
|
|
|
|
str += hex::format(" <span class=\"offsetcolumn\">%08lX</span>  <span class=\"hexcolumn\">", col << 4);
|
|
|
|
for (u64 i = 0 ; i < 16; i++) {
|
|
|
|
|
|
|
|
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
|
|
|
str += "   ";
|
|
|
|
else
|
|
|
|
str += hex::format("%02lX ", buffer[((col << 4) - start) + i]);
|
|
|
|
|
|
|
|
if ((i & 0xF) == 0x7)
|
|
|
|
str += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
str += "</span>  <span class=\"textcolumn\">";
|
|
|
|
|
|
|
|
for (u64 i = 0 ; i < 16; i++) {
|
|
|
|
|
|
|
|
if (col == (start >> 4) && i < (start & 0xF) || col == (end >> 4) && i > (end & 0xF))
|
|
|
|
str += " ";
|
|
|
|
else {
|
|
|
|
u8 c = buffer[((col << 4) - start) + i];
|
|
|
|
char displayChar = (c < 32 || c >= 128) ? '.' : c;
|
|
|
|
str += hex::format("%c", displayChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str += "</span><br/>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
str +=
|
|
|
|
R"(
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::SetClipboardText(str.c_str());
|
|
|
|
}
|
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
static std::vector<std::pair<u64, u64>> findString(prv::Provider* &provider, std::string string) {
|
|
|
|
std::vector<std::pair<u64, u64>> results;
|
|
|
|
|
|
|
|
u32 foundCharacters = 0;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(1024, 0x00);
|
|
|
|
size_t dataSize = provider->getSize();
|
|
|
|
for (u64 offset = 0; offset < dataSize; offset += 1024) {
|
2020-12-06 12:48:56 +00:00
|
|
|
size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset);
|
2020-11-15 22:04:46 +00:00
|
|
|
provider->read(offset, buffer.data(), usedBufferSize);
|
|
|
|
|
|
|
|
for (u64 i = 0; i < usedBufferSize; i++) {
|
|
|
|
if (buffer[i] == string[foundCharacters])
|
|
|
|
foundCharacters++;
|
|
|
|
else
|
|
|
|
foundCharacters = 0;
|
|
|
|
|
|
|
|
if (foundCharacters == string.size()) {
|
|
|
|
results.emplace_back(offset + i - foundCharacters + 1, offset + i + 1);
|
|
|
|
foundCharacters = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::vector<std::pair<u64, u64>> findHex(prv::Provider* &provider, std::string string) {
|
|
|
|
std::vector<std::pair<u64, u64>> results;
|
|
|
|
|
|
|
|
if ((string.size() % 2) == 1)
|
|
|
|
string = "0" + string;
|
|
|
|
|
|
|
|
std::vector<u8> hex;
|
|
|
|
hex.reserve(string.size() / 2);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < string.size(); i += 2) {
|
|
|
|
char byte[3] = { string[i], string[i + 1], 0 };
|
|
|
|
hex.push_back(strtoul(byte, nullptr, 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 foundCharacters = 0;
|
|
|
|
|
|
|
|
std::vector<u8> buffer(1024, 0x00);
|
|
|
|
size_t dataSize = provider->getSize();
|
|
|
|
for (u64 offset = 0; offset < dataSize; offset += 1024) {
|
2020-12-06 12:48:56 +00:00
|
|
|
size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset);
|
2020-11-15 22:04:46 +00:00
|
|
|
provider->read(offset, buffer.data(), usedBufferSize);
|
|
|
|
|
|
|
|
for (u64 i = 0; i < usedBufferSize; i++) {
|
|
|
|
if (buffer[i] == hex[foundCharacters])
|
|
|
|
foundCharacters++;
|
|
|
|
else
|
|
|
|
foundCharacters = 0;
|
|
|
|
|
|
|
|
if (foundCharacters == hex.size()) {
|
|
|
|
results.emplace_back(offset + i - foundCharacters + 1, offset + i + 1);
|
|
|
|
foundCharacters = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
void ViewHexEditor::drawSearchPopup() {
|
2020-11-15 22:04:46 +00:00
|
|
|
static auto InputCallback = [](ImGuiInputTextCallbackData* data) -> int {
|
|
|
|
auto _this = static_cast<ViewHexEditor*>(data->UserData);
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-11-12 08:38:52 +00:00
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
*_this->m_lastSearchBuffer = _this->m_searchFunction(provider, data->Buf);
|
2020-11-15 22:04:46 +00:00
|
|
|
_this->m_lastSearchIndex = 0;
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
if (_this->m_lastSearchBuffer->size() > 0)
|
|
|
|
_this->m_memoryEditor.GotoAddrAndHighlight((*_this->m_lastSearchBuffer)[0].first, (*_this->m_lastSearchBuffer)[0].second);
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
return 0;
|
|
|
|
};
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
static auto Find = [this](char *buffer) {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
|
|
|
*this->m_lastSearchBuffer = this->m_searchFunction(provider, buffer);
|
2020-11-15 22:04:46 +00:00
|
|
|
this->m_lastSearchIndex = 0;
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
if (this->m_lastSearchBuffer->size() > 0)
|
|
|
|
this->m_memoryEditor.GotoAddrAndHighlight((*this->m_lastSearchBuffer)[0].first, (*this->m_lastSearchBuffer)[0].second);
|
|
|
|
};
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
static auto FindNext = [this]() {
|
|
|
|
if (this->m_lastSearchBuffer->size() > 0) {
|
|
|
|
++this->m_lastSearchIndex %= this->m_lastSearchBuffer->size();
|
|
|
|
this->m_memoryEditor.GotoAddrAndHighlight((*this->m_lastSearchBuffer)[this->m_lastSearchIndex].first,
|
|
|
|
(*this->m_lastSearchBuffer)[this->m_lastSearchIndex].second);
|
2020-11-11 13:42:01 +00:00
|
|
|
}
|
2020-11-15 22:04:46 +00:00
|
|
|
};
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
static auto FindPrevious = [this]() {
|
|
|
|
if (this->m_lastSearchBuffer->size() > 0) {
|
|
|
|
this->m_lastSearchIndex--;
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
if (this->m_lastSearchIndex < 0)
|
|
|
|
this->m_lastSearchIndex = this->m_lastSearchBuffer->size() - 1;
|
|
|
|
|
|
|
|
this->m_lastSearchIndex %= this->m_lastSearchBuffer->size();
|
|
|
|
|
|
|
|
this->m_memoryEditor.GotoAddrAndHighlight((*this->m_lastSearchBuffer)[this->m_lastSearchIndex].first,
|
|
|
|
(*this->m_lastSearchBuffer)[this->m_lastSearchIndex].second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopupContextVoid("hex.view.hexeditor.menu.file.search"_lang)) {
|
|
|
|
ImGui::TextUnformatted("hex.view.hexeditor.menu.file.search"_lang);
|
2020-11-15 22:04:46 +00:00
|
|
|
if (ImGui::BeginTabBar("searchTabs")) {
|
2021-02-17 13:47:25 +00:00
|
|
|
std::vector<char> *currBuffer = nullptr;
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginTabItem("hex.view.hexeditor.search.string"_lang)) {
|
2020-11-15 22:04:46 +00:00
|
|
|
this->m_searchFunction = findString;
|
|
|
|
this->m_lastSearchBuffer = &this->m_lastStringSearch;
|
2021-02-17 13:47:25 +00:00
|
|
|
currBuffer = &this->m_searchStringBuffer;
|
2020-11-15 22:04:46 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(), ImGuiInputTextFlags_CallbackCompletion,
|
2020-11-15 22:04:46 +00:00
|
|
|
InputCallback, this);
|
|
|
|
ImGui::EndTabItem();
|
2020-11-11 13:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginTabItem("hex.view.hexeditor.search.hex"_lang)) {
|
2020-11-15 22:04:46 +00:00
|
|
|
this->m_searchFunction = findHex;
|
|
|
|
this->m_lastSearchBuffer = &this->m_lastHexSearch;
|
2021-02-17 13:47:25 +00:00
|
|
|
currBuffer = &this->m_searchHexBuffer;
|
2020-11-15 22:04:46 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(),
|
2020-11-15 22:04:46 +00:00
|
|
|
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CallbackCompletion,
|
|
|
|
InputCallback, this);
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
if (currBuffer != nullptr) {
|
|
|
|
if (ImGui::Button("hex.view.hexeditor.search.find"_lang))
|
|
|
|
Find(currBuffer->data());
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
if (this->m_lastSearchBuffer->size() > 0) {
|
|
|
|
if ((ImGui::Button("hex.view.hexeditor.search.find_next"_lang)))
|
|
|
|
FindNext();
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
ImGui::SameLine();
|
2020-11-11 13:42:01 +00:00
|
|
|
|
2021-02-17 13:47:25 +00:00
|
|
|
if ((ImGui::Button("hex.view.hexeditor.search.find_prev"_lang)))
|
|
|
|
FindPrevious();
|
|
|
|
}
|
2020-11-11 13:42:01 +00:00
|
|
|
}
|
2020-11-15 22:04:46 +00:00
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
2020-11-11 13:42:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 22:04:46 +00:00
|
|
|
|
2020-11-11 13:42:01 +00:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
void ViewHexEditor::drawGotoPopup() {
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2020-12-27 14:39:06 +00:00
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginPopup("hex.view.hexeditor.menu.file.goto"_lang)) {
|
|
|
|
ImGui::TextUnformatted("hex.view.hexeditor.menu.file.goto"_lang);
|
2020-11-19 22:24:34 +00:00
|
|
|
if (ImGui::BeginTabBar("gotoTabs")) {
|
|
|
|
s64 newOffset = 0;
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.begin"_lang)) {
|
2020-11-19 22:24:34 +00:00
|
|
|
ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
if (this->m_gotoAddress >= provider->getActualSize())
|
|
|
|
this->m_gotoAddress = provider->getActualSize() - 1;
|
2020-11-10 20:31:04 +00:00
|
|
|
|
2020-11-19 22:24:34 +00:00
|
|
|
newOffset = this->m_gotoAddress;
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.current"_lang)) {
|
2020-11-19 22:24:34 +00:00
|
|
|
ImGui::InputScalar("##nolabel", ImGuiDataType_S64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
|
|
|
|
if (this->m_memoryEditor.DataPreviewAddr == -1 || this->m_memoryEditor.DataPreviewAddrEnd == -1) {
|
|
|
|
this->m_memoryEditor.DataPreviewAddr = 0;
|
|
|
|
this->m_memoryEditor.DataPreviewAddrEnd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s64 currHighlightStart = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
|
|
|
|
newOffset = this->m_gotoAddress + currHighlightStart;
|
2020-12-27 14:39:06 +00:00
|
|
|
if (newOffset >= provider->getActualSize()) {
|
|
|
|
newOffset = provider->getActualSize() - 1;
|
|
|
|
this->m_gotoAddress = (provider->getActualSize() - 1) - currHighlightStart;
|
2020-11-19 22:24:34 +00:00
|
|
|
} else if (newOffset < 0) {
|
|
|
|
newOffset = 0;
|
|
|
|
this->m_gotoAddress = -currHighlightStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginTabItem("hex.view.hexeditor.goto.offset.end"_lang)) {
|
2020-11-19 22:24:34 +00:00
|
|
|
ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal);
|
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
if (this->m_gotoAddress >= provider->getActualSize())
|
|
|
|
this->m_gotoAddress = provider->getActualSize() - 1;
|
2020-11-19 22:24:34 +00:00
|
|
|
|
2020-12-27 14:39:06 +00:00
|
|
|
newOffset = (provider->getActualSize() - 1) - this->m_gotoAddress;
|
2020-11-19 22:24:34 +00:00
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::Button("hex.view.hexeditor.menu.file.goto"_lang)) {
|
2020-12-27 14:39:06 +00:00
|
|
|
provider->setCurrentPage(std::floor(newOffset / double(prv::Provider::PageSize)));
|
2020-11-19 22:24:34 +00:00
|
|
|
this->m_memoryEditor.GotoAddr = newOffset;
|
|
|
|
this->m_memoryEditor.DataPreviewAddr = newOffset;
|
|
|
|
this->m_memoryEditor.DataPreviewAddrEnd = newOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 08:38:52 +00:00
|
|
|
ImGui::EndPopup();
|
2020-11-11 13:42:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-10 22:59:36 +00:00
|
|
|
void ViewHexEditor::drawEditPopup() {
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::BeginMenu("hex.view.hexeditor.menu.edit.copy"_lang, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
|
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.bytes"_lang, "CTRL + ALT + C"))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyBytes();
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.hex"_lang, "CTRL + SHIFT + C"))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyString();
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.c"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::C);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.cpp"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::Cpp);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.csharp"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::CSharp);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.rust"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::Rust);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.python"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::Python);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.java"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::Java);
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.js"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyLanguageArray(Language::JavaScript);
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.ascii"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyHexView();
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.copy.html"_lang))
|
2021-01-10 22:59:36 +00:00
|
|
|
this->copyHexViewHTML();
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.bookmark"_lang, nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
|
2021-02-17 13:57:32 +00:00
|
|
|
auto base = SharedData::currentProvider->getBaseAddress();
|
|
|
|
|
|
|
|
size_t start = base + std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
|
|
|
size_t end = base + std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
2021-01-10 22:59:36 +00:00
|
|
|
|
2021-01-20 19:16:24 +00:00
|
|
|
ImHexApi::Bookmarks::add(start, end - start + 1, { }, { });
|
2021-01-10 22:59:36 +00:00
|
|
|
}
|
2021-01-11 12:50:04 +00:00
|
|
|
|
2021-01-12 22:28:41 +00:00
|
|
|
auto provider = SharedData::currentProvider;
|
2021-02-11 22:09:45 +00:00
|
|
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.set_base"_lang, nullptr, false, provider != nullptr && provider->isReadable())) {
|
2021-01-20 19:16:24 +00:00
|
|
|
std::memset(this->m_baseAddressBuffer, 0x00, sizeof(this->m_baseAddressBuffer));
|
2021-02-11 22:09:45 +00:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.edit.set_base"_lang); });
|
2021-01-11 12:50:04 +00:00
|
|
|
}
|
2021-01-10 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 20:31:04 +00:00
|
|
|
}
|