1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Region validity check not working correctly with non-zero base address

Fixes #683
This commit is contained in:
WerWolv 2022-08-17 16:28:44 +02:00
parent e779285be4
commit 55b877d5e0
6 changed files with 27 additions and 4 deletions

View File

@ -266,7 +266,7 @@ namespace hex::prv {
}
std::pair<Region, bool> Provider::getRegionValidity(u64 address) const {
if (address > this->getActualSize())
if ((address - this->getBaseAddress()) > this->getActualSize())
return { Region::Invalid(), false };
bool insideValidRegion = false;

View File

@ -17,6 +17,8 @@ namespace hex::plugin::builtin::prv {
[[nodiscard]] bool isResizable() const override { return false; }
[[nodiscard]] bool isSavable() const override { return false; }
void setBaseAddress(u64 address) override;
void readRaw(u64 offset, void *buffer, size_t size) override;
void writeRaw(u64 offset, const void *buffer, size_t size) override;
[[nodiscard]] size_t getActualSize() const override;

View File

@ -358,8 +358,10 @@ namespace hex::plugin::builtin::prv {
}
std::pair<Region, bool> DiskProvider::getRegionValidity(u64 address) const {
address -= this->getBaseAddress();
if (address < this->getActualSize())
return { Region { address, this->getActualSize() - address }, true };
return { Region { this->getBaseAddress() + address, this->getActualSize() - address }, true };
else
return { Region::Invalid(), false };
}

View File

@ -336,8 +336,10 @@ namespace hex::plugin::builtin::prv {
}
std::pair<Region, bool> FileProvider::getRegionValidity(u64 address) const {
address -= this->getBaseAddress();
if (address < this->getActualSize())
return { Region { address, this->getActualSize() - address }, true };
return { Region { this->getBaseAddress() + address, this->getActualSize() - address }, true };
else
return { Region::Invalid(), false };
}

View File

@ -325,8 +325,10 @@ namespace hex::plugin::builtin::prv {
}
std::pair<Region, bool> GDBProvider::getRegionValidity(u64 address) const {
address -= this->getBaseAddress();
if (address < this->getActualSize())
return { Region { address, this->getActualSize() - address }, true };
return { Region { this->getBaseAddress() + address, this->getActualSize() - address }, true };
else
return { Region::Invalid(), false };
}

View File

@ -153,6 +153,21 @@ namespace hex::plugin::builtin::prv {
}
void IntelHexProvider::setBaseAddress(u64 address) {
auto oldBase = this->getBaseAddress();
auto intervals = this->m_data.findOverlapping(oldBase, oldBase + this->getActualSize());
for (auto &interval : intervals) {
interval.start = (interval.start - oldBase) + address;
interval.stop = (interval.stop - oldBase) + address;
}
this->m_data = std::move(intervals);
Provider::setBaseAddress(address);
}
void IntelHexProvider::readRaw(u64 offset, void *buffer, size_t size) {
auto intervals = this->m_data.findOverlapping(offset, (offset + size) - 1);