CodeViewDebugData ReadCodeViewDebugData(DebugDirectory debugDir) { Debug.Assert(debugDir.Type == ImageDebugType.CodeView); //Console.WriteLine("ReadCodeViewDebugData: Debug directory with AddressOfRawData 0x" + debugDir.AddressOfRawData.ToString("x")); // sanity check read size if (debugDir.SizeOfData > 1000) { Console.WriteLine("ReadCodeViewDebugData: SizeOfData > 1000 - assuming bad data"); return(null); } BinaryReader reader; if (!TryReadAtRVA((int)debugDir.AddressOfRawData, (int)debugDir.SizeOfData, out reader)) { Console.WriteLine("ReadCodeViewDebugData: Unable to read rva=0x" + debugDir.AddressOfRawData.ToString("x") + " size=" + debugDir.SizeOfData); return(null); } int signature = reader.ReadInt32(); if (signature != PEFileConstants.CodeViewSignature) { Console.WriteLine("ReadCodeViewDebugData: Invalid codeview signature Expected: " + PEFileConstants.CodeViewSignature + " Actual: " + signature); return(null); } CodeViewDebugData codeView = new CodeViewDebugData(); codeView.Signature = new Guid(reader.ReadBytes(16)); codeView.Age = (int)reader.ReadUInt32(); codeView.PdbPath = reader.ReadNullTerminatedString(Encoding.UTF8); //Console.WriteLine("ReadCodeViewDebugData: PdbPath=" + codeView.PdbPath + " Age=" + codeView.Age + " Signature="+codeView.Signature); return(codeView); }
List <DebugDirectory> ReadDebugDirectories() { // there might not be a debug directory, in which case return an empty list if (OptionalHeaderDirectoryEntries.DebugTableDirectory.RelativeVirtualAddress == 0) { return(new List <DebugDirectory>()); } BinaryReader reader; if (!TryDirectoryToReader(OptionalHeaderDirectoryEntries.DebugTableDirectory, out reader)) { throw new PEReaderException("Unable to load DebugDirectory from PE"); } int countDirectories = (int)(OptionalHeaderDirectoryEntries.DebugTableDirectory.Size / PEFileConstants.SizeofDebugDirectory); List <DebugDirectory> debugDirectories = new List <DebugDirectory>(); for (int i = 0; i < countDirectories; i++) { DebugDirectory debugDir = new DebugDirectory(); debugDir.Characteristics = reader.ReadUInt32(); debugDir.TimeDateStamp = reader.ReadUInt32(); debugDir.MajorVersion = reader.ReadUInt16(); debugDir.MinorVersion = reader.ReadUInt16(); debugDir.Type = (ImageDebugType)reader.ReadUInt32(); debugDir.SizeOfData = reader.ReadUInt32(); debugDir.AddressOfRawData = reader.ReadUInt32(); debugDir.PointerToRawData = reader.ReadUInt32(); debugDirectories.Add(debugDir); } return(debugDirectories); }