2020-12-22 18:10:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/helpers/shared_data.hpp>
|
2021-01-30 22:39:06 +01:00
|
|
|
#include <hex/providers/overlay.hpp>
|
2021-01-04 00:19:56 +01:00
|
|
|
|
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-09-21 02:29:54 +02:00
|
|
|
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;
|
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);
|
|
|
|
|
2021-07-27 21:07:36 +02:00
|
|
|
virtual void resize(ssize_t newSize);
|
|
|
|
|
2021-08-21 13:53:50 +02:00
|
|
|
virtual void save();
|
|
|
|
virtual void saveAs(const std::string &path);
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual void readRaw(u64 offset, void *buffer, size_t size) = 0;
|
|
|
|
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
|
2021-09-21 02:29:54 +02:00
|
|
|
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);
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::map<u64, u8>& getPatches();
|
2021-09-21 02:29:54 +02:00
|
|
|
const std::map<u64, u8>& getPatches() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
void applyPatches();
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
[[nodiscard]] Overlay* newOverlay();
|
|
|
|
void deleteOverlay(Overlay *overlay);
|
|
|
|
[[nodiscard]] const std::list<Overlay*>& getOverlays();
|
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
u32 getPageCount() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
u32 getCurrentPage() const;
|
|
|
|
void setCurrentPage(u32 page);
|
|
|
|
|
2021-01-11 13:50:04 +01:00
|
|
|
virtual void setBaseAddress(u64 address);
|
2021-09-21 02:29:54 +02:00
|
|
|
virtual u64 getBaseAddress() const;
|
2021-12-09 21:10:24 +01:00
|
|
|
virtual u64 getCurrentPageAddress() const;
|
2021-09-21 02:29:54 +02:00
|
|
|
virtual size_t getSize() const;
|
|
|
|
virtual std::optional<u32> getPageOfAddress(u64 address) const;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
[[nodiscard]] virtual std::string getName() const = 0;
|
|
|
|
[[nodiscard]] virtual std::vector<std::pair<std::string, std::string>> getDataInformation() const = 0;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-26 21:43:24 +01:00
|
|
|
void addPatch(u64 offset, const void *buffer, size_t size);
|
|
|
|
|
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
bool canUndo() const;
|
|
|
|
bool canRedo() const;
|
2021-03-26 21:43:24 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
protected:
|
|
|
|
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;
|
2020-12-22 18:10:01 +01:00
|
|
|
std::vector<std::map<u64, u8>> m_patches;
|
2021-01-30 22:39:06 +01:00
|
|
|
std::list<Overlay*> m_overlays;
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|