diff --git a/docs/FunctionalTestBuildScripts.md b/docs/FunctionalTestBuildScripts.md new file mode 100644 index 000000000..440cb28c7 --- /dev/null +++ b/docs/FunctionalTestBuildScripts.md @@ -0,0 +1,15 @@ +# Build Scripts + +This file records scripts used to compile the test files, in alphabetical order. +Base scenario is a simple hello world program built with different parameters for testing purpose. +Test files are located in [BaselineTestsData](https://github.com/microsoft/binskim/tree/main/src/Test.FunctionalTests.BinSkim.Driver/BaselineTestsData) and [FunctionalTestsData](https://github.com/microsoft/binskim/tree/main/src/Test.FunctionalTests.BinSkim.Rules/FunctionalTestsData). + +## clangcl.pe.c.codeview.exe + +A simple hello world program, compiled with `clang 13.0.0` that generates a .exe and associated .pdb file. Script to reproduce: +`clang-cl -o clangcl.pe.c.codeview.exe -fuse-ld=lld-link hello.c -m32 -Z7 -MTd` + +## Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe + +A simple hello world program, compiled with `rustc 1.58.1` that generates a .exe and associated .pdb file. Script to reproduce: +`rustc -g -Clink-arg=/DEBUG:FULL src\main.rs -o Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe` diff --git a/src/BinaryParsers/PEBinary/ProgramDatabase/ObjectModuleDetails.cs b/src/BinaryParsers/PEBinary/ProgramDatabase/ObjectModuleDetails.cs index 09b1975f0..9e9a6f2ea 100644 --- a/src/BinaryParsers/PEBinary/ProgramDatabase/ObjectModuleDetails.cs +++ b/src/BinaryParsers/PEBinary/ProgramDatabase/ObjectModuleDetails.cs @@ -224,6 +224,11 @@ public string GetDialect(out string versionNumber) } } + /// + /// The CV_CFL_LANG enumeration, + /// which specifies the code language of the application or linked module in the debug interface access SDK. + /// https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang + /// public enum Language : uint { C = 0x00, @@ -242,11 +247,13 @@ public enum Language : uint Java = 0x0D, JScript = 0x0E, MSIL = 0x0F, - HLSL = 0x10, // High Level Shader Language + HLSL = 0x10, ObjectiveC = 0x11, ObjectiveCxx = 0x12, Swift = 0x13, - NASM = 0x4E, // The Netwide Assembler + ALIASOBJ = 0x14, + Rust = 0x15, + NASM = 0x4E, Unknown } diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 382f3c940..3fd734e6f 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -1,5 +1,9 @@ # BinSkim Release History +## Unreleased + +* FEATURE: Add new PE `CV_CFL_LANG` language code for `ALIASOBJ` and `Rust`. [530](https://github.com/microsoft/binskim/pull/530) + ## **v1.9.3** [NuGet Package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.BinSkim/1.9.3) * BUGFIX: Fix `KeyNotFoundException` exception raised by `BA2006.BuildWithSecureTools` when individual `MinimumToolVersions` properties are removed from XML configuration. [#565](https://github.com/microsoft/binskim/pull/565) diff --git a/src/Test.UnitTests.BinaryParsers/PEBinary/PEBinaryTests.cs b/src/Test.UnitTests.BinaryParsers/PEBinary/PEBinaryTests.cs index 6fdc950ff..08b3c2169 100644 --- a/src/Test.UnitTests.BinaryParsers/PEBinary/PEBinaryTests.cs +++ b/src/Test.UnitTests.BinaryParsers/PEBinary/PEBinaryTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.IO; using System.Reflection; @@ -9,6 +10,9 @@ using FluentAssertions; +using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase; +using Microsoft.CodeAnalysis.Sarif.Driver; + using Xunit; namespace Microsoft.CodeAnalysis.BinaryParsers @@ -70,6 +74,19 @@ public void PEBinary_PdbIsStripped() } } + [Fact] + public void PEBinary_ContainsExpectedLanguageCode() + { + if (!PlatformSpecificHelpers.RunningOnWindows()) { return; } + + ContainsLanguageCode("clangcl.pe.c.codeview.exe", Language.C).Should().BeTrue(); + ContainsLanguageCode("clangcl.pe.cpp.codeview.exe", Language.Cxx).Should().BeTrue(); + // As of v1.58.1 Rust official compiler RustC does not yet use the new CV_CFL_LANG code for Rust. + // We will have another test file when new version use it. + ContainsLanguageCode("Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe", Language.Rust).Should().BeFalse(); + ContainsLanguageCode("Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll", Language.Cxx).Should().BeTrue(); + } + [Fact] public void PEBinary_CanCreateIDiaSourceFromMsdia() { @@ -92,5 +109,27 @@ public void PEBinary_TryLoadPdbFromSymbolFolder() peBinary.PdbParseException.Should().BeNull(); } } + + private static bool ContainsLanguageCode(string fileName, Language language) + { + string fileFullPath = Path.Combine(TestData, "PE", fileName); + using (var peBinary = new PEBinary(new Uri(fileFullPath))) + { + peBinary.Valid.Should().BeTrue(); + peBinary.Pdb.Should().NotBeNull(); + peBinary.PdbParseException.Should().BeNull(); + + var languages = new HashSet(); + foreach (DisposableEnumerableView omView in peBinary.Pdb.CreateObjectModuleIterator()) + { + ObjectModuleDetails omDetails = omView.Value.GetObjectModuleDetails(); + if (omDetails.Library == omDetails.Name) + { + languages.Add(omDetails.Language); + } + } + return languages.Contains(language); + } + } } } diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe new file mode 100644 index 000000000..b6fd38ef0 Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.exe differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.pdb b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.pdb new file mode 100644 index 000000000..1ab85621b Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_RustC_Rust_debuginfo2_v1.58.1.pdb differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll new file mode 100644 index 000000000..2a45cd938 Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.dll differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.pdb b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.pdb new file mode 100644 index 000000000..8b0f50797 Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/Native_x64_VS2019_CPlusPlus_DEBUG_DEFAULT.pdb differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.exe b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.exe new file mode 100644 index 000000000..5ed9a6721 Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.exe differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.pdb b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.pdb new file mode 100644 index 000000000..0f2a2fe5e Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.c.codeview.pdb differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.exe b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.exe new file mode 100644 index 000000000..83ca050b5 Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.exe differ diff --git a/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.pdb b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.pdb new file mode 100644 index 000000000..f6fe6f42a Binary files /dev/null and b/src/Test.UnitTests.BinaryParsers/TestsData/PE/clangcl.pe.cpp.codeview.pdb differ