diff --git a/src/Microsoft.DotNet.SignTool.Tests/Resources/CoreLibCrossARM.dll b/src/Microsoft.DotNet.SignTool.Tests/Resources/CoreLibCrossARM.dll new file mode 100644 index 00000000000..dc8e84db1c7 Binary files /dev/null and b/src/Microsoft.DotNet.SignTool.Tests/Resources/CoreLibCrossARM.dll differ diff --git a/src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs b/src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs index f6762494f91..2a1c45431d5 100644 --- a/src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs +++ b/src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs @@ -429,6 +429,41 @@ public void EmptyPKT() }); } + [Fact] + public void CrossGenNative() + { + // List of files to be considered for signing + var itemsToSign = new[] + { + GetResourcePath("CoreLibCrossARM.dll") + }; + + // Default signing information + var strongNameSignInfo = new Dictionary() + { + { "581d91ccdfc4ea9c", new SignInfo("ArcadeCertTest", "ArcadeStrongTest") } + }; + + // Overriding information + var fileSignInfo = new Dictionary() + { + { new ExplicitCertificateKey("EmptyPKT.dll"), "3PartySHA2" } + }; + + ValidateFileSignInfos(itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, new[] + { + "File 'CoreLibCrossARM.dll' Certificate='Microsoft400'", + }); + + ValidateGeneratedProject(itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, new[] + { +$@" + Microsoft400 +", + }); + } + + [Fact] public void DefaultCertificateForAssemblyWithoutStrongName() { diff --git a/src/Microsoft.DotNet.SignTool/src/Configuration.cs b/src/Microsoft.DotNet.SignTool/src/Configuration.cs index 580f17c3e6e..f1a996e4b80 100644 --- a/src/Microsoft.DotNet.SignTool/src/Configuration.cs +++ b/src/Microsoft.DotNet.SignTool/src/Configuration.cs @@ -361,20 +361,19 @@ private static bool IsThirdPartyCertificate(string name) private static void GetPEInfo(string fullPath, out bool isManaged, out string publicKeyToken, out string targetFramework, out string copyright) { - AssemblyName assemblyName = ContentUtil.GetAssemblyName(fullPath); + isManaged = ContentUtil.IsManaged(fullPath); - if (assemblyName == null) + if (!isManaged) { - isManaged = false; publicKeyToken = string.Empty; targetFramework = string.Empty; copyright = string.Empty; return; } + AssemblyName assemblyName = AssemblyName.GetAssemblyName(fullPath); var pktBytes = assemblyName.GetPublicKeyToken(); - isManaged = true; publicKeyToken = (pktBytes == null || pktBytes.Length == 0) ? string.Empty : string.Join("", pktBytes.Select(b => b.ToString("x2"))); GetTargetFrameworkAndCopyright(fullPath, out targetFramework, out copyright); } diff --git a/src/Microsoft.DotNet.SignTool/src/ContentUtil.cs b/src/Microsoft.DotNet.SignTool/src/ContentUtil.cs index 283780ccd16..37989cb9c81 100644 --- a/src/Microsoft.DotNet.SignTool/src/ContentUtil.cs +++ b/src/Microsoft.DotNet.SignTool/src/ContentUtil.cs @@ -67,15 +67,14 @@ public static bool IsPublicSigned(PEReader peReader) return (header.Flags & CorFlags.StrongNameSigned) == CorFlags.StrongNameSigned; } - public static AssemblyName GetAssemblyName(string fullFilePath) + public static bool IsManaged(string filePath) { - try + using (var stream = new FileStream(filePath, FileMode.Open)) + using (var peReader = new PEReader(stream)) { - return AssemblyName.GetAssemblyName(fullFilePath); - } - catch - { - return null; + var corEntry = peReader.PEHeaders.PEHeader.CorHeaderTableDirectory; + + return corEntry.RelativeVirtualAddress == 0x2008 && corEntry.Size == 0x48; } } diff --git a/src/Microsoft.DotNet.SignTool/src/FileSignInfo.cs b/src/Microsoft.DotNet.SignTool/src/FileSignInfo.cs index 5406e083bb6..05b98ffa84b 100644 --- a/src/Microsoft.DotNet.SignTool/src/FileSignInfo.cs +++ b/src/Microsoft.DotNet.SignTool/src/FileSignInfo.cs @@ -48,7 +48,7 @@ internal static bool IsZipContainer(string path) internal bool IsPEFile() => IsPEFile(FileName); - internal bool IsManaged() => ContentUtil.GetAssemblyName(FullPath) != null; + internal bool IsManaged() => ContentUtil.IsManaged(FullPath); internal bool IsVsix() => IsVsix(FileName);