prv: Make data overlays work everywhere, not just in the hex editor view
This commit is contained in:
parent
ef747cc4c0
commit
2a7b698a3d
@ -25,7 +25,7 @@ namespace hex::prv {
|
||||
bool isReadable() 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 readRaw(u64 offset, void *buffer, size_t size) override;
|
||||
|
@ -23,13 +23,15 @@ namespace hex::prv {
|
||||
virtual bool isReadable() = 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 readRaw(u64 offset, void *buffer, size_t size) = 0;
|
||||
virtual void writeRaw(u64 offset, const void *buffer, size_t size) = 0;
|
||||
virtual size_t getActualSize() = 0;
|
||||
|
||||
void applyOverlays(u64 offset, void *buffer, size_t size);
|
||||
|
||||
std::map<u64, u8>& getPatches();
|
||||
void applyPatches();
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace hex::prv {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -26,6 +26,18 @@ namespace hex::prv {
|
||||
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() {
|
||||
return this->m_patches.back();
|
||||
|
@ -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)
|
||||
return;
|
||||
|
||||
@ -133,6 +133,9 @@ namespace hex::prv {
|
||||
for (u64 i = 0; i < size; i++)
|
||||
if (this->m_patches.back().contains(offset + 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) {
|
||||
|
@ -30,12 +30,6 @@ namespace hex {
|
||||
ImU8 byte;
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user