Skip to content

Commit

Permalink
Add new PE CV_CFL_LANG language code for ALIASOBJ and Rust (#530)
Browse files Browse the repository at this point in the history
* Add Language Code for PE

* Add Objective C baseline

* Add new PE CV_CFL_LANG language code for ALIASOBJ and RUST

* Update Rust string

* re-baseline with latest Sarif SDK

* fix comments

* fix comments for md file

* add . to end of sentence in md file

* FunctionalTestBuildScripts.md add spacing before code

* update FunctionalTestBuildScripts.md

* update to Rust 1.5.8.1

* Fix merge issue for release history file

* remove extra baseline expected sarif file

* Update ReleaseHistory.md

Co-authored-by: Eddy Nakamura <[email protected]>
Co-authored-by: Michael C. Fanning <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2022
1 parent f1b6332 commit 95e5b35
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 2 deletions.
15 changes: 15 additions & 0 deletions docs/FunctionalTestBuildScripts.md
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ public string GetDialect(out string versionNumber)
}
}

/// <summary>
/// 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
/// </summary>
public enum Language : uint
{
C = 0x00,
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
39 changes: 39 additions & 0 deletions src/Test.UnitTests.BinaryParsers/PEBinary/PEBinaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// 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;

using Dia2Lib;

using FluentAssertions;

using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase;
using Microsoft.CodeAnalysis.Sarif.Driver;

using Xunit;

namespace Microsoft.CodeAnalysis.BinaryParsers
Expand Down Expand Up @@ -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()
{
Expand All @@ -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<Language>();
foreach (DisposableEnumerableView<Symbol> omView in peBinary.Pdb.CreateObjectModuleIterator())
{
ObjectModuleDetails omDetails = omView.Value.GetObjectModuleDetails();
if (omDetails.Library == omDetails.Name)
{
languages.Add(omDetails.Language);
}
}
return languages.Contains(language);
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 95e5b35

Please sign in to comment.