Skip to content

Commit 6052d55

Browse files
committed
disasm: Separated load_fixup_record_pages()
1 parent 1578718 commit 6052d55

File tree

2 files changed

+86
-75
lines changed

2 files changed

+86
-75
lines changed

src/le.cpp

Lines changed: 85 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class LinearExecutable::Loader
6767
bool load_object_page_header (ObjectPageHeader *hdr);
6868
bool load_fixup_record_offsets (void);
6969
bool load_fixup_record_table (void);
70+
bool load_fixup_record_pages (size_t oi);
7071

7172
public:
7273
LinearExecutable *load (istream *is, const std::string &name);
@@ -396,12 +397,11 @@ LinearExecutable::Loader::load_fixup_record_offsets (void)
396397
}
397398

398399
bool
399-
LinearExecutable::Loader::load_fixup_record_table (void)
400+
LinearExecutable::Loader::load_fixup_record_pages (size_t oi)
400401
{
401402
Fixup fixup;
402403
ObjectHeader *obj;
403404
size_t n;
404-
size_t oi;
405405
size_t offset;
406406
size_t end;
407407
uint8_t addr_flags;
@@ -412,103 +412,114 @@ LinearExecutable::Loader::load_fixup_record_table (void)
412412
uint8_t obj_index;
413413
istream *is = this->is;
414414

415-
this->le->fixups.resize (this->le->objects.size ());
415+
obj = &this->le->objects[oi];
416416

417-
for (oi = 0; oi < this->le->objects.size (); oi++)
417+
for (n = obj->first_page_index;
418+
n < obj->first_page_index + obj->page_count; n++)
418419
{
419-
obj = &this->le->objects[oi];
420+
offset = this->header_offset
421+
+ this->le->header.fixup_record_table_offset
422+
+ this->fixup_record_offsets[n];
423+
end = offset
424+
+ this->fixup_record_offsets[n + 1]
425+
- this->fixup_record_offsets[n];
426+
427+
is->seekg (offset);
420428

421-
for (n = obj->first_page_index;
422-
n < obj->first_page_index + obj->page_count; n++)
429+
while (offset < end)
423430
{
424-
offset = this->header_offset
425-
+ this->le->header.fixup_record_table_offset
426-
+ this->fixup_record_offsets[n];
427-
end = offset
428-
+ this->fixup_record_offsets[n + 1]
429-
- this->fixup_record_offsets[n];
431+
if (end - offset < 2)
432+
return false;
430433

431-
is->seekg (offset);
434+
read_u8 (is, &addr_flags);
435+
read_u8 (is, &reloc_flags);
432436

433-
while (offset < end)
437+
if (!is->good ())
438+
return false;
439+
440+
if ((addr_flags & 0x20) != 0)
434441
{
435-
if (end - offset < 2)
436-
return false;
442+
cerr << "Fixup lists not supported.\n";
443+
return false;
444+
}
445+
446+
if ((addr_flags & 0xf) != 0x7) /* 32-bit offset */
447+
{
448+
cerr << "Unsupported fixup type " << std::hex << std::showbase
449+
<< (addr_flags & 0xf) << ".\n";
450+
return false;
451+
}
437452

438-
read_u8 (is, &addr_flags);
439-
read_u8 (is, &reloc_flags);
453+
if ((reloc_flags & 0x3) != 0x0) /* internal ref */
454+
{
455+
cerr << "Unsupported reloc type " << std::hex << std::showbase
456+
<< (reloc_flags & 0x03) << ".\n";
457+
}
440458

441-
if (!is->good ())
442-
return false;
459+
offset += 2;
443460

444-
if ((addr_flags & 0x20) != 0)
445-
{
446-
cerr << "Fixup lists not supported.\n";
447-
return false;
448-
}
449-
450-
if ((addr_flags & 0xf) != 0x7) /* 32-bit offset */
451-
{
452-
cerr << "Unsupported fixup type " << std::hex << std::showbase
453-
<< (addr_flags & 0xf) << ".\n";
454-
return false;
455-
}
456-
457-
if ((reloc_flags & 0x3) != 0x0) /* internal ref */
458-
{
459-
cerr << "Unsupported reloc type " << std::hex << std::showbase
460-
<< (reloc_flags & 0x03) << ".\n";
461-
}
461+
if (end - offset < 3)
462+
return false;
462463

463-
offset += 2;
464+
read_le<int16_t> (is, &src_off);
465+
read_u8 (is, &obj_index);
464466

465-
if (end - offset < 3)
466-
return false;
467+
if (!is->good ())
468+
return false;
469+
470+
if (obj_index < 1 || obj_index > this->le->objects.size ())
471+
return false;
467472

468-
read_le<int16_t> (is, &src_off);
469-
read_u8 (is, &obj_index);
473+
obj_index--;
470474

471-
if (!is->good ())
475+
offset += 3;
476+
477+
if ((reloc_flags & 0x10) != 0) /* 32-bit offset */
478+
{
479+
if (end - offset < 4)
472480
return false;
473481

474-
if (obj_index < 1 || obj_index > this->le->objects.size ())
482+
read_le<uint32_t> (is, &dst_off_32);
483+
offset += 4;
484+
}
485+
else /* 16-bit offset */
486+
{
487+
if (end - offset < 2)
475488
return false;
476489

477-
obj_index--;
490+
read_le<uint16_t> (is, &dst_off_16);
491+
dst_off_32 = dst_off_16;
492+
offset += 2;
493+
}
478494

479-
offset += 3;
495+
if (!is->good ())
496+
return false;
480497

481-
if ((reloc_flags & 0x10) != 0) /* 32-bit offset */
482-
{
483-
if (end - offset < 4)
484-
return false;
498+
fixup.offset = (n - obj->first_page_index)
499+
* this->le->header.page_size
500+
+ src_off;
501+
fixup.address = this->le->objects[obj_index].base_address
502+
+ dst_off_32;
485503

486-
read_le<uint32_t> (is, &dst_off_32);
487-
offset += 4;
488-
}
489-
else /* 16-bit offset */
490-
{
491-
if (end - offset < 2)
492-
return false;
504+
this->le->fixups[oi][fixup.offset] = fixup;
505+
this->le->fixup_addresses.insert (fixup.address);
506+
}
507+
}
493508

494-
read_le<uint16_t> (is, &dst_off_16);
495-
dst_off_32 = dst_off_16;
496-
offset += 2;
497-
}
509+
return true;
510+
}
498511

499-
if (!is->good ())
500-
return false;
512+
bool
513+
LinearExecutable::Loader::load_fixup_record_table (void)
514+
{
515+
size_t oi;
501516

502-
fixup.offset = (n - obj->first_page_index)
503-
* this->le->header.page_size
504-
+ src_off;
505-
fixup.address = this->le->objects[obj_index].base_address
506-
+ dst_off_32;
517+
this->le->fixups.resize (this->le->objects.size ());
507518

508-
this->le->fixups[oi][fixup.offset] = fixup;
509-
this->le->fixup_addresses.insert (fixup.address);
510-
}
511-
}
519+
for (oi = 0; oi < this->le->objects.size (); oi++)
520+
{
521+
if (!load_fixup_record_pages (oi))
522+
return false;
512523
}
513524

514525
return true;

src/le_disasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ print_region (const Region *reg, const Image::Object *obj, LinearExecutable *le,
300300
LEFM::const_iterator itr;
301301

302302
#ifdef DEBUG
303-
std::cerr << "Region: " << *reg << ":\n";
303+
std::cerr << "Region: " << *reg << std::endl;
304304
#endif
305305

306306
obj = img->get_object_at_address (reg->get_address ());

0 commit comments

Comments
 (0)