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)); }
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); }
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); }
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); } }
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; } }
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; }
public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize) { return GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize); }
public static ushort GetUInt16(IDataStream stream, ulong offset) { return(BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0)); }
public static byte GetByte(IDataStream stream, ulong offset) { return(stream.GetBytes(offset, 1)[0]); }
public static ulong GetUInt64(IDataStream stream, ulong offset) { return(BitConverter.ToUInt64(stream.GetBytes(offset, 8), 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))); }
public static uint GetUInt32(IDataStream stream, ulong offset) { return BitConverter.ToUInt32(stream.GetBytes(offset, 4), 0); }
public static ushort GetUInt16(IDataStream stream, ulong offset) { return BitConverter.ToUInt16(stream.GetBytes(offset, 2), 0); }
public static byte GetByte(IDataStream stream, ulong offset) { return stream.GetBytes(offset, 1)[0]; }
public static byte[] GetBytes(IDataStream stream) { return stream.GetBytes(0, stream.StreamLength); }
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; }
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); }
public static string GetHexString(IDataStream stream, ulong offset, ulong count) { count = Math.Min(count, stream.StreamLength - offset); return BitConverter.ToString(stream.GetBytes(offset, count)); }
public static ulong GetArbitraryUInt(IDataStream stream, ulong offset, int intSize) { return(GetArbitraryUInt(stream.GetBytes(offset, (ulong)intSize), 0, intSize)); }
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); }
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)); }
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; }
public static byte[] GetBytes(IDataStream stream) { return(stream.GetBytes(0, stream.StreamLength)); }
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; }
public static uint GetUInt32(IDataStream stream, ulong offset) { return(BitConverter.ToUInt32(stream.GetBytes(offset, 4), 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; }
public virtual byte[] GetBytes(ulong offset, ulong length) { return(_stream.GetBytes(_start + offset, length)); }
public static ulong GetUInt64(IDataStream stream, ulong offset) { return BitConverter.ToUInt64(stream.GetBytes(offset, 8), 0); }