| 43 | } |
| 44 | |
| 45 | int extractBinaryType(std::filesystem::path path) |
| 46 | { |
| 47 | int extra_flags = 0; |
| 48 | |
| 49 | /* Check for MacOS app file, and extract the actual executable if so. */ |
| 50 | std::filesystem::path executable_path = extractMacOSExecutable(path); |
| 51 | if (!executable_path.empty()) { |
| 52 | path = executable_path; |
| 53 | extra_flags = BT_MACOSAPP; |
| 54 | } |
| 55 | |
| 56 | std::ostringstream oss; |
| 57 | oss << "file --brief --dereference "; |
| 58 | oss << path; |
| 59 | |
| 60 | std::string outputstr = queryCmd(oss.str()); |
| 61 | |
| 62 | if (outputstr.find("pie executable") != std::string::npos) { |
| 63 | extra_flags |= BT_PIEAPP; |
| 64 | } |
| 65 | |
| 66 | if (outputstr.find("ELF 32-bit") != std::string::npos) { |
| 67 | return BT_ELF32 | extra_flags; |
| 68 | } |
| 69 | |
| 70 | if (outputstr.find("ELF 64-bit") != std::string::npos) { |
| 71 | return BT_ELF64 | extra_flags; |
| 72 | } |
| 73 | |
| 74 | if (outputstr.find("PE32 executable") != std::string::npos) { |
| 75 | return BT_PE32 | extra_flags; |
| 76 | } |
| 77 | |
| 78 | if (outputstr.find("PE32+ executable") != std::string::npos) { |
| 79 | return BT_PE32P | extra_flags; |
| 80 | } |
| 81 | |
| 82 | if (outputstr.find("MS-DOS executable, NE") != std::string::npos) { |
| 83 | return BT_NE | extra_flags; |
| 84 | } |
| 85 | |
| 86 | if (outputstr.find("Bourne-Again shell script") != std::string::npos) { |
| 87 | return BT_SH | extra_flags; |
| 88 | } |
| 89 | |
| 90 | if (outputstr.find("Mach-O universal binary") != std::string::npos) { |
| 91 | return BT_MACOSUNI | extra_flags; |
| 92 | } |
| 93 | |
| 94 | if (outputstr.find("Mach-O executable i386") != std::string::npos) { |
| 95 | return BT_MACOS32 | extra_flags; |
| 96 | } |
| 97 | |
| 98 | if (outputstr.find("Mach-O 64-bit") != std::string::npos) { |
| 99 | return BT_MACOS64 | extra_flags; |
| 100 | } |
| 101 | |
| 102 | return BT_UNKNOWN | extra_flags; |
no test coverage detected