PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11using System;
12using System.IO;
13
14namespace Mono.Cecil.PE {
15
16	class BinaryStreamReader : BinaryReader {
17
18		public int Position {
19			get { return (int) BaseStream.Position; }
20			set { BaseStream.Position = value; }
21		}
22
23		public int Length {
24			get { return (int) BaseStream.Length; }
25		}
26
27		public BinaryStreamReader (Stream stream)
28			: base (stream)
29		{
30		}
31
32		public void Advance (int bytes)
33		{
34			BaseStream.Seek (bytes, SeekOrigin.Current);
35		}
36
37		public void MoveTo (uint position)
38		{
39			BaseStream.Seek (position, SeekOrigin.Begin);
40		}
41
42		public void Align (int align)
43		{
44			align--;
45			var position = Position;
46			Advance (((position + align) & ~align) - position);
47		}
48
49		public DataDirectory ReadDataDirectory ()
50		{
51			return new DataDirectory (ReadUInt32 (), ReadUInt32 ());
52		}
53	}
54}