Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2019-10-19 01:58:32 +0300
committerZoltan Varga <vargaz@gmail.com>2019-10-19 01:58:32 +0300
commit09a316c202f4c295c0c86ddb5f6c77be457a5b14 (patch)
tree0ff5289ac1b68e0da1190025707f69b139bf8f5f
parentcb6c1ca9aaef869841bfc3e2e7407b81b979b875 (diff)
parentf58568f39ba45ae810f7a88253515a65c4f79c32 (diff)
Merge remote-tracking branch 'jb/master' into HEAD
-rw-r--r--.azure-pipelines.yml38
-rw-r--r--.github/workflows/main.yml35
-rw-r--r--.gitignore2
-rw-r--r--Mono.Cecil.PE/ImageReader.cs2
-rw-r--r--Mono.Cecil.nunit2
-rw-r--r--Mono.Cecil/AssemblyWriter.cs8
-rw-r--r--Mono.Cecil/ModuleDefinition.cs16
-rw-r--r--Mono.Cecil/VariantType.cs2
-rw-r--r--Mono.Security.Cryptography/CryptoConvert.cs46
-rw-r--r--Mono.Security.Cryptography/CryptoService.cs42
-rw-r--r--Test/Mono.Cecil.Tests/CompilationService.cs3
-rw-r--r--Test/Mono.Cecil.Tests/PortablePdbTests.cs37
-rw-r--r--Test/Resources/assemblies/foo.dllbin0 -> 3072 bytes
-rw-r--r--Test/Resources/assemblies/hello2.exebin0 -> 3584 bytes
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs16
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs30
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs27
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/Interfaces.cs10
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/LICENSE35
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs22
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs131
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs55
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs116
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbInfo.cs43
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs20
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs19
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs17
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbTokenLine.cs11
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs15
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/ISymUnmanagedDocumentWriter.cs3
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs19
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs3
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/SymDocumentWriter.cs20
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs48
-rw-r--r--symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs6
47 files changed, 587 insertions, 444 deletions
diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
deleted file mode 100644
index f463b22..0000000
--- a/.azure-pipelines.yml
+++ /dev/null
@@ -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'
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..589e5cd
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -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
diff --git a/.gitignore b/.gitignore
index b369ea1..956178e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@ TestResults
project.lock.json
.vs/
.idea/
+packages/*
+nuget.exe
diff --git a/Mono.Cecil.PE/ImageReader.cs b/Mono.Cecil.PE/ImageReader.cs
index 6fb5e1c..9731ba9 100644
--- a/Mono.Cecil.PE/ImageReader.cs
+++ b/Mono.Cecil.PE/ImageReader.cs
@@ -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;
}
diff --git a/Mono.Cecil.nunit b/Mono.Cecil.nunit
index 4ea9a96..2acfc12 100644
--- a/Mono.Cecil.nunit
+++ b/Mono.Cecil.nunit
@@ -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" />
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs
index d6cf5c2..b359ddf 100644
--- a/Mono.Cecil/AssemblyWriter.cs
+++ b/Mono.Cecil/AssemblyWriter.cs
@@ -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;
diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs
index 6b4e596..81b74c4 100644
--- a/Mono.Cecil/ModuleDefinition.cs
+++ b/Mono.Cecil/ModuleDefinition.cs
@@ -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; }
diff --git a/Mono.Cecil/VariantType.cs b/Mono.Cecil/VariantType.cs
index 81aa7fa..c5e222d 100644
--- a/Mono.Cecil/VariantType.cs
+++ b/Mono.Cecil/VariantType.cs
@@ -29,6 +29,8 @@ namespace Mono.Cecil {
UI1 = 17,
UI2 = 18,
UI4 = 19,
+ I8 = 20,
+ UI8 = 21,
Int = 22,
UInt = 23
}
diff --git a/Mono.Security.Cryptography/CryptoConvert.cs b/Mono.Security.Cryptography/CryptoConvert.cs
index a37d3b9..cd68f99 100644
--- a/Mono.Security.Cryptography/CryptoConvert.cs
+++ b/Mono.Security.Cryptography/CryptoConvert.cs
@@ -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;
+ }
}
}
diff --git a/Mono.Security.Cryptography/CryptoService.cs b/Mono.Security.Cryptography/CryptoService.cs
index 7a4198b..dd9613f 100644
--- a/Mono.Security.Cryptography/CryptoService.cs
+++ b/Mono.Security.Cryptography/CryptoService.cs
@@ -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 {
diff --git a/Test/Mono.Cecil.Tests/CompilationService.cs b/Test/Mono.Cecil.Tests/CompilationService.cs
index 681db51..0c9d35c 100644
--- a/Test/Mono.Cecil.Tests/CompilationService.cs
+++ b/Test/Mono.Cecil.Tests/CompilationService.cs
@@ -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",
diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs
index 6e1efbc..e741865 100644
--- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs
+++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs
@@ -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);
+ }
}
}
diff --git a/Test/Resources/assemblies/foo.dll b/Test/Resources/assemblies/foo.dll
new file mode 100644
index 0000000..56b17e0
--- /dev/null
+++ b/Test/Resources/assemblies/foo.dll
Binary files differ
diff --git a/Test/Resources/assemblies/hello2.exe b/Test/Resources/assemblies/hello2.exe
new file mode 100644
index 0000000..6cc52a9
--- /dev/null
+++ b/Test/Resources/assemblies/hello2.exe
Binary files differ
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs b/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs
index d92a5b7..fce6373 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/BitAccess.cs
@@ -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; }
}
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs b/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs
index 6719131..2a6dff2 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/BitSet.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs b/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs
index 49c51ce..153201c 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/CvInfo.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs b/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs
index 48a1851..8f7ab4b 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/DataStream.cs
@@ -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;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs
index 588f3c1..354925d 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiDbgHdr.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs
index 0ca7915..a245104 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiHeader.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs
index 8ab3717..1617621 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiModuleInfo.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs b/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs
index de9fde9..7730296 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/DbiSecCon.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs b/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs
index db0e41b..221c07f 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/IntHashTable.cs
@@ -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.Collections;
@@ -114,14 +107,14 @@ namespace Microsoft.Cci.Pdb {
*/
// A typical resize algorithm would pick the smallest prime number in this array
- // that is larger than twice the previous capacity.
- // Suppose our Hashtable currently has capacity x and enough elements are added
- // such that a resize needs to occur. Resizing first computes 2x then finds the
- // first prime in the table greater than 2x, i.e. if primes are ordered
- // p_1, p_2, …, p_i,…, it finds p_n such that p_n-1 < 2x < p_n.
- // Doubling is important for preserving the asymptotic complexity of the
- // hashtable operations such as add. Having a prime guarantees that double
- // hashing does not lead to infinite loops. IE, your hash function will be
+ // that is larger than twice the previous capacity.
+ // Suppose our Hashtable currently has capacity x and enough elements are added
+ // such that a resize needs to occur. Resizing first computes 2x then finds the
+ // first prime in the table greater than 2x, i.e. if primes are ordered
+ // p_1, p_2, …, p_i,…, it finds p_n such that p_n-1 < 2x < p_n.
+ // Doubling is important for preserving the asymptotic complexity of the
+ // hashtable operations such as add. Having a prime guarantees that double
+ // hashing does not lead to infinite loops. IE, your hash function will be
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
private static readonly int[] primes = {
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/Interfaces.cs b/symbols/pdb/Microsoft.Cci.Pdb/Interfaces.cs
index 82561fb..acc7f26 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/Interfaces.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/Interfaces.cs
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
-namespace Microsoft.Cci {
+namespace Microsoft.Cci.Pdb {
/// <summary>
/// A range of CLR IL operations that comprise a lexical scope, specified as an IL offset and a length.
/// </summary>
- public interface ILocalScope {
+ interface ILocalScope {
/// <summary>
/// The offset of the first operation in the scope.
/// </summary>
@@ -22,7 +22,7 @@ namespace Microsoft.Cci {
/// A description of the lexical scope in which a namespace type has been nested. This scope is tied to a particular
/// method body, so that partial types can be accommodated.
/// </summary>
- public interface INamespaceScope {
+ interface INamespaceScope {
/// <summary>
/// Zero or more used namespaces. These correspond to using clauses in C#.
@@ -35,7 +35,7 @@ namespace Microsoft.Cci {
/// <summary>
/// A namespace that is used (imported) inside a namespace scope.
/// </summary>
- public interface IUsedNamespace {
+ interface IUsedNamespace {
/// <summary>
/// An alias for a namespace. For example the "x" of "using x = y.z;" in C#. Empty if no alias is present.
/// </summary>
@@ -50,7 +50,7 @@ namespace Microsoft.Cci {
/// <summary>
/// The name of an entity. Typically name instances come from a common pool. Within the pool no two distinct instances will have the same Value or UniqueKey.
/// </summary>
- public interface IName {
+ interface IName {
/// <summary>
/// An integer that is unique within the pool from which the name instance has been allocated. Useful as a hashtable key.
/// </summary>
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/LICENSE b/symbols/pdb/Microsoft.Cci.Pdb/LICENSE
index 7bfc997..f54f08d 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/LICENSE
+++ b/symbols/pdb/Microsoft.Cci.Pdb/LICENSE
@@ -1,22 +1,21 @@
-Microsoft Public License (Ms-PL)
+The MIT License (MIT)
-This license governs use of the accompanying software. If you use the software, you
-accept this license. If you do not accept the license, do not use the software.
+Copyright (c) Microsoft
-1. Definitions
-The terms "reproduce," "reproduction," "derivative works," and "distribution" have the
-same meaning here as under U.S. copyright law.
-A "contribution" is the original software, or any additions or changes to the software.
-A "contributor" is any person that distributes its contribution under this license.
-"Licensed patents" are a contributor's patent claims that read directly on its contribution.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-2. Grant of Rights
-(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
-(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
-3. Conditions and Limitations
-(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
-(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
-(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
-(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
-(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs b/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs
index a6669b5..875c97e 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs
index 434841b..833d849 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs
@@ -1,22 +1,22 @@
-//-----------------------------------------------------------------------------
-//
-// 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.
-//
-//-----------------------------------------------------------------------------
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
using System;
using System.Runtime.InteropServices;
namespace Microsoft.Cci.Pdb {
+ /// <summary />
internal class PdbConstant {
internal string name;
internal uint token;
internal object value;
+ internal PdbConstant(string name, uint token, object value) {
+ this.name = name;
+ this.token = token;
+ this.value = value;
+ }
+
internal PdbConstant(BitAccess bits) {
bits.ReadUInt32(out this.token);
byte tag1;
@@ -78,7 +78,7 @@ namespace Microsoft.Cci.Pdb {
break;
default:
//TODO: error
- break;
+ break;
}
} else {
//TODO: error
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs
index d7f8f0f..43ada45 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbDebugException.cs
@@ -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;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs
index 38d1d56..83c611d 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbException.cs
@@ -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;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs
index 9435d6e..35c0d3d 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFile.cs
@@ -1,29 +1,40 @@
-//-----------------------------------------------------------------------------
-//
// 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.
-//
-//-----------------------------------------------------------------------------
-using System;
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System;
+using System.Collections;
using System.Collections.Generic;
using System.IO;
-using Mono.Cecil.Cil;
namespace Microsoft.Cci.Pdb {
+
internal class PdbFile {
+
+ /// <summary>
+ /// GUID of the Basic source language.
+ /// </summary>
+ private static readonly Guid BasicLanguageGuid = new Guid(974311608, -15764, 4560, 180, 66, 0, 160, 36, 74, 29, 210);
+
private PdbFile() // This class can't be instantiated.
{
}
- static void LoadGuidStream(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor) {
+ static void LoadInjectedSourceInformation(BitAccess bits, out Guid doctype, out Guid language, out Guid vendor, out Guid checksumAlgo, out byte[] checksum) {
+ int checksumSize;
+ int injectedSourceSize;
+ checksum = null;
+
bits.ReadGuid(out language);
bits.ReadGuid(out vendor);
bits.ReadGuid(out doctype);
+ bits.ReadGuid(out checksumAlgo);
+ bits.ReadInt32(out checksumSize);
+ bits.ReadInt32(out injectedSourceSize);
+
+ if (checksumSize > 0) {
+ checksum = new byte[checksumSize];
+ bits.ReadBytes(checksum);
+ }
}
static Dictionary<string, int> LoadNameIndex(BitAccess bits, out int age, out Guid guid) {
@@ -131,11 +142,11 @@ namespace Microsoft.Cci.Pdb {
return ht;
}
+ private static PdbFunction match = new PdbFunction();
+
private static int FindFunction(PdbFunction[] funcs, ushort sec, uint off) {
- var match = new PdbFunction {
- segment = sec,
- address = off,
- };
+ match.segment = sec;
+ match.address = off;
return Array.BinarySearch(funcs, match, PdbFunction.byAddress);
}
@@ -146,11 +157,13 @@ namespace Microsoft.Cci.Pdb {
MsfDirectory dir,
Dictionary<string, int> nameIndex,
PdbReader reader,
- uint limit) {
+ uint limit,
+ Dictionary<string, PdbSource> sourceCache)
+ {
Array.Sort(funcs, PdbFunction.byAddressAndToken);
int begin = bits.Position;
- IntHashTable checks = ReadSourceFileInfo(bits, limit, names, dir, nameIndex, reader);
+ IntHashTable checks = ReadSourceFileInfo(bits, limit, names, dir, nameIndex, reader, sourceCache);
// Read the lines next.
bits.Position = begin;
@@ -213,6 +226,11 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt32(out file.linsiz); // Size of payload.
PdbSource src = (PdbSource)checks[(int)file.index];
+ if (src.language.Equals(BasicLanguageGuid))
+ {
+ func.AdjustVisualBasicScopes();
+ }
+
PdbLines tmp = new PdbLines(src, file.count);
func.lines[block++] = tmp;
PdbLine[] lines = tmp.lines;
@@ -258,7 +276,9 @@ namespace Microsoft.Cci.Pdb {
bool readStrings,
MsfDirectory dir,
Dictionary<string, int> nameIndex,
- PdbReader reader) {
+ PdbReader reader,
+ Dictionary<string, PdbSource> sourceCache)
+ {
PdbFunction[] funcs = null;
bits.Position = 0;
@@ -276,7 +296,8 @@ namespace Microsoft.Cci.Pdb {
if (funcs != null) {
bits.Position = info.cbSyms + info.cbOldLines;
LoadManagedLines(funcs, names, bits, dir, nameIndex, reader,
- (uint)(info.cbSyms + info.cbOldLines + info.cbLines));
+ (uint)(info.cbSyms + info.cbOldLines + info.cbLines),
+ sourceCache);
for (int i = 0; i < funcs.Length; i++) {
funcList.Add(funcs[i]);
@@ -337,32 +358,43 @@ namespace Microsoft.Cci.Pdb {
bits.Position = end;
}
- internal static PdbFunction[] LoadFunctions(Stream read, out Dictionary<uint, PdbTokenLine> tokenToSourceMapping, out string sourceServerData, out int age, out Guid guid) {
- tokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
- BitAccess bits = new BitAccess(512 * 1024);
+ internal static PdbInfo LoadFunctions(Stream read) {
+ PdbInfo pdbInfo = new PdbInfo();
+
+ pdbInfo.TokenToSourceMapping = new Dictionary<uint, PdbTokenLine>();
+ BitAccess bits = new BitAccess(64 * 1024);
PdbFileHeader head = new PdbFileHeader(read, bits);
PdbReader reader = new PdbReader(read, head.pageSize);
MsfDirectory dir = new MsfDirectory(reader, head, bits);
DbiModuleInfo[] modules = null;
DbiDbgHdr header;
+ Dictionary<string, PdbSource> sourceCache = new Dictionary<string, PdbSource>();
dir.streams[1].Read(reader, bits);
- Dictionary<string, int> nameIndex = LoadNameIndex(bits, out age, out guid);
+ Dictionary<string, int> nameIndex = LoadNameIndex(bits, out pdbInfo.Age, out pdbInfo.Guid);
int nameStream;
if (!nameIndex.TryGetValue("/NAMES", out nameStream)) {
- throw new PdbException("No `name' stream");
+ throw new PdbException("Could not find the '/NAMES' stream: the PDB file may be a public symbol file instead of a private symbol file");
}
dir.streams[nameStream].Read(reader, bits);
IntHashTable names = LoadNameStream(bits);
int srcsrvStream;
if (!nameIndex.TryGetValue("SRCSRV", out srcsrvStream))
- sourceServerData = string.Empty;
+ pdbInfo.SourceServerData = string.Empty;
else {
DataStream dataStream = dir.streams[srcsrvStream];
byte[] bytes = new byte[dataStream.contentSize];
dataStream.Read(reader, bits);
- sourceServerData = bits.ReadBString(bytes.Length);
+ pdbInfo.SourceServerData = bits.ReadBString(bytes.Length);
+ }
+
+ int sourceLinkStream;
+ if (nameIndex.TryGetValue("SOURCELINK", out sourceLinkStream)) {
+ DataStream dataStream = dir.streams[sourceLinkStream];
+ pdbInfo.SourceLinkData = new byte[dataStream.contentSize];
+ dataStream.Read(reader, bits);
+ bits.ReadBytes(pdbInfo.SourceLinkData);
}
dir.streams[3].Read(reader, bits);
@@ -376,10 +408,10 @@ namespace Microsoft.Cci.Pdb {
if (module.stream > 0) {
dir.streams[module.stream].Read(reader, bits);
if (module.moduleName == "TokenSourceLineInfo") {
- LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, tokenToSourceMapping);
+ LoadTokenToSourceInfo(bits, module, names, dir, nameIndex, reader, pdbInfo.TokenToSourceMapping, sourceCache);
continue;
}
- LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader);
+ LoadFuncsFromDbiModule(bits, module, names, funcList, true, dir, nameIndex, reader, sourceCache);
}
}
}
@@ -400,11 +432,12 @@ namespace Microsoft.Cci.Pdb {
//
Array.Sort(funcs, PdbFunction.byAddressAndToken);
//Array.Sort(funcs, PdbFunction.byToken);
- return funcs;
+ pdbInfo.Functions = funcs;
+ return pdbInfo;
}
private static void LoadTokenToSourceInfo(BitAccess bits, DbiModuleInfo module, IntHashTable names, MsfDirectory dir,
- Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<uint, PdbTokenLine> tokenToSourceMapping) {
+ Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<uint, PdbTokenLine> tokenToSourceMapping, Dictionary<string,PdbSource> sourceCache) {
bits.Position = 0;
int sig;
bits.ReadInt32(out sig);
@@ -477,15 +510,18 @@ namespace Microsoft.Cci.Pdb {
bits.Position = module.cbSyms + module.cbOldLines;
int limit = module.cbSyms + module.cbOldLines + module.cbLines;
- IntHashTable sourceFiles = ReadSourceFileInfo(bits, (uint)limit, names, dir, nameIndex, reader);
+ IntHashTable sourceFiles = ReadSourceFileInfo(bits, (uint)limit, names, dir, nameIndex, reader, sourceCache);
foreach (var tokenLine in tokenToSourceMapping.Values) {
tokenLine.sourceFile = (PdbSource)sourceFiles[(int)tokenLine.file_id];
}
}
+ public static readonly Guid SymDocumentType_Text = new Guid(1518771467, 26129, 4563, 189, 42, 0, 0, 248, 8, 73, 189);
+
private static IntHashTable ReadSourceFileInfo(BitAccess bits, uint limit, IntHashTable names, MsfDirectory dir,
- Dictionary<string, int> nameIndex, PdbReader reader) {
+ Dictionary<string, int> nameIndex, PdbReader reader, Dictionary<string, PdbSource> sourceCache)
+ {
IntHashTable checks = new IntHashTable();
int begin = bits.Position;
@@ -508,17 +544,26 @@ namespace Microsoft.Cci.Pdb {
bits.ReadUInt8(out chk.type);
string name = (string)names[(int)chk.name];
- int guidStream;
- Guid doctypeGuid = DocumentType.Text.ToGuid();
- Guid languageGuid = Guid.Empty;
- Guid vendorGuid = Guid.Empty;
- if (nameIndex.TryGetValue("/SRC/FILES/"+name.ToUpperInvariant(), out guidStream)) {
- var guidBits = new BitAccess(0x100);
- dir.streams[guidStream].Read(reader, guidBits);
- LoadGuidStream(guidBits, out doctypeGuid, out languageGuid, out vendorGuid);
- }
- PdbSource src = new PdbSource(/*(uint)ni,*/ name, doctypeGuid, languageGuid, vendorGuid);
+ PdbSource src;
+ if (!sourceCache.TryGetValue(name, out src))
+ {
+ int guidStream;
+ Guid doctypeGuid = SymDocumentType_Text;
+ Guid languageGuid = Guid.Empty;
+ Guid vendorGuid = Guid.Empty;
+ Guid checksumAlgoGuid = Guid.Empty;
+ byte[] checksum = null;
+ if (nameIndex.TryGetValue("/SRC/FILES/" + name.ToUpperInvariant(), out guidStream))
+ {
+ var guidBits = new BitAccess(0x100);
+ dir.streams[guidStream].Read(reader, guidBits);
+ LoadInjectedSourceInformation(guidBits, out doctypeGuid, out languageGuid, out vendorGuid, out checksumAlgoGuid, out checksum);
+ }
+
+ src = new PdbSource(name, doctypeGuid, languageGuid, vendorGuid, checksumAlgoGuid, checksum);
+ sourceCache.Add(name, src);
+ }
checks.Add(ni, src);
bits.Position += chk.len;
bits.Align(4);
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
index 0a92038..8204123 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
@@ -1,19 +1,20 @@
-//-----------------------------------------------------------------------------
-//
// 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.Linq;
using System.Text;
namespace Microsoft.Cci.Pdb {
internal class PdbFileHeader {
+ private readonly byte[] windowsPdbMagic = new byte[32] {
+ 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
+ 0x74, 0x20, 0x43, 0x2F, 0x43, 0x2B, 0x2B, 0x20, // "t C/C++ "
+ 0x4D, 0x53, 0x46, 0x20, 0x37, 0x2E, 0x30, 0x30, // "MSF 7.00"
+ 0x0D, 0x0A, 0x1A, 0x44, 0x53, 0x00, 0x00, 0x00 // "^^^DS^^^"
+ };
+
//internal PdbFileHeader(int pageSize) {
// this.magic = new byte[32] {
// 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, // "Microsof"
@@ -24,8 +25,6 @@ namespace Microsoft.Cci.Pdb {
// this.pageSize = pageSize;
//}
- const string MAGIC = "Microsoft C/C++ MSF 7.00";
-
internal PdbFileHeader(Stream reader, BitAccess bits) {
bits.MinCapacity(56);
reader.Seek(0, SeekOrigin.Begin);
@@ -39,18 +38,20 @@ namespace Microsoft.Cci.Pdb {
bits.ReadInt32(out this.directorySize); // 44..47
bits.ReadInt32(out this.zero); // 48..51
- if (Magic != MAGIC) {
- throw new InvalidOperationException("Magic is wrong.");
+ if (!this.magic.SequenceEqual(windowsPdbMagic))
+ {
+ throw new PdbException("The PDB file is not recognized as a Windows PDB file");
}
+
int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
this.directoryRoot = new int[directoryPages];
bits.FillBuffer(reader, directoryPages * 4);
bits.ReadInt32(this.directoryRoot);
}
- string Magic {
- get { return StringFromBytesUTF8(magic, 0, MAGIC.Length); }
- }
+ //internal string Magic {
+ // get { return StringFromBytesUTF8(magic); }
+ //}
//internal void Write(Stream writer, BitAccess bits) {
// bits.MinCapacity(pageSize);
@@ -68,18 +69,18 @@ namespace Microsoft.Cci.Pdb {
//////////////////////////////////////////////////// Helper Functions.
//
- static string StringFromBytesUTF8(byte[] bytes) {
- return StringFromBytesUTF8(bytes, 0, bytes.Length);
- }
+ //internal static string StringFromBytesUTF8(byte[] bytes) {
+ // return StringFromBytesUTF8(bytes, 0, bytes.Length);
+ //}
- static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
- for (int i = 0; i < length; i++) {
- if (bytes[offset + i] < ' ') {
- length = i;
- }
- }
- return Encoding.UTF8.GetString(bytes, offset, length);
- }
+ //internal static string StringFromBytesUTF8(byte[] bytes, int offset, int length) {
+ // for (int i = 0; i < length; i++) {
+ // if (bytes[offset + i] < ' ') {
+ // length = i;
+ // }
+ // }
+ // return Encoding.UTF8.GetString(bytes, offset, length);
+ //}
////////////////////////////////////////////////////////////// Fields.
//
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs
index b02b97f..affc5ea 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFunction.cs
@@ -1,17 +1,12 @@
-//-----------------------------------------------------------------------------
-//
// 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.Collections;
using System.Collections.Generic;
+#pragma warning disable 1591 // TODO: doc comments
+
namespace Microsoft.Cci.Pdb {
internal class PdbFunction {
static internal readonly Guid msilMetaData = new Guid(0xc6ea3fc9, 0x59b3, 0x49d6, 0xbc, 0x25,
@@ -43,6 +38,13 @@ namespace Microsoft.Cci.Pdb {
internal List<ILocalScope>/*?*/ iteratorScopes;
internal PdbSynchronizationInformation/*?*/ synchronizationInformation;
+ /// <summary>
+ /// Flag saying whether the method has been identified as a product of VB compilation using
+ /// the legacy Windows PDB symbol format, in which case scope ends need to be shifted by 1
+ /// due to different semantics of scope limits in VB and C# compilers.
+ /// </summary>
+ private bool visualBasicScopesAdjusted = false;
+
private static string StripNamespace(string module) {
int li = module.LastIndexOf('.');
if (li > 0) {
@@ -51,6 +53,36 @@ namespace Microsoft.Cci.Pdb {
return module;
}
+ /// <summary>
+ /// When the Windows PDB reader identifies a PdbFunction as having 'Basic' as its source language,
+ /// it calls this method which adjusts all scopes by adding 1 to their lengths to compensate
+ /// for different behavior of VB vs. the C# compiler w.r.t. emission of scope info.
+ /// </summary>
+ internal void AdjustVisualBasicScopes()
+ {
+ if (!visualBasicScopesAdjusted)
+ {
+ visualBasicScopesAdjusted = true;
+
+ // Don't adjust root scope as that one is correct
+ foreach (PdbScope scope in scopes)
+ {
+ AdjustVisualBasicScopes(scope.scopes);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Recursively update the entire scope tree by adding 1 to the length of each scope.
+ /// </summary>
+ private void AdjustVisualBasicScopes(PdbScope[] scopes)
+ {
+ foreach (PdbScope scope in scopes)
+ {
+ scope.length++;
+ AdjustVisualBasicScopes(scope.scopes);
+ }
+ }
internal static PdbFunction[] LoadManagedFunctions(/*string module,*/
BitAccess bits, uint limit,
@@ -260,15 +292,7 @@ namespace Microsoft.Cci.Pdb {
if (oem.idOem == msilMetaData) {
string name = bits.ReadString();
if (name == "MD2") {
- byte version;
- bits.ReadUInt8(out version);
- if (version == 4) {
- byte count;
- bits.ReadUInt8(out count);
- bits.Align(4);
- while (count-- > 0)
- this.ReadCustomMetadata(bits);
- }
+ ReadMD2CustomMetadata(bits);
} else if (name == "asyncMethodInfo") {
this.synchronizationInformation = new PdbSynchronizationInformation(bits);
}
@@ -338,27 +362,47 @@ namespace Microsoft.Cci.Pdb {
}
}
- private void ReadCustomMetadata(BitAccess bits) {
- int savedPosition = bits.Position;
+ internal void ReadMD2CustomMetadata(BitAccess bits)
+ {
byte version;
bits.ReadUInt8(out version);
- if (version != 4) {
- throw new PdbDebugException("Unknown custom metadata item version: {0}", version);
- }
- byte kind;
- bits.ReadUInt8(out kind);
- bits.Align(4);
- uint numberOfBytesInItem;
- bits.ReadUInt32(out numberOfBytesInItem);
- switch (kind) {
- case 0: this.ReadUsingInfo(bits); break;
- case 1: this.ReadForwardInfo(bits); break;
- case 2: break; // this.ReadForwardedToModuleInfo(bits); break;
- case 3: this.ReadIteratorLocals(bits); break;
- case 4: this.ReadForwardIterator(bits); break;
- // TODO: handle unknown custom metadata, 5 & 6 are new with roslyn, see https://roslyn.codeplex.com/workitem/54
+ if (version == 4) {
+ byte count;
+ bits.ReadUInt8(out count);
+ bits.Align(4);
+ while (count-- > 0)
+ this.ReadCustomMetadata(bits);
}
- bits.Position = savedPosition+(int)numberOfBytesInItem;
+ }
+
+ private void ReadCustomMetadata(BitAccess bits)
+ {
+ int savedPosition = bits.Position;
+ byte version;
+ bits.ReadUInt8(out version);
+ byte kind;
+ bits.ReadUInt8(out kind);
+ bits.Position += 2; // 2-bytes padding
+ uint numberOfBytesInItem;
+ bits.ReadUInt32(out numberOfBytesInItem);
+ if (version == 4)
+ {
+ switch (kind)
+ {
+ case 0: this.ReadUsingInfo(bits); break;
+ case 1: this.ReadForwardInfo(bits); break;
+ case 2: break; // this.ReadForwardedToModuleInfo(bits); break;
+ case 3: this.ReadIteratorLocals(bits); break;
+ case 4: this.ReadForwardIterator(bits); break;
+ case 5: break; // dynamic locals - see http://index/#Microsoft.VisualStudio.LanguageServices/Shared/CustomDebugInfoReader.cs,a3031f7681d76e93
+ case 6: break; // EnC data
+ case 7: break; // EnC data for lambdas and closures
+ // ignore any other unknown record types that may be added in future, instead of throwing an exception
+ // see more details here: https://github.com/tmat/roslyn/blob/portable-pdb/docs/specs/PortablePdb-Metadata.md
+ default: break; // throw new PdbDebugException("Unknown custom metadata item kind: {0}", kind);
+ }
+ }
+ bits.Position = savedPosition + (int)numberOfBytesInItem;
}
private void ReadForwardIterator(BitAccess bits) {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbInfo.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbInfo.cs
new file mode 100644
index 0000000..5a4e32b
--- /dev/null
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbInfo.cs
@@ -0,0 +1,43 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+
+namespace Microsoft.Cci.Pdb {
+
+ /// <summary>
+ /// This class represents the information read from a PDB file (both legacy Windows and Portable).
+ /// </summary>
+ internal class PdbInfo {
+ /// <summary>
+ /// Enumeration of per-function information contained in the PDB file.
+ /// </summary>
+ public PdbFunction[] Functions;
+
+ /// <summary>
+ /// Mapping from tokens to source files and line numbers.
+ /// </summary>
+ public Dictionary<uint, PdbTokenLine> TokenToSourceMapping;
+
+ /// <summary>
+ /// Source server data information.
+ /// </summary>
+ public string SourceServerData;
+
+ /// <summary>
+ /// Age of the PDB file is used to match the PDB against the PE binary.
+ /// </summary>
+ public int Age;
+
+ /// <summary>
+ /// GUID of the PDB file is used to match the PDB against the PE binary.
+ /// </summary>
+ public Guid Guid;
+
+ /// <summary>
+ /// Source link data information.
+ /// </summary>
+ public byte[] SourceLinkData;
+ }
+}
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs
index f6fe3a9..5e73677 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbLine.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs
index 382638b..18d8974 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbLines.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs
index edfd926..28d02c1 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbReader.cs
@@ -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;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs
index 92ac385..9dad77b 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbScope.cs
@@ -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 {
@@ -22,16 +15,21 @@ namespace Microsoft.Cci.Pdb {
internal uint offset;
internal uint length;
- internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) {
+ internal PdbScope(uint address, uint offset, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces) {
this.constants = constants;
this.slots = slots;
this.scopes = new PdbScope[0];
this.usedNamespaces = usedNamespaces;
this.address = address;
- this.offset = 0;
+ this.offset = offset;
this.length = length;
}
+ internal PdbScope(uint address, uint length, PdbSlot[] slots, PdbConstant[] constants, string[] usedNamespaces)
+ : this(address, 0, length, slots, constants, usedNamespaces)
+ {
+ }
+
internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind) {
//this.segment = block.seg;
this.address = block.off;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs
index e2b76d5..b9b8ef7 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbSlot.cs
@@ -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 {
@@ -19,6 +12,14 @@ namespace Microsoft.Cci.Pdb {
//internal uint segment;
//internal uint address;
+ internal PdbSlot(uint slot, uint typeToken, string name, ushort flags)
+ {
+ this.slot = slot;
+ this.typeToken = typeToken;
+ this.name = name;
+ this.flags = flags;
+ }
+
internal PdbSlot(BitAccess bits) {
AttrSlotSym slot;
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs
index ac40f85..6310b73 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbSource.cs
@@ -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 {
@@ -17,13 +10,17 @@ namespace Microsoft.Cci.Pdb {
internal Guid doctype;
internal Guid language;
internal Guid vendor;
+ internal Guid checksumAlgorithm;
+ internal byte[] checksum;
- internal PdbSource(/*uint index, */string name, Guid doctype, Guid language, Guid vendor) {
+ internal PdbSource(/*uint index, */string name, Guid doctype, Guid language, Guid vendor, Guid checksumAlgorithm, byte[] checksum) {
//this.index = index;
this.name = name;
this.doctype = doctype;
this.language = language;
this.vendor = vendor;
+ this.checksumAlgorithm = checksumAlgorithm;
+ this.checksum = checksum;
}
}
}
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbTokenLine.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbTokenLine.cs
index 879339b..d59c9c8 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbTokenLine.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbTokenLine.cs
@@ -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 {
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs b/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs
index 1c4da18..74d0e63 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/SourceLocationProvider.cs
@@ -1,16 +1,13 @@
-//-----------------------------------------------------------------------------
-//
-// Copyright (C) Microsoft Corporation. All Rights Reserved.
-//
-//-----------------------------------------------------------------------------
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
using System;
using System.Collections.Generic;
using System.IO;
-using Microsoft.Cci;
-using Microsoft.Cci.Pdb;
-using System.Text;
-namespace Microsoft.Cci {
+#pragma warning disable 1591 // TODO: doc comments
+
+namespace Microsoft.Cci.Pdb {
internal sealed class PdbIteratorScope : ILocalScope {
diff --git a/symbols/pdb/Mono.Cecil.Pdb/ISymUnmanagedDocumentWriter.cs b/symbols/pdb/Mono.Cecil.Pdb/ISymUnmanagedDocumentWriter.cs
index e64ec78..2e8589e 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/ISymUnmanagedDocumentWriter.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/ISymUnmanagedDocumentWriter.cs
@@ -6,6 +6,7 @@
// Licensed under the MIT/X11 license.
//
+using System;
using System.Runtime.InteropServices;
namespace Mono.Cecil.Pdb {
@@ -14,5 +15,7 @@ namespace Mono.Cecil.Pdb {
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
interface ISymUnmanagedDocumentWriter {
+ void SetSource (uint sourceSize, [MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 0)] byte [] source);
+ void SetCheckSum (Guid algorithmId, uint checkSumSize, [MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] checkSum);
}
}
diff --git a/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs b/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs
index 9280e0f..2d6b1ba 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/NativePdbReader.cs
@@ -90,17 +90,12 @@ namespace Mono.Cecil.Pdb {
bool PopulateFunctions ()
{
using (pdb_file) {
- Dictionary<uint, PdbTokenLine> tokenToSourceMapping;
- string sourceServerData;
- int age;
- Guid guid;
+ var info = PdbFile.LoadFunctions (pdb_file.value);
- var funcs = PdbFile.LoadFunctions (pdb_file.value, out tokenToSourceMapping, out sourceServerData, out age, out guid);
-
- if (this.guid != guid)
+ if (this.guid != info.Guid)
return false;
- foreach (PdbFunction function in funcs)
+ foreach (PdbFunction function in info.Functions)
functions.Add (function.token, function);
}
@@ -357,9 +352,11 @@ namespace Mono.Cecil.Pdb {
return document;
document = new Document (name) {
- Language = source.language.ToLanguage (),
- LanguageVendor = source.vendor.ToVendor (),
- Type = source.doctype.ToType (),
+ LanguageGuid = source.language,
+ LanguageVendorGuid = source.vendor,
+ TypeGuid = source.doctype,
+ HashAlgorithmGuid = source.checksumAlgorithm,
+ Hash = source.checksum,
};
documents.Add (name, document);
return document;
diff --git a/symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs b/symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs
index a0a0747..01b6c7a 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/NativePdbWriter.cs
@@ -246,6 +246,9 @@ namespace Mono.Cecil.Pdb {
document.LanguageVendorGuid,
document.TypeGuid);
+ if (!document.Hash.IsNullOrEmpty ())
+ doc_writer.SetCheckSum (document.HashAlgorithmGuid, document.Hash);
+
documents [document.Url] = doc_writer;
return doc_writer;
}
diff --git a/symbols/pdb/Mono.Cecil.Pdb/SymDocumentWriter.cs b/symbols/pdb/Mono.Cecil.Pdb/SymDocumentWriter.cs
index 83cea8e..3112c80 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/SymDocumentWriter.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/SymDocumentWriter.cs
@@ -13,16 +13,26 @@ namespace Mono.Cecil.Pdb
{
internal class SymDocumentWriter
{
- readonly ISymUnmanagedDocumentWriter m_unmanagedDocumentWriter;
+ readonly ISymUnmanagedDocumentWriter writer;
- public SymDocumentWriter (ISymUnmanagedDocumentWriter unmanagedDocumentWriter)
+ public ISymUnmanagedDocumentWriter Writer
{
- m_unmanagedDocumentWriter = unmanagedDocumentWriter;
+ get { return writer; }
}
- public ISymUnmanagedDocumentWriter GetUnmanaged ()
+ public SymDocumentWriter (ISymUnmanagedDocumentWriter writer)
{
- return m_unmanagedDocumentWriter;
+ this.writer = writer;
+ }
+
+ public void SetSource (byte [] source)
+ {
+ writer.SetSource ((uint) source.Length, source);
+ }
+
+ public void SetCheckSum (Guid hashAlgo, byte [] checkSum)
+ {
+ writer.SetCheckSum (hashAlgo, (uint) checkSum.Length, checkSum);
}
}
}
diff --git a/symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs b/symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs
index 7006c68..f309f2f 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/SymWriter.cs
@@ -28,7 +28,7 @@ namespace Mono.Cecil.Pdb
static Guid s_symUnmangedWriterIID = new Guid("0b97726e-9e6d-4f05-9a26-424022093caa");
static Guid s_CorSymWriter_SxS_ClassID = new Guid ("108296c1-281e-11d3-bd22-0000f80849bd");
- readonly ISymUnmanagedWriter2 m_writer;
+ readonly ISymUnmanagedWriter2 writer;
readonly Collection<ISymUnmanagedDocumentWriter> documents;
public SymWriter ()
@@ -36,7 +36,7 @@ namespace Mono.Cecil.Pdb
object objWriter;
CoCreateInstance (ref s_CorSymWriter_SxS_ClassID, null, 1, ref s_symUnmangedWriterIID, out objWriter);
- m_writer = (ISymUnmanagedWriter2) objWriter;
+ writer = (ISymUnmanagedWriter2) objWriter;
documents = new Collection<ISymUnmanagedDocumentWriter> ();
}
@@ -45,10 +45,10 @@ namespace Mono.Cecil.Pdb
int size;
// get size of debug info
- m_writer.GetDebugInfo (out idd, 0, out size, null);
+ writer.GetDebugInfo (out idd, 0, out size, null);
byte[] debug_info = new byte[size];
- m_writer.GetDebugInfo (out idd, size, out size, debug_info);
+ writer.GetDebugInfo (out idd, size, out size, debug_info);
return debug_info;
}
@@ -63,23 +63,23 @@ namespace Mono.Cecil.Pdb
int startOffset,
int endOffset)
{
- m_writer.DefineLocalVariable2 (name, (int)attributes, sigToken, 1 /* ILOffset*/, addr1, addr2, addr3, startOffset, endOffset);
+ writer.DefineLocalVariable2 (name, (int)attributes, sigToken, 1 /* ILOffset*/, addr1, addr2, addr3, startOffset, endOffset);
}
public void DefineConstant2 (string name, object value, int sigToken)
{
if (value == null) {
- m_writer.DefineConstant2 (name, 0, sigToken);
+ writer.DefineConstant2 (name, 0, sigToken);
return;
}
- m_writer.DefineConstant2 (name, value, sigToken);
+ writer.DefineConstant2 (name, value, sigToken);
}
public void Close ()
{
- m_writer.Close ();
- Marshal.ReleaseComObject (m_writer);
+ writer.Close ();
+ Marshal.ReleaseComObject (writer);
foreach (var document in documents)
Marshal.ReleaseComObject (document);
@@ -87,69 +87,69 @@ namespace Mono.Cecil.Pdb
public void CloseMethod ()
{
- m_writer.CloseMethod ();
+ writer.CloseMethod ();
}
public void CloseNamespace ()
{
- m_writer.CloseNamespace ();
+ writer.CloseNamespace ();
}
public void CloseScope (int endOffset)
{
- m_writer.CloseScope (endOffset);
+ writer.CloseScope (endOffset);
}
public SymDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType)
{
- ISymUnmanagedDocumentWriter unmanagedDocumentWriter;
- m_writer.DefineDocument (url, ref language, ref languageVendor, ref documentType, out unmanagedDocumentWriter);
+ ISymUnmanagedDocumentWriter doc_writer;
+ writer.DefineDocument (url, ref language, ref languageVendor, ref documentType, out doc_writer);
- documents.Add (unmanagedDocumentWriter);
- return new SymDocumentWriter (unmanagedDocumentWriter);
+ documents.Add (doc_writer);
+ return new SymDocumentWriter (doc_writer);
}
public void DefineSequencePoints (SymDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
{
- m_writer.DefineSequencePoints (document.GetUnmanaged(), offsets.Length, offsets, lines, columns, endLines, endColumns);
+ writer.DefineSequencePoints (document.Writer, offsets.Length, offsets, lines, columns, endLines, endColumns);
}
public void Initialize (object emitter, string filename, bool fFullBuild)
{
- m_writer.Initialize (emitter, filename, null, fFullBuild);
+ writer.Initialize (emitter, filename, null, fFullBuild);
}
public void SetUserEntryPoint (int methodToken)
{
- m_writer.SetUserEntryPoint (methodToken);
+ writer.SetUserEntryPoint (methodToken);
}
public void OpenMethod (int methodToken)
{
- m_writer.OpenMethod (methodToken);
+ writer.OpenMethod (methodToken);
}
public void OpenNamespace (string name)
{
- m_writer.OpenNamespace (name);
+ writer.OpenNamespace (name);
}
public int OpenScope (int startOffset)
{
int result;
- m_writer.OpenScope (startOffset, out result);
+ writer.OpenScope (startOffset, out result);
return result;
}
public void UsingNamespace (string fullName)
{
- m_writer.UsingNamespace (fullName);
+ writer.UsingNamespace (fullName);
}
public void DefineCustomMetadata (string name, byte [] metadata)
{
var handle = GCHandle.Alloc (metadata, GCHandleType.Pinned);
- m_writer.SetSymAttribute (0, name, (uint) metadata.Length, handle.AddrOfPinnedObject ());
+ writer.SetSymAttribute (0, name, (uint) metadata.Length, handle.AddrOfPinnedObject ());
handle.Free ();
}
}
diff --git a/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs b/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs
index 2269cb5..797f680 100644
--- a/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs
+++ b/symbols/pdb/Test/Mono.Cecil.Tests/PdbTests.cs
@@ -99,7 +99,8 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (@"c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
- Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
+ Assert.AreEqual (DocumentHashAlgorithm.MD5, document.HashAlgorithm);
+ Assert.AreEqual (new byte [] { 228, 176, 152, 54, 82, 238, 238, 68, 237, 156, 5, 142, 118, 160, 118, 245 }, document.Hash);
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));
@@ -119,7 +120,8 @@ namespace Mono.Cecil.Tests {
Assert.AreEqual (@"c:\tmp\VBConsApp\Program.vb", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
- Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
+ Assert.AreEqual (DocumentHashAlgorithm.MD5, document.HashAlgorithm);
+ Assert.AreEqual (new byte [] { 184, 188, 100, 23, 27, 123, 187, 201, 175, 206, 110, 198, 242, 139, 154, 119 }, document.Hash);
Assert.AreEqual (DocumentLanguage.Basic, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}, readOnly: !Platform.HasNativePdbSupport, symbolReaderProvider: typeof(PdbReaderProvider), symbolWriterProvider: typeof(PdbWriterProvider));