1
0
mirror of synced 2025-01-05 19:24:26 +01:00
ImHex/plugins/libimhex/source/providers/provider.cpp
WerWolv dbbc525174
Added Plugin support (#102)
* Build refactoring and initial plugin support

* Possibly fixed linux / mac build

* Added libdl to libglad build script

* Add glfw to imgui dependencies

* Refactored common functionality into "libimhex" for plugins

* Added plugin loading and example plugin

* Added proper API for creating a custom view and a custom tools entry with plugins
2020-12-22 18:10:01 +01:00

66 lines
1.5 KiB
C++

#include "providers/provider.hpp"
#include <hex.hpp>
#include <cmath>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace hex::prv {
Provider::Provider() {
this->m_patches.emplace_back();
}
void Provider::read(u64 offset, void *buffer, size_t size) {
this->readRaw(offset, buffer, size);
}
void Provider::write(u64 offset, const void *buffer, size_t size) {
this->writeRaw(offset, buffer, size);
}
std::map<u64, u8>& Provider::getPatches() {
return this->m_patches.back();
}
void Provider::applyPatches() {
for (auto &[patchAddress, patch] : this->m_patches.back())
this->writeRaw(patchAddress, &patch, 1);
}
u32 Provider::getPageCount() {
return std::ceil(this->getActualSize() / double(PageSize));
}
u32 Provider::getCurrentPage() const {
return this->m_currPage;
}
void Provider::setCurrentPage(u32 page) {
if (page < getPageCount())
this->m_currPage = page;
}
size_t Provider::getBaseAddress() {
return PageSize * this->m_currPage;
}
size_t Provider::getSize() {
return std::min(this->getActualSize() - PageSize * this->m_currPage, PageSize);
}
std::optional<u32> Provider::getPageOfAddress(u64 address) {
u32 page = std::floor(address / double(PageSize));
if (page >= this->getPageCount())
return { };
return page;
}
}