4
0
mirror of https://github.com/QuasarApp/LIEF.git synced 2025-05-09 18:29:34 +00:00

Merge pull request from 1orenz0/master

[PE] Pad section contents when rebuilding binary
This commit is contained in:
Romain 2018-06-20 05:18:40 +02:00 committed by GitHub
commit 149d352a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -540,14 +540,23 @@ Builder& Builder::operator<<(const Section& section) {
std::copy(name, name + sizeof(header.Name), std::begin(header.Name));
this->ios_.write(reinterpret_cast<uint8_t*>(&header), sizeof(pe_section));
size_t pad_length = 0;
if (section.content().size() > section.size()) {
LOG(WARNING) << section.name()
<< " content size is bigger than section's header size"
<< std::endl;
}
else {
pad_length = section.size() - section.content().size();
}
// Pad section content with zeroes
std::vector<uint8_t> zero_pad (pad_length, 0);
const size_t saved_offset = this->ios_.tellp();
this->ios_.seekp(section.offset());
this->ios_.write(section.content());
this->ios_.write(zero_pad);
this->ios_.seekp(saved_offset);
return *this;
}