Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #177 from jairbubbles/portablePdb
Browse files Browse the repository at this point in the history
Properly detect when .pdb file use the new Portable PDB format
  • Loading branch information
GeertvanHorrik authored Sep 11, 2017
2 parents 75f9935 + d3dd63e commit d1f2ecf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GitLink/GitLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Pdb\PdbStream.cs" />
<Compile Include="Pdb\SrcSrv.cs" />
<Compile Include="Pdb\SrcSrvContext.cs" />
<Compile Include="Helpers\PortablePdbHelper.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\BitBucketProvider.cs" />
Expand Down
55 changes: 55 additions & 0 deletions src/GitLink/Helpers/PortablePdbHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PortablePdbHelper.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2016 CatenaLogic. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace GitLink
{
using System.IO;

internal static class PortablePdbHelper
{
/// <summary>
/// Is the given .pdb using the new Portable format ? (https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PortablePdb-Metadata.md)
/// </summary>
/// <param name="pdbPath">.pdb file path</param>
/// <returns>Returns if it's a Portable PDB</returns>
public static bool IsPortablePdb(string pdbPath)
{
using (var fs = File.Open(pdbPath, FileMode.Open, FileAccess.Read))
using (var br = new BinaryReader(fs))
{
// More infos in chapter II.24.2 of ECMA-335 (http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf)
var signature = 0x424A5342;
if (br.ReadUInt32() != signature)
{
return false;
}

var majorVersion = br.ReadUInt16();
if (majorVersion != 1)
{
return false;
}

var minorVersion = br.ReadUInt16();
if (minorVersion != 1)
{
return false;
}

var reserved = br.ReadUInt32();
if (reserved != 0)
{
return false;
}

var versionLength = br.ReadUInt32();
var version = System.Text.Encoding.UTF8.GetString(br.ReadBytes((int)versionLength));

return version.StartsWith("PDB v1.0");
}
}
}
}
6 changes: 6 additions & 0 deletions src/GitLink/Linker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public static class Linker
}
}

if (PortablePdbHelper.IsPortablePdb(pdbPath))
{
Log.Warning("Portable PDB format is not compatible with GitLink. Please use SourceLink (https://github.com/ctaggart/SourceLink).");
return true;
}

if (options.IndexAllDepotFiles)
{
if (repositoryDirectory == null)
Expand Down

0 comments on commit d1f2ecf

Please sign in to comment.