mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-05-09 18:29:34 +00:00
Merge pull request #187 from 1orenz0/master
[PE] Pad section contents when rebuilding binary
This commit is contained in:
commit
149d352a49
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user