Пример #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));
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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;
			}
		}
Пример #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;
 }
Пример #7
0
		public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize) {
			return GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize);
		}
Пример #8
0
 public static ushort GetUInt16(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0));
 }
Пример #9
0
 public static byte GetByte(IDataStream stream, ulong offset)
 {
     return(stream.GetBytes(offset, 1)[0]);
 }
Пример #10
0
 public static ulong GetUInt64(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt64(stream.GetBytes(offset, 8), 0));
 }
Пример #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)));
 }
Пример #12
0
		public static uint GetUInt32(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt32(stream.GetBytes(offset, 4), 0);
		}
Пример #13
0
		public static ushort GetUInt16(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0);
		}
Пример #14
0
		public static byte GetByte(IDataStream stream, ulong offset) {
			return stream.GetBytes(offset, 1)[0];
		}
Пример #15
0
		public static byte[] GetBytes(IDataStream stream) {
			return stream.GetBytes(0, stream.StreamLength);
		}
Пример #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;
		}
Пример #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);
		}
Пример #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));
		}
Пример #19
0
 public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize)
 {
     return(GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize));
 }
Пример #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);
		}
Пример #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));
 }
Пример #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;
 }
Пример #23
0
 public static byte[] GetBytes(IDataStream stream)
 {
     return(stream.GetBytes(0, stream.StreamLength));
 }
Пример #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;
 }
Пример #25
0
 public static uint GetUInt32(IDataStream stream, ulong offset)
 {
     return(BitConverter.ToUInt32(stream.GetBytes(offset, 4), 0));
 }
Пример #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;
 }
Пример #27
0
 public virtual byte[] GetBytes(ulong offset, ulong length)
 {
     return(_stream.GetBytes(_start + offset, length));
 }
Пример #28
0
		public static ulong GetUInt64(IDataStream stream, ulong offset) {
			return BitConverter.ToUInt64(stream.GetBytes(offset, 8), 0);
		}