2020-11-11 09:18:35 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-11-11 09:18:35 +01:00
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
2020-11-16 00:23:27 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2021-01-03 15:00:16 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
2022-10-02 20:35:30 +02:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2022-01-24 20:53:17 +01:00
|
|
|
#include <windows.h>
|
2021-01-03 15:00:16 +01:00
|
|
|
#else
|
2022-01-24 20:53:17 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/fcntl.h>
|
2021-01-03 15:00:16 +01:00
|
|
|
#endif
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin::prv {
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
class FileProvider : public hex::prv::Provider {
|
2020-11-11 09:18:35 +01:00
|
|
|
public:
|
2022-08-12 15:11:27 +02:00
|
|
|
FileProvider() = default;;
|
|
|
|
~FileProvider() override = default;;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool isAvailable() const override;
|
|
|
|
[[nodiscard]] bool isReadable() const override;
|
|
|
|
[[nodiscard]] bool isWritable() const override;
|
|
|
|
[[nodiscard]] bool isResizable() const override;
|
|
|
|
[[nodiscard]] bool isSavable() const override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-03-21 14:50:47 +01:00
|
|
|
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
2020-11-27 13:44:52 +01:00
|
|
|
void write(u64 offset, const void *buffer, size_t size) override;
|
2022-01-20 23:24:26 +01:00
|
|
|
|
|
|
|
void resize(size_t newSize) override;
|
|
|
|
void insert(u64 offset, size_t size) override;
|
2022-06-17 14:21:56 +02:00
|
|
|
void remove(u64 offset, size_t size) override;
|
2020-11-27 09:09:48 +01:00
|
|
|
|
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override;
|
2020-11-27 13:44:52 +01:00
|
|
|
void writeRaw(u64 offset, const void *buffer, size_t size) override;
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] size_t getActualSize() const override;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
void save() override;
|
2022-03-04 11:36:37 +01:00
|
|
|
void saveAs(const std::fs::path &path) override;
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
[[nodiscard]] std::string getName() const override;
|
|
|
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
[[nodiscard]] bool hasFilePicker() const override { return true; }
|
|
|
|
[[nodiscard]] bool handleFilePicker() override;
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
void setPath(const std::fs::path &path);
|
2021-12-07 22:47:41 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool open() override;
|
|
|
|
void close() override;
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
void loadSettings(const nlohmann::json &settings) override;
|
|
|
|
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override;
|
|
|
|
|
|
|
|
[[nodiscard]] std::string getTypeName() const override {
|
|
|
|
return "hex.builtin.provider.file";
|
|
|
|
}
|
|
|
|
|
2022-08-14 09:38:38 +02:00
|
|
|
std::pair<Region, bool> getRegionValidity(u64 address) const override;
|
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
protected:
|
2022-03-04 11:36:37 +01:00
|
|
|
std::fs::path m_path;
|
2021-09-08 15:18:24 +02:00
|
|
|
void *m_mappedFile = nullptr;
|
2022-02-01 22:09:44 +01:00
|
|
|
size_t m_fileSize = 0;
|
2020-11-15 16:06:10 +01:00
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
struct stat m_fileStats = { };
|
2022-02-01 22:09:44 +01:00
|
|
|
bool m_fileStatsValid = false;
|
|
|
|
bool m_emptyFile = false;
|
2020-11-11 09:18:35 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
bool m_readable = false, m_writable = false;
|
2020-11-11 09:18:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|