diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-01-20 02:58:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 02:58:10 +0300 |
commit | 79b43e8e72866f450dee8b59510cb5767b1491ec (patch) | |
tree | d1f2230a0dff3f9f925bd4b85b45a3944256c3df /Mono.Cecil | |
parent | 8b593d5fb0c5d7ead5636d59f77eed55689cbc40 (diff) |
Fix deterministic MVID and add PdbChecksum (#810)
* Fix deterministic MVID and add PdbChecksum (#31)
* Fix how pdb path is calculated in the tests
* Fix portable PDB stamp in CodeView header (#32)
* Introduce ISymbolWriter.Write
This mostly cleans up the code to make it easier to understand. `ISymbolWriter.GetDebugHeader` no longer actually writes the symbols, there's a new `Write` method for just that.
The assembly writer calls `Write` first and then the image writer calls `GetDebugHeader` when it's needed.
This is partially taken from https://github.com/jbevain/cecil/pull/617.
Diffstat (limited to 'Mono.Cecil')
-rw-r--r-- | Mono.Cecil/AssemblyWriter.cs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs index 6515151..25076ff 100644 --- a/Mono.Cecil/AssemblyWriter.cs +++ b/Mono.Cecil/AssemblyWriter.cs @@ -118,13 +118,16 @@ namespace Mono.Cecil { metadata.SetSymbolWriter (symbol_writer); BuildMetadata (module, metadata); - if (parameters.DeterministicMvid) - metadata.ComputeDeterministicMvid (); + if (symbol_writer != null) + symbol_writer.Write (); 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); } @@ -156,6 +159,26 @@ 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 { @@ -2649,25 +2672,6 @@ 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 { |