Skip to content

Commit

Permalink
The last data directory might not be null
Browse files Browse the repository at this point in the history
See: bc203f2b6a928f1457e9ca99456747bcb7adbbfff789d1c47e9479aac11598af
  • Loading branch information
romainthomas committed Feb 21, 2021
1 parent 2a197a2 commit 3c65ffe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/PE/Binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,11 +1137,6 @@ std::vector<uint8_t> Binary::authentihash(ALGORITHMS algo) const {
.write(dir->size());
}

// Empty data directory
ios
.write<uint32_t>(0)
.write<uint32_t>(0);

for (const Section* sec : this->sections_) {
std::array<char, 8> name = {0};
const std::string& sec_name = sec->name();
Expand Down
6 changes: 0 additions & 6 deletions src/PE/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ void Builder::build(void) {
*this << directory;
}

DataDirectory last_one;
last_one.RVA(0);
last_one.size(0);

*this << last_one;

LIEF_DEBUG("[+] Sections");

for (const Section& section : this->binary_->sections()) {
Expand Down
7 changes: 6 additions & 1 deletion src/PE/Parser.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ void Parser::parse_data_directories(void) {
}

this->binary_->data_directories_.reserve(nbof_datadir);
for (size_t i = 0; i < nbof_datadir; ++i) {
// WARNING: The PE specifications require that the data directory table ends with a null entry (RVA / Size,
// set to 0).
// Nevertheless it seems that this requirement is not enforced by the PE loader.
// The binary bc203f2b6a928f1457e9ca99456747bcb7adbbfff789d1c47e9479aac11598af contains a non-null final
// data directory (watermarking?)
for (size_t i = 0; i < (nbof_datadir + 1); ++i) {
std::unique_ptr<DataDirectory> directory{new DataDirectory{&data_directory[i], static_cast<DATA_DIRECTORY>(i)}};
LIEF_DEBUG("Processing directory #{:d} ()", i, to_string(static_cast<DATA_DIRECTORY>(i)));
LIEF_DEBUG(" - RVA: 0x{:04x}", data_directory[i].RelativeVirtualAddress);
Expand Down

0 comments on commit 3c65ffe

Please sign in to comment.