1
0
mirror of synced 2024-11-28 09:30:51 +01:00

Added patches display window

This commit is contained in:
WerWolv 2020-11-29 02:06:41 +01:00
parent 8a4b663890
commit 7316be0bc2
5 changed files with 113 additions and 1 deletions

View File

@ -52,6 +52,7 @@ add_executable(ImHex
source/views/view_data_inspector.cpp source/views/view_data_inspector.cpp
source/views/view_disassembler.cpp source/views/view_disassembler.cpp
source/views/view_bookmarks.cpp source/views/view_bookmarks.cpp
source/views/view_patches.cpp
libs/glad/source/glad.c libs/glad/source/glad.c

View File

@ -32,7 +32,7 @@ namespace hex::prv {
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0; virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
virtual size_t getActualSize() = 0; virtual size_t getActualSize() = 0;
const std::map<u64, u8>& getPatches() { return this->m_patches.back(); } std::map<u64, u8>& getPatches() { return this->m_patches.back(); }
void applyPatches() { void applyPatches() {
for (auto &[patchAddress, patch] : this->m_patches.back()) for (auto &[patchAddress, patch] : this->m_patches.back())
this->writeRaw(patchAddress, &patch, 1); this->writeRaw(patchAddress, &patch, 1);

View File

@ -0,0 +1,29 @@
#pragma once
#include <hex.hpp>
#include "imgui.h"
#include "views/view.hpp"
#include <optional>
namespace hex {
namespace prv { class Provider; }
class ViewPatches : public View {
public:
explicit ViewPatches(prv::Provider* &dataProvider);
~ViewPatches() override;
void createView() override;
void createMenu() override;
private:
prv::Provider* &m_dataProvider;
u64 m_selectedPatch;
};
}

View File

@ -12,6 +12,7 @@
#include "views/view_data_inspector.hpp" #include "views/view_data_inspector.hpp"
#include "views/view_disassembler.hpp" #include "views/view_disassembler.hpp"
#include "views/view_bookmarks.hpp" #include "views/view_bookmarks.hpp"
#include "views/view_patches.hpp"
#include "providers/provider.hpp" #include "providers/provider.hpp"
@ -34,6 +35,7 @@ int main() {
window.addView<hex::ViewStrings>(dataProvider); window.addView<hex::ViewStrings>(dataProvider);
window.addView<hex::ViewDisassembler>(dataProvider); window.addView<hex::ViewDisassembler>(dataProvider);
window.addView<hex::ViewBookmarks>(dataProvider); window.addView<hex::ViewBookmarks>(dataProvider);
window.addView<hex::ViewPatches>(dataProvider);
window.addView<hex::ViewTools>(); window.addView<hex::ViewTools>();
window.addView<hex::ViewHelp>(); window.addView<hex::ViewHelp>();

View File

@ -0,0 +1,80 @@
#include "views/view_patches.hpp"
#include "providers/provider.hpp"
#include "helpers/utils.hpp"
#include <string>
using namespace std::literals::string_literals;
namespace hex {
ViewPatches::ViewPatches(prv::Provider* &dataProvider) : View("Patches"), m_dataProvider(dataProvider) {
}
ViewPatches::~ViewPatches() {
}
void ViewPatches::createView() {
if (ImGui::Begin("Patches", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) {
if (ImGui::BeginTable("##patchesTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable |
ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Offset");
ImGui::TableSetupColumn("Previous Value");
ImGui::TableSetupColumn("Patched Value");
ImGui::TableHeadersRow();
auto& patches = this->m_dataProvider->getPatches();
u32 index = 0;
for (const auto &[address, patch] : patches) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(("##patchLine" + std::to_string(index)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
Region selectRegion = { address, 1 };
View::postEvent(Events::SelectionChangeRequest, &selectRegion);
}
if (ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) {
ImGui::OpenPopup("PatchContextMenu");
this->m_selectedPatch = address;
}
ImGui::SameLine();
ImGui::Text("0x%08lX", address);
ImGui::TableNextColumn();
u8 previousValue = 0x00;
this->m_dataProvider->readRaw(address, &previousValue, sizeof(u8));
ImGui::Text("0x%02X", previousValue);
ImGui::TableNextColumn();
ImGui::Text("0x%02X", patch);
index += 1;
}
if (ImGui::BeginPopup("PatchContextMenu")) {
if (ImGui::MenuItem("Remove")) {
patches.erase(this->m_selectedPatch);
}
ImGui::EndPopup();
}
ImGui::EndTable();
}
}
}
ImGui::End();
}
void ViewPatches::createMenu() {
}
}