Esempio n. 1
0
 public static uint GetUInt24(IDataStream stream, ulong offset)
 {
     byte[] bytes32 = new byte[4];
     byte[] bytes24 = stream.GetBytes(offset, 3);
     Array.Copy(bytes24, bytes32, 3);
     return(BitConverter.ToUInt32(bytes32, 0));
 }
Esempio n. 2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            ulong read = Math.Min((ulong)count, _stream.StreamLength - _position);

            _stream.GetBytes(_position, read);
            _position += read;
            return((int)read);
        }
Esempio n. 3
0
        public static string CreateTemporaryFile(IDataStream stream)
        {
            ulong        BLOCK_SIZE = 1024 * 1024;      // Write 1MB at a time
            string       tempFile   = Path.GetTempFileName();
            BinaryWriter writer     = new BinaryWriter(new FileStream(tempFile, FileMode.Create));
            ulong        offset     = 0;

            while (offset < stream.StreamLength)
            {
                ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
                writer.Write(stream.GetBytes(offset, read));
                offset += read;
            }
            writer.Close();
            return(tempFile);
        }
Esempio n. 4
0
        public static int GetInt24(IDataStream stream, ulong offset)
        {
            byte[] bytes32 = new byte[4];
            byte[] bytes24 = stream.GetBytes(offset, 3);
            Array.Copy(bytes24, bytes32, 3);
            int res = BitConverter.ToInt32(bytes32, 0);

            if ((bytes32[2] & 0x80) == 0x80)
            {
                return(res - 0x1000000);
            }
            else
            {
                return(res);
            }
        }
Esempio n. 5
0
		public static int GetInt24(IDataStream stream, ulong offset) {
			byte[] bytes32 = new byte[4];
			byte[] bytes24 = stream.GetBytes(offset, 3);
			Array.Copy(bytes24, bytes32, 3);
			int res = BitConverter.ToInt32(bytes32, 0);
			if ((bytes32[2] & 0x80) == 0x80) {
				return res - 0x1000000;
			} else {
				return res;
			}
		}
Esempio n. 6
0
 private static bool IsGif(IDataStream stream)
 {
     if (stream.StreamLength > 6) {
                 byte[] header = stream.GetBytes(0, 3);
                 return header[0] == 'G' && header[1] == 'I' && header[2] == 'F';
             }
             return false;
 }
Esempio n. 7
0
		public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize) {
			return GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize);
		}
Esempio n. 8
0
 public static ushort GetUInt16(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0));
 }
Esempio n. 9
0
 public static byte GetByte(IDataStream stream, ulong offset)
 {
     return(stream.GetBytes(offset, 1)[0]);
 }
Esempio n. 10
0
 public static ulong GetUInt64(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt64(stream.GetBytes(offset, 8), 0));
 }
Esempio n. 11
0
 public static string GetHexString(IDataStream stream, ulong offset, ulong count)
 {
     count = Math.Min(count, stream.StreamLength - offset);
     return(BitConverter.ToString(stream.GetBytes(offset, count)));
 }
Esempio n. 12
0
		public static uint GetUInt32(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt32(stream.GetBytes(offset, 4), 0);
		}
Esempio n. 13
0
		public static ushort GetUInt16(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0);
		}
Esempio n. 14
0
		public static byte GetByte(IDataStream stream, ulong offset) {
			return stream.GetBytes(offset, 1)[0];
		}
Esempio n. 15
0
		public static byte[] GetBytes(IDataStream stream) {
			return stream.GetBytes(0, stream.StreamLength);
		}
Esempio n. 16
0
		public static string CreateTemporaryFile(IDataStream stream) {
			ulong BLOCK_SIZE = 1024 * 1024; // Write 1MB at a time
			string tempFile = Path.GetTempFileName();
			BinaryWriter writer = new BinaryWriter(new FileStream(tempFile, FileMode.Create));
			ulong offset = 0;
			while (offset < stream.StreamLength) {
				ulong read = Math.Min(BLOCK_SIZE, stream.StreamLength - offset);
				writer.Write(stream.GetBytes(offset, read));
				offset += read;
			}
			writer.Close();
			return tempFile;
		}
Esempio n. 17
0
		public static string GetUnicodeString(IDataStream stream, ulong offset, ulong count) {
			count = Math.Min(count, stream.StreamLength - offset);
			return Encoding.Unicode.GetString(stream.GetBytes(offset, count), 0, (int)count);
		}
Esempio n. 18
0
		public static string GetHexString(IDataStream stream, ulong offset, ulong count) {
			count = Math.Min(count, stream.StreamLength - offset);
			return BitConverter.ToString(stream.GetBytes(offset, count));
		}
Esempio n. 19
0
 public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize)
 {
     return(GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize));
 }
Esempio n. 20
0
		public static uint GetUInt24(IDataStream stream, ulong offset) {
			byte[] bytes32 = new byte[4];
			byte[] bytes24 = stream.GetBytes(offset, 3);
			Array.Copy(bytes24, bytes32, 3);
			return BitConverter.ToUInt32(bytes32, 0);
		}
Esempio n. 21
0
 public static string GetUnicodeString(IDataStream stream, ulong offset, ulong count)
 {
     count = Math.Min(count, stream.StreamLength - offset);
     return(Encoding.Unicode.GetString(stream.GetBytes(offset, count), 0, (int)count));
 }
Esempio n. 22
0
 private static bool IsPng(IDataStream stream)
 {
     if (stream.StreamLength > 8) {
                 byte[] header = stream.GetBytes(0, 8);
                 return header[0] == 0x89
                         && header[1] == 0x50
                         && header[2] == 0x4E
                         && header[3] == 0x47
                         && header[4] == 0x0D
                         && header[5] == 0x0A
                         && header[6] == 0x1A
                         && header[7] == 0x0A;
             }
             return false;
 }
Esempio n. 23
0
 public static byte[] GetBytes(IDataStream stream)
 {
     return(stream.GetBytes(0, stream.StreamLength));
 }
Esempio n. 24
0
 private static bool IsTif(IDataStream stream)
 {
     if (stream.StreamLength > 4) {
                 byte[] header = stream.GetBytes(0, 4);
                 return ((header[0] == 'I' && header[1] == 'I')
                     || (header[0] == 'M' && header[1] == 'M'))
                     && BitConverter.ToUInt16(header, 2) == 42;
             }
             return false;
 }
Esempio n. 25
0
 public static uint GetUInt32(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt32(stream.GetBytes(offset, 4), 0));
 }
Esempio n. 26
0
 private static bool IsBmp(IDataStream stream)
 {
     if (stream.StreamLength > 2) {
                 byte[] header = stream.GetBytes(0, 2);
                 return header[0] == 0x42 && header[1] == 0x4D;
             }
             return false;
 }
Esempio n. 27
0
 public virtual byte[] GetBytes(ulong offset, ulong length)
 {
     return(_stream.GetBytes(_start + offset, length));
 }
Esempio n. 28
0
		public static ulong GetUInt64(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt64(stream.GetBytes(offset, 8), 0);
		}