2020-12-22 18:10:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <list>
|
2020-12-22 18:10:01 +01:00
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-01-30 22:39:06 +01:00
|
|
|
#include <hex/providers/overlay.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-02-27 23:25:39 +01:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
namespace hex::prv {
|
|
|
|
|
|
|
|
class Provider {
|
|
|
|
public:
|
|
|
|
constexpr static size_t PageSize = 0x1000'0000;
|
|
|
|
|
|
|
|
Provider();
|
2021-02-04 01:14:05 +01:00
|
|
|
virtual ~Provider();
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] virtual bool isAvailable() const = 0;
|
2022-02-01 22:09:44 +01:00
|
|
|
[[nodiscard]] virtual bool isReadable() const = 0;
|
|
|
|
[[nodiscard]] virtual bool isWritable() const = 0;
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] virtual bool isResizable() const = 0;
|
2022-02-01 22:09:44 +01:00
|
|
|
[[nodiscard]] virtual bool isSavable() const = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-21 14:50:47 +01:00
|
|
|
virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true);
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual void write(u64 offset, const void *buffer, size_t size);
|
|
|
|
|
2022-01-20 23:24:26 +01:00
|
|
|
virtual void resize(size_t newSize);
|
|
|
|
virtual void insert(u64 offset, size_t size);
|
2022-06-17 14:21:56 +02:00
|
|
|
virtual void remove(u64 offset, size_t size);
|
2021-07-27 21:07:36 +02:00
|
|
|
|
2021-08-21 13:53:50 +02:00
|
|
|
virtual void save();
|
2022-03-04 11:36:37 +01:00
|
|
|
virtual void saveAs(const std::fs::path &path);
|
2021-08-21 13:53:50 +02:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
virtual void readRaw(u64 offset, void *buffer, size_t size) = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
|
2022-02-01 22:09:44 +01:00
|
|
|
[[nodiscard]] virtual size_t getActualSize() const = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-21 14:50:47 +01:00
|
|
|
void applyOverlays(u64 offset, void *buffer, size_t size);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] std::map<u64, u8> &getPatches();
|
|
|
|
[[nodiscard]] const std::map<u64, u8> &getPatches() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
void applyPatches();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] Overlay *newOverlay();
|
2021-01-30 22:39:06 +01:00
|
|
|
void deleteOverlay(Overlay *overlay);
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::list<Overlay *> &getOverlays();
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] u32 getPageCount() const;
|
|
|
|
[[nodiscard]] u32 getCurrentPage() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
void setCurrentPage(u32 page);
|
|
|
|
|
2021-01-11 13:50:04 +01:00
|
|
|
virtual void setBaseAddress(u64 address);
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] virtual u64 getBaseAddress() const;
|
|
|
|
[[nodiscard]] virtual u64 getCurrentPageAddress() const;
|
|
|
|
[[nodiscard]] virtual size_t getSize() const;
|
|
|
|
[[nodiscard]] virtual std::optional<u32> getPageOfAddress(u64 address) const;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
[[nodiscard]] virtual std::string getName() const = 0;
|
2021-09-21 02:29:54 +02:00
|
|
|
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-09-04 11:16:20 +02:00
|
|
|
[[nodiscard]] virtual bool open() = 0;
|
|
|
|
virtual void close() = 0;
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2022-01-09 21:27:59 +01:00
|
|
|
void addPatch(u64 offset, const void *buffer, size_t size, bool createUndo = false);
|
|
|
|
void createUndoPoint();
|
2021-03-26 21:43:24 +01:00
|
|
|
|
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool canUndo() const;
|
|
|
|
[[nodiscard]] bool canRedo() const;
|
|
|
|
|
2022-08-12 15:11:27 +02:00
|
|
|
[[nodiscard]] virtual bool hasFilePicker() const;
|
|
|
|
virtual bool handleFilePicker();
|
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] virtual bool hasLoadInterface() const;
|
|
|
|
[[nodiscard]] virtual bool hasInterface() const;
|
|
|
|
virtual void drawLoadInterface();
|
|
|
|
virtual void drawInterface();
|
2021-03-26 21:43:24 +01:00
|
|
|
|
2022-09-22 09:05:09 +02:00
|
|
|
[[nodiscard]] u32 getID() const;
|
|
|
|
void setID(u32 id);
|
2022-08-08 21:23:52 +02:00
|
|
|
|
|
|
|
[[nodiscard]] virtual nlohmann::json storeSettings(nlohmann::json settings = { }) const;
|
|
|
|
virtual void loadSettings(const nlohmann::json &settings);
|
|
|
|
|
|
|
|
[[nodiscard]] virtual std::string getTypeName() const = 0;
|
|
|
|
|
|
|
|
void markDirty(bool dirty = true) { this->m_dirty = dirty; }
|
|
|
|
[[nodiscard]] bool isDirty() const { return this->m_dirty; }
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
[[nodiscard]] virtual std::pair<Region, bool> getRegionValidity(u64 address) const;
|
2022-08-10 09:26:48 +02:00
|
|
|
|
2022-08-14 10:07:45 +02:00
|
|
|
void skipLoadInterface() { this->m_skipLoadInterface = true; }
|
|
|
|
[[nodiscard]] bool shouldSkipLoadInterface() const { return this->m_skipLoadInterface; }
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
protected:
|
2022-02-01 22:09:44 +01:00
|
|
|
u32 m_currPage = 0;
|
2021-01-11 13:50:04 +01:00
|
|
|
u64 m_baseAddress = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-26 21:43:24 +01:00
|
|
|
u32 m_patchTreeOffset = 0;
|
2022-01-09 21:27:59 +01:00
|
|
|
std::list<std::map<u64, u8>> m_patches;
|
2022-01-24 20:53:17 +01:00
|
|
|
std::list<Overlay *> m_overlays;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
u32 m_id;
|
|
|
|
|
|
|
|
bool m_dirty = false;
|
2022-08-14 10:07:45 +02:00
|
|
|
bool m_skipLoadInterface = false;
|
2022-08-08 21:23:52 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static u32 s_idCounter;
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|