Skip to content

Commit bfb39b9

Browse files
committed
fix LIEF crash if scanning dos exe file
1 parent be43489 commit bfb39b9

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ find_package(Boost REQUIRED COMPONENTS system filesystem)
2525

2626
find_package(OpenSSL REQUIRED)
2727

28-
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
29-
3028
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt")
3129
message(STATUS "Submodule 'libs/miniz' not found. Updating submodules...")
3230
execute_process(
@@ -126,7 +124,6 @@ set(LINK_COMMON
126124
OpenSSL::SSL
127125
Boost::system
128126
Boost::filesystem
129-
Python3::Python
130127
)
131128

132129
set(LINK_GUI
@@ -136,7 +133,6 @@ set(LINK_GUI
136133
set(INCLUDE_DIR
137134
${CURL_INCLUDE_DIR}
138135
${Boost_INCLUDE_DIRS}
139-
${Python3_INCLUDE_DIRS}
140136
libs/miniz
141137
libs/LIEF/include
142138
src

src/binary.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,28 @@ QString decideExe(const QDir& dir) {
2626
QStringList exeFiles = dir.entryList(filters, QDir::Files);
2727

2828
for (const QString& file : exeFiles) {
29+
QString path = dir.filePath(file);
30+
std::string pathStr = path.toStdString();
31+
32+
if (!LIEF::PE::is_pe(pathStr))
33+
continue;
34+
2935
try {
3036
std::unique_ptr<LIEF::PE::Binary> binary =
31-
LIEF::PE::Parser::parse(dir.filePath(file).toStdString());
37+
LIEF::PE::Parser::parse(pathStr);
3238

3339
bool found = std::any_of(binary->imports().begin(),
34-
binary->imports().end(), [](const LIEF::PE::Import& imp) {
35-
return imp.name() == "DDRAW.dll" || imp.name() == "d3d11.dll";
36-
});
40+
binary->imports().end(), [](const LIEF::PE::Import& imp) {
41+
return imp.name() == "DDRAW.dll" ||
42+
imp.name() == "d3d11.dll";
43+
});
3744

3845
if (found) {
3946
fileName = file;
4047
break;
4148
}
4249
} catch (const std::exception& e) {
43-
std::cerr << "Error: " << e.what() << std::endl;
50+
std::cerr << "LIEF parse error: " << e.what() << std::endl;
4451
}
4552
}
4653

0 commit comments

Comments
 (0)