/Mono.Cecil.PE/BinaryStreamReader.cs

http://github.com/jbevain/cecil · C# · 54 lines · 35 code · 10 blank · 9 comment · 0 complexity · 5471e9719ea1aa3a944654547495b5b5 MD5 · raw file

  1. //
  2. // Author:
  3. // Jb Evain (jbevain@gmail.com)
  4. //
  5. // Copyright (c) 2008 - 2015 Jb Evain
  6. // Copyright (c) 2008 - 2011 Novell, Inc.
  7. //
  8. // Licensed under the MIT/X11 license.
  9. //
  10. using System;
  11. using System.IO;
  12. namespace Mono.Cecil.PE {
  13. class BinaryStreamReader : BinaryReader {
  14. public int Position {
  15. get { return (int) BaseStream.Position; }
  16. set { BaseStream.Position = value; }
  17. }
  18. public int Length {
  19. get { return (int) BaseStream.Length; }
  20. }
  21. public BinaryStreamReader (Stream stream)
  22. : base (stream)
  23. {
  24. }
  25. public void Advance (int bytes)
  26. {
  27. BaseStream.Seek (bytes, SeekOrigin.Current);
  28. }
  29. public void MoveTo (uint position)
  30. {
  31. BaseStream.Seek (position, SeekOrigin.Begin);
  32. }
  33. public void Align (int align)
  34. {
  35. align--;
  36. var position = Position;
  37. Advance (((position + align) & ~align) - position);
  38. }
  39. public DataDirectory ReadDataDirectory ()
  40. {
  41. return new DataDirectory (ReadUInt32 (), ReadUInt32 ());
  42. }
  43. }
  44. }