diff options
Diffstat (limited to 'Mono.Cecil/AssemblyWriter.cs')
-rw-r--r-- | Mono.Cecil/AssemblyWriter.cs | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs index e60ab1d..c83f997 100644 --- a/Mono.Cecil/AssemblyWriter.cs +++ b/Mono.Cecil/AssemblyWriter.cs @@ -118,17 +118,13 @@ namespace Mono.Cecil { metadata.SetSymbolWriter (symbol_writer); BuildMetadata (module, metadata); - ImageDebugHeader debugHeader = null; - if (symbol_writer != null) - debugHeader = symbol_writer.GetDebugHeader (); + if (parameters.DeterministicMvid) + metadata.ComputeDeterministicMvid (); - var writer = ImageWriter.CreateWriter (module, metadata, stream, debugHeader); + var writer = ImageWriter.CreateWriter (module, metadata, stream); stream.value.SetLength (0); writer.WriteImage (); - if (parameters.DeterministicMvid) - ComputeDeterministicMvid (writer, module); - if (parameters.HasStrongNameKey) CryptoService.StrongName (stream.value, writer, parameters); } @@ -160,26 +156,6 @@ namespace Mono.Cecil { return symbol_writer_provider.GetSymbolWriter (module, fq_name); } - - static void ComputeDeterministicMvid (ImageWriter writer, ModuleDefinition module) - { - long previousPosition = writer.BaseStream.Position; - writer.BaseStream.Seek(0, SeekOrigin.Begin); - - // The hash should be computed with the MVID set to all zeroes - // which it is - we explicitly write all zeroes GUID into the heap - // as the MVID. - // Same goes for strong name signature, which also already in the image but all zeroes right now. - Guid guid = CryptoService.ComputeGuid (CryptoService.ComputeHash (writer.BaseStream)); - - // The MVID GUID is always the first GUID in the GUID heap - writer.MoveToRVA (TextSegment.GuidHeap); - writer.WriteBytes (guid.ToByteArray ()); - writer.Flush (); - module.Mvid = guid; - - writer.BaseStream.Seek(previousPosition, SeekOrigin.Begin); - } } abstract class MetadataTable { @@ -2666,6 +2642,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 { |