2021-12-07 22:47:57 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
|
2023-04-19 21:56:34 +02:00
|
|
|
#include <wolv/net/socket_client.hpp>
|
2023-03-12 18:27:29 +01:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <array>
|
2021-12-07 22:47:57 +01:00
|
|
|
#include <mutex>
|
|
|
|
#include <string_view>
|
|
|
|
#include <thread>
|
|
|
|
|
2022-11-07 00:04:47 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2021-12-07 22:47:57 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
class GDBProvider : public hex::prv::Provider {
|
2021-12-07 22:47:57 +01:00
|
|
|
public:
|
2022-08-08 21:23:52 +02:00
|
|
|
GDBProvider();
|
2023-01-01 02:29:38 +01:00
|
|
|
~GDBProvider() override = default;
|
2021-12-07 22:47:57 +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;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
|
|
|
void read(u64 offset, void *buffer, size_t size, bool overlays) override;
|
|
|
|
void write(u64 offset, const void *buffer, size_t size) override;
|
|
|
|
|
|
|
|
void readRaw(u64 offset, void *buffer, size_t size) override;
|
|
|
|
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;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
|
|
|
void save() override;
|
|
|
|
|
|
|
|
[[nodiscard]] std::string getName() const override;
|
2023-06-04 10:42:11 +02:00
|
|
|
[[nodiscard]] std::vector<Description> getDataDescription() const override;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool open() override;
|
|
|
|
void close() override;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
[[nodiscard]] bool isConnected() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasLoadInterface() const override { return true; }
|
2023-03-16 16:48:15 +01:00
|
|
|
bool drawLoadInterface() override;
|
2021-12-12 00:41:44 +01:00
|
|
|
|
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.gdb";
|
|
|
|
}
|
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64 address) const override;
|
2023-01-24 09:07:11 +01:00
|
|
|
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
|
2022-08-14 14:45:18 +02:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
protected:
|
2023-04-19 21:56:34 +02:00
|
|
|
wolv::net::SocketClient m_socket;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
|
|
|
std::string m_ipAddress;
|
2022-03-04 20:52:39 +01:00
|
|
|
int m_port = 0;
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2022-03-04 20:52:39 +01:00
|
|
|
u64 m_size = 0;
|
2022-01-20 23:24:26 +01:00
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
constexpr static size_t CacheLineSize = 0x10;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
|
|
|
struct CacheLine {
|
|
|
|
u64 address;
|
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
std::array<u8, CacheLineSize> data;
|
2021-12-07 22:47:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::list<CacheLine> m_cache;
|
2023-03-12 18:27:29 +01:00
|
|
|
std::atomic<bool> m_resetCache = false;
|
2021-12-07 22:47:57 +01:00
|
|
|
|
2021-12-07 23:36:28 +01:00
|
|
|
std::thread m_cacheUpdateThread;
|
2021-12-07 22:47:57 +01:00
|
|
|
std::mutex m_cacheLock;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|