From 4c7593f74d38d3c25cf7235884972ea66d9a8884 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 1 Mar 2011 18:04:16 +0100 Subject: [PATCH] Distinguish between msvc and mingw binaries Distinguish between binaries built using MSVC and MinGW. --- src/plugins/projectexplorer/abi.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/plugins/projectexplorer/abi.cpp b/src/plugins/projectexplorer/abi.cpp index 903e65eef39..b95eae47342 100644 --- a/src/plugins/projectexplorer/abi.cpp +++ b/src/plugins/projectexplorer/abi.cpp @@ -408,19 +408,38 @@ QList Abi::abisOfBinary(const QString &path) // Windows PE // Windows can have its magic bytes everywhere... int pePos = data.indexOf("PE\0\0"); - if (pePos >= 0 && pePos + 5 < data.size()) { + if (pePos >= 0 && pePos + 72 < data.size()) { + Architecture arch = UnknownArchitecture; + OSFlavor flavor = UnknownFlavor; + int width = 0; + + // Get machine field from COFF file header quint16 machine = (data.at(pePos + 5) << 8) + data.at(pePos + 4); switch (machine) { case 0x8664: // x86_64 - result.append(Abi(Abi::X86Architecture, Abi::WindowsOS, Abi::WindowsMsvcFlavor, Abi::PEFormat, 64)); + arch = Abi::X86Architecture; + width = 64; break; case 0x014c: // i386 - result.append(Abi(Abi::X86Architecture, Abi::WindowsOS, Abi::WindowsMsvcFlavor, Abi::PEFormat, 32)); + arch = Abi::X86Architecture; + width = 32; break; case 0x0200: // ia64 - result.append(Abi(Abi::ItaniumArchitecture, Abi::WindowsOS, Abi::WindowsMsvcFlavor, Abi::PEFormat, 64)); + arch = Abi::ItaniumArchitecture; + width = 64; break; } + + // Get Major and Minor Image Version from optional header fields + quint32 image = (data.at(pePos + 71) << 24) + (data.at(pePos + 70) << 16) + + (data.at(pePos + 69) << 8) + data.at(pePos + 68); + if (image == 1) // Image is 1 for mingw and 4.something for MSVC + flavor = WindowsMSysFlavor; + else + flavor = WindowsMsvcFlavor; + + if (arch != UnknownArchitecture && flavor != UnknownFlavor && width != 0) + result.append(Abi(arch, WindowsOS, flavor, PEFormat, width)); } } return result;