Skip to content

Commit

Permalink
Fix checks and add testers
Browse files Browse the repository at this point in the history
  • Loading branch information
yardenshafir committed Nov 21, 2022
1 parent ddc6aad commit 54cf779
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
20 changes: 14 additions & 6 deletions checksec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ Checksec::Checksec(std::string filepath) : filepath_(filepath), loadedImage_(fil
if (debugDir.Type == 20) {
if (debugDir.PointerToRawData != 0) {
auto dataPtr = debugDir.PointerToRawData + loadedImage_.get()->fileBuffer->buf;
try {
extendedDllCharacteristics_ = *((uint16_t*)dataPtr);
} catch (...) {
if ((dataPtr < loadedImage_.get()->fileBuffer->buf) ||
(dataPtr > loadedImage_.get()->fileBuffer->buf +
loadedImage_.get()->fileBuffer->bufLen)) {
std::cerr << "Warn: dataPtr is out of bounds"
<< "\n";
extendedDllCharacteristics_ = 0;
return;
}
extendedDllCharacteristics_ = *((uint16_t*)dataPtr);
}
}
}
Expand Down Expand Up @@ -149,11 +153,15 @@ Checksec::Checksec(std::string filepath) : filepath_(filepath), loadedImage_(fil
if (debugDir.Type == 20) {
if (debugDir.PointerToRawData != 0) {
auto dataPtr = debugDir.PointerToRawData + loadedImage_.get()->fileBuffer->buf;
try {
extendedDllCharacteristics_ = *((uint16_t*)dataPtr);
} catch (...) {
if ((dataPtr < loadedImage_.get()->fileBuffer->buf) ||
(dataPtr > loadedImage_.get()->fileBuffer->buf +
loadedImage_.get()->fileBuffer->bufLen)) {
std::cerr << "Warn: dataPtr is out of bounds"
<< "\n";
extendedDllCharacteristics_ = 0;
return;
}
extendedDllCharacteristics_ = *((uint16_t*)dataPtr);
}
}
}
Expand Down
Binary file added test/assets/32/pegoat-cetcompat.exe
Binary file not shown.
Binary file added test/assets/64/pegoat-cetcompat.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions test/winchecksec-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ TEST(Winchecksec, NoCetCompat64) {

EXPECT_FALSE(checksec.isCetCompat());
}

TEST(Winchecksec, CetCompat64) {
auto *path = WINCHECKSEC_TEST_ASSETS "/64/pegoat-cetcompat.exe";

auto checksec = checksec::Checksec(path);

EXPECT_TRUE(checksec.isCetCompat());
}

0 comments on commit 54cf779

Please sign in to comment.