Skip to content

Commit

Permalink
getting rid off sarif sdk from codebase
Browse files Browse the repository at this point in the history
and update dotnet to 8

Mid step for MSDIA and linux changes

Changes
  • Loading branch information
AllDwarf committed Oct 1, 2024
1 parent aa28314 commit 144f302
Show file tree
Hide file tree
Showing 37 changed files with 648 additions and 629 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
run: dotnet tool install -g dotnet-format

- name: dotnet format
run: dotnet-format --folder --check --exclude .\src\sarif-sdk\
run: dotnet-format --folder --check
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

14 changes: 4 additions & 10 deletions BuildAndTest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ echo public const string Version = AssemblyVersion + Prerelease;
echo } >> %VERSION_CONSTANTS%
echo } >> %VERSION_CONSTANTS%

::Download Submodules
if not exist %~dp0src\sarif-sdk\src\Sarif.Sdk.sln (git submodule update --init --recursive)

::Restore packages
echo Restoring packages...
Expand All @@ -65,24 +63,20 @@ call :RunTestProject BinSkim.Rules Functional || goto :ExitFailed

::Create the BinSkim platform specific publish packages
echo Creating Platform Specific BinSkim 'Publish' Packages
call :CreatePublishPackage netcoreapp3.1 win-x64 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 linux-x64 || goto :ExitFailed
call :CreatePublishPackage netcoreapp3.1 osx-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 win-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 linux-x64 || goto :ExitFailed
call :CreatePublishPackage net6.0 osx-x64 || goto :ExitFailed
call :CreatePublishPackage net8.0 win-x64 || goto :ExitFailed
call :CreatePublishPackage net8.0 linux-x64 || goto :ExitFailed
call :CreatePublishPackage net8.0 osx-x64 || goto :ExitFailed

::Build NuGet package
echo BuildPackages.cmd
call BuildPackages.cmd || goto :ExitFailed

echo dotnet-format
dotnet tool update --global dotnet-format --version 4.1.131201
dotnet-format --folder --exclude .\src\sarif-sdk\

::Update BinSkimRules.md to cover any xml changes
echo Exporting any BinSkim rules
.\bld\bin\x64_Release\netcoreapp3.1\BinSkim.exe export-rules .\docs\BinSkimRules.md
.\bld\bin\x64_Release\net8.0\BinSkim.exe export-rules .\docs\BinSkimRules.md

goto :Exit

Expand Down
4 changes: 0 additions & 4 deletions BuildAndTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ if [[ "$(uname)" == "Linux" || "$(uname)" == "Darwin" ]]; then
sed 's#\\#/#g' src/BinSkim.sln > src/BinSkimUnix.sln
fi

if [ ! -f src/sarif-sdk/src/Sarif.Sdk.sln ]; then
echo "Get submodule..."
git submodule update --init --recursive
fi

dotnet build src/BinSkimUnix.sln --configuration Release /p:Platform="x64"

Expand Down
2 changes: 0 additions & 2 deletions ado-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ jobs:
script: "BuildAndTest.cmd"

- task: ComponentGovernanceComponentDetection@0
inputs:
ignoreDirectories: 'src\sarif-sdk'

- job: mac
pool:
Expand Down
7 changes: 4 additions & 3 deletions src/BinSkim.Driver/BinSkim.Driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="Sarif.Driver" Version="4.5.4" />
<PackageReference Include="Sarif.Sdk" Version="4.5.4" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Reflection.Metadata" Version="7.0.2" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -42,7 +44,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\sarif-sdk\src\Sarif.Driver\Sarif.Driver.csproj" />
<ProjectReference Include="..\BinaryParsers\BinaryParsers.csproj" />
<ProjectReference Include="..\BinSkim.Rules\BinSkim.Rules.csproj" />
<ProjectReference Include="..\BinSkim.Sdk\BinSkim.Sdk.csproj" />
Expand Down
10 changes: 6 additions & 4 deletions src/BinSkim.Rules/BinSkim.Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.netcore.props))\build.netcore.props" />
<PropertyGroup>
<RootNamespace>Microsoft.CodeAnalysis.IL.Rules</RootNamespace>
<TargetFramework>$(NetStandardVersion)</TargetFramework>
<TargetFramework>$(NetCoreVersion)</TargetFramework>
<Platforms>x64</Platforms>
</PropertyGroup>

Expand All @@ -17,12 +17,14 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Composition" Version="7.0.0" />
<PackageReference Include="Sarif.Driver" Version="4.5.4" />
<PackageReference Include="Sarif.Sdk" Version="4.5.4" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Composition" Version="8.0.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\sarif-sdk\src\Sarif.Driver\Sarif.Driver.csproj" />
<ProjectReference Include="..\BinaryParsers\BinaryParsers.csproj" />
<ProjectReference Include="..\BinSkim.Sdk\BinSkim.Sdk.csproj" />
</ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions src/BinSkim.Sdk/BinSkim.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.netcore.props))\build.netcore.props" />
<PropertyGroup>
<RootNamespace>Microsoft.CodeAnalysis.IL.Sdk</RootNamespace>
<TargetFramework>$(NetStandardVersion)</TargetFramework>
<TargetFrameworks>$(NetCoreVersion)</TargetFrameworks>
<Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="Sarif.Driver" Version="4.5.4" />
<PackageReference Include="Sarif.Sdk" Version="4.5.4" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BinaryParsers\BinaryParsers.csproj" />
<ProjectReference Include="..\sarif-sdk\src\Sarif.Driver\Sarif.Driver.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/BinSkim.Sdk/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void Dispose()
private static void ConfigureTelemetryContext(TelemetryContext context)
{
context.Session.Id = CreateRandomSessionId();
context.Component.Version = Assembly.GetCallingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
AssemblyFileVersionAttribute? versionAttribute = Assembly.GetCallingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>();
context.Component.Version = versionAttribute?.Version ?? "Unknown";
context.Device.OperatingSystem = RuntimeInformation.OSDescription;
}

Expand Down
47 changes: 1 addition & 46 deletions src/BinSkim.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -42,22 +42,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.UnitTests.BinSkim.Rule
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.UnitTests.BinSkim.Driver", "Test.UnitTests.BinSkim.Driver\Test.UnitTests.BinSkim.Driver.csproj", "{B64DBE60-C7E6-48C1-BB7F-B12129DF98B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sarif.Driver", "sarif-sdk\src\Sarif.Driver\Sarif.Driver.csproj", "{27C37565-AA27-4452-BABF-75DAF151A8F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sarif-sdk", "sarif-sdk", "{E69E2009-ECED-4750-AA40-BFDD4FD13DAB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sarif", "sarif-sdk\src\Sarif\Sarif.csproj", "{C0DA9150-1651-457E-A700-A5CC389571A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.UnitTests.Sarif", "sarif-sdk\src\Test.UnitTests.Sarif\Test.UnitTests.Sarif.csproj", "{D976E333-3E50-41DD-B324-603B92237FC6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.UnitTests.Sarif.Driver", "sarif-sdk\src\Test.UnitTests.Sarif.Driver\Test.UnitTests.Sarif.Driver.csproj", "{F8B27B8D-9DEE-4950-9257-83B8CD3714FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Utilities.Sarif", "sarif-sdk\src\Test.Utilities.Sarif\Test.Utilities.Sarif.csproj", "{33EE1C90-2A26-428C-8006-B585E07AB620}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sarif.Converters", "sarif-sdk\src\Sarif.Converters\Sarif.Converters.csproj", "{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.UnitTests.Sarif.Converters", "sarif-sdk\src\Test.UnitTests.Sarif.Converters\Test.UnitTests.Sarif.Converters.csproj", "{E29D948B-BF8D-41D3-9924-01E994602D8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.ConcurrencyTests", "Test.ConcurrencyTests\Test.ConcurrencyTests.csproj", "{27A04162-2037-41FB-AD76-E179451BB627}"
EndProject
Global
Expand Down Expand Up @@ -140,22 +124,6 @@ Global
{B64DBE60-C7E6-48C1-BB7F-B12129DF98B2}.Release|Any CPU.Build.0 = Release|x64
{B64DBE60-C7E6-48C1-BB7F-B12129DF98B2}.Release|x64.ActiveCfg = Release|x64
{B64DBE60-C7E6-48C1-BB7F-B12129DF98B2}.Release|x64.Build.0 = Release|x64
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Debug|x64.ActiveCfg = Debug|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Debug|x64.Build.0 = Debug|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Release|Any CPU.Build.0 = Release|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Release|x64.ActiveCfg = Release|Any CPU
{27C37565-AA27-4452-BABF-75DAF151A8F2}.Release|x64.Build.0 = Release|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Debug|x64.Build.0 = Debug|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Release|Any CPU.Build.0 = Release|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Release|x64.ActiveCfg = Release|Any CPU
{C0DA9150-1651-457E-A700-A5CC389571A6}.Release|x64.Build.0 = Release|Any CPU
{D976E333-3E50-41DD-B324-603B92237FC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D976E333-3E50-41DD-B324-603B92237FC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D976E333-3E50-41DD-B324-603B92237FC6}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -180,14 +148,6 @@ Global
{33EE1C90-2A26-428C-8006-B585E07AB620}.Release|Any CPU.Build.0 = Release|Any CPU
{33EE1C90-2A26-428C-8006-B585E07AB620}.Release|x64.ActiveCfg = Release|Any CPU
{33EE1C90-2A26-428C-8006-B585E07AB620}.Release|x64.Build.0 = Release|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Debug|x64.ActiveCfg = Debug|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Debug|x64.Build.0 = Debug|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Release|Any CPU.Build.0 = Release|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Release|x64.ActiveCfg = Release|Any CPU
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB}.Release|x64.Build.0 = Release|Any CPU
{E29D948B-BF8D-41D3-9924-01E994602D8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E29D948B-BF8D-41D3-9924-01E994602D8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E29D948B-BF8D-41D3-9924-01E994602D8A}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -208,11 +168,6 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{27C37565-AA27-4452-BABF-75DAF151A8F2} = {E69E2009-ECED-4750-AA40-BFDD4FD13DAB}
{C0DA9150-1651-457E-A700-A5CC389571A6} = {E69E2009-ECED-4750-AA40-BFDD4FD13DAB}
{0C7A9CC9-991F-4971-8C82-9C8DDE66C3EB} = {E69E2009-ECED-4750-AA40-BFDD4FD13DAB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AD3DFD92-76F5-471C-AAAB-9762C40A363E}
EndGlobalSection
Expand Down
15 changes: 7 additions & 8 deletions src/BinaryParsers/BinaryParsers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.netcore.props))\build.netcore.props" />
<PropertyGroup>
<RootNamespace>Microsoft.CodeAnalysis.BinaryParsers</RootNamespace>
<TargetFramework>$(NetStandardVersion)</TargetFramework>
<TargetFramework>$(NetCoreVersion)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>x64</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ELFSharp" Version="2.17.2" />
<PackageReference Include="ELFSharp" Version="2.17.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="7.0.2" />
<PackageReference Include="Sarif.Driver" Version="4.5.4" />
<PackageReference Include="Sarif.Sdk" Version="4.5.4" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\sarif-sdk\src\Sarif.Driver\Sarif.Driver.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="Dia2Lib">
<HintPath>..\..\refs\Dia2Lib.dll</HintPath>
Expand Down
1 change: 0 additions & 1 deletion src/BinaryParsers/ElfBinary/Dwarf/DwarfMemoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public ulong ReadLength(out bool is64bit)
/// <summary>
/// Reads the string from the current position in the stream.
/// </summary>
[HandleProcessCorruptedStateExceptions]
public string ReadString()
{
string result = Marshal.PtrToStringAnsi(pointer + Position);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

public interface IResourceReleaser
{
void Release(object resource);
object GetObjectForIUnknown(nint pointer);
}
11 changes: 7 additions & 4 deletions src/BinaryParsers/PEBinary/ProgramDatabase/MSDiaComWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

using Dia2Lib;

Expand All @@ -23,27 +24,29 @@ private static extern int DllGetClassObject(
[In, MarshalAs(UnmanagedType.LPStruct)] Guid riid,
out IntPtr ppvObject);

private static void CoCreateFromMsdia(Guid clsidOfServer, Guid riid, out IntPtr pvObject)
[SupportedOSPlatform("windows")]
private static void CoCreateFromMsdia(Guid clsidOfServer, Guid riid, out IntPtr pvObject, IResourceReleaser resourceReleaser)
{
IntPtr pClassFactory = IntPtr.Zero;
int hr = DllGetClassObject(clsidOfServer, new Guid("00000001-0000-0000-C000-000000000046"), out pClassFactory);
if (hr != 0)
{
throw new InvalidOperationException("Could not get class object.");
}

var classFactory = (IClassFactory)Marshal.GetObjectForIUnknown(pClassFactory);
classFactory.CreateInstance(IntPtr.Zero, ref riid, out pvObject);
Marshal.Release(pClassFactory);
Marshal.ReleaseComObject(classFactory);
resourceReleaser.Release(pClassFactory);
}

private const string IDiaDataSourceRiid = "79F1BB5F-B66E-48E5-B6A9-1545C323CA3D";
private const string DiaSourceClsid = "E6756135-1E65-4D17-8576-610761398C3C";

[SupportedOSPlatform("windows")]
public static IDiaDataSource GetDiaSource()
{
IntPtr diaSourcePtr = IntPtr.Zero;
CoCreateFromMsdia(new Guid(DiaSourceClsid), new Guid(IDiaDataSourceRiid), out diaSourcePtr);
CoCreateFromMsdia(new Guid(DiaSourceClsid), new Guid(IDiaDataSourceRiid), out diaSourcePtr, new ResourceReleaser());
object objectForIUnknown = Marshal.GetObjectForIUnknown(diaSourcePtr);
var diaSourceInstance = objectForIUnknown as IDiaDataSource;
return diaSourceInstance;
Expand Down
Loading

0 comments on commit 144f302

Please sign in to comment.