2023-01-01 01:29:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
#if defined(OS_WINDOWS) || defined (OS_LINUX)
|
|
|
|
|
2023-01-01 01:29:38 +00:00
|
|
|
#include <hex/providers/provider.hpp>
|
2023-11-21 13:38:01 +00:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-01-01 01:29:38 +00:00
|
|
|
|
2023-01-03 15:34:22 +00:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2023-01-05 08:30:15 +00:00
|
|
|
#include <hex/ui/widgets.hpp>
|
2023-01-28 10:41:09 +00:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2023-01-03 15:34:22 +00:00
|
|
|
|
2023-11-18 13:34:33 +00:00
|
|
|
#include <set>
|
2023-12-07 22:33:15 +00:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
#include <windows.h>
|
|
|
|
#elif defined(OS_LINUX)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2023-01-01 01:29:38 +00:00
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
namespace hex::plugin::builtin {
|
2023-01-01 01:29:38 +00:00
|
|
|
|
|
|
|
class ProcessMemoryProvider : public hex::prv::Provider {
|
|
|
|
public:
|
|
|
|
ProcessMemoryProvider() = default;
|
|
|
|
~ProcessMemoryProvider() override = default;
|
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
[[nodiscard]] bool isAvailable() const override {
|
|
|
|
#ifdef _WIN32
|
|
|
|
return this->m_processHandle != nullptr;
|
|
|
|
#elif __linux__
|
|
|
|
return this->m_processId != -1;
|
|
|
|
#endif
|
|
|
|
}
|
2023-01-01 01:29:38 +00:00
|
|
|
[[nodiscard]] bool isReadable() const override { return true; }
|
|
|
|
[[nodiscard]] bool isWritable() const override { return true; }
|
|
|
|
[[nodiscard]] bool isResizable() const override { return false; }
|
|
|
|
[[nodiscard]] bool isSavable() const override { return false; }
|
2023-07-05 18:49:57 +00:00
|
|
|
[[nodiscard]] bool isDumpable() const override { return false; }
|
2023-01-01 01:29:38 +00:00
|
|
|
|
|
|
|
void readRaw(u64 address, void *buffer, size_t size) override;
|
|
|
|
void writeRaw(u64 address, const void *buffer, size_t size) override;
|
2023-12-07 22:33:15 +00:00
|
|
|
[[nodiscard]] u64 getActualSize() const override { return 0xFFFF'FFFF'FFFF; }
|
2023-01-01 01:29:38 +00:00
|
|
|
|
|
|
|
void save() override {}
|
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
[[nodiscard]] std::string getName() const override { return hex::format("hex.builtin.provider.process_memory.name"_lang, this->m_selectedProcess != nullptr ? this->m_selectedProcess->name : ""); }
|
2023-06-04 08:42:11 +00:00
|
|
|
[[nodiscard]] std::vector<Description> getDataDescription() const override {
|
2023-12-07 22:33:15 +00:00
|
|
|
return {
|
|
|
|
{ "hex.builtin.provider.process_memory.process_name"_lang, this->m_selectedProcess->name },
|
|
|
|
{ "hex.builtin.provider.process_memory.process_id"_lang, std::to_string(this->m_selectedProcess->id) }
|
|
|
|
};
|
2023-01-01 01:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool open() override;
|
|
|
|
void close() override;
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasLoadInterface() const override { return true; }
|
|
|
|
[[nodiscard]] bool hasInterface() const override { return true; }
|
2023-03-16 15:48:15 +00:00
|
|
|
bool drawLoadInterface() override;
|
2023-01-01 01:29:38 +00:00
|
|
|
void drawInterface() override;
|
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
void loadSettings(const nlohmann::json &) override {}
|
|
|
|
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json) const override { return { }; }
|
2023-01-01 01:29:38 +00:00
|
|
|
|
|
|
|
[[nodiscard]] std::string getTypeName() const override {
|
2023-12-07 22:33:15 +00:00
|
|
|
return "hex.builtin.provider.process_memory";
|
2023-01-01 01:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64) const override;
|
2023-01-24 08:07:11 +00:00
|
|
|
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
|
2023-01-01 01:29:38 +00:00
|
|
|
|
2023-01-04 09:02:17 +00:00
|
|
|
private:
|
|
|
|
void reloadProcessModules();
|
|
|
|
|
2023-01-01 01:29:38 +00:00
|
|
|
private:
|
|
|
|
struct Process {
|
|
|
|
u32 id;
|
|
|
|
std::string name;
|
2023-11-16 21:24:06 +00:00
|
|
|
ImGuiExt::Texture icon;
|
2023-01-01 01:29:38 +00:00
|
|
|
};
|
|
|
|
|
2023-01-01 11:26:27 +00:00
|
|
|
struct MemoryRegion {
|
2023-01-01 01:29:38 +00:00
|
|
|
Region region;
|
|
|
|
std::string name;
|
2023-01-01 11:26:27 +00:00
|
|
|
|
|
|
|
constexpr bool operator<(const MemoryRegion &other) const {
|
|
|
|
return this->region.getStartAddress() < other.region.getStartAddress();
|
|
|
|
}
|
2023-01-01 01:29:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Process> m_processes;
|
2023-01-05 08:30:15 +00:00
|
|
|
const Process *m_selectedProcess = nullptr;
|
2023-01-01 01:29:38 +00:00
|
|
|
|
2023-01-01 11:26:27 +00:00
|
|
|
std::set<MemoryRegion> m_memoryRegions;
|
2023-01-05 08:30:15 +00:00
|
|
|
ui::SearchableWidget<Process> m_processSearchWidget = ui::SearchableWidget<Process>([](const std::string &search, const Process &process) {
|
2023-01-28 10:41:09 +00:00
|
|
|
return hex::containsIgnoreCase(process.name, search);
|
2023-01-05 08:30:15 +00:00
|
|
|
});
|
|
|
|
ui::SearchableWidget<MemoryRegion> m_regionSearchWidget = ui::SearchableWidget<MemoryRegion>([](const std::string &search, const MemoryRegion &memoryRegion) {
|
2023-01-28 10:41:09 +00:00
|
|
|
return hex::containsIgnoreCase(memoryRegion.name, search);
|
2023-01-05 08:30:15 +00:00
|
|
|
});
|
2023-01-01 01:29:38 +00:00
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE m_processHandle = nullptr;
|
|
|
|
#elif __linux__
|
|
|
|
pid_t m_processId = -1;
|
|
|
|
#endif
|
2023-01-01 01:29:38 +00:00
|
|
|
|
|
|
|
bool m_enumerationFailed = false;
|
|
|
|
};
|
|
|
|
|
2023-12-07 22:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|