Merge pull request #149 from ezquat/fix-66

Fix issue #66: ignore 0th section header when sorting, don't overwrite NOBITS
This commit is contained in:
Eelco Dolstra 2019-03-06 14:01:14 +08:00 committed by GitHub
commit 60662393ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -475,7 +475,7 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
/* Sort the sections by offset. */
CompShdr comp;
comp.elfFile = this;
sort(shdrs.begin(), shdrs.end(), comp);
sort(shdrs.begin() + 1, shdrs.end(), comp);
/* Restore the sh_link mappings. */
for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
@ -642,7 +642,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
for (auto & i : replacedSections) {
std::string sectionName = i.first;
Elf_Shdr & shdr = findSection(sectionName);
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
if (shdr.sh_type != SHT_NOBITS)
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
}
for (auto & i : replacedSections) {