Improve bookmark API
This commit is contained in:
parent
be738eb5e7
commit
b2648afc7b
@ -5,7 +5,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "patches.hpp"
|
#include "patches.hpp"
|
||||||
#include <hex/helpers/utils.hpp>
|
#include <hex/api/imhex_api.hpp>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ namespace hex {
|
|||||||
[[nodiscard]] static const Patches& getPatches() { return ProjectFile::s_patches; }
|
[[nodiscard]] static const Patches& getPatches() { return ProjectFile::s_patches; }
|
||||||
static void setPatches(const Patches &patches) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_patches = patches; }
|
static void setPatches(const Patches &patches) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_patches = patches; }
|
||||||
|
|
||||||
[[nodiscard]] static const std::list<Bookmark>& getBookmarks() { return ProjectFile::s_bookmarks; }
|
[[nodiscard]] static const std::list<ImHexApi::Bookmarks::Entry>& getBookmarks() { return ProjectFile::s_bookmarks; }
|
||||||
static void setBookmarks(const std::list<Bookmark> &bookmarks) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_bookmarks = bookmarks; }
|
static void setBookmarks(const std::list<ImHexApi::Bookmarks::Entry> &bookmarks) { ProjectFile::s_hasUnsavedChanged = true; ProjectFile::s_bookmarks = bookmarks; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline std::string s_currProjectFilePath;
|
static inline std::string s_currProjectFilePath;
|
||||||
@ -40,7 +40,7 @@ namespace hex {
|
|||||||
static inline std::string s_filePath;
|
static inline std::string s_filePath;
|
||||||
static inline std::string s_pattern;
|
static inline std::string s_pattern;
|
||||||
static inline Patches s_patches;
|
static inline Patches s_patches;
|
||||||
static inline std::list<Bookmark> s_bookmarks;
|
static inline std::list<ImHexApi::Bookmarks::Entry> s_bookmarks;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -13,14 +13,11 @@ namespace hex {
|
|||||||
|
|
||||||
class ViewBookmarks : public View {
|
class ViewBookmarks : public View {
|
||||||
public:
|
public:
|
||||||
explicit ViewBookmarks(std::list<Bookmark> &bookmarks);
|
ViewBookmarks();
|
||||||
~ViewBookmarks() override;
|
~ViewBookmarks() override;
|
||||||
|
|
||||||
void drawContent() override;
|
void drawContent() override;
|
||||||
void drawMenu() override;
|
void drawMenu() override;
|
||||||
|
|
||||||
private:
|
|
||||||
std::list<Bookmark> &m_bookmarks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ namespace hex {
|
|||||||
|
|
||||||
class ViewHexEditor : public View {
|
class ViewHexEditor : public View {
|
||||||
public:
|
public:
|
||||||
ViewHexEditor(std::vector<lang::PatternData*> &patternData, const std::list<Bookmark> &bookmarks);
|
ViewHexEditor(std::vector<lang::PatternData*> &patternData);
|
||||||
~ViewHexEditor() override;
|
~ViewHexEditor() override;
|
||||||
|
|
||||||
void drawContent() override;
|
void drawContent() override;
|
||||||
@ -33,7 +33,6 @@ namespace hex {
|
|||||||
imgui_addons::ImGuiFileBrowser m_fileBrowser;
|
imgui_addons::ImGuiFileBrowser m_fileBrowser;
|
||||||
|
|
||||||
std::vector<lang::PatternData*> &m_patternData;
|
std::vector<lang::PatternData*> &m_patternData;
|
||||||
const std::list<Bookmark> &m_bookmarks;
|
|
||||||
|
|
||||||
std::map<u64, u32> m_highlightedBytes;
|
std::map<u64, u32> m_highlightedBytes;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
|||||||
|
|
||||||
add_library(libimhex SHARED
|
add_library(libimhex SHARED
|
||||||
source/api/event.cpp
|
source/api/event.cpp
|
||||||
|
source/api/imhex_api.cpp
|
||||||
source/api/content_registry.cpp
|
source/api/content_registry.cpp
|
||||||
source/helpers/utils.cpp
|
source/helpers/utils.cpp
|
||||||
source/helpers/shared_data.cpp
|
source/helpers/shared_data.cpp
|
||||||
|
@ -22,8 +22,7 @@ namespace hex {
|
|||||||
It allows you to add/register new content that will be picked up and used by the ImHex core or by other
|
It allows you to add/register new content that will be picked up and used by the ImHex core or by other
|
||||||
plugins when needed.
|
plugins when needed.
|
||||||
*/
|
*/
|
||||||
class ContentRegistry {
|
struct ContentRegistry {
|
||||||
public:
|
|
||||||
ContentRegistry() = delete;
|
ContentRegistry() = delete;
|
||||||
|
|
||||||
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
|
/* Settings Registry. Allows adding of new entries into the ImHex preferences window. */
|
||||||
|
31
plugins/libimhex/include/hex/api/imhex_api.hpp
Normal file
31
plugins/libimhex/include/hex/api/imhex_api.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <hex.hpp>
|
||||||
|
#include <hex/helpers/utils.hpp>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
namespace hex {
|
||||||
|
|
||||||
|
struct ImHexApi {
|
||||||
|
ImHexApi() = delete;
|
||||||
|
|
||||||
|
struct Bookmarks {
|
||||||
|
Bookmarks() = delete;
|
||||||
|
|
||||||
|
struct Entry {
|
||||||
|
Region region;
|
||||||
|
|
||||||
|
std::vector<char> name;
|
||||||
|
std::vector<char> comment;
|
||||||
|
u32 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void add(Region region, std::string_view name, std::string_view comment, u32 color = 0x00000000);
|
||||||
|
static void add(u64 addr, size_t size, std::string_view name, std::string_view comment, u32 color = 0x00000000);
|
||||||
|
|
||||||
|
static std::list<Entry>& getEntries();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
#include <any>
|
#include <any>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
|
#include <hex/api/imhex_api.hpp>
|
||||||
#include <hex/api/event.hpp>
|
#include <hex/api/event.hpp>
|
||||||
#include <hex/views/view.hpp>
|
#include <hex/views/view.hpp>
|
||||||
|
|
||||||
@ -55,6 +57,7 @@ namespace hex {
|
|||||||
static std::vector<ContentRegistry::DataInspector::Entry> dataInspectorEntries;
|
static std::vector<ContentRegistry::DataInspector::Entry> dataInspectorEntries;
|
||||||
static u32 patternPaletteOffset;
|
static u32 patternPaletteOffset;
|
||||||
static std::string errorPopupMessage;
|
static std::string errorPopupMessage;
|
||||||
|
static std::list<ImHexApi::Bookmarks::Entry> bookmarkEntries;
|
||||||
|
|
||||||
static int mainArgc;
|
static int mainArgc;
|
||||||
static char **mainArgv;
|
static char **mainArgv;
|
||||||
|
@ -197,11 +197,4 @@ namespace hex {
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Bookmark {
|
|
||||||
Region region;
|
|
||||||
|
|
||||||
std::vector<char> name;
|
|
||||||
std::vector<char> comment;
|
|
||||||
u32 color;
|
|
||||||
};
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
#include <hex.hpp>
|
#include <hex.hpp>
|
||||||
|
#include <hex/api/imhex_api.hpp>
|
||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
#include <hex/views/view.hpp>
|
#include <hex/views/view.hpp>
|
||||||
#include <hex/providers/provider.hpp>
|
#include <hex/providers/provider.hpp>
|
||||||
|
31
plugins/libimhex/source/api/imhex_api.cpp
Normal file
31
plugins/libimhex/source/api/imhex_api.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <hex/api/imhex_api.hpp>
|
||||||
|
|
||||||
|
#include <hex/api/event.hpp>
|
||||||
|
#include <hex/helpers/shared_data.hpp>
|
||||||
|
|
||||||
|
namespace hex {
|
||||||
|
|
||||||
|
void ImHexApi::Bookmarks::add(Region region, std::string_view name, std::string_view comment, u32 color) {
|
||||||
|
Entry entry;
|
||||||
|
|
||||||
|
entry.region = region;
|
||||||
|
|
||||||
|
entry.name.reserve(name.length());
|
||||||
|
entry.comment.reserve(comment.length());
|
||||||
|
std::copy(name.begin(), name.end(), std::back_inserter(entry.name));
|
||||||
|
std::copy(comment.begin(), comment.end(), std::back_inserter(entry.comment));
|
||||||
|
|
||||||
|
entry.color = color;
|
||||||
|
|
||||||
|
EventManager::post(Events::AddBookmark, &entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImHexApi::Bookmarks::add(u64 addr, size_t size, std::string_view name, std::string_view comment, u32 color) {
|
||||||
|
Bookmarks::add(Region{addr, size}, name, comment, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<ImHexApi::Bookmarks::Entry>& ImHexApi::Bookmarks::getEntries() {
|
||||||
|
return SharedData::bookmarkEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,7 @@ namespace hex {
|
|||||||
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
|
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
|
||||||
u32 SharedData::patternPaletteOffset;
|
u32 SharedData::patternPaletteOffset;
|
||||||
std::string SharedData::errorPopupMessage;
|
std::string SharedData::errorPopupMessage;
|
||||||
|
std::list<ImHexApi::Bookmarks::Entry> SharedData::bookmarkEntries;
|
||||||
|
|
||||||
int SharedData::mainArgc;
|
int SharedData::mainArgc;
|
||||||
char **SharedData::mainArgv;
|
char **SharedData::mainArgv;
|
||||||
|
@ -45,12 +45,13 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyObject* LoaderScript::Py_addBookmark(PyObject *self, PyObject *args) {
|
PyObject* LoaderScript::Py_addBookmark(PyObject *self, PyObject *args) {
|
||||||
Bookmark bookmark;
|
u64 address;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
char *name = nullptr;
|
char *name = nullptr;
|
||||||
char *comment = nullptr;
|
char *comment = nullptr;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "K|n|s|s", &bookmark.region.address, &bookmark.region.size, &name, &comment)) {
|
if (!PyArg_ParseTuple(args, "K|n|s|s", &address, &size, &name, &comment)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -60,10 +61,7 @@ namespace hex {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::copy(name, name + std::strlen(name), std::back_inserter(bookmark.name));
|
ImHexApi::Bookmarks::add(address, size, name, comment);
|
||||||
std::copy(comment, comment + std::strlen(comment), std::back_inserter(bookmark.comment));
|
|
||||||
|
|
||||||
View::postEvent(Events::AddBookmark, &bookmark);
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,11 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
void to_json(json& j, const hex::Bookmark& b) {
|
void to_json(json& j, const ImHexApi::Bookmarks::Entry& b) {
|
||||||
j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() } };
|
j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() } };
|
||||||
}
|
}
|
||||||
|
|
||||||
void from_json(const json& j, hex::Bookmark& b) {
|
void from_json(const json& j, ImHexApi::Bookmarks::Entry& b) {
|
||||||
std::string name, comment;
|
std::string name, comment;
|
||||||
|
|
||||||
j.at("address").get_to(b.region.address);
|
j.at("address").get_to(b.region.address);
|
||||||
@ -38,7 +38,7 @@ namespace hex {
|
|||||||
ProjectFile::s_patches = projectFileData["patches"].get<Patches>();
|
ProjectFile::s_patches = projectFileData["patches"].get<Patches>();
|
||||||
|
|
||||||
for (auto &element : projectFileData["bookmarks"].items()) {
|
for (auto &element : projectFileData["bookmarks"].items()) {
|
||||||
ProjectFile::s_bookmarks.push_back(element.value().get<Bookmark>());
|
ProjectFile::s_bookmarks.push_back(element.value().get<ImHexApi::Bookmarks::Entry>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (json::exception &e) {
|
} catch (json::exception &e) {
|
||||||
|
@ -29,10 +29,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Shared Data
|
// Shared Data
|
||||||
std::vector<lang::PatternData*> patternData;
|
std::vector<lang::PatternData*> patternData;
|
||||||
std::list<Bookmark> bookmarks;
|
|
||||||
|
|
||||||
// Create views
|
// Create views
|
||||||
ContentRegistry::Views::add<ViewHexEditor>(patternData, bookmarks);
|
ContentRegistry::Views::add<ViewHexEditor>(patternData);
|
||||||
ContentRegistry::Views::add<ViewPattern>(patternData);
|
ContentRegistry::Views::add<ViewPattern>(patternData);
|
||||||
ContentRegistry::Views::add<ViewPatternData>(patternData);
|
ContentRegistry::Views::add<ViewPatternData>(patternData);
|
||||||
ContentRegistry::Views::add<ViewDataInspector>();
|
ContentRegistry::Views::add<ViewDataInspector>();
|
||||||
@ -40,7 +39,7 @@ int main(int argc, char **argv) {
|
|||||||
ContentRegistry::Views::add<ViewInformation>();
|
ContentRegistry::Views::add<ViewInformation>();
|
||||||
ContentRegistry::Views::add<ViewStrings>();
|
ContentRegistry::Views::add<ViewStrings>();
|
||||||
ContentRegistry::Views::add<ViewDisassembler>();
|
ContentRegistry::Views::add<ViewDisassembler>();
|
||||||
ContentRegistry::Views::add<ViewBookmarks>(bookmarks);
|
ContentRegistry::Views::add<ViewBookmarks>();
|
||||||
ContentRegistry::Views::add<ViewPatches>();
|
ContentRegistry::Views::add<ViewPatches>();
|
||||||
ContentRegistry::Views::add<ViewTools>();
|
ContentRegistry::Views::add<ViewTools>();
|
||||||
ContentRegistry::Views::add<ViewCommandPalette>();
|
ContentRegistry::Views::add<ViewCommandPalette>();
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
ViewBookmarks::ViewBookmarks(std::list<Bookmark> &bookmarks) : View("Bookmarks"), m_bookmarks(bookmarks) {
|
ViewBookmarks::ViewBookmarks() : View("Bookmarks") {
|
||||||
View::subscribeEvent(Events::AddBookmark, [this](const void *userData) {
|
View::subscribeEvent(Events::AddBookmark, [this](const void *userData) {
|
||||||
Bookmark bookmark = *reinterpret_cast<const Bookmark*>(userData);
|
auto bookmark = *reinterpret_cast<const ImHexApi::Bookmarks::Entry*>(userData);
|
||||||
bookmark.comment.resize(0xF'FFFF);
|
bookmark.comment.resize(0xF'FFFF);
|
||||||
|
|
||||||
if (bookmark.name.empty()) {
|
if (bookmark.name.empty()) {
|
||||||
@ -25,15 +25,15 @@ namespace hex {
|
|||||||
|
|
||||||
bookmark.color = ImGui::GetColorU32(ImGuiCol_Header);
|
bookmark.color = ImGui::GetColorU32(ImGuiCol_Header);
|
||||||
|
|
||||||
this->m_bookmarks.push_back(bookmark);
|
SharedData::bookmarkEntries.push_back(bookmark);
|
||||||
ProjectFile::markDirty();
|
ProjectFile::markDirty();
|
||||||
});
|
});
|
||||||
|
|
||||||
View::subscribeEvent(Events::ProjectFileLoad, [this](const void*) {
|
View::subscribeEvent(Events::ProjectFileLoad, [](const void*) {
|
||||||
this->m_bookmarks = ProjectFile::getBookmarks();
|
SharedData::bookmarkEntries = ProjectFile::getBookmarks();
|
||||||
});
|
});
|
||||||
View::subscribeEvent(Events::ProjectFileStore, [this](const void*) {
|
View::subscribeEvent(Events::ProjectFileStore, [](const void*) {
|
||||||
ProjectFile::setBookmarks(this->m_bookmarks);
|
ProjectFile::setBookmarks(SharedData::bookmarkEntries);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,15 +47,17 @@ namespace hex {
|
|||||||
if (ImGui::Begin("Bookmarks", &this->getWindowOpenState())) {
|
if (ImGui::Begin("Bookmarks", &this->getWindowOpenState())) {
|
||||||
if (ImGui::BeginChild("##scrolling")) {
|
if (ImGui::BeginChild("##scrolling")) {
|
||||||
|
|
||||||
if (this->m_bookmarks.empty()) {
|
auto &bookmarks = ImHexApi::Bookmarks::getEntries();
|
||||||
|
|
||||||
|
if (bookmarks.empty()) {
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
ImGui::Indent(30);
|
ImGui::Indent(30);
|
||||||
ImGui::TextWrapped("No bookmarks created yet. Add one with Edit -> Add Bookmark");
|
ImGui::TextWrapped("No bookmarks created yet. Add one with Edit -> Add Bookmark");
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 id = 1;
|
u32 id = 1;
|
||||||
std::list<Bookmark>::const_iterator bookmarkToRemove = this->m_bookmarks.end();
|
auto bookmarkToRemove = bookmarks.end();
|
||||||
for (auto iter = this->m_bookmarks.begin(); iter != this->m_bookmarks.end(); iter++) {
|
for (auto iter = bookmarks.begin(); iter != bookmarks.end(); iter++) {
|
||||||
auto &[region, name, comment, color] = *iter;
|
auto &[region, name, comment, color] = *iter;
|
||||||
|
|
||||||
auto headerColor = ImColor(color);
|
auto headerColor = ImColor(color);
|
||||||
@ -97,14 +99,14 @@ namespace hex {
|
|||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
ImGui::TextUnformatted("Name");
|
ImGui::TextUnformatted("Name");
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::InputText("##nameInput", name.data(), 64);
|
ImGui::InputText("##nameInput", std::string(name.data()).data(), 64);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::ColorEdit4("Color", (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha);
|
ImGui::ColorEdit4("Color", (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha);
|
||||||
color = headerColor;
|
color = headerColor;
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
ImGui::TextUnformatted("Comment");
|
ImGui::TextUnformatted("Comment");
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::InputTextMultiline("##colorInput", comment.data(), 0xF'FFFF);
|
ImGui::InputTextMultiline("##colorInput", std::string(comment.data()).data(), 0xF'FFFF);
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -113,8 +115,8 @@ namespace hex {
|
|||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bookmarkToRemove != this->m_bookmarks.end()) {
|
if (bookmarkToRemove != bookmarks.end()) {
|
||||||
this->m_bookmarks.erase(bookmarkToRemove);
|
bookmarks.erase(bookmarkToRemove);
|
||||||
ProjectFile::markDirty();
|
ProjectFile::markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,18 +31,6 @@ namespace hex {
|
|||||||
return hex::format("#%s = ???", input.data());
|
return hex::format("#%s = ???", input.data());
|
||||||
});
|
});
|
||||||
|
|
||||||
ContentRegistry::CommandPaletteCommands::add(
|
|
||||||
ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
|
|
||||||
"/bm", "Create Bookmark",
|
|
||||||
[](auto input) {
|
|
||||||
Bookmark bookmark;
|
|
||||||
bookmark.name.resize(64);
|
|
||||||
std::strncpy(bookmark.name.data(), input.c_str(), bookmark.name.size());
|
|
||||||
|
|
||||||
View::postEvent(Events::AddBookmark, &bookmark);
|
|
||||||
return "";
|
|
||||||
});
|
|
||||||
|
|
||||||
this->m_lastResults = this->getCommandResults("");
|
this->m_lastResults = this->getCommandResults("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "views/view_hexeditor.hpp"
|
#include "views/view_hexeditor.hpp"
|
||||||
|
|
||||||
#include <hex/providers/provider.hpp>
|
#include <hex/providers/provider.hpp>
|
||||||
|
#include <hex/api/imhex_api.hpp>
|
||||||
#include "providers/file_provider.hpp"
|
#include "providers/file_provider.hpp"
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@ -15,8 +16,8 @@
|
|||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData, const std::list<Bookmark> &bookmarks)
|
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData)
|
||||||
: View("Hex Editor"), m_patternData(patternData), m_bookmarks(bookmarks) {
|
: View("Hex Editor"), m_patternData(patternData) {
|
||||||
|
|
||||||
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
|
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
|
||||||
auto provider = SharedData::currentProvider;
|
auto provider = SharedData::currentProvider;
|
||||||
@ -44,7 +45,7 @@ namespace hex {
|
|||||||
|
|
||||||
std::optional<u32> currColor, prevColor;
|
std::optional<u32> currColor, prevColor;
|
||||||
|
|
||||||
for (const auto &[region, name, comment, color] : _this->m_bookmarks) {
|
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
|
||||||
if (off >= region.address && off < (region.address + region.size))
|
if (off >= region.address && off < (region.address + region.size))
|
||||||
currColor = (color & 0x00FFFFFF) | 0x80000000;
|
currColor = (color & 0x00FFFFFF) | 0x80000000;
|
||||||
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
|
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
|
||||||
@ -74,11 +75,9 @@ namespace hex {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this->m_memoryEditor.HoverFn = [](const ImU8 *data, size_t addr) {
|
this->m_memoryEditor.HoverFn = [](const ImU8 *data, size_t addr) {
|
||||||
ViewHexEditor *_this = (ViewHexEditor *) data;
|
|
||||||
|
|
||||||
bool tooltipShown = false;
|
bool tooltipShown = false;
|
||||||
|
|
||||||
for (const auto &[region, name, comment, color] : _this->m_bookmarks) {
|
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
|
||||||
if (addr >= region.address && addr < (region.address + region.size)) {
|
if (addr >= region.address && addr < (region.address + region.size)) {
|
||||||
if (!tooltipShown) {
|
if (!tooltipShown) {
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
@ -1041,14 +1040,13 @@ R"(
|
|||||||
if (ImGui::MenuItem("Create bookmark", nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
|
if (ImGui::MenuItem("Create bookmark", nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
|
||||||
size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
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 end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd);
|
||||||
Bookmark bookmark = { start, end - start + 1, { }, { } };
|
|
||||||
|
|
||||||
View::postEvent(Events::AddBookmark, &bookmark);
|
ImHexApi::Bookmarks::add(start, end - start + 1, { }, { });
|
||||||
}
|
}
|
||||||
|
|
||||||
auto provider = SharedData::currentProvider;
|
auto provider = SharedData::currentProvider;
|
||||||
if (ImGui::MenuItem("Set base address", nullptr, false, provider != nullptr && provider->isReadable())) {
|
if (ImGui::MenuItem("Set base address", nullptr, false, provider != nullptr && provider->isReadable())) {
|
||||||
std::memset(this->m_baseAddressBuffer, sizeof(this->m_baseAddressBuffer), 0x00);
|
std::memset(this->m_baseAddressBuffer, 0x00, sizeof(this->m_baseAddressBuffer));
|
||||||
View::doLater([]{ ImGui::OpenPopup("Set base address"); });
|
View::doLater([]{ ImGui::OpenPopup("Set base address"); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user