1
0
mirror of synced 2024-12-01 02:37:18 +01:00

prv: Make data overlays work everywhere, not just in the hex editor view

This commit is contained in:
WerWolv 2021-03-21 14:50:47 +01:00
parent ef747cc4c0
commit 2a7b698a3d
5 changed files with 21 additions and 10 deletions

View File

@ -25,7 +25,7 @@ namespace hex::prv {
bool isReadable() override; bool isReadable() override;
bool isWritable() override; bool isWritable() override;
void read(u64 offset, void *buffer, size_t size) override; void read(u64 offset, void *buffer, size_t size, bool overlays) override;
void write(u64 offset, const void *buffer, size_t size) override; void write(u64 offset, const void *buffer, size_t size) override;
void readRaw(u64 offset, void *buffer, size_t size) override; void readRaw(u64 offset, void *buffer, size_t size) override;

View File

@ -23,13 +23,15 @@ namespace hex::prv {
virtual bool isReadable() = 0; virtual bool isReadable() = 0;
virtual bool isWritable() = 0; virtual bool isWritable() = 0;
virtual void read(u64 offset, void *buffer, size_t size); virtual void read(u64 offset, void *buffer, size_t size, bool overlays = true);
virtual void write(u64 offset, const void *buffer, size_t size); virtual void write(u64 offset, const void *buffer, size_t size);
virtual void readRaw(u64 offset, void *buffer, size_t size) = 0; virtual void readRaw(u64 offset, void *buffer, size_t size) = 0;
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0; virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
virtual size_t getActualSize() = 0; virtual size_t getActualSize() = 0;
void applyOverlays(u64 offset, void *buffer, size_t size);
std::map<u64, u8>& getPatches(); std::map<u64, u8>& getPatches();
void applyPatches(); void applyPatches();

View File

@ -18,7 +18,7 @@ namespace hex::prv {
this->deleteOverlay(overlay); this->deleteOverlay(overlay);
} }
void Provider::read(u64 offset, void *buffer, size_t size) { void Provider::read(u64 offset, void *buffer, size_t size, bool overlays) {
this->readRaw(offset, buffer, size); this->readRaw(offset, buffer, size);
} }
@ -26,6 +26,18 @@ namespace hex::prv {
this->writeRaw(offset, buffer, size); this->writeRaw(offset, buffer, size);
} }
void Provider::applyOverlays(u64 offset, void *buffer, size_t size) {
for (auto &overlay : this->m_overlays) {
auto overlayOffset = overlay->getAddress();
auto overlaySize = overlay->getSize();
s128 overlapMin = std::max(offset, overlayOffset);
s128 overlapMax = std::min(offset + size, overlayOffset + overlaySize);
if (overlapMax > overlapMin)
std::memcpy(static_cast<u8*>(buffer) + std::max<s128>(0, overlapMin - offset), overlay->getData().data() + std::max<s128>(0, overlapMin - overlayOffset), overlapMax - overlapMin);
}
}
std::map<u64, u8>& Provider::getPatches() { std::map<u64, u8>& Provider::getPatches() {
return this->m_patches.back(); return this->m_patches.back();

View File

@ -124,7 +124,7 @@ namespace hex::prv {
} }
void FileProvider::read(u64 offset, void *buffer, size_t size) { void FileProvider::read(u64 offset, void *buffer, size_t size, bool overlays) {
if ((offset + size) > this->getSize() || buffer == nullptr || size == 0) if ((offset + size) > this->getSize() || buffer == nullptr || size == 0)
return; return;
@ -133,6 +133,9 @@ namespace hex::prv {
for (u64 i = 0; i < size; i++) for (u64 i = 0; i < size; i++)
if (this->m_patches.back().contains(offset + i)) if (this->m_patches.back().contains(offset + i))
reinterpret_cast<u8*>(buffer)[i] = this->m_patches.back()[offset + PageSize * this->m_currPage + i]; reinterpret_cast<u8*>(buffer)[i] = this->m_patches.back()[offset + PageSize * this->m_currPage + i];
if (overlays)
this->applyOverlays(offset, buffer, size);
} }
void FileProvider::write(u64 offset, const void *buffer, size_t size) { void FileProvider::write(u64 offset, const void *buffer, size_t size) {

View File

@ -30,12 +30,6 @@ namespace hex {
ImU8 byte; ImU8 byte;
provider->read(off, &byte, sizeof(ImU8)); provider->read(off, &byte, sizeof(ImU8));
for (auto &overlay : SharedData::currentProvider->getOverlays()) {
auto overlayAddress = overlay->getAddress();
if (off >= overlayAddress && off < overlayAddress + overlay->getSize())
byte = overlay->getData()[off - overlayAddress];
}
return byte; return byte;
}; };