You've already forked linux-packaging-mono
Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
parent
cf815e07e0
commit
95fdb59ea6
2
external/cecil/Mono.Cecil.PE/ImageReader.cs
vendored
2
external/cecil/Mono.Cecil.PE/ImageReader.cs
vendored
@@ -350,7 +350,7 @@ namespace Mono.Cecil.PE {
|
||||
PointerToRawData = ReadInt32 (),
|
||||
};
|
||||
|
||||
if (directory.AddressOfRawData == 0) {
|
||||
if (directory.PointerToRawData == 0) {
|
||||
entries [i] = new ImageDebugHeaderEntry (directory, Empty<byte>.Array);
|
||||
continue;
|
||||
}
|
||||
|
8
external/cecil/Mono.Cecil.PE/ImageWriter.cs
vendored
8
external/cecil/Mono.Cecil.PE/ImageWriter.cs
vendored
@@ -814,14 +814,6 @@ namespace Mono.Cecil.PE {
|
||||
return pe_header_size + SizeOfOptionalHeader () + (sections * section_header_size);
|
||||
}
|
||||
|
||||
public void PatchMvid (Guid guid)
|
||||
{
|
||||
uint offset = GetRVAFileOffset (text, text_map.GetRVA (TextSegment.GuidHeap));
|
||||
BaseStream.Seek (offset, SeekOrigin.Begin);
|
||||
var arr = guid.ToByteArray ();
|
||||
BaseStream.Write (arr, 0, arr.Length);
|
||||
}
|
||||
|
||||
void PatchWin32Resources (ByteBuffer resources)
|
||||
{
|
||||
PatchResourceDirectoryTable (resources);
|
||||
|
1
external/cecil/Mono.Cecil.csproj
vendored
1
external/cecil/Mono.Cecil.csproj
vendored
@@ -1,7 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ProjectInfo.cs" />
|
||||
|
3861
external/cecil/Mono.Cecil/AssemblyReader.cs
vendored
3861
external/cecil/Mono.Cecil/AssemblyReader.cs
vendored
File diff suppressed because it is too large
Load Diff
1
external/cecil/Mono.Cecil/AssemblyReader.cs.REMOVED.git-id
vendored
Normal file
1
external/cecil/Mono.Cecil/AssemblyReader.cs.REMOVED.git-id
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1728338c6228125c82803b552e530972592837b2
|
85
external/cecil/Mono.Cecil/AssemblyWriter.cs
vendored
85
external/cecil/Mono.Cecil/AssemblyWriter.cs
vendored
@@ -109,6 +109,7 @@ namespace Mono.Cecil {
|
||||
|
||||
if (parameters.DeterministicMvid)
|
||||
module.Mvid = Guid.Empty;
|
||||
|
||||
var metadata = new MetadataBuilder (module, fq_name, timestamp, symbol_writer_provider);
|
||||
try {
|
||||
module.metadata_builder = metadata;
|
||||
@@ -117,62 +118,21 @@ namespace Mono.Cecil {
|
||||
metadata.SetSymbolWriter (symbol_writer);
|
||||
BuildMetadata (module, metadata);
|
||||
|
||||
if (parameters.DeterministicMvid)
|
||||
metadata.ComputeDeterministicMvid ();
|
||||
|
||||
var writer = ImageWriter.CreateWriter (module, metadata, stream);
|
||||
stream.value.SetLength (0);
|
||||
writer.WriteImage ();
|
||||
|
||||
if (parameters.StrongNameKeyPair != null)
|
||||
CryptoService.StrongName (stream.value, writer, parameters.StrongNameKeyPair);
|
||||
if (parameters.DeterministicMvid) {
|
||||
module.Mvid = ComputeGuid (stream.value);
|
||||
writer.PatchMvid (module.Mvid);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
module.metadata_builder = null;
|
||||
}
|
||||
}
|
||||
|
||||
static void CopyStreamChunk (Stream stream, Stream dest_stream, byte [] buffer, int length)
|
||||
{
|
||||
while (length > 0) {
|
||||
int read = stream.Read (buffer, 0, System.Math.Min (buffer.Length, length));
|
||||
dest_stream.Write (buffer, 0, read);
|
||||
length -= read;
|
||||
}
|
||||
}
|
||||
|
||||
static byte [] ComputeHash (Stream stream)
|
||||
{
|
||||
const int buffer_size = 8192;
|
||||
|
||||
var sha1 = new SHA1Managed ();
|
||||
|
||||
stream.Seek (0, SeekOrigin.Begin);
|
||||
var buffer = new byte [buffer_size];
|
||||
|
||||
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write))
|
||||
CopyStreamChunk (stream, crypto_stream, buffer, (int) stream.Length);
|
||||
return sha1.Hash;
|
||||
}
|
||||
|
||||
static unsafe Guid ComputeGuid (Stream stream)
|
||||
{
|
||||
byte[] hashCode = ComputeHash (stream);
|
||||
|
||||
// From corefx/src/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobContentId.cs
|
||||
Guid guid = default(Guid);
|
||||
byte* guidPtr = (byte*)&guid;
|
||||
for (var i = 0; i < 16; i++) {
|
||||
guidPtr[i] = hashCode[i];
|
||||
}
|
||||
// modify the guid data so it decodes to the form of a "random" guid ala rfc4122
|
||||
guidPtr[7] = (byte)((guidPtr[7] & 0x0f) | (4 << 4));
|
||||
guidPtr[8] = (byte)((guidPtr[8] & 0x3f) | (2 << 6));
|
||||
|
||||
return guid;
|
||||
}
|
||||
|
||||
static void BuildMetadata (ModuleDefinition module, MetadataBuilder metadata)
|
||||
{
|
||||
if (!module.HasImage) {
|
||||
@@ -1559,12 +1519,20 @@ namespace Mono.Cecil {
|
||||
{
|
||||
var constraints = generic_parameter.Constraints;
|
||||
|
||||
var rid = generic_parameter.token.RID;
|
||||
var gp_rid = generic_parameter.token.RID;
|
||||
|
||||
for (int i = 0; i < constraints.Count; i++)
|
||||
table.AddRow (new GenericParamConstraintRow (
|
||||
rid,
|
||||
MakeCodedRID (GetTypeToken (constraints [i]), CodedIndex.TypeDefOrRef)));
|
||||
for (int i = 0; i < constraints.Count; i++) {
|
||||
var constraint = constraints [i];
|
||||
|
||||
var rid = table.AddRow (new GenericParamConstraintRow (
|
||||
gp_rid,
|
||||
MakeCodedRID (GetTypeToken (constraint.ConstraintType), CodedIndex.TypeDefOrRef)));
|
||||
|
||||
constraint.token = new MetadataToken (TokenType.GenericParamConstraint, rid);
|
||||
|
||||
if (constraint.HasCustomAttributes)
|
||||
AddCustomAttributes (constraint);
|
||||
}
|
||||
}
|
||||
|
||||
void AddInterfaces (TypeDefinition type)
|
||||
@@ -2690,6 +2658,25 @@ namespace Mono.Cecil {
|
||||
|
||||
method_debug_information_table.rows [rid - 1].Col2 = GetBlobIndex (signature);
|
||||
}
|
||||
|
||||
public void ComputeDeterministicMvid ()
|
||||
{
|
||||
var guid = CryptoService.ComputeGuid (CryptoService.ComputeHash (
|
||||
data,
|
||||
resources,
|
||||
string_heap,
|
||||
user_string_heap,
|
||||
blob_heap,
|
||||
table_heap,
|
||||
code));
|
||||
|
||||
var position = guid_heap.position;
|
||||
guid_heap.position = 0;
|
||||
guid_heap.WriteBytes (guid.ToByteArray ());
|
||||
guid_heap.position = position;
|
||||
|
||||
module.Mvid = guid;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SignatureWriter : ByteBuffer {
|
||||
|
96
external/cecil/Mono.Cecil/GenericParameter.cs
vendored
96
external/cecil/Mono.Cecil/GenericParameter.cs
vendored
@@ -23,7 +23,7 @@ namespace Mono.Cecil {
|
||||
internal IGenericParameterProvider owner;
|
||||
|
||||
ushort attributes;
|
||||
Collection<TypeReference> constraints;
|
||||
GenericParameterConstraintCollection constraints;
|
||||
Collection<CustomAttribute> custom_attributes;
|
||||
|
||||
public GenericParameterAttributes Attributes {
|
||||
@@ -52,7 +52,7 @@ namespace Mono.Cecil {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<TypeReference> Constraints {
|
||||
public Collection<GenericParameterConstraint> Constraints {
|
||||
get {
|
||||
if (constraints != null)
|
||||
return constraints;
|
||||
@@ -60,7 +60,7 @@ namespace Mono.Cecil {
|
||||
if (HasImage)
|
||||
return Module.Read (ref constraints, this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter));
|
||||
|
||||
return constraints = new Collection<TypeReference> ();
|
||||
return constraints = new GenericParameterConstraintCollection (this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,4 +265,94 @@ namespace Mono.Cecil {
|
||||
items[i].position = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GenericParameterConstraint : ICustomAttributeProvider {
|
||||
|
||||
internal GenericParameter generic_parameter;
|
||||
internal MetadataToken token;
|
||||
|
||||
TypeReference constraint_type;
|
||||
Collection<CustomAttribute> custom_attributes;
|
||||
|
||||
public TypeReference ConstraintType {
|
||||
get { return constraint_type; }
|
||||
set { constraint_type = value; }
|
||||
}
|
||||
|
||||
public bool HasCustomAttributes {
|
||||
get {
|
||||
if (custom_attributes != null)
|
||||
return custom_attributes.Count > 0;
|
||||
|
||||
if (generic_parameter == null)
|
||||
return false;
|
||||
|
||||
return this.GetHasCustomAttributes (generic_parameter.Module);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<CustomAttribute> CustomAttributes {
|
||||
get {
|
||||
if (generic_parameter == null)
|
||||
return custom_attributes = new Collection<CustomAttribute> ();
|
||||
|
||||
return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, generic_parameter.Module));
|
||||
}
|
||||
}
|
||||
|
||||
public MetadataToken MetadataToken {
|
||||
get { return token; }
|
||||
set { token = value; }
|
||||
}
|
||||
|
||||
internal GenericParameterConstraint (TypeReference constraintType, MetadataToken token)
|
||||
{
|
||||
this.constraint_type = constraintType;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public GenericParameterConstraint (TypeReference constraintType)
|
||||
{
|
||||
Mixin.CheckType (constraintType, Mixin.Argument.constraintType);
|
||||
|
||||
this.constraint_type = constraintType;
|
||||
this.token = new MetadataToken (TokenType.GenericParamConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
class GenericParameterConstraintCollection : Collection<GenericParameterConstraint>
|
||||
{
|
||||
readonly GenericParameter generic_parameter;
|
||||
|
||||
internal GenericParameterConstraintCollection (GenericParameter genericParameter)
|
||||
{
|
||||
this.generic_parameter = genericParameter;
|
||||
}
|
||||
|
||||
internal GenericParameterConstraintCollection (GenericParameter genericParameter, int length)
|
||||
: base (length)
|
||||
{
|
||||
this.generic_parameter = genericParameter;
|
||||
}
|
||||
|
||||
protected override void OnAdd (GenericParameterConstraint item, int index)
|
||||
{
|
||||
item.generic_parameter = generic_parameter;
|
||||
}
|
||||
|
||||
protected override void OnInsert (GenericParameterConstraint item, int index)
|
||||
{
|
||||
item.generic_parameter = generic_parameter;
|
||||
}
|
||||
|
||||
protected override void OnSet (GenericParameterConstraint item, int index)
|
||||
{
|
||||
item.generic_parameter = generic_parameter;
|
||||
}
|
||||
|
||||
protected override void OnRemove (GenericParameterConstraint item, int index)
|
||||
{
|
||||
item.generic_parameter = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
external/cecil/Mono.Cecil/MetadataSystem.cs
vendored
8
external/cecil/Mono.Cecil/MetadataSystem.cs
vendored
@@ -56,7 +56,7 @@ namespace Mono.Cecil {
|
||||
internal Dictionary<uint, Row<MethodSemanticsAttributes, MetadataToken>> Semantics;
|
||||
internal Dictionary<uint, Row<PInvokeAttributes, uint, uint>> PInvokes;
|
||||
internal Dictionary<MetadataToken, Range []> GenericParameters;
|
||||
internal Dictionary<uint, Collection<MetadataToken>> GenericConstraints;
|
||||
internal Dictionary<uint, Collection<Row<uint, MetadataToken>>> GenericConstraints;
|
||||
|
||||
internal Document [] Documents;
|
||||
internal Dictionary<uint, Collection<Row<uint, Range, Range, uint, uint, uint>>> LocalScopes;
|
||||
@@ -149,7 +149,7 @@ namespace Mono.Cecil {
|
||||
if (Semantics != null) Semantics = new Dictionary<uint, Row<MethodSemanticsAttributes, MetadataToken>> (capacity: 0);
|
||||
if (PInvokes != null) PInvokes = new Dictionary<uint, Row<PInvokeAttributes, uint, uint>> (capacity: 0);
|
||||
if (GenericParameters != null) GenericParameters = new Dictionary<MetadataToken, Range []> (capacity: 0);
|
||||
if (GenericConstraints != null) GenericConstraints = new Dictionary<uint, Collection<MetadataToken>> (capacity: 0);
|
||||
if (GenericConstraints != null) GenericConstraints = new Dictionary<uint, Collection<Row<uint, MetadataToken>>> (capacity: 0);
|
||||
|
||||
Documents = Empty<Document>.Array;
|
||||
ImportScopes = Empty<ImportDebugInformation>.Array;
|
||||
@@ -335,12 +335,12 @@ namespace Mono.Cecil {
|
||||
SecurityDeclarations.Remove (owner.MetadataToken);
|
||||
}
|
||||
|
||||
public bool TryGetGenericConstraintMapping (GenericParameter generic_parameter, out Collection<MetadataToken> mapping)
|
||||
public bool TryGetGenericConstraintMapping (GenericParameter generic_parameter, out Collection<Row<uint, MetadataToken>> mapping)
|
||||
{
|
||||
return GenericConstraints.TryGetValue (generic_parameter.token.RID, out mapping);
|
||||
}
|
||||
|
||||
public void SetGenericConstraintMapping (uint gp_rid, Collection<MetadataToken> mapping)
|
||||
public void SetGenericConstraintMapping (uint gp_rid, Collection<Row<uint, MetadataToken>> mapping)
|
||||
{
|
||||
GenericConstraints [gp_rid] = mapping;
|
||||
}
|
||||
|
@@ -1191,6 +1191,7 @@ namespace Mono.Cecil {
|
||||
returnType,
|
||||
propertyType,
|
||||
interfaceType,
|
||||
constraintType,
|
||||
}
|
||||
|
||||
public static void CheckName (object name)
|
||||
|
@@ -102,20 +102,48 @@ namespace Mono.Cecil {
|
||||
if (!File.Exists (file))
|
||||
return Empty<byte>.Array;
|
||||
|
||||
using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
return ComputeHash (stream);
|
||||
}
|
||||
|
||||
public static byte [] ComputeHash (Stream stream)
|
||||
{
|
||||
const int buffer_size = 8192;
|
||||
|
||||
var sha1 = new SHA1Managed ();
|
||||
var buffer = new byte [buffer_size];
|
||||
|
||||
using (var stream = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.Read)) {
|
||||
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write))
|
||||
CopyStreamChunk (stream, crypto_stream, buffer, (int) stream.Length);
|
||||
|
||||
var buffer = new byte [buffer_size];
|
||||
return sha1.Hash;
|
||||
}
|
||||
|
||||
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write))
|
||||
CopyStreamChunk (stream, crypto_stream, buffer, (int) stream.Length);
|
||||
public static byte [] ComputeHash (params ByteBuffer [] buffers)
|
||||
{
|
||||
var sha1 = new SHA1Managed ();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return sha1.Hash;
|
||||
}
|
||||
|
||||
public static Guid ComputeGuid (byte [] hash)
|
||||
{
|
||||
// From corefx/src/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobContentId.cs
|
||||
var guid = new byte [16];
|
||||
Buffer.BlockCopy (hash, 0, guid, 0, 16);
|
||||
|
||||
// modify the guid data so it decodes to the form of a "random" guid ala rfc4122
|
||||
guid [7] = (byte) ((guid [7] & 0x0f) | (4 << 4));
|
||||
guid [8] = (byte) ((guid [8] & 0x3f) | (2 << 6));
|
||||
|
||||
return new Guid (guid);
|
||||
}
|
||||
}
|
||||
|
||||
static partial class Mixin {
|
||||
|
@@ -449,6 +449,21 @@ namespace Mono.Cecil.Tests {
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericParameterConstraint ()
|
||||
{
|
||||
TestModule ("GenericParameterConstraintAttributes.dll", module => {
|
||||
var type = module.GetType ("Foo.Library`1");
|
||||
var gp = type.GenericParameters.Single ();
|
||||
var constraint = gp.Constraints.Single ();
|
||||
|
||||
Assert.IsTrue (constraint.HasCustomAttributes);
|
||||
var attributes = constraint.CustomAttributes;
|
||||
Assert.AreEqual (1, attributes.Count);
|
||||
Assert.AreEqual ("System.Runtime.CompilerServices.NullableAttribute", attributes [0].AttributeType.FullName);
|
||||
}, verify: !Platform.OnMono);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullCharInString ()
|
||||
{
|
||||
|
@@ -669,5 +669,19 @@ class Program
|
||||
Assert.AreEqual (Path.GetFileName (debug_header_pdb_path), pdb_path);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteAndReadAgainModuleWithDeterministicMvid ()
|
||||
{
|
||||
const string resource = "mylib.dll";
|
||||
string destination = Path.GetTempFileName ();
|
||||
|
||||
using (var module = GetResourceModule (resource, new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
|
||||
module.Write (destination, new WriterParameters { DeterministicMvid = true, SymbolWriterProvider = new SymbolWriterProvider () });
|
||||
}
|
||||
|
||||
using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -98,8 +98,8 @@ namespace Mono.Cecil.Tests {
|
||||
Assert.IsTrue (t.HasConstraints);
|
||||
Assert.AreEqual (2, t.Constraints.Count);
|
||||
|
||||
Assert.AreEqual ("Zap", t.Constraints [0].FullName);
|
||||
Assert.AreEqual ("IZoom", t.Constraints [1].FullName);
|
||||
Assert.AreEqual ("Zap", t.Constraints [0].ConstraintType.FullName);
|
||||
Assert.AreEqual ("IZoom", t.Constraints [1].ConstraintType.FullName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace Mono.Cecil.Tests {
|
||||
var t2 = duel.GenericParameters [1];
|
||||
var t3 = duel.GenericParameters [2];
|
||||
|
||||
Assert.AreEqual (t1, t2.Constraints [0]);
|
||||
Assert.AreEqual (t2, t3.Constraints [0]);
|
||||
Assert.AreEqual (t1, t2.Constraints [0].ConstraintType);
|
||||
Assert.AreEqual (t2, t3.Constraints [0].ConstraintType);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user