sys: Allow multiple files to be loaded simultaneously
This commit is contained in:
parent
a302448b76
commit
8631cb0c2a
@ -21,11 +21,11 @@ namespace hex::prv {
|
||||
explicit FileProvider(std::string path);
|
||||
~FileProvider() override;
|
||||
|
||||
bool isAvailable() override;
|
||||
bool isReadable() override;
|
||||
bool isWritable() override;
|
||||
bool isResizable() override;
|
||||
bool isSavable() override;
|
||||
bool isAvailable() const override;
|
||||
bool isReadable() const override;
|
||||
bool isWritable() const override;
|
||||
bool isResizable() const override;
|
||||
bool isSavable() const override;
|
||||
|
||||
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
||||
void write(u64 offset, const void *buffer, size_t size) override;
|
||||
@ -33,12 +33,13 @@ namespace hex::prv {
|
||||
|
||||
void readRaw(u64 offset, void *buffer, size_t size) override;
|
||||
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
||||
size_t getActualSize() override;
|
||||
size_t getActualSize() const override;
|
||||
|
||||
void save() override;
|
||||
void saveAs(const std::string &path) override;
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> getDataInformation() override;
|
||||
[[nodiscard]] std::string getName() const override;
|
||||
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override;
|
||||
|
||||
private:
|
||||
#if defined(OS_WINDOWS)
|
||||
|
@ -138,7 +138,7 @@ namespace hex::plugin::builtin {
|
||||
constexpr static auto MaxStringLength = 32;
|
||||
|
||||
std::string stringBuffer(std::min<ssize_t>(MaxStringLength, currSelection.size), 0x00);
|
||||
SharedData::currentProvider->read(currSelection.address, stringBuffer.data(), stringBuffer.size());
|
||||
ImHexApi::Provider::get()->read(currSelection.address, stringBuffer.data(), stringBuffer.size());
|
||||
if (currSelection.size > MaxStringLength)
|
||||
stringBuffer += "...";
|
||||
|
||||
|
@ -380,7 +380,7 @@ namespace hex::plugin::builtin {
|
||||
std::vector<u8> data;
|
||||
data.resize(size);
|
||||
|
||||
SharedData::currentProvider->readRaw(address, data.data(), size);
|
||||
ImHexApi::Provider::get()->readRaw(address, data.data(), size);
|
||||
|
||||
this->setBufferOnOutput(2, data);
|
||||
}
|
||||
@ -407,7 +407,7 @@ namespace hex::plugin::builtin {
|
||||
}) { }
|
||||
|
||||
void process() override {
|
||||
auto size = SharedData::currentProvider->getActualSize();
|
||||
auto size = ImHexApi::Provider::get()->getActualSize();
|
||||
|
||||
this->setIntegerOnOutput(0, size);
|
||||
}
|
||||
|
@ -89,12 +89,12 @@ namespace hex::plugin::builtin {
|
||||
|
||||
/* base_address() */
|
||||
ContentRegistry::PatternLanguageFunctions::add(nsStdMem, "base_address", ContentRegistry::PatternLanguageFunctions::NoParameters, [](auto &ctx, auto params) -> ASTNode* {
|
||||
return new ASTNodeIntegerLiteral(u64(SharedData::currentProvider->getBaseAddress()));
|
||||
return new ASTNodeIntegerLiteral(u64(ImHexApi::Provider::get()->getBaseAddress()));
|
||||
});
|
||||
|
||||
/* size() */
|
||||
ContentRegistry::PatternLanguageFunctions::add(nsStdMem, "size", ContentRegistry::PatternLanguageFunctions::NoParameters, [](auto &ctx, auto params) -> ASTNode* {
|
||||
return new ASTNodeIntegerLiteral(u64(SharedData::currentProvider->getActualSize()));
|
||||
return new ASTNodeIntegerLiteral(u64(ImHexApi::Provider::get()->getActualSize()));
|
||||
});
|
||||
|
||||
/* find_sequence(occurrence_index, bytes...) */
|
||||
@ -112,8 +112,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
std::vector<u8> bytes(sequence.size(), 0x00);
|
||||
u32 occurrences = 0;
|
||||
for (u64 offset = 0; offset < SharedData::currentProvider->getSize() - sequence.size(); offset++) {
|
||||
SharedData::currentProvider->read(offset, bytes.data(), bytes.size());
|
||||
for (u64 offset = 0; offset < ImHexApi::Provider::get()->getSize() - sequence.size(); offset++) {
|
||||
ImHexApi::Provider::get()->read(offset, bytes.data(), bytes.size());
|
||||
|
||||
if (bytes == sequence) {
|
||||
if (LITERAL_COMPARE(occurrenceIndex, occurrences < occurrenceIndex)) {
|
||||
@ -133,7 +133,7 @@ namespace hex::plugin::builtin {
|
||||
auto address = AS_TYPE(ASTNodeIntegerLiteral, params[0])->getValue();
|
||||
auto size = AS_TYPE(ASTNodeIntegerLiteral, params[1])->getValue();
|
||||
|
||||
if (LITERAL_COMPARE(address, address >= SharedData::currentProvider->getActualSize()))
|
||||
if (LITERAL_COMPARE(address, address >= ImHexApi::Provider::get()->getActualSize()))
|
||||
ctx.getConsole().abortEvaluation("address out of range");
|
||||
|
||||
return std::visit([&](auto &&address, auto &&size) {
|
||||
@ -141,7 +141,7 @@ namespace hex::plugin::builtin {
|
||||
ctx.getConsole().abortEvaluation("invalid read size");
|
||||
|
||||
u8 value[(u8)size];
|
||||
SharedData::currentProvider->read(address, value, size);
|
||||
ImHexApi::Provider::get()->read(address, value, size);
|
||||
|
||||
switch ((u8)size) {
|
||||
case 1: return new ASTNodeIntegerLiteral(*reinterpret_cast<u8*>(value));
|
||||
@ -159,7 +159,7 @@ namespace hex::plugin::builtin {
|
||||
auto address = AS_TYPE(ASTNodeIntegerLiteral, params[0])->getValue();
|
||||
auto size = AS_TYPE(ASTNodeIntegerLiteral, params[1])->getValue();
|
||||
|
||||
if (LITERAL_COMPARE(address, address >= SharedData::currentProvider->getActualSize()))
|
||||
if (LITERAL_COMPARE(address, address >= ImHexApi::Provider::get()->getActualSize()))
|
||||
ctx.getConsole().abortEvaluation("address out of range");
|
||||
|
||||
return std::visit([&](auto &&address, auto &&size) {
|
||||
@ -167,7 +167,7 @@ namespace hex::plugin::builtin {
|
||||
ctx.getConsole().abortEvaluation("invalid read size");
|
||||
|
||||
u8 value[(u8)size];
|
||||
SharedData::currentProvider->read(address, value, size);
|
||||
ImHexApi::Provider::get()->read(address, value, size);
|
||||
|
||||
switch ((u8)size) {
|
||||
case 1: return new ASTNodeIntegerLiteral(*reinterpret_cast<s8*>(value));
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/api/imhex_api.hpp>
|
||||
|
||||
#include <hex/helpers/net.hpp>
|
||||
#include <hex/helpers/shared_data.hpp>
|
||||
@ -156,8 +157,8 @@ namespace hex::plugin::builtin {
|
||||
evaluator.setFunction("read", [](auto args) -> std::optional<long double> {
|
||||
u8 value = 0;
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider == nullptr || !provider->isReadable() || args[0] >= provider->getActualSize())
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (!ImHexApi::Provider::isValid() || !provider->isReadable() || args[0] >= provider->getActualSize())
|
||||
return { };
|
||||
|
||||
provider->read(args[0], &value, sizeof(u8));
|
||||
@ -166,8 +167,8 @@ namespace hex::plugin::builtin {
|
||||
}, 1, 1);
|
||||
|
||||
evaluator.setFunction("write", [](auto args) -> std::optional<long double> {
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider == nullptr || !provider->isWritable() || args[0] >= provider->getActualSize())
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (!ImHexApi::Provider::isValid() || !provider->isWritable() || args[0] >= provider->getActualSize())
|
||||
return { };
|
||||
|
||||
if (args[1] > 0xFF)
|
||||
|
@ -28,19 +28,19 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Interface::addToolbarItem([] {
|
||||
const static auto buttonSize = ImVec2(ImGui::GetCurrentWindow()->MenuBarHeight(), ImGui::GetCurrentWindow()->MenuBarHeight());
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
// Undo
|
||||
ImGui::Disabled([&provider] {
|
||||
if (ImGui::ToolBarButton(ICON_VS_DISCARD, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue), buttonSize))
|
||||
provider->undo();
|
||||
}, provider == nullptr || !provider->canUndo());
|
||||
}, !ImHexApi::Provider::isValid() || !provider->canUndo());
|
||||
|
||||
// Redo
|
||||
ImGui::Disabled([&provider] {
|
||||
if (ImGui::ToolBarButton(ICON_VS_REDO, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue), buttonSize))
|
||||
provider->redo();
|
||||
}, provider == nullptr || !provider->canRedo());
|
||||
}, !ImHexApi::Provider::isValid() || !provider->canRedo());
|
||||
|
||||
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||
@ -60,7 +60,7 @@ namespace hex::plugin::builtin {
|
||||
ImGui::Disabled([&provider] {
|
||||
if (ImGui::ToolBarButton(ICON_VS_SAVE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue), buttonSize))
|
||||
provider->save();
|
||||
}, provider == nullptr || !provider->isWritable() || !provider->isSavable());
|
||||
}, !ImHexApi::Provider::isValid() || !provider->isWritable() || !provider->isSavable());
|
||||
|
||||
// Save file as
|
||||
ImGui::Disabled([&provider] {
|
||||
@ -68,7 +68,7 @@ namespace hex::plugin::builtin {
|
||||
hex::openFileBrowser("hex.view.hexeditor.save_as"_lang, DialogMode::Save, { }, [&provider](auto path) {
|
||||
provider->saveAs(path);
|
||||
});
|
||||
}, provider == nullptr || !provider->isSavable());
|
||||
}, !ImHexApi::Provider::isValid() || !provider->isSavable());
|
||||
|
||||
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||
@ -82,8 +82,33 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ImHexApi::Bookmarks::add(region.address, region.size, { }, { });
|
||||
}
|
||||
}, provider == nullptr || !provider->isReadable());
|
||||
}, !ImHexApi::Provider::isValid() || !provider->isReadable());
|
||||
|
||||
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||
ImGui::Spacing();
|
||||
|
||||
// Provider switcher
|
||||
ImGui::Disabled([] {
|
||||
auto &providers = ImHexApi::Provider::getProviders();
|
||||
|
||||
std::string preview;
|
||||
if (ImHexApi::Provider::isValid())
|
||||
preview = providers[SharedData::currentProvider]->getName();
|
||||
|
||||
ImGui::SetNextItemWidth(200 * SharedData::globalScale);
|
||||
if (ImGui::BeginCombo("", preview.c_str())) {
|
||||
|
||||
for (int i = 0; i < providers.size(); i++) {
|
||||
if (ImGui::Selectable(providers[i]->getName().c_str())) {
|
||||
SharedData::currentProvider = i;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
}, !ImHexApi::Provider::isValid());
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -6,8 +6,12 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <hex/helpers/concepts.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
||||
namespace prv { class Provider; }
|
||||
|
||||
struct ImHexApi {
|
||||
ImHexApi() = delete;
|
||||
|
||||
@ -36,6 +40,24 @@ namespace hex {
|
||||
static std::list<Entry>& getEntries();
|
||||
};
|
||||
|
||||
struct Provider {
|
||||
|
||||
static prv::Provider* get();
|
||||
static const std::vector<prv::Provider*>& getProviders();
|
||||
|
||||
static bool isValid();
|
||||
|
||||
template<hex::derived_from<prv::Provider> T>
|
||||
static void add(auto&& ... args) {
|
||||
add(new T(std::forward<decltype(args)>(args)...));
|
||||
}
|
||||
|
||||
static void remove(prv::Provider *provider);
|
||||
|
||||
private:
|
||||
static void add(prv::Provider *provider);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,10 @@ namespace hex {
|
||||
|
||||
public:
|
||||
static std::vector<std::function<void()>> deferredCalls;
|
||||
static prv::Provider *currentProvider;
|
||||
|
||||
static std::vector<prv::Provider*> providers;
|
||||
static u32 currentProvider;
|
||||
|
||||
static std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> settingsEntries;
|
||||
static nlohmann::json settingsJson;
|
||||
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
|
||||
|
@ -19,11 +19,11 @@ namespace hex::prv {
|
||||
Provider();
|
||||
virtual ~Provider();
|
||||
|
||||
virtual bool isAvailable() = 0;
|
||||
virtual bool isReadable() = 0;
|
||||
virtual bool isWritable() = 0;
|
||||
virtual bool isResizable() = 0;
|
||||
virtual bool isSavable() = 0;
|
||||
virtual bool isAvailable() const = 0;
|
||||
virtual bool isReadable() const = 0;
|
||||
virtual bool isWritable() const = 0;
|
||||
virtual bool isResizable() const = 0;
|
||||
virtual bool isSavable() const = 0;
|
||||
|
||||
virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true);
|
||||
virtual void readRelative(u64 offset, void *buffer, size_t size, bool overlays = true);
|
||||
@ -37,35 +37,37 @@ namespace hex::prv {
|
||||
|
||||
virtual void readRaw(u64 offset, 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() const = 0;
|
||||
|
||||
void applyOverlays(u64 offset, void *buffer, size_t size);
|
||||
|
||||
std::map<u64, u8>& getPatches();
|
||||
const std::map<u64, u8>& getPatches() const;
|
||||
void applyPatches();
|
||||
|
||||
[[nodiscard]] Overlay* newOverlay();
|
||||
void deleteOverlay(Overlay *overlay);
|
||||
[[nodiscard]] const std::list<Overlay*>& getOverlays();
|
||||
|
||||
u32 getPageCount();
|
||||
u32 getPageCount() const;
|
||||
u32 getCurrentPage() const;
|
||||
void setCurrentPage(u32 page);
|
||||
|
||||
virtual void setBaseAddress(u64 address);
|
||||
virtual u64 getBaseAddress();
|
||||
virtual size_t getSize();
|
||||
virtual std::optional<u32> getPageOfAddress(u64 address);
|
||||
virtual u64 getBaseAddress() const;
|
||||
virtual size_t getSize() const;
|
||||
virtual std::optional<u32> getPageOfAddress(u64 address) const;
|
||||
|
||||
virtual std::vector<std::pair<std::string, std::string>> getDataInformation() = 0;
|
||||
[[nodiscard]] virtual std::string getName() const = 0;
|
||||
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
|
||||
|
||||
void addPatch(u64 offset, const void *buffer, size_t size);
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
bool canUndo();
|
||||
bool canRedo();
|
||||
bool canUndo() const;
|
||||
bool canRedo() const;
|
||||
|
||||
protected:
|
||||
u32 m_currPage = 0;
|
||||
|
@ -43,4 +43,38 @@ namespace hex {
|
||||
return SharedData::bookmarkEntries;
|
||||
}
|
||||
|
||||
|
||||
prv::Provider* ImHexApi::Provider::get() {
|
||||
if (!ImHexApi::Provider::isValid())
|
||||
return nullptr;
|
||||
|
||||
return SharedData::providers[SharedData::currentProvider];
|
||||
}
|
||||
|
||||
const std::vector<prv::Provider*>& ImHexApi::Provider::getProviders() {
|
||||
return SharedData::providers;
|
||||
}
|
||||
|
||||
bool ImHexApi::Provider::isValid() {
|
||||
return !SharedData::providers.empty();
|
||||
}
|
||||
|
||||
void ImHexApi::Provider::add(prv::Provider *provider) {
|
||||
SharedData::providers.push_back(provider);
|
||||
SharedData::currentProvider = SharedData::providers.size() - 1;
|
||||
}
|
||||
|
||||
void ImHexApi::Provider::remove(prv::Provider *provider) {
|
||||
auto &providers = SharedData::providers;
|
||||
|
||||
auto it = std::find(providers.begin(), providers.end(), provider);
|
||||
|
||||
providers.erase(it);
|
||||
|
||||
if (it - providers.begin() == SharedData::currentProvider)
|
||||
SharedData::currentProvider = 0;
|
||||
|
||||
delete provider;
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,10 @@
|
||||
namespace hex {
|
||||
|
||||
std::vector<std::function<void()>> SharedData::deferredCalls;
|
||||
prv::Provider *SharedData::currentProvider;
|
||||
|
||||
std::vector<prv::Provider*> SharedData::providers;
|
||||
u32 SharedData::currentProvider;
|
||||
|
||||
std::map<std::string, std::vector<ContentRegistry::Settings::Entry>> SharedData::settingsEntries;
|
||||
nlohmann::json SharedData::settingsJson;
|
||||
std::vector<ContentRegistry::CommandPaletteCommands::Entry> SharedData::commandPaletteCommands;
|
||||
|
@ -49,7 +49,7 @@ namespace hex::pl {
|
||||
this->m_preprocessor->addPragmaHandler("base_address", [](std::string value) {
|
||||
auto baseAddress = strtoull(value.c_str(), nullptr, 0);
|
||||
|
||||
SharedData::currentProvider->setBaseAddress(baseAddress);
|
||||
ImHexApi::Provider::get()->setBaseAddress(baseAddress);
|
||||
return true;
|
||||
});
|
||||
|
||||
|
@ -57,6 +57,10 @@ namespace hex::prv {
|
||||
return *(this->m_patches.end() - 1 - this->m_patchTreeOffset);
|
||||
}
|
||||
|
||||
const std::map<u64, u8>& Provider::getPatches() const {
|
||||
return *(this->m_patches.end() - 1 - this->m_patchTreeOffset);
|
||||
}
|
||||
|
||||
void Provider::applyPatches() {
|
||||
for (auto &[patchAddress, patch] : getPatches())
|
||||
this->writeRaw(patchAddress, &patch, 1);
|
||||
@ -77,7 +81,7 @@ namespace hex::prv {
|
||||
}
|
||||
|
||||
|
||||
u32 Provider::getPageCount() {
|
||||
u32 Provider::getPageCount() const {
|
||||
return std::ceil(this->getActualSize() / double(PageSize));
|
||||
}
|
||||
|
||||
@ -95,15 +99,15 @@ namespace hex::prv {
|
||||
this->m_baseAddress = address;
|
||||
}
|
||||
|
||||
u64 Provider::getBaseAddress() {
|
||||
u64 Provider::getBaseAddress() const {
|
||||
return this->m_baseAddress + PageSize * this->m_currPage;
|
||||
}
|
||||
|
||||
size_t Provider::getSize() {
|
||||
size_t Provider::getSize() const {
|
||||
return std::min(this->getActualSize() - PageSize * this->m_currPage, PageSize);
|
||||
}
|
||||
|
||||
std::optional<u32> Provider::getPageOfAddress(u64 address) {
|
||||
std::optional<u32> Provider::getPageOfAddress(u64 address) const {
|
||||
u32 page = std::floor((address - this->getBaseAddress()) / double(PageSize));
|
||||
|
||||
if (page >= this->getPageCount())
|
||||
@ -134,11 +138,11 @@ namespace hex::prv {
|
||||
this->m_patchTreeOffset--;
|
||||
}
|
||||
|
||||
bool Provider::canUndo() {
|
||||
bool Provider::canUndo() const {
|
||||
return this->m_patchTreeOffset < this->m_patches.size() - 1;
|
||||
}
|
||||
|
||||
bool Provider::canRedo() {
|
||||
bool Provider::canRedo() const {
|
||||
return this->m_patchTreeOffset > 0;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace hex {
|
||||
bool View::handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) { return false; }
|
||||
|
||||
bool View::isAvailable() {
|
||||
return SharedData::currentProvider != nullptr && SharedData::currentProvider->isAvailable();
|
||||
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
|
||||
}
|
||||
|
||||
std::vector<std::function<void()>>& View::getDeferedCalls() {
|
||||
|
@ -198,8 +198,8 @@ namespace hex::init {
|
||||
bool deleteSharedData() {
|
||||
SharedData::deferredCalls.clear();
|
||||
|
||||
delete SharedData::currentProvider;
|
||||
SharedData::currentProvider = nullptr;
|
||||
while (ImHexApi::Provider::isValid())
|
||||
ImHexApi::Provider::remove(ImHexApi::Provider::get());
|
||||
|
||||
SharedData::settingsEntries.clear();
|
||||
SharedData::settingsJson.clear();
|
||||
|
@ -18,7 +18,7 @@ namespace hex::prv {
|
||||
}
|
||||
|
||||
|
||||
bool FileProvider::isAvailable() {
|
||||
bool FileProvider::isAvailable() const {
|
||||
#if defined(OS_WINDOWS)
|
||||
return this->m_file != nullptr && this->m_mapping != nullptr && this->m_mappedFile != nullptr;
|
||||
#else
|
||||
@ -26,19 +26,19 @@ namespace hex::prv {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileProvider::isReadable() {
|
||||
bool FileProvider::isReadable() const {
|
||||
return isAvailable() && this->m_readable;
|
||||
}
|
||||
|
||||
bool FileProvider::isWritable() {
|
||||
bool FileProvider::isWritable() const {
|
||||
return isAvailable() && this->m_writable;
|
||||
}
|
||||
|
||||
bool FileProvider::isResizable() {
|
||||
bool FileProvider::isResizable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileProvider::isSavable() {
|
||||
bool FileProvider::isSavable() const {
|
||||
return !this->getPatches().empty();
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ namespace hex::prv {
|
||||
std::vector<u8> buffer(std::min<size_t>(0xFF'FFFF, file.getSize()), 0x00);
|
||||
size_t bufferSize = buffer.size();
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
|
||||
if (bufferSize > provider->getActualSize() - offset)
|
||||
bufferSize = provider->getActualSize() - offset;
|
||||
@ -137,11 +137,15 @@ namespace hex::prv {
|
||||
this->open();
|
||||
}
|
||||
|
||||
size_t FileProvider::getActualSize() {
|
||||
size_t FileProvider::getActualSize() const {
|
||||
return this->m_fileSize;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> FileProvider::getDataInformation() {
|
||||
std::string FileProvider::getName() const {
|
||||
return std::filesystem::path(this->m_path).filename().string();
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, std::string>> FileProvider::getDataInformation() const {
|
||||
std::vector<std::pair<std::string, std::string>> result;
|
||||
|
||||
result.emplace_back("hex.builtin.provider.file.path"_lang, this->m_path);
|
||||
|
@ -91,7 +91,7 @@ namespace hex {
|
||||
{
|
||||
std::array<u8, 0x10> bytes = { 0 };
|
||||
size_t byteCount = std::min<size_t>(0x10 - offset, region.size);
|
||||
SharedData::currentProvider->read(region.address, bytes.data() + offset, byteCount);
|
||||
ImHexApi::Provider::get()->read(region.address, bytes.data() + offset, byteCount);
|
||||
|
||||
for (size_t byte = 0; byte < 0x10; byte++) {
|
||||
if (byte < offset)
|
||||
@ -108,7 +108,7 @@ namespace hex {
|
||||
std::array<u8, 0x10> bytes = { 0 };
|
||||
for (u32 i = 0x10 - offset; i < region.size; i += 0x10) {
|
||||
size_t byteCount = std::min<size_t>(region.size - i, 0x10);
|
||||
SharedData::currentProvider->read(region.address + i, bytes.data(), byteCount);
|
||||
ImHexApi::Provider::get()->read(region.address + i, bytes.data(), byteCount);
|
||||
|
||||
for (size_t byte = 0; byte < byteCount; byte++) {
|
||||
ImGui::Text("%02X", bytes[byte]);
|
||||
|
@ -12,9 +12,9 @@ namespace hex {
|
||||
|
||||
ViewDataInspector::ViewDataInspector() : View("hex.view.data_inspector.name") {
|
||||
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (provider == nullptr || region.address == (size_t)-1) {
|
||||
if (!ImHexApi::Provider::isValid() || region.address == (size_t)-1) {
|
||||
this->m_validBytes = 0;
|
||||
} else {
|
||||
this->m_validBytes = u64(provider->getSize() - region.address);
|
||||
@ -34,7 +34,7 @@ namespace hex {
|
||||
this->m_shouldInvalidate = false;
|
||||
|
||||
this->m_cachedData.clear();
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
for (auto &entry : ContentRegistry::DataInspector::getEntries()) {
|
||||
if (this->m_validBytes < entry.requiredSize)
|
||||
continue;
|
||||
@ -48,9 +48,9 @@ namespace hex {
|
||||
|
||||
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (provider != nullptr && provider->isReadable() && this->m_validBytes > 0) {
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable() && this->m_validBytes > 0) {
|
||||
if (ImGui::BeginTable("##datainspector", 2,
|
||||
ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg,
|
||||
ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * (this->m_cachedData.size() + 1)))) {
|
||||
|
@ -100,11 +100,11 @@ namespace hex {
|
||||
void ViewDataProcessor::processNodes() {
|
||||
if (this->m_dataOverlays.size() != this->m_endNodes.size()) {
|
||||
for (auto overlay : this->m_dataOverlays)
|
||||
SharedData::currentProvider->deleteOverlay(overlay);
|
||||
ImHexApi::Provider::get()->deleteOverlay(overlay);
|
||||
this->m_dataOverlays.clear();
|
||||
|
||||
for (u32 i = 0; i < this->m_endNodes.size(); i++)
|
||||
this->m_dataOverlays.push_back(SharedData::currentProvider->newOverlay());
|
||||
this->m_dataOverlays.push_back(ImHexApi::Provider::get()->newOverlay());
|
||||
|
||||
u32 overlayIndex = 0;
|
||||
for (auto endNode : this->m_endNodes) {
|
||||
@ -128,7 +128,7 @@ namespace hex {
|
||||
this->m_currNodeError = e;
|
||||
|
||||
for (auto overlay : this->m_dataOverlays)
|
||||
SharedData::currentProvider->deleteOverlay(overlay);
|
||||
ImHexApi::Provider::get()->deleteOverlay(overlay);
|
||||
this->m_dataOverlays.clear();
|
||||
|
||||
} catch (std::runtime_error &e) {
|
||||
|
@ -59,7 +59,7 @@ namespace hex {
|
||||
|
||||
cs_option(capstoneHandle, CS_OPT_SKIPDATA, CS_OPT_ON);
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
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);
|
||||
@ -106,8 +106,8 @@ namespace hex {
|
||||
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.disassembler.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
ImGui::TextUnformatted("hex.view.disassembler.position"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
|
@ -43,8 +43,8 @@ namespace hex {
|
||||
if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) {
|
||||
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr && provider->isAvailable()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid() && provider->isAvailable()) {
|
||||
|
||||
ImGui::TextUnformatted("hex.common.region"_lang);
|
||||
ImGui::Separator();
|
||||
|
@ -35,7 +35,7 @@ namespace hex {
|
||||
this->m_searchHexBuffer.resize(0xFFF, 0x00);
|
||||
|
||||
this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (!provider->isAvailable() || !provider->isReadable())
|
||||
return 0x00;
|
||||
|
||||
@ -46,7 +46,7 @@ namespace hex {
|
||||
};
|
||||
|
||||
this->m_memoryEditor.WriteFn = [](ImU8 *data, size_t off, ImU8 d) -> void {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (!provider->isAvailable() || !provider->isWritable())
|
||||
return;
|
||||
|
||||
@ -60,7 +60,7 @@ namespace hex {
|
||||
|
||||
std::optional<u32> currColor, prevColor;
|
||||
|
||||
off += SharedData::currentProvider->getBaseAddress();
|
||||
off += ImHexApi::Provider::get()->getBaseAddress();
|
||||
|
||||
u32 alpha = static_cast<u32>(_this->m_highlightAlpha) << 24;
|
||||
|
||||
@ -96,7 +96,7 @@ namespace hex {
|
||||
this->m_memoryEditor.HoverFn = [](const ImU8 *data, size_t off) {
|
||||
bool tooltipShown = false;
|
||||
|
||||
off += SharedData::currentProvider->getBaseAddress();
|
||||
off += ImHexApi::Provider::get()->getBaseAddress();
|
||||
|
||||
for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) {
|
||||
if (off >= region.address && off < (region.address + region.size)) {
|
||||
@ -120,7 +120,7 @@ namespace hex {
|
||||
if (_this->m_currEncodingFile.getLongestSequence() == 0)
|
||||
return { ".", 1, 0xFFFF8000 };
|
||||
|
||||
auto &provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
size_t size = std::min<size_t>(_this->m_currEncodingFile.getLongestSequence(), provider->getActualSize() - addr);
|
||||
|
||||
std::vector<u8> buffer(size);
|
||||
@ -144,7 +144,7 @@ namespace hex {
|
||||
});
|
||||
|
||||
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
auto page = provider->getPageOfAddress(region.address);
|
||||
|
||||
if (!page.has_value())
|
||||
@ -272,9 +272,9 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawContent() {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
size_t dataSize = (provider == nullptr || !provider->isReadable()) ? 0x00 : provider->getSize();
|
||||
size_t dataSize = (!ImHexApi::Provider::isValid() || !provider->isReadable()) ? 0x00 : provider->getSize();
|
||||
|
||||
this->m_memoryEditor.DrawWindow(View::toWindowName("hex.view.hexeditor.name").c_str(), &this->getWindowOpenState(), this, dataSize, dataSize == 0 ? 0x00 : provider->getBaseAddress());
|
||||
|
||||
@ -318,19 +318,17 @@ namespace hex {
|
||||
}
|
||||
|
||||
static void save() {
|
||||
auto provider = SharedData::currentProvider;
|
||||
provider->save();
|
||||
ImHexApi::Provider::get()->save();
|
||||
}
|
||||
|
||||
static void saveAs() {
|
||||
hex::openFileBrowser("hex.view.hexeditor.save_as"_lang, DialogMode::Save, { }, [](auto path) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
provider->saveAs(path);
|
||||
ImHexApi::Provider::get()->saveAs(path);
|
||||
});
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawAlwaysVisible() {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (ImGui::BeginPopupModal("hex.view.hexeditor.exit_application.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::NewLine();
|
||||
@ -431,7 +429,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawMenu() {
|
||||
auto &provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
bool providerValid = ImHexApi::Provider::isValid();
|
||||
|
||||
if (ImGui::BeginMenu("hex.menu.file"_lang)) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) {
|
||||
@ -451,18 +450,17 @@ namespace hex {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, provider != nullptr && provider->isWritable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, providerValid && provider->isWritable())) {
|
||||
save();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_as"_lang, "CTRL + SHIFT + S", false, provider != nullptr && provider->isWritable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_as"_lang, "CTRL + SHIFT + S", false, providerValid && provider->isWritable())) {
|
||||
saveAs();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.close"_lang, "", false, provider != nullptr && provider->isAvailable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.close"_lang, "", false, providerValid && provider->isAvailable())) {
|
||||
EventManager::post<EventFileUnloaded>();
|
||||
delete SharedData::currentProvider;
|
||||
SharedData::currentProvider = nullptr;
|
||||
ImHexApi::Provider::remove(ImHexApi::Provider::get());
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.quit"_lang, "", false)) {
|
||||
@ -478,7 +476,7 @@ namespace hex {
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_project"_lang, "", false, provider != nullptr && provider->isWritable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) {
|
||||
if (ProjectFile::getProjectFilePath() == "") {
|
||||
hex::openFileBrowser("hex.view.hexeditor.save_project"_lang, DialogMode::Save, { { "Project File", "hexproj" } }, [](auto path) {
|
||||
if (path.ends_with(".hexproj")) {
|
||||
@ -528,8 +526,9 @@ namespace hex {
|
||||
auto patchData = File(path, File::Mode::Read).readBytes();
|
||||
auto patch = hex::loadIPSPatch(patchData);
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
for (auto &[address, value] : patch) {
|
||||
SharedData::currentProvider->write(address, &value, 1);
|
||||
provider->write(address, &value, 1);
|
||||
}
|
||||
this->getWindowOpenState() = true;
|
||||
});
|
||||
@ -542,8 +541,9 @@ namespace hex {
|
||||
auto patchData = File(path, File::Mode::Read).readBytes();
|
||||
auto patch = hex::loadIPS32Patch(patchData);
|
||||
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
for (auto &[address, value] : patch) {
|
||||
SharedData::currentProvider->write(address, &value, 1);
|
||||
provider->write(address, &value, 1);
|
||||
}
|
||||
this->getWindowOpenState() = true;
|
||||
});
|
||||
@ -558,7 +558,7 @@ namespace hex {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("hex.view.hexeditor.menu.file.export"_lang, provider != nullptr && provider->isWritable())) {
|
||||
if (ImGui::BeginMenu("hex.view.hexeditor.menu.file.export"_lang, providerValid && provider->isWritable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.export.ips"_lang)) {
|
||||
Patches patches = provider->getPatches();
|
||||
if (!patches.contains(0x00454F45) && patches.contains(0x00454F46)) {
|
||||
@ -626,12 +626,12 @@ namespace hex {
|
||||
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) {
|
||||
if (ctrl && keys['Z']) {
|
||||
if (SharedData::currentProvider != nullptr)
|
||||
SharedData::currentProvider->undo();
|
||||
if (ImHexApi::Provider::isValid())
|
||||
ImHexApi::Provider::get()->undo();
|
||||
return true;
|
||||
} else if (ctrl && keys['Y']) {
|
||||
if (SharedData::currentProvider != nullptr)
|
||||
SharedData::currentProvider->redo();
|
||||
if (ImHexApi::Provider::isValid())
|
||||
ImHexApi::Provider::get()->redo();
|
||||
} else if (ctrl && keys['F']) {
|
||||
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.file.search"_lang); });
|
||||
return true;
|
||||
@ -651,7 +651,8 @@ namespace hex {
|
||||
this->pasteBytes();
|
||||
return true;
|
||||
} else if (ctrl && keys['A']) {
|
||||
EventManager::post<RequestSelectionChange>(Region { SharedData::currentProvider->getBaseAddress(), SharedData::currentProvider->getActualSize() });
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
EventManager::post<RequestSelectionChange>(Region { provider->getBaseAddress(), provider->getActualSize() });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -695,11 +696,9 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::openFile(const std::string &path) {
|
||||
auto& provider = SharedData::currentProvider;
|
||||
ImHexApi::Provider::add<prv::FileProvider>(path);
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
delete provider;
|
||||
|
||||
provider = new prv::FileProvider(path);
|
||||
if (!provider->isWritable()) {
|
||||
this->m_memoryEditor.ReadOnly = true;
|
||||
View::showErrorPopup("hex.view.hexeditor.error.read_only"_lang);
|
||||
@ -709,8 +708,7 @@ namespace hex {
|
||||
|
||||
if (!provider->isAvailable()) {
|
||||
View::showErrorPopup("hex.view.hexeditor.error.open"_lang);
|
||||
delete provider;
|
||||
provider = nullptr;
|
||||
ImHexApi::Provider::remove(provider);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -737,7 +735,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::copyBytes() const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -756,7 +754,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::pasteBytes() const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -798,7 +796,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::copyString() const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -813,7 +811,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::copyLanguageArray(Language language) const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -915,7 +913,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::copyHexView() const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -962,7 +960,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewHexEditor::copyHexViewHTML() const {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
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);
|
||||
@ -1095,7 +1093,7 @@ R"(
|
||||
void ViewHexEditor::drawSearchPopup() {
|
||||
static auto InputCallback = [](ImGuiInputTextCallbackData* data) -> int {
|
||||
auto _this = static_cast<ViewHexEditor*>(data->UserData);
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
*_this->m_lastSearchBuffer = _this->m_searchFunction(provider, data->Buf);
|
||||
_this->m_lastSearchIndex = 0;
|
||||
@ -1107,7 +1105,7 @@ R"(
|
||||
};
|
||||
|
||||
static auto Find = [this](char *buffer) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
*this->m_lastSearchBuffer = this->m_searchFunction(provider, buffer);
|
||||
this->m_lastSearchIndex = 0;
|
||||
@ -1187,7 +1185,7 @@ R"(
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawGotoPopup() {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
auto baseAddress = provider->getBaseAddress();
|
||||
auto dataSize = provider->getActualSize();
|
||||
|
||||
@ -1253,10 +1251,12 @@ R"(
|
||||
}
|
||||
|
||||
void ViewHexEditor::drawEditPopup() {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.undo"_lang, "CTRL + Z", false, SharedData::currentProvider != nullptr))
|
||||
SharedData::currentProvider->undo();
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.redo"_lang, "CTRL + Y", false, SharedData::currentProvider != nullptr))
|
||||
SharedData::currentProvider->redo();
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
bool providerValid = ImHexApi::Provider::isValid();
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.undo"_lang, "CTRL + Z", false, providerValid))
|
||||
provider->undo();
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.redo"_lang, "CTRL + Y", false, providerValid))
|
||||
provider->redo();
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
@ -1299,13 +1299,13 @@ R"(
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.paste"_lang, "CTRL + V", false, bytesSelected))
|
||||
this->pasteBytes();
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.select_all"_lang, "CTRL + A", false, SharedData::currentProvider != nullptr))
|
||||
EventManager::post<RequestSelectionChange>(Region { SharedData::currentProvider->getBaseAddress(), SharedData::currentProvider->getActualSize() });
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.select_all"_lang, "CTRL + A", false, providerValid))
|
||||
EventManager::post<RequestSelectionChange>(Region { provider->getBaseAddress(), provider->getActualSize() });
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.bookmark"_lang, nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) {
|
||||
auto base = SharedData::currentProvider->getBaseAddress();
|
||||
auto base = ImHexApi::Provider::get()->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);
|
||||
@ -1313,15 +1313,14 @@ R"(
|
||||
ImHexApi::Bookmarks::add(start, end - start + 1, { }, { });
|
||||
}
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.set_base"_lang, nullptr, false, provider != nullptr && provider->isReadable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.set_base"_lang, nullptr, false, providerValid && provider->isReadable())) {
|
||||
std::memset(this->m_baseAddressBuffer, 0x00, sizeof(this->m_baseAddressBuffer));
|
||||
View::doLater([]{ ImGui::OpenPopup("hex.view.hexeditor.menu.edit.set_base"_lang); });
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.resize"_lang, nullptr, false, provider != nullptr && provider->isResizable())) {
|
||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.edit.resize"_lang, nullptr, false, providerValid && provider->isResizable())) {
|
||||
View::doLater([this]{
|
||||
this->m_resizeSize = SharedData::currentProvider->getActualSize();
|
||||
this->m_resizeSize = ImHexApi::Provider::get()->getActualSize();
|
||||
ImGui::OpenPopup("hex.view.hexeditor.menu.edit.resize"_lang);
|
||||
});
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace hex {
|
||||
this->m_analyzing = true;
|
||||
|
||||
std::thread([this]{
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
this->m_analyzedRegion = { provider->getBaseAddress(), provider->getBaseAddress() + provider->getSize() };
|
||||
|
||||
@ -110,8 +110,8 @@ namespace hex {
|
||||
if (ImGui::BeginChild("##scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav)) {
|
||||
|
||||
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
ImGui::TextUnformatted("hex.view.information.control"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
@ -131,7 +131,7 @@ namespace hex {
|
||||
ImGui::TextUnformatted("hex.view.information.region"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, value] : (SharedData::currentProvider)->getDataInformation()) {
|
||||
for (auto &[name, value] : provider->getDataInformation()) {
|
||||
ImGui::LabelText(name.c_str(), "%s", value.c_str());
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,14 @@ namespace hex {
|
||||
|
||||
ViewPatches::ViewPatches() : View("hex.view.patches.name") {
|
||||
EventManager::subscribe<EventProjectFileStore>(this, []{
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr)
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid())
|
||||
ProjectFile::setPatches(provider->getPatches());
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProjectFileLoad>(this, []{
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr)
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid())
|
||||
provider->getPatches() = ProjectFile::getPatches();
|
||||
});
|
||||
}
|
||||
@ -31,9 +31,9 @@ namespace hex {
|
||||
|
||||
void ViewPatches::drawContent() {
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.patches.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
|
||||
if (ImGui::BeginTable("##patchesTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable |
|
||||
ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
|
||||
|
@ -49,8 +49,8 @@ namespace hex {
|
||||
|
||||
void ViewPatternData::drawContent() {
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.pattern_data.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
|
||||
if (beginPatternDataTable(provider, SharedData::patternData, this->m_sortedPatternData)) {
|
||||
ImGui::TableHeadersRow();
|
||||
|
@ -106,12 +106,11 @@ namespace hex {
|
||||
return;
|
||||
|
||||
pl::Preprocessor preprocessor;
|
||||
auto provider = SharedData::currentProvider;
|
||||
|
||||
if (provider == nullptr)
|
||||
if (ImHexApi::Provider::isValid())
|
||||
return;
|
||||
|
||||
std::string mimeType = magic::getMIMEType(provider);
|
||||
std::string mimeType = magic::getMIMEType(ImHexApi::Provider::get());
|
||||
|
||||
bool foundCorrectType = false;
|
||||
preprocessor.addPragmaHandler("MIME", [&mimeType, &foundCorrectType](std::string value) {
|
||||
@ -193,9 +192,9 @@ namespace hex {
|
||||
|
||||
void ViewPatternEditor::drawContent() {
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.pattern.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_None | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (provider != nullptr && provider->isAvailable()) {
|
||||
if (ImHexApi::Provider::isValid() && provider->isAvailable()) {
|
||||
auto textEditorSize = ImGui::GetContentRegionAvail();
|
||||
textEditorSize.y *= 4.0/5.0;
|
||||
textEditorSize.y -= ImGui::GetTextLineHeightWithSpacing();
|
||||
@ -340,7 +339,7 @@ namespace hex {
|
||||
EventManager::post<EventPatternChanged>();
|
||||
|
||||
std::thread([this, buffer = std::string(buffer)] {
|
||||
auto result = this->m_patternLanguageRuntime->executeString(SharedData::currentProvider, buffer);
|
||||
auto result = this->m_patternLanguageRuntime->executeString(ImHexApi::Provider::get(), buffer);
|
||||
|
||||
auto error = this->m_patternLanguageRuntime->getError();
|
||||
if (error.has_value()) {
|
||||
|
@ -27,7 +27,7 @@ namespace hex {
|
||||
|
||||
std::string readString(const FoundString &foundString) {
|
||||
std::string string(foundString.size + 1, '\0');
|
||||
SharedData::currentProvider->read(foundString.offset, string.data(), foundString.size);
|
||||
ImHexApi::Provider::get()->read(foundString.offset, string.data(), foundString.size);
|
||||
|
||||
return string;
|
||||
}
|
||||
@ -57,7 +57,7 @@ namespace hex {
|
||||
this->m_searching = true;
|
||||
|
||||
std::thread([this] {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
std::vector<u8> buffer(1024, 0x00);
|
||||
u32 foundCharacters = 0;
|
||||
@ -91,10 +91,10 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewStrings::drawContent() {
|
||||
auto provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.strings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
||||
ImGui::Disabled([this]{
|
||||
if (ImGui::InputInt("hex.view.strings.min_length"_lang, &this->m_minimumLength, 1, 0))
|
||||
this->m_foundStrings.clear();
|
||||
|
@ -151,7 +151,7 @@ namespace hex {
|
||||
YR_RULES *rules;
|
||||
yr_compiler_get_rules(compiler, &rules);
|
||||
|
||||
auto &provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
std::vector<YaraMatch> newMatches;
|
||||
|
||||
@ -167,7 +167,7 @@ namespace hex {
|
||||
context.currBlock.fetch_data = [](auto *block) -> const u8* {
|
||||
auto &context = *static_cast<ScanContext*>(block->context);
|
||||
|
||||
auto &provider = SharedData::currentProvider;
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
|
||||
context.buffer.resize(std::min<u64>(0xF'FFFF, provider->getSize() - context.currBlock.base));
|
||||
|
||||
@ -178,7 +178,7 @@ namespace hex {
|
||||
return context.buffer.data();
|
||||
};
|
||||
iterator.file_size = [](auto *iterator) -> u64 {
|
||||
return SharedData::currentProvider->getSize();
|
||||
return ImHexApi::Provider::get()->getSize();
|
||||
};
|
||||
|
||||
iterator.context = &context;
|
||||
@ -199,7 +199,7 @@ namespace hex {
|
||||
|
||||
iterator->last_error = ERROR_SUCCESS;
|
||||
context.currBlock.base = address;
|
||||
context.currBlock.size = std::min<u64>(0xF'FFFF, SharedData::currentProvider->getSize() - address);
|
||||
context.currBlock.size = std::min<u64>(0xF'FFFF, ImHexApi::Provider::get()->getSize() - address);
|
||||
context.currBlock.context = &context;
|
||||
|
||||
if (context.currBlock.size == 0) return nullptr;
|
||||
|
@ -139,7 +139,7 @@
|
||||
return HTBOTTOMRIGHT;
|
||||
case RegionClient:
|
||||
default:
|
||||
if ((cursor.y < (window.top + titleBarHeight * 2)) && !ImGui::IsAnyItemHovered())
|
||||
if ((cursor.y < (window.top + titleBarHeight)) && !(ImGui::IsAnyItemHovered() || ImGui::IsAnyItemFocused()))
|
||||
return HTCAPTION;
|
||||
else break;
|
||||
}
|
||||
|
@ -65,8 +65,6 @@ namespace hex {
|
||||
}
|
||||
|
||||
Window::Window() {
|
||||
SharedData::currentProvider = nullptr;
|
||||
|
||||
{
|
||||
for (const auto &[argument, value] : init::getInitArguments()) {
|
||||
if (argument == "update-available") {
|
||||
@ -200,7 +198,7 @@ namespace hex {
|
||||
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](std::string windowTitle) {
|
||||
std::string title = "ImHex";
|
||||
|
||||
if (SharedData::currentProvider != nullptr) {
|
||||
if (ImHexApi::Provider::isValid()) {
|
||||
if (!windowTitle.empty())
|
||||
title += " - " + windowTitle;
|
||||
|
||||
@ -373,7 +371,7 @@ namespace hex {
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
if (SharedData::currentProvider == nullptr) {
|
||||
if (!ImHexApi::Provider::isValid()) {
|
||||
static char title[256];
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));
|
||||
if (ImGui::Begin(title)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user