Skip to content

Commit

Permalink
Not all 'application/...' mime types are ELF executables
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Aug 28, 2023
1 parent c8a5df4 commit 6f81c37
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ bool Executable::hasShebang(const QString& path) {

bool Executable::isElf(const QString& path) {
QMimeDatabase mimeDatabase;
QMimeType mimeType = mimeDatabase.mimeTypeForFile(path);

QStringList allMimeTypeNames = {mimeType.name()};
allMimeTypeNames.append(mimeType.allAncestors());
qDebug() << "All MIME types for file:" << allMimeTypeNames;

if (allMimeTypeNames.contains("application/x-executable") || \
allMimeTypeNames.contains("application/x-pie-executable") || \
allMimeTypeNames.contains("application/vnd-appimage")) {
QString mimeType = mimeDatabase.mimeTypeForFile(path).name();
// NOTE: Not all "application/..." mime types are ELF executables, e.g., disk images
// have "application/..." mime types, too.
if (mimeType == "application/x-executable" || \
mimeType == "application/x-pie-executable" || \
mimeType == "application/vnd-appimage") {
qDebug() << "File is an ELF executable.";
return true;
} else {
Expand Down

0 comments on commit 6f81c37

Please sign in to comment.