public void Read(RecursionCounter counter, IImageStream stream, uint scopeEnd) { if (!counter.Increment()) { throw new PdbException("Scopes too deep"); } while (stream.Position < scopeEnd) { var size = stream.ReadUInt16(); var begin = stream.Position; var end = begin + size; var type = (SymbolType)stream.ReadUInt16(); DbiScope child = null; uint? childEnd = null; switch (type) { case SymbolType.S_BLOCK32: { stream.Position += 4; childEnd = stream.ReadUInt32(); var len = stream.ReadUInt32(); var addr = PdbAddress.ReadAddress(stream); var name = PdbReader.ReadCString(stream); child = new DbiScope(name, addr.Offset, len); break; } case SymbolType.S_UNAMESPACE: Namespaces.Add(new DbiNamespace(PdbReader.ReadCString(stream))); break; case SymbolType.S_MANSLOT: { var variable = new DbiVariable(); variable.Read(stream); Variables.Add(variable); break; } } stream.Position = end; if (child != null) { child.Read(counter, stream, childEnd.Value); Children.Add(child); child = null; } } counter.Decrement(); if (stream.Position != scopeEnd) { Debugger.Break(); } }
private void FixOffsets(RecursionCounter counter, DbiScope scope) { if (!counter.Increment()) { return; } scope.BeginOffset -= Address.Offset; scope.EndOffset -= Address.Offset; foreach (var child in scope.Children) { FixOffsets(counter, child); } counter.Decrement(); }
public void Read(IImageStream stream, long recEnd) { stream.Position += 4; var end = stream.ReadUInt32(); stream.Position += 4; var len = stream.ReadUInt32(); stream.Position += 8; Token = stream.ReadUInt32(); Address = PdbAddress.ReadAddress(stream); stream.Position += 1 + 2; Name = PdbReader.ReadCString(stream); stream.Position = recEnd; Root = new DbiScope("", Address.Offset, len); Root.Read(new RecursionCounter(), stream, end); FixOffsets(new RecursionCounter(), Root); }