966f3b8597
* sys: Initial effort to replace existing project files with a better system * sys: Added back marking provider as dirty * sys: Remove git commit information from project files * sys: Format data processor save file nicely * fix: Automatic pattern loading not working correctly * ui: Added warning popup when closing a provider with modifications Closes #604 * sys: Fixed build issues * tests: Removed useless debug logs * patterns: Updated pattern language * sys: Added log message when crashing with a signal * sys: Make sure abnormal termination handlers are being called more reliably
118 lines
3.7 KiB
C++
118 lines
3.7 KiB
C++
#pragma once
|
|
|
|
#include <hex.hpp>
|
|
|
|
#include <list>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <hex/api/imhex_api.hpp>
|
|
#include <hex/providers/overlay.hpp>
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
namespace pl {
|
|
class PatternLanguage;
|
|
}
|
|
|
|
namespace hex::prv {
|
|
|
|
class Provider {
|
|
public:
|
|
constexpr static size_t PageSize = 0x1000'0000;
|
|
|
|
Provider();
|
|
virtual ~Provider();
|
|
|
|
[[nodiscard]] virtual bool isAvailable() const = 0;
|
|
[[nodiscard]] virtual bool isReadable() const = 0;
|
|
[[nodiscard]] virtual bool isWritable() const = 0;
|
|
[[nodiscard]] virtual bool isResizable() const = 0;
|
|
[[nodiscard]] virtual bool isSavable() const = 0;
|
|
|
|
virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true);
|
|
virtual void write(u64 offset, const void *buffer, size_t size);
|
|
|
|
virtual void resize(size_t newSize);
|
|
virtual void insert(u64 offset, size_t size);
|
|
virtual void remove(u64 offset, size_t size);
|
|
|
|
virtual void save();
|
|
virtual void saveAs(const std::fs::path &path);
|
|
|
|
virtual void readRaw(u64 offset, void *buffer, size_t size) = 0;
|
|
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
|
|
[[nodiscard]] virtual size_t getActualSize() const = 0;
|
|
|
|
void applyOverlays(u64 offset, void *buffer, size_t size);
|
|
|
|
[[nodiscard]] std::map<u64, u8> &getPatches();
|
|
[[nodiscard]] const std::map<u64, u8> &getPatches() const;
|
|
void applyPatches();
|
|
|
|
[[nodiscard]] Overlay *newOverlay();
|
|
void deleteOverlay(Overlay *overlay);
|
|
[[nodiscard]] const std::list<Overlay *> &getOverlays();
|
|
|
|
[[nodiscard]] u32 getPageCount() const;
|
|
[[nodiscard]] u32 getCurrentPage() const;
|
|
void setCurrentPage(u32 page);
|
|
|
|
virtual void setBaseAddress(u64 address);
|
|
[[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;
|
|
|
|
[[nodiscard]] virtual std::string getName() const = 0;
|
|
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
|
|
|
|
[[nodiscard]] virtual bool open();
|
|
virtual void close();
|
|
|
|
void addPatch(u64 offset, const void *buffer, size_t size, bool createUndo = false);
|
|
void createUndoPoint();
|
|
|
|
void undo();
|
|
void redo();
|
|
|
|
[[nodiscard]] bool canUndo() const;
|
|
[[nodiscard]] bool canRedo() const;
|
|
|
|
[[nodiscard]] virtual bool hasLoadInterface() const;
|
|
[[nodiscard]] virtual bool hasInterface() const;
|
|
virtual void drawLoadInterface();
|
|
virtual void drawInterface();
|
|
|
|
[[nodiscard]] u32 getID() const {
|
|
return this->m_id;
|
|
}
|
|
|
|
[[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; }
|
|
|
|
protected:
|
|
u32 m_currPage = 0;
|
|
u64 m_baseAddress = 0;
|
|
|
|
u32 m_patchTreeOffset = 0;
|
|
std::list<std::map<u64, u8>> m_patches;
|
|
std::list<Overlay *> m_overlays;
|
|
|
|
u32 m_id;
|
|
|
|
bool m_dirty = false;
|
|
|
|
private:
|
|
static u32 s_idCounter;
|
|
};
|
|
|
|
} |