support jumptable segments

This commit is contained in:
Sean 2024-05-21 21:26:08 -07:00
parent be5873d13c
commit f3a1293e46
2 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,9 @@ bool Segment::isDPS() {
return (kind & 0x1f) == 0x12;
}
bool Segment::isJump() {
return (kind & 0x1f) == 0x02;
}
bool OMF::load(const char *filename, uint32_t org) {
handle = TheHandle::createFromFile(filename);
@ -382,6 +385,20 @@ bool OMF::relocSegments() {
break;
}
}
if (seg.isJump()) { // patch jumptable
for (int i = 8; i < seg.length; i += 14) {
uint16_t segnum = data[i + 4] | (data[i + 5] << 8);
int32_t subOffset = data[i + 6] | (data[i + 7] << 8) |
(data[i + 8] << 16) | (data[i + 9] << 24);
for (auto &sub : segments) {
if (sub.segnum == segnum) {
subOffset += sub.mapped;
break;
}
}
patch(data, i + 11, 3, subOffset);
}
}
seg.data = TheHandle::createFromArray(data);
}
return true;

View File

@ -26,6 +26,7 @@ struct Segment {
bool map(std::vector<uint32_t> &memory, bool force);
void initDPS();
bool isDPS();
bool isJump();
};
class OMF {