Imported Upstream version 6.8.0.73

Former-commit-id: d18deab1b47cfd3ad8cba82b3f37d00eec2170af
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-12-10 18:00:56 +00:00
parent bceda29824
commit 73ee7591e8
1043 changed files with 16271 additions and 22080 deletions

View File

@@ -1,38 +0,0 @@
trigger:
- master
pr:
- master
jobs:
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
dotnet build -c Debug Mono.Cecil.sln
displayName: 'Build'
- script: |
dotnet test --no-build -c Debug -f netcoreapp2.1 Mono.Cecil.sln
displayName: 'Test .NET Core'
- task: NuGetToolInstaller@0
displayName: 'Install nuget'
- task: NuGetCommand@2
inputs:
command: 'custom'
arguments: 'install NUnit.Console -Version 3.9.0 -OutputDirectory ./packages'
displayName: 'Get NUnit.Console'
- script: |
mono ./packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./Mono.Cecil.nunit
displayName: 'Test .NET 4.0 using Mono'
- job: Windows
pool:
vmImage: 'vs2017-win2016'
steps:
- script: |
dotnet build -c Debug Mono.Cecil.sln
displayName: 'Build'
- script: |
dotnet test --no-build -c Debug Mono.Cecil.sln
displayName: 'Test'

View File

@@ -0,0 +1,35 @@
name: CI
on:
push:
branches:
- master
- release/*
pull_request:
branches:
- master
- release/*
jobs:
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: dotnet build -c Debug Mono.Cecil.sln
- name: Test
run: dotnet test --no-build -c Debug Mono.Cecil.sln
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: dotnet build -c Debug Mono.Cecil.sln
- name: Test .NET Core
run: dotnet test --no-build -c Debug Mono.Cecil.sln
- name: Get NuGet
run: curl -o ./nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- name: Get NUnit.Console
run: mono ./nuget.exe install NUnit.Console -Version 3.9.0 -OutputDirectory ./packages
- name: Test .NET 4.0 using Mono
run: mono ./packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./Mono.Cecil.nunit

View File

@@ -14,3 +14,5 @@ TestResults
project.lock.json
.vs/
.idea/
packages/*
nuget.exe

View File

@@ -350,7 +350,7 @@ namespace Mono.Cecil.PE {
PointerToRawData = ReadInt32 (),
};
if (directory.PointerToRawData == 0) {
if (directory.PointerToRawData == 0 || directory.SizeOfData < 0) {
entries [i] = new ImageDebugHeaderEntry (directory, Empty<byte>.Array);
continue;
}

View File

@@ -1,6 +1,6 @@
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" runtimeFramework="v4.0.30319">
<Config name="Debug" runtimeFramework="v4.0.30319" domainUsage="Single">
<assembly path="./Test/bin/Debug/net40/Mono.Cecil.Tests.dll" />
<assembly path="./rocks/Test/bin/Debug/net40/Mono.Cecil.Rocks.Tests.dll" />
<assembly path="./symbols/mdb/Test/bin/Debug/net40/Mono.Cecil.Mdb.Tests.dll" />

View File

@@ -102,8 +102,8 @@ namespace Mono.Cecil {
if (symbol_writer_provider == null && parameters.WriteSymbols)
symbol_writer_provider = new DefaultSymbolWriterProvider ();
if (parameters.StrongNameKeyPair != null && name != null) {
name.PublicKey = parameters.StrongNameKeyPair.PublicKey;
if (parameters.HasStrongNameKey && name != null) {
name.PublicKey = CryptoService.GetPublicKey (parameters);
module.Attributes |= ModuleAttributes.StrongNameSigned;
}
@@ -125,8 +125,8 @@ namespace Mono.Cecil {
stream.value.SetLength (0);
writer.WriteImage ();
if (parameters.StrongNameKeyPair != null)
CryptoService.StrongName (stream.value, writer, parameters.StrongNameKeyPair);
if (parameters.HasStrongNameKey)
CryptoService.StrongName (stream.value, writer, parameters);
}
} finally {
module.metadata_builder = null;

View File

@@ -199,6 +199,8 @@ namespace Mono.Cecil {
Stream symbol_stream;
ISymbolWriterProvider symbol_writer_provider;
bool write_symbols;
byte [] key_blob;
string key_container;
SR.StrongNameKeyPair key_pair;
public uint? Timestamp {
@@ -221,6 +223,20 @@ namespace Mono.Cecil {
set { write_symbols = value; }
}
public bool HasStrongNameKey {
get { return key_pair != null || key_blob != null || key_container != null; }
}
public byte [] StrongNameKeyBlob {
get { return key_blob; }
set { key_blob = value; }
}
public string StrongNameKeyContainer {
get { return key_container; }
set { key_container = value; }
}
public SR.StrongNameKeyPair StrongNameKeyPair {
get { return key_pair; }
set { key_pair = value; }

View File

@@ -29,6 +29,8 @@ namespace Mono.Cecil {
UI1 = 17,
UI2 = 18,
UI4 = 19,
I8 = 20,
UI8 = 21,
Int = 22,
UInt = 23
}

View File

@@ -44,6 +44,16 @@ namespace Mono.Security.Cryptography {
return (uint)((bytes [offset+3] << 24) | (bytes [offset+2] << 16) | (bytes [offset+1] << 8) | bytes [offset]);
}
static private byte [] GetBytesLE (int val)
{
return new byte [] {
(byte) (val & 0xff),
(byte) ((val >> 8) & 0xff),
(byte) ((val >> 16) & 0xff),
(byte) ((val >> 24) & 0xff)
};
}
static private byte[] Trim (byte[] array)
{
for (int i=0; i < array.Length; i++) {
@@ -240,5 +250,41 @@ namespace Mono.Security.Cryptography {
}
throw new CryptographicException ("Unknown blob format.");
}
static public byte[] ToCapiPublicKeyBlob (RSA rsa)
{
RSAParameters p = rsa.ExportParameters (false);
int keyLength = p.Modulus.Length; // in bytes
byte[] blob = new byte [20 + keyLength];
blob [0] = 0x06; // Type - PUBLICKEYBLOB (0x06)
blob [1] = 0x02; // Version - Always CUR_BLOB_VERSION (0x02)
// [2], [3] // RESERVED - Always 0
blob [5] = 0x24; // ALGID - Always 00 24 00 00 (for CALG_RSA_SIGN)
blob [8] = 0x52; // Magic - RSA1 (ASCII in hex)
blob [9] = 0x53;
blob [10] = 0x41;
blob [11] = 0x31;
byte[] bitlen = GetBytesLE (keyLength << 3);
blob [12] = bitlen [0]; // bitlen
blob [13] = bitlen [1];
blob [14] = bitlen [2];
blob [15] = bitlen [3];
// public exponent (DWORD)
int pos = 16;
int n = p.Exponent.Length;
while (n > 0)
blob [pos++] = p.Exponent [--n];
// modulus
pos = 20;
byte[] part = p.Modulus;
int len = part.Length;
Array.Reverse (part, 0, len);
Buffer.BlockCopy (part, 0, blob, pos, len);
pos += len;
return blob;
}
}
}

View File

@@ -26,11 +26,33 @@ namespace Mono.Cecil {
static class CryptoService {
public static void StrongName (Stream stream, ImageWriter writer, StrongNameKeyPair key_pair)
public static byte [] GetPublicKey (WriterParameters parameters)
{
using (var rsa = parameters.CreateRSA ()) {
var cspBlob = CryptoConvert.ToCapiPublicKeyBlob (rsa);
var publicKey = new byte [12 + cspBlob.Length];
Buffer.BlockCopy (cspBlob, 0, publicKey, 12, cspBlob.Length);
// The first 12 bytes are documented at:
// http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp
// ALG_ID - Signature
publicKey [1] = 36;
// ALG_ID - Hash
publicKey [4] = 4;
publicKey [5] = 128;
// Length of Public Key (in bytes)
publicKey [8] = (byte) (cspBlob.Length >> 0);
publicKey [9] = (byte) (cspBlob.Length >> 8);
publicKey [10] = (byte) (cspBlob.Length >> 16);
publicKey [11] = (byte) (cspBlob.Length >> 24);
return publicKey;
}
}
public static void StrongName (Stream stream, ImageWriter writer, WriterParameters parameters)
{
int strong_name_pointer;
var strong_name = CreateStrongName (key_pair, HashStream (stream, writer, out strong_name_pointer));
var strong_name = CreateStrongName (parameters, HashStream (stream, writer, out strong_name_pointer));
PatchStrongName (stream, strong_name_pointer, strong_name);
}
@@ -40,11 +62,11 @@ namespace Mono.Cecil {
stream.Write (strong_name, 0, strong_name.Length);
}
static byte [] CreateStrongName (StrongNameKeyPair key_pair, byte [] hash)
static byte [] CreateStrongName (WriterParameters parameters, byte [] hash)
{
const string hash_algo = "SHA1";
using (var rsa = key_pair.CreateRSA ()) {
using (var rsa = parameters.CreateRSA ()) {
var formatter = new RSAPKCS1SignatureFormatter (rsa);
formatter.SetHashAlgorithm (hash_algo);
@@ -74,7 +96,6 @@ namespace Mono.Cecil {
var sha1 = new SHA1Managed ();
var buffer = new byte [buffer_size];
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
stream.Seek (0, SeekOrigin.Begin);
CopyStreamChunk (stream, crypto_stream, buffer, header_size);
@@ -125,7 +146,7 @@ namespace Mono.Cecil {
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
for (int i = 0; i < buffers.Length; i++) {
crypto_stream.Write (buffers [0].buffer, 0, buffers [0].length);
crypto_stream.Write (buffers [i].buffer, 0, buffers [i].length);
}
}
@@ -148,12 +169,17 @@ namespace Mono.Cecil {
static partial class Mixin {
public static RSA CreateRSA (this StrongNameKeyPair key_pair)
public static RSA CreateRSA (this WriterParameters writer_parameters)
{
byte [] key;
string key_container;
if (!TryGetKeyContainer (key_pair, out key, out key_container))
if (writer_parameters.StrongNameKeyBlob != null)
return CryptoConvert.FromCapiKeyBlob (writer_parameters.StrongNameKeyBlob);
if (writer_parameters.StrongNameKeyContainer != null)
key_container = writer_parameters.StrongNameKeyContainer;
else if (!TryGetKeyContainer (writer_parameters.StrongNameKeyPair, out key, out key_container))
return CryptoConvert.FromCapiKeyBlob (key);
var parameters = new CspParameters {

View File

@@ -354,6 +354,9 @@ namespace Mono.Cecil.Tests {
static string WinSdkTool (string tool)
{
var sdks = new [] {
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools",
@"Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools",

View File

@@ -683,5 +683,42 @@ class Program
using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
}
}
[Test]
public void DoubleWriteAndReadAgainModuleWithDeterministicMvid ()
{
Guid mvid1_in, mvid1_out, mvid2_in, mvid2_out;
{
const string resource = "foo.dll";
string destination = Path.GetTempFileName ();
using (var module = GetResourceModule (resource, new ReaderParameters { })) {
mvid1_in = module.Mvid;
module.Write (destination, new WriterParameters { DeterministicMvid = true });
}
using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { })) {
mvid1_out = module.Mvid;
}
}
{
const string resource = "hello2.exe";
string destination = Path.GetTempFileName ();
using (var module = GetResourceModule (resource, new ReaderParameters { })) {
mvid2_in = module.Mvid;
module.Write (destination, new WriterParameters { DeterministicMvid = true });
}
using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { })) {
mvid2_out = module.Mvid;
}
}
Assert.AreNotEqual (mvid1_in, mvid2_in);
Assert.AreNotEqual (mvid1_out, mvid2_out);
}
}
}

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Text;
@@ -19,6 +12,11 @@ namespace Microsoft.Cci.Pdb {
this.buffer = new byte[capacity];
}
internal BitAccess(byte[] buffer) {
this.buffer = buffer;
offset = 0;
}
internal byte[] Buffer {
get { return buffer; }
}

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,32 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
//
// File: CvInfo.cs
//
// Generic CodeView information definitions
//
// Structures, constants, etc. for accessing and interpreting
// CodeView information.
//
// The master copy of this file resides in the langapi project (in C++).
// All Microsoft projects are required to use the master copy without
// modification. Modification of the master version or a copy
// without consultation with all parties concerned is extremely
// risky.
//
// When this file is modified, the corresponding documentation file
// omfdeb.doc in the langapi project must be updated.
//
// This is a read-only copy of the C++ file converted to C#.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

View File

@@ -1,13 +1,6 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the Microsoft Public License.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//-----------------------------------------------------------------------------
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.Cci.Pdb {

Some files were not shown because too many files have changed in this diff Show More