feat: Added ability to query provider information from pattern language

This commit is contained in:
WerWolv
2023-01-24 09:07:11 +01:00
parent 915106f360
commit cf9df6e36d
18 changed files with 122 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ namespace hex::plugin::windows {
void saveAs(const std::fs::path &) override {}
[[nodiscard]] std::string getName() const override { return hex::format("hex.windows.provider.process_memory.name"_lang, this->m_selectedProcess != nullptr ? this->m_selectedProcess->name : ""); }
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataInformation() const override {
[[nodiscard]] std::vector<std::pair<std::string, std::string>> getDataDescription() const override {
return {
{ "hex.windows.provider.process_memory.process_name"_lang, this->m_selectedProcess->name },
{ "hex.windows.provider.process_memory.process_id"_lang, std::to_string(this->m_selectedProcess->id) }
@@ -61,6 +61,7 @@ namespace hex::plugin::windows {
}
[[nodiscard]] std::pair<Region, bool> getRegionValidity(u64) const override;
std::variant<std::string, i128> queryInformation(const std::string &category, const std::string &argument) override;
private:
void reloadProcessModules();

View File

@@ -269,4 +269,31 @@ namespace hex::plugin::windows {
}
}
std::variant<std::string, i128> ProcessMemoryProvider::queryInformation(const std::string &category, const std::string &argument) {
auto findRegionByName = [this](const std::string &name) {
return std::find_if(this->m_memoryRegions.begin(), this->m_memoryRegions.end(),
[name](const auto &region) {
return region.name == name;
});
};
if (category == "region_address") {
if (auto iter = findRegionByName(argument); iter != this->m_memoryRegions.end())
return iter->region.getStartAddress();
else
return 0;
} else if (category == "region_size") {
if (auto iter = findRegionByName(argument); iter != this->m_memoryRegions.end())
return iter->region.getSize();
else
return 0;
} else if (category == "process_id") {
return this->m_selectedProcess->id;
} else if (category == "process_name") {
return this->m_selectedProcess->name;
} else
return Provider::queryInformation(category, argument);
}
}