1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Hopefully fixed the whole plugin mess I started

This commit is contained in:
WerWolv 2021-01-12 23:28:41 +01:00
parent 8ae15abb85
commit dc85616549
27 changed files with 137 additions and 173 deletions

View File

@ -182,11 +182,16 @@ set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_link_directories(imhex PRIVATE ${CRYPTO_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS})
if (WIN32)
target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle imgui libimhex ${Python_LIBRARIES})
target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcrypto.a libwinpthread.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES})
elseif (UNIX)
target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle imgui libimhex ${Python_LIBRARIES} dl)
target_link_libraries(imhex magic crypto ${CMAKE_DL_LIBS} capstone LLVMDemangle libimhex ${Python_LIBRARIES} dl)
endif()
add_custom_command(TARGET imhex POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:libimhex>
$<TARGET_FILE_DIR:imhex>)
if (WIN32)
# Install binaries directly in the prefix, usually C:\Program Files\ImHex.
set(CMAKE_INSTALL_BINDIR ".")

View File

@ -8,6 +8,8 @@ find_package(Freetype REQUIRED)
pkg_search_module(GLM REQUIRED glm)
pkg_search_module(GLFW REQUIRED glfw3)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_library(imgui
source/imgui.cpp
source/imgui_demo.cpp

View File

@ -4,9 +4,11 @@ project(glad)
set(CMAKE_CXX_STANDARD 17)
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_library(glad
source/glad.c
)

View File

@ -4,9 +4,11 @@ project(LLVMDemangle)
set(CMAKE_CXX_STANDARD 17)
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_library(LLVMDemangle
Demangle/Demangle.cpp
Demangle/ItaniumDemangle.cpp

View File

@ -14,10 +14,10 @@ namespace hex {
Plugin(std::string_view path);
~Plugin();
void initializePlugin(SharedData &sharedData) const;
void initializePlugin() const;
private:
using InitializePluginFunc = void(*)(SharedData &sharedData);
using InitializePluginFunc = void(*)();
void *m_handle = nullptr;

View File

@ -8,13 +8,16 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/nlohmann_json ${CMAK
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
endif()
add_library(libimhex STATIC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_library(libimhex SHARED
source/helpers/event.cpp
source/helpers/utils.cpp
source/helpers/content_registry.cpp
source/helpers/shared_data.cpp
source/lang/preprocessor.cpp
source/lang/lexer.cpp

View File

@ -28,106 +28,39 @@ namespace hex {
SharedData(const SharedData&) = delete;
SharedData(SharedData&&) = delete;
static auto& get() {
static SharedData instance;
return instance;
}
friend void hex::plugin::internal::initializePlugin(SharedData &sharedData);
friend class Window;
template<typename T>
T& getVariable(std::string variableName) {
return std::any_cast<T&>((*this->sharedVariables)[variableName]);
static T& getVariable(std::string variableName) {
return std::any_cast<T&>(SharedData::sharedVariables[variableName]);
}
template<typename T>
void setVariable(std::string variableName, T value) {
(*this->sharedVariables)[variableName] = value;
}
private:
void initializeData() {
static int mainArgcStorage;
static char **mainArgvStorage;
static ImGuiContext *imGuiContextStorage;
static std::vector<EventHandler> eventHandlersStorage;
static std::vector<std::function<void()>> deferredCallsStorage;
static prv::Provider *currentProviderStorage;
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntriesStorage;
static std::map<std::string, std::any> sharedVariablesStorage;
static ImVec2 windowPosStorage, windowSizeStorage;
static nlohmann::json settingsJsonStorage;
static std::map<std::string, Events> customEventsStorage;
static u32 customEventsLastIdStorage = u32(Events::Events_BuiltinEnd) + 1;
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommandsStorage;
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctionsStorage;
static std::vector<View*> viewsStorage;
static std::vector<std::function<void()>> toolsStorage;
this->imguiContext = &imGuiContextStorage;
this->eventHandlers = &eventHandlersStorage;
this->deferredCalls = &deferredCallsStorage;
this->currentProvider = &currentProviderStorage;
this->settingsEntries = &settingsEntriesStorage;
this->sharedVariables = &sharedVariablesStorage;
this->windowPos = &windowPosStorage;
this->windowSize = &windowSizeStorage;
this->settingsJson = &settingsJsonStorage;
this->customEvents = &customEventsStorage;
this->customEventsLastId = &customEventsLastIdStorage;
this->commandPaletteCommands = &commandPaletteCommandsStorage;
this->patternLanguageFunctions = &patternLanguageFunctionsStorage;
this->views = &viewsStorage;
this->tools = &toolsStorage;
this->mainArgc = &mainArgcStorage;
this->mainArgv = &mainArgvStorage;
}
void initializeData(const SharedData &other) {
this->imguiContext = other.imguiContext;
this->eventHandlers = other.eventHandlers;
this->deferredCalls = other.deferredCalls;
this->currentProvider = other.currentProvider;
this->settingsEntries = other.settingsEntries;
this->sharedVariables = other.sharedVariables;
this->windowPos = other.windowPos;
this->windowSize = other.windowSize;
this->settingsJson = other.settingsJson;
this->customEvents = other.customEvents;
this->customEventsLastId = other.customEventsLastId;
this->commandPaletteCommands = other.commandPaletteCommands;
this->patternLanguageFunctions = other.patternLanguageFunctions;
this->views = other.views;
this->tools = other.tools;
this->mainArgc = other.mainArgc;
this->mainArgv = other.mainArgv;
static void setVariable(std::string variableName, T value) {
SharedData::sharedVariables[variableName] = value;
}
public:
ImGuiContext **imguiContext;
std::vector<EventHandler> *eventHandlers;
std::vector<std::function<void()>> *deferredCalls;
prv::Provider **currentProvider;
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> *settingsEntries;
nlohmann::json *settingsJson;
std::map<std::string, Events> *customEvents;
u32 *customEventsLastId;
std::vector<ContentRegistry::CommandPaletteCommands::Entry> *commandPaletteCommands;
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> *patternLanguageFunctions;
std::vector<View*> *views;
std::vector<std::function<void()>> *tools;
static std::vector<EventHandler> eventHandlers;
static std::vector<std::function<void()>> deferredCalls;
static prv::Provider *currentProvider;
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntries;
static nlohmann::json settingsJson;
static std::map<std::string, Events> customEvents;
static u32 customEventsLastId;
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctions;
static std::vector<View*> views;
static std::vector<std::function<void()>> tools;
int *mainArgc;
char ***mainArgv;
static int mainArgc;
static char **mainArgv;
ImVec2 *windowPos;
ImVec2 *windowSize;
static ImVec2 windowPos;
static ImVec2 windowSize;
private:
std::map<std::string, std::any> *sharedVariables;
static std::map<std::string, std::any> sharedVariables;
};
}

View File

@ -11,13 +11,8 @@
#define IMHEX_PLUGIN_SETUP namespace hex::plugin { void setup(); } \
namespace hex::plugin::internal { \
void initializePlugin(SharedData &sharedData) { \
if (glGetString == NULL) \
gladLoadGL(); \
SharedData::get().initializeData(sharedData); \
ImGui::SetCurrentContext(*sharedData.imguiContext); \
void initializePlugin() { \
hex::plugin::setup(); \
\
} \
} \
void hex::plugin::setup()

View File

@ -10,14 +10,14 @@ namespace hex {
/* Settings */
void ContentRegistry::Settings::load() {
std::ifstream settingsFile(std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path() / "settings.json");
std::ifstream settingsFile(std::filesystem::path((SharedData::mainArgv)[0]).parent_path() / "settings.json");
if (settingsFile.good())
settingsFile >> getSettingsData();
}
void ContentRegistry::Settings::store() {
std::ofstream settingsFile(std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path() / "settings.json", std::ios::trunc);
std::ofstream settingsFile(std::filesystem::path((SharedData::mainArgv)[0]).parent_path() / "settings.json", std::ios::trunc);
settingsFile << getSettingsData();
}
@ -40,19 +40,19 @@ namespace hex {
}
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>>& ContentRegistry::Settings::getEntries() {
return *SharedData::get().settingsEntries;
return SharedData::settingsEntries;
}
nlohmann::json& ContentRegistry::Settings::getSettingsData() {
return *SharedData::get().settingsJson;
return SharedData::settingsJson;
}
/* Events */
auto ContentRegistry::Events::get(std::string_view name) {
auto &customEvents = *SharedData::get().customEvents;
auto &lastId = *SharedData::get().customEventsLastId;
auto &customEvents = SharedData::customEvents;
auto &lastId = SharedData::customEventsLastId;
if (!customEvents.contains(name.data())) {
customEvents[name.data()] = static_cast<hex::Events>(lastId);
@ -70,7 +70,7 @@ namespace hex {
}
std::vector<ContentRegistry::CommandPaletteCommands::Entry>& ContentRegistry::CommandPaletteCommands::getEntries() {
return *SharedData::get().commandPaletteCommands;
return SharedData::commandPaletteCommands;
}
@ -81,7 +81,7 @@ namespace hex {
}
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function>& ContentRegistry::PatternLanguageFunctions::getEntries() {
return *SharedData::get().patternLanguageFunctions;
return SharedData::patternLanguageFunctions;
}
@ -96,7 +96,7 @@ namespace hex {
}
std::vector<View*>& ContentRegistry::Views::getEntries() {
return *SharedData::get().views;
return SharedData::views;
}
@ -107,7 +107,7 @@ namespace hex {
}
std::vector<std::function<void()>>& ContentRegistry::Tools::getEntries() {
return *SharedData::get().tools;
return SharedData::tools;
}
}

View File

@ -5,21 +5,21 @@
namespace hex {
void EventManager::post(Events eventType, const void *userData) {
for (auto &handler : *SharedData::get().eventHandlers)
for (auto &handler : SharedData::eventHandlers)
if (eventType == handler.eventType)
handler.callback(userData);
}
void EventManager::subscribe(Events eventType, void *owner, std::function<void(const void*)> callback) {
for (auto &handler : *SharedData::get().eventHandlers)
for (auto &handler : SharedData::eventHandlers)
if (eventType == handler.eventType && owner == handler.owner)
return;
SharedData::get().eventHandlers->push_back(EventHandler { owner, eventType, callback });
SharedData::eventHandlers.push_back(EventHandler { owner, eventType, callback });
}
void EventManager::unsubscribe(Events eventType, void *sender) {
std::erase_if(*SharedData::get().eventHandlers, [&eventType, &sender](EventHandler handler) {
std::erase_if(SharedData::eventHandlers, [&eventType, &sender](EventHandler handler) {
return eventType == handler.eventType && sender == handler.owner;
});
}

View File

@ -0,0 +1,24 @@
#include <helpers/shared_data.hpp>
namespace hex {
std::vector<EventHandler> SharedData::eventHandlers;
std::vector<std::function<void()>> SharedData::deferredCalls;
prv::Provider *SharedData::currentProvider;
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> SharedData::settingsEntries;
nlohmann::json SharedData::settingsJson;
std::map<std::string, Events> SharedData::customEvents;
u32 SharedData::customEventsLastId;
std::vector<ContentRegistry::CommandPaletteCommands::Entry> SharedData::commandPaletteCommands;
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> SharedData::patternLanguageFunctions;
std::vector<View*> SharedData::views;
std::vector<std::function<void()>> SharedData::tools;
int SharedData::mainArgc;
char **SharedData::mainArgv;
ImVec2 SharedData::windowPos;
ImVec2 SharedData::windowSize;
std::map<std::string, std::any> SharedData::sharedVariables;
}

View File

@ -17,7 +17,7 @@ namespace hex {
bool View::handleShortcut(int key, int mods) { return false; }
std::vector<std::function<void()>>& View::getDeferedCalls() {
return *SharedData::get().deferredCalls;
return SharedData::deferredCalls;
}
void View::postEvent(Events eventType, const void *userData) {
@ -76,7 +76,7 @@ namespace hex {
}
void View::doLater(std::function<void()> &&function) {
SharedData::get().deferredCalls->push_back(function);
SharedData::deferredCalls.push_back(function);
}
void View::confirmButtons(const char *textLeft, const char *textRight, std::function<void()> leftButtonFn, std::function<void()> rightButtonFn) {

View File

@ -179,10 +179,10 @@ namespace hex {
}
bool LoaderScript::processFile(std::string_view scriptPath) {
Py_SetProgramName(Py_DecodeLocale((*SharedData::get().mainArgv)[0], nullptr));
Py_SetProgramName(Py_DecodeLocale((SharedData::mainArgv)[0], nullptr));
if (std::filesystem::exists(std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path().string() + "/lib/python" PYTHON_VERSION_MAJOR_MINOR))
Py_SetPythonHome(Py_DecodeLocale(std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path().string().c_str(), nullptr));
if (std::filesystem::exists(std::filesystem::path((SharedData::mainArgv)[0]).parent_path().string() + "/lib/python" PYTHON_VERSION_MAJOR_MINOR))
Py_SetPythonHome(Py_DecodeLocale(std::filesystem::path((SharedData::mainArgv)[0]).parent_path().string().c_str(), nullptr));
PyImport_AppendInittab("_imhex", []() -> PyObject* {

View File

@ -5,8 +5,8 @@
namespace hex {
// hex::plugin::internal::initializePlugin(SharedData&)
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin8internal16initializePluginERNS_10SharedDataE";
// hex::plugin::internal::initializePlugin()
constexpr auto InitializePluginSymbol = "_ZN3hex6plugin8internal16initializePluginEv";
Plugin::Plugin(std::string_view path) {
this->m_handle = dlopen(path.data(), RTLD_LAZY);
@ -22,9 +22,9 @@ namespace hex {
dlclose(this->m_handle);
}
void Plugin::initializePlugin(SharedData &sharedData) const {
void Plugin::initializePlugin() const {
if (this->m_initializePluginFunction != nullptr)
this->m_initializePluginFunction(sharedData);
this->m_initializePluginFunction();
}
void PluginHandler::load(std::string_view pluginFolder) {

View File

@ -61,7 +61,7 @@ namespace hex {
{
u8 bytes[10] = { 0 };
(*SharedData::get().currentProvider)->read(region.address, bytes, std::min(region.size, size_t(10)));
(SharedData::currentProvider)->read(region.address, bytes, std::min(region.size, size_t(10)));
std::string bytesString;
for (u8 i = 0; i < std::min(region.size, size_t(10)); i++) {

View File

@ -40,8 +40,8 @@ namespace hex {
void ViewCommandPalette::drawContent() {
auto windowPos = *SharedData::get().windowPos;
auto windowSize = *SharedData::get().windowSize;
auto windowPos = SharedData::windowPos;
auto windowSize = SharedData::windowSize;
auto paletteSize = this->getMinSize();
ImGui::SetNextWindowPos(ImVec2(windowPos.x + (windowSize.x - paletteSize.x) / 2.0F, windowPos.y), ImGuiCond_Always);
if (ImGui::BeginPopup("Command Palette")) {

View File

@ -13,7 +13,7 @@ namespace hex {
View::subscribeEvent(Events::RegionSelected, [this](const void* userData){
Region region = *static_cast<const Region*>(userData);
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider == nullptr) {
this->m_validBytes = 0;
@ -141,7 +141,7 @@ namespace hex {
if (ImGui::Begin("Data Inspector", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {
if (ImGui::BeginTable("##datainspector", 2,

View File

@ -51,7 +51,7 @@ namespace hex {
if (cs_open(Disassembler::toCapstoneArchictecture(this->m_architecture), mode, &capstoneHandle) == CS_ERR_OK) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
std::vector<u8> buffer(2048, 0x00);
for (u64 address = 0; address < (this->m_codeRegion[1] - this->m_codeRegion[0] + 1); address += 2048) {
size_t bufferSize = std::min(u64(2048), (this->m_codeRegion[1] - this->m_codeRegion[0] + 1) - address);
@ -95,7 +95,7 @@ namespace hex {
if (ImGui::Begin("Disassembler", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {
ImGui::TextUnformatted("Position");
ImGui::Separator();

View File

@ -41,7 +41,7 @@ namespace hex {
if (ImGui::Begin("Hashing", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isAvailable()) {
ImGui::TextUnformatted("Region");

View File

@ -19,7 +19,7 @@ namespace hex {
: View("Hex Editor"), m_patternData(patternData) {
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (!provider->isAvailable() || !provider->isReadable())
return 0x00;
@ -30,7 +30,7 @@ namespace hex {
};
this->m_memoryEditor.WriteFn = [](ImU8 *data, size_t off, ImU8 d) -> void {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (!provider->isAvailable() || !provider->isWritable())
return;
@ -71,7 +71,7 @@ namespace hex {
View::subscribeEvent(Events::SelectionChangeRequest, [this](const void *userData) {
const Region &region = *reinterpret_cast<const Region*>(userData);
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
auto page = provider->getPageOfAddress(region.address);
if (!page.has_value())
return;
@ -110,7 +110,7 @@ namespace hex {
}
void ViewHexEditor::drawContent() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
size_t dataSize = (provider == nullptr || !provider->isReadable()) ? 0x00 : provider->getSize();
@ -300,7 +300,7 @@ namespace hex {
}
void ViewHexEditor::drawMenu() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Open File...", "CTRL + O")) {
@ -415,7 +415,7 @@ namespace hex {
bool ViewHexEditor::handleShortcut(int key, int mods) {
if (mods == GLFW_MOD_CONTROL && key == GLFW_KEY_S) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
for (const auto &[address, value] : provider->getPatches())
provider->writeRaw(address, &value, sizeof(u8));
return true;
@ -444,7 +444,7 @@ namespace hex {
void ViewHexEditor::openFile(std::string path) {
auto& provider = *SharedData::get().currentProvider;
auto& provider = SharedData::currentProvider;
if (provider != nullptr)
delete provider;
@ -493,7 +493,7 @@ namespace hex {
}
void ViewHexEditor::copyBytes() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
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);
@ -512,7 +512,7 @@ namespace hex {
}
void ViewHexEditor::copyString() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
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);
@ -527,7 +527,7 @@ namespace hex {
}
void ViewHexEditor::copyLanguageArray(Language language) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
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);
@ -629,7 +629,7 @@ namespace hex {
}
void ViewHexEditor::copyHexView() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
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);
@ -676,7 +676,7 @@ namespace hex {
}
void ViewHexEditor::copyHexViewHTML() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
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);
@ -809,7 +809,7 @@ R"(
void ViewHexEditor::drawSearchPopup() {
static auto InputCallback = [](ImGuiInputTextCallbackData* data) -> int {
auto _this = static_cast<ViewHexEditor*>(data->UserData);
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
*_this->m_lastSearchBuffer = _this->m_searchFunction(provider, data->Buf);
_this->m_lastSearchIndex = 0;
@ -821,7 +821,7 @@ R"(
};
static auto Find = [this](char *buffer) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
*this->m_lastSearchBuffer = this->m_searchFunction(provider, buffer);
this->m_lastSearchIndex = 0;
@ -899,7 +899,7 @@ R"(
}
void ViewHexEditor::drawGotoPopup() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (ImGui::BeginPopup("Goto")) {
ImGui::TextUnformatted("Goto");
@ -1003,7 +1003,7 @@ R"(
View::postEvent(Events::AddBookmark, &bookmark);
}
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (ImGui::MenuItem("Set base address", nullptr, false, provider != nullptr && provider->isReadable())) {
std::memset(this->m_baseAddressBuffer, sizeof(this->m_baseAddressBuffer), 0x00);
View::doLater([]{ ImGui::OpenPopup("Set base address"); });

View File

@ -49,7 +49,7 @@ namespace hex {
if (ImGui::Begin("Data Information", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav);
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {
if (this->m_shouldInvalidate) {
@ -135,7 +135,7 @@ namespace hex {
if (this->m_dataValid) {
for (auto &[name, value] : (*SharedData::get().currentProvider)->getDataInformation()) {
for (auto &[name, value] : (SharedData::currentProvider)->getDataInformation()) {
ImGui::LabelText(name.c_str(), "%s", value.c_str());
}

View File

@ -13,13 +13,13 @@ namespace hex {
ViewPatches::ViewPatches() : View("Patches") {
View::subscribeEvent(Events::ProjectFileStore, [this](const void*) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr)
ProjectFile::setPatches(provider->getPatches());
});
View::subscribeEvent(Events::ProjectFileLoad, [this](const void*) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr)
provider->getPatches() = ProjectFile::getPatches();
});
@ -32,7 +32,7 @@ namespace hex {
void ViewPatches::drawContent() {
if (ImGui::Begin("Patches", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {

View File

@ -112,7 +112,7 @@ namespace hex {
if (error)
return;
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider == nullptr)
return;
@ -224,7 +224,7 @@ namespace hex {
void ViewPattern::drawContent() {
if (ImGui::Begin("Pattern", &this->getWindowOpenState(), ImGuiWindowFlags_None | ImGuiWindowFlags_NoCollapse)) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isAvailable()) {
auto textEditorSize = ImGui::GetContentRegionAvail();
@ -378,7 +378,7 @@ namespace hex {
return;
}
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
hex::lang::Evaluator evaluator(provider, defaultDataEndianess);
auto patternData = evaluator.evaluate(ast.value());

View File

@ -50,7 +50,7 @@ namespace hex {
void ViewPatternData::drawContent() {
if (ImGui::Begin("Pattern Data", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {
if (beginPatternDataTable(provider, this->m_patternData, this->m_sortedPatternData)) {

View File

@ -47,7 +47,7 @@ namespace hex {
void ViewStrings::drawContent() {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (this->m_shouldInvalidate) {
this->m_shouldInvalidate = false;

View File

@ -42,7 +42,7 @@ namespace hex {
this->m_mathEvaluator.setFunction("read", [this](auto args) -> std::optional<long double> {
u8 value = 0;
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider == nullptr || !provider->isReadable() || args[0] >= provider->getActualSize())
return { };
@ -52,7 +52,7 @@ namespace hex {
}, 1, 1);
this->m_mathEvaluator.setFunction("write", [this](auto args) -> std::optional<long double> {
auto provider = *SharedData::get().currentProvider;
auto provider = SharedData::currentProvider;
if (provider == nullptr || !provider->isWritable() || args[0] >= provider->getActualSize())
return { };

View File

@ -45,10 +45,8 @@ namespace hex {
}
Window::Window(int &argc, char **&argv) {
SharedData::get().initializeData();
hex::SharedData::get().mainArgc = &argc;
hex::SharedData::get().mainArgv = &argv;
hex::SharedData::mainArgc = argc;
hex::SharedData::mainArgv = argv;
ContentRegistry::Settings::load();
View::postEvent(Events::SettingsChanged, nullptr);
@ -254,21 +252,21 @@ namespace hex {
{
int x = 0, y = 0;
glfwGetWindowPos(this->m_window, &x, &y);
*SharedData::get().windowPos = ImVec2(x, y);
SharedData::windowPos = ImVec2(x, y);
}
{
int width = 0, height = 0;
glfwGetWindowSize(this->m_window, &width, &height);
*SharedData::get().windowSize = ImVec2(width, height);
SharedData::windowSize = ImVec2(width, height);
}
glfwSetWindowPosCallback(this->m_window, [](GLFWwindow *window, int x, int y) {
*SharedData::get().windowPos = ImVec2(x, y);
SharedData::windowPos = ImVec2(x, y);
});
glfwSetWindowSizeCallback(this->m_window, [](GLFWwindow *window, int width, int height) {
*SharedData::get().windowSize = ImVec2(width, height);
SharedData::windowSize = ImVec2(width, height);
});
glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) {
@ -297,6 +295,8 @@ namespace hex {
void Window::initImGui() {
IMGUI_CHECKVERSION();
auto *ctx = ImGui::CreateContext();
GImGui = ctx;
ImGuiIO& io = ImGui::GetIO();
ImGuiStyle& style = ImGui::GetStyle();
@ -307,7 +307,7 @@ namespace hex {
style.ScaleAllSizes(this->m_globalScale);
#ifdef __MINGW32__
std::filesystem::path resourcePath = std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path();
std::filesystem::path resourcePath = std::filesystem::path((SharedData::mainArgv)[0]).parent_path();
#elif defined(__linux__)
std::filesystem::path resourcePath = "/usr/share/ImHex";
#else
@ -346,15 +346,13 @@ namespace hex {
}
void Window::initPlugins() {
(*SharedData::get().imguiContext) = ImGui::GetCurrentContext();
try {
auto pluginFolderPath = std::filesystem::path((*SharedData::get().mainArgv)[0]).parent_path() / "plugins";
auto pluginFolderPath = std::filesystem::path((SharedData::mainArgv)[0]).parent_path() / "plugins";
PluginHandler::load(pluginFolderPath.string());
} catch (std::runtime_error &e) { return; }
for (const auto &plugin : PluginHandler::getPlugins()) {
plugin.initializePlugin(SharedData::get());
plugin.initializePlugin();
}
}