Skip to content

Commit

Permalink
Merge pull request #1 from ethteck/master
Browse files Browse the repository at this point in the history
Enforcing specific reloc data generation order
  • Loading branch information
NEstelami committed Feb 26, 2020
2 parents a207add + 72bc162 commit 4f96394
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions ZAP2/Overlays/ZOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,43 @@ ZOverlay* ZOverlay::FromELF(string elfFilePath, string cfgFolderPath)


Elf_Half sec_num = reader.sections.size();

for (int i = 0; i < sec_num; ++i)
{
section* pSec = reader.sections[i];

string sectionName = pSec->get_name();
vector<string> sections = {".rel.text", ".rel.data" , ".rel.rodata"};

if (pSec->get_type() == SHT_REL)
for (auto sectionSearched : sections)
{
for (int i = 0; i < sec_num; ++i)
{
relocation_section_accessor* symbols = new relocation_section_accessor(reader, pSec);
section* pSec = reader.sections[i];

for (Elf_Xword j = 0; j < symbols->get_entries_num(); j++)
string sectionName = pSec->get_name();

if (pSec->get_type() == SHT_REL && sectionName == sectionSearched)
{
std::string name;
Elf64_Addr offset;
Elf64_Addr symbolValue;
Elf_Xword size;
Elf_Sxword addend;
Elf_Sxword calcValue;
Elf_Word type;

symbols->get_entry(j, offset, symbolValue, name, type, addend, calcValue);

RelocationType typeConverted = (RelocationType)type;
SectionType sectionType = GetSectionTypeFromStr(sectionName);

if (name == ".text" || name == ".data" || name == ".bss" || name == ".rodata")
relocation_section_accessor* symbols = new relocation_section_accessor(reader, pSec);

for (Elf_Xword j = 0; j < symbols->get_entries_num(); j++)
{
RelocationEntry* reloc = new RelocationEntry(sectionType, typeConverted, offset);
ovl->entries.push_back(reloc);
std::string name;
Elf64_Addr offset;
Elf64_Addr symbolValue;
Elf_Xword size;
Elf_Sxword addend;
Elf_Sxword calcValue;
Elf_Word type;

symbols->get_entry(j, offset, symbolValue, name, type, addend, calcValue);

RelocationType typeConverted = (RelocationType)type;
SectionType sectionType = GetSectionTypeFromStr(sectionName);

if (name == ".text" || name == ".data" || name == ".bss" || name == ".rodata")
{
RelocationEntry* reloc = new RelocationEntry(sectionType, typeConverted, offset);
ovl->entries.push_back(reloc);
}
}
break;
}
}
}
Expand Down

0 comments on commit 4f96394

Please sign in to comment.