2021-09-11 14:41:18 +02:00
|
|
|
#include <hex/providers/provider.hpp>
|
2021-09-11 14:40:53 +02:00
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
#include <hex/helpers/file.hpp>
|
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
#include <stdexcept>
|
2021-09-11 14:40:53 +02:00
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
namespace hex::test {
|
|
|
|
using namespace hex::prv;
|
|
|
|
|
|
|
|
class TestProvider : public prv::Provider {
|
|
|
|
public:
|
2021-10-12 21:32:33 +02:00
|
|
|
TestProvider(std::vector<u8> data) : Provider(){
|
|
|
|
this->setData(data);
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
~TestProvider() override = default;
|
|
|
|
|
2021-09-21 02:48:41 +02:00
|
|
|
[[nodiscard]] bool isAvailable() const override { return true; }
|
|
|
|
[[nodiscard]] bool isReadable() const override { return true; }
|
|
|
|
[[nodiscard]] bool isWritable() const override { return false; }
|
|
|
|
[[nodiscard]] bool isResizable() const override { return false; }
|
|
|
|
[[nodiscard]] bool isSavable() const override { return false; }
|
|
|
|
|
2021-10-12 21:32:33 +02:00
|
|
|
void setData(const std::vector<u8> &data) {
|
|
|
|
if (data.empty()) {
|
|
|
|
hex::log::fatal("No data provided");
|
|
|
|
throw std::runtime_error("");
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_data = data;
|
|
|
|
}
|
|
|
|
|
2021-09-21 02:48:41 +02:00
|
|
|
[[nodiscard]] std::string getName() const override {
|
|
|
|
return "";
|
|
|
|
}
|
2021-09-11 14:41:18 +02:00
|
|
|
|
2021-09-21 02:48:41 +02:00
|
|
|
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override {
|
2021-09-11 14:41:18 +02:00
|
|
|
return { };
|
|
|
|
}
|
|
|
|
|
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override {
|
2021-10-12 21:32:33 +02:00
|
|
|
if (offset + size >= this->m_data.size()) return;
|
|
|
|
|
|
|
|
std::memcpy(buffer, &this->m_data[offset], size);
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeRaw(u64 offset, const void *buffer, size_t size) override {
|
2021-10-12 21:32:33 +02:00
|
|
|
if (offset + size >= this->m_data.size()) return;
|
|
|
|
|
|
|
|
std::memcpy(&this->m_data[offset], buffer, size);
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
|
2021-09-21 02:48:41 +02:00
|
|
|
size_t getActualSize() const override {
|
2021-10-12 21:32:33 +02:00
|
|
|
return this->m_data.size();
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-10-12 21:32:33 +02:00
|
|
|
std::vector<u8> m_data;
|
2021-09-11 14:41:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|