2022-11-14 10:02:46 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
2023-11-18 14:50:43 +01:00
|
|
|
#include <hex/api/event_manager.hpp>
|
2023-04-08 21:07:57 +02:00
|
|
|
|
2022-11-14 10:02:46 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
class ViewProvider : public hex::prv::Provider {
|
|
|
|
public:
|
2023-04-08 21:07:57 +02:00
|
|
|
explicit ViewProvider() {
|
2023-12-08 10:29:44 +01:00
|
|
|
EventProviderClosing::subscribe(this, [this](const prv::Provider *provider, bool*) {
|
2023-04-08 21:07:57 +02:00
|
|
|
if (this->m_provider == provider)
|
2023-11-07 15:31:54 +01:00
|
|
|
ImHexApi::Provider::remove(this, false);
|
2023-04-08 21:07:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
~ViewProvider() override {
|
2023-12-08 10:29:44 +01:00
|
|
|
EventProviderClosing::unsubscribe(this);
|
2023-04-08 21:07:57 +02:00
|
|
|
}
|
2022-11-14 10:02:46 +01:00
|
|
|
|
2023-01-30 18:15:42 +01:00
|
|
|
[[nodiscard]] bool isAvailable() const override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return this->m_provider->isAvailable();
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool isReadable() const override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return this->m_provider->isReadable();
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool isWritable() const override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return this->m_provider->isWritable();
|
|
|
|
}
|
2022-11-14 10:02:46 +01:00
|
|
|
[[nodiscard]] bool isResizable() const override { return true; }
|
2023-07-05 20:49:57 +02:00
|
|
|
|
|
|
|
[[nodiscard]] bool isSavable() const override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return this->m_provider->isSavable();
|
|
|
|
}
|
2022-11-14 10:02:46 +01:00
|
|
|
|
|
|
|
void save() override {
|
|
|
|
this->m_provider->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool open() override { return true; }
|
|
|
|
void close() override { }
|
|
|
|
|
2023-11-25 12:43:48 +01:00
|
|
|
void resizeRaw(size_t newSize) override {
|
2022-11-14 10:02:46 +01:00
|
|
|
this->m_size = newSize;
|
|
|
|
}
|
2023-11-25 12:43:48 +01:00
|
|
|
void insertRaw(u64 offset, size_t size) override {
|
2023-01-30 18:15:42 +01:00
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return;
|
|
|
|
|
2022-11-14 10:02:46 +01:00
|
|
|
this->m_size += size;
|
|
|
|
this->m_provider->insert(offset + this->m_startAddress, size);
|
|
|
|
}
|
|
|
|
|
2023-11-25 12:43:48 +01:00
|
|
|
void removeRaw(u64 offset, size_t size) override {
|
2023-01-30 18:15:42 +01:00
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return;
|
|
|
|
|
2022-11-14 10:02:46 +01:00
|
|
|
this->m_size -= size;
|
|
|
|
this->m_provider->remove(offset + this->m_startAddress, size);
|
|
|
|
}
|
|
|
|
|
2023-01-30 18:15:42 +01:00
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->m_provider->read(offset + this->m_startAddress, buffer, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeRaw(u64 offset, const void *buffer, size_t size) override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->m_provider->write(offset + this->m_startAddress, buffer, size);
|
|
|
|
}
|
|
|
|
|
2023-12-07 12:06:26 +01:00
|
|
|
[[nodiscard]] u64 getActualSize() const override { return this->m_size; }
|
2022-11-14 10:02:46 +01:00
|
|
|
|
2023-01-30 18:15:42 +01:00
|
|
|
[[nodiscard]] std::string getName() const override {
|
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return "View";
|
|
|
|
else
|
|
|
|
return hex::format("{} View", this->m_provider->getName());
|
|
|
|
}
|
2023-06-04 10:42:11 +02:00
|
|
|
[[nodiscard]] std::vector<Description> getDataDescription() const override {
|
2023-01-30 18:15:42 +01:00
|
|
|
if (this->m_provider == nullptr)
|
|
|
|
return { };
|
|
|
|
|
|
|
|
return this->m_provider->getDataDescription();
|
|
|
|
}
|
2022-11-14 10:02:46 +01:00
|
|
|
|
|
|
|
void loadSettings(const nlohmann::json &settings) override { hex::unused(settings); }
|
|
|
|
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; }
|
|
|
|
|
|
|
|
[[nodiscard]] std::string getTypeName() const override {
|
|
|
|
return "hex.builtin.provider.view";
|
|
|
|
}
|
|
|
|
|
|
|
|
void setProvider(u64 startAddress, size_t size, hex::prv::Provider *provider) {
|
|
|
|
this->m_startAddress = startAddress;
|
|
|
|
this->m_size = size;
|
|
|
|
this->m_provider = provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64 address) const override {
|
|
|
|
address -= this->getBaseAddress();
|
|
|
|
|
|
|
|
if (address < this->getActualSize())
|
|
|
|
return { Region { this->getBaseAddress() + address, this->getActualSize() - address }, true };
|
|
|
|
else
|
|
|
|
return { Region::Invalid(), false };
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u64 m_startAddress = 0x00;
|
|
|
|
size_t m_size = 0x00;
|
|
|
|
prv::Provider *m_provider = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|