void Read(IList <PdbCustomDebugInfo> result) { if (reader.Length < 4) { return; } int version = reader.ReadByte(); Debug.Assert(version == CustomDebugInfoConstants.Version); if (version != CustomDebugInfoConstants.Version) { return; } int count = reader.ReadByte(); reader.Position += 2; while (reader.CanRead(8U)) { int recVersion = reader.ReadByte(); Debug.Assert(recVersion == CustomDebugInfoConstants.RecordVersion); var recKind = (PdbCustomDebugInfoKind)reader.ReadByte(); reader.Position++; int alignmentSize = reader.ReadByte(); int recSize = reader.ReadInt32(); if (recSize < 8 || (ulong)reader.Position - 8 + (uint)recSize > reader.Length) { return; } if (recKind <= PdbCustomDebugInfoKind.DynamicLocals) { alignmentSize = 0; } if (alignmentSize > 3) { return; } var nextRecPos = reader.Position - 8 + (uint)recSize; if (recVersion == CustomDebugInfoConstants.RecordVersion) { ulong recPosEnd = (ulong)reader.Position - 8 + (uint)recSize - (uint)alignmentSize; var cdi = ReadRecord(recKind, recPosEnd); Debug.Assert(cdi != null); Debug.Assert(reader.Position <= recPosEnd); if (reader.Position > recPosEnd) { return; } if (cdi != null) { Debug.Assert(cdi.Kind == recKind); result.Add(cdi); } } reader.Position = nextRecPos; } }
static bool IsWindowsPdb(DataReader reader) { const string SIG = "Microsoft C/C++ MSF 7.00\r\n\u001ADS\0"; if (!reader.CanRead(SIG.Length)) { return(false); } return(reader.ReadString(SIG.Length, Encoding.ASCII) == SIG); }
/// <summary> /// Creates a reader that can access a blob or returns false on failure /// </summary> /// <param name="offset">Offset of blob</param> /// <param name="reader">Updated with the reader</param> /// <returns></returns> public bool TryCreateReader(uint offset, out DataReader reader) { reader = dataReader; if (!IsValidOffset(offset)) { return(false); } reader.Position = offset; if (!reader.TryReadCompressedUInt32(out uint length)) { return(false); } if (!reader.CanRead(length)) { return(false); } reader = reader.Slice(reader.Position, length); return(true); }
/// <summary> /// Returns true if it's possibly resources file data /// </summary> /// <param name="reader">Reader</param> /// <returns></returns> public static bool CouldBeResourcesFile(DataReader reader) => reader.CanRead(4U) && reader.ReadUInt32() == 0xBEEFCACE;