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:
authorAustin Wise <AustinWise@gmail.com>2016-07-13 22:51:21 +0300
committerAustin Wise <AustinWise@gmail.com>2016-07-13 22:53:45 +0300
commit003083beae9f74720eaa563fcd969ad315bc4e66 (patch)
tree1e21aa36ad1dd36f39197855345c6ed817dd4c84
parentac3e4bf57c46ec0db98a8b04cc92e098aefe7d33 (diff)
Validate PDB magic and ImageDebugDirectory type and version.
-rw-r--r--symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs33
-rw-r--r--symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs5
2 files changed, 24 insertions, 14 deletions
diff --git a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
index e1f56db..0a92038 100644
--- a/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
+++ b/symbols/pdb/Microsoft.Cci.Pdb/PdbFileHeader.cs
@@ -24,6 +24,8 @@ 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);
@@ -37,15 +39,18 @@ 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.");
+ }
int directoryPages = ((((directorySize + pageSize - 1) / pageSize) * 4) + pageSize - 1) / pageSize;
this.directoryRoot = new int[directoryPages];
bits.FillBuffer(reader, directoryPages * 4);
bits.ReadInt32(this.directoryRoot);
}
- //internal string Magic {
- // get { return StringFromBytesUTF8(magic); }
- //}
+ string Magic {
+ get { return StringFromBytesUTF8(magic, 0, MAGIC.Length); }
+ }
//internal void Write(Stream writer, BitAccess bits) {
// bits.MinCapacity(pageSize);
@@ -63,18 +68,18 @@ namespace Microsoft.Cci.Pdb {
//////////////////////////////////////////////////// Helper Functions.
//
- //internal static string StringFromBytesUTF8(byte[] bytes) {
- // return StringFromBytesUTF8(bytes, 0, bytes.Length);
- //}
+ static string StringFromBytesUTF8(byte[] bytes) {
+ return StringFromBytesUTF8(bytes, 0, bytes.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);
- //}
+ 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/Mono.Cecil.Pdb/PdbReader.cs b/symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs
index d56ead0..d06ac91 100644
--- a/symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs
+++ b/symbols/pdb/Mono.Cecil.Pdb/PdbReader.cs
@@ -41,6 +41,11 @@ namespace Mono.Cecil.Pdb {
public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header)
{
+ if (directory.Type != 2) //IMAGE_DEBUG_TYPE_CODEVIEW
+ return false;
+ if (directory.MajorVersion != 0 || directory.MinorVersion != 0)
+ return false;
+
if (header.Length < 24)
return false;