internal override void Read(BinaryReader reader) { Version = reader.ReadUInt16(); VersionNeededToExtract = reader.ReadUInt16(); Flags = (HeaderFlags) reader.ReadUInt16(); CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16(); LastModifiedTime = reader.ReadUInt16(); LastModifiedDate = reader.ReadUInt16(); Crc = reader.ReadUInt32(); CompressedSize = reader.ReadUInt32(); UncompressedSize = reader.ReadUInt32(); ushort nameLength = reader.ReadUInt16(); ushort extraLength = reader.ReadUInt16(); ushort commentLength = reader.ReadUInt16(); DiskNumberStart = reader.ReadUInt16(); InternalFileAttributes = reader.ReadUInt16(); ExternalFileAttributes = reader.ReadUInt32(); RelativeOffsetOfEntryHeader = reader.ReadUInt32(); byte[] name = reader.ReadBytes(nameLength); Name = DecodeString(name); byte[] extra = reader.ReadBytes(extraLength); byte[] comment = reader.ReadBytes(commentLength); Comment = DecodeString(comment); LoadExtra(extra); }
internal override void Read(BinaryReader reader) { Version = reader.ReadUInt16(); VersionNeededToExtract = reader.ReadUInt16(); Flags = (HeaderFlags) reader.ReadUInt16(); CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16(); LastModifiedTime = reader.ReadUInt16(); LastModifiedDate = reader.ReadUInt16(); Crc = reader.ReadUInt32(); CompressedSize = reader.ReadUInt32(); UncompressedSize = reader.ReadUInt32(); ushort nameLength = reader.ReadUInt16(); ushort extraLength = reader.ReadUInt16(); ushort commentLength = reader.ReadUInt16(); DiskNumberStart = reader.ReadUInt16(); InternalFileAttributes = reader.ReadUInt16(); ExternalFileAttributes = reader.ReadUInt32(); RelativeOffsetOfEntryHeader = reader.ReadUInt32(); byte[] name = reader.ReadBytes(nameLength); Name = DecodeString(name); byte[] extra = reader.ReadBytes(extraLength); byte[] comment = reader.ReadBytes(commentLength); Comment = DecodeString(comment); LoadExtra(extra); var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField); if (unicodePathExtra != null) { Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName; } }
static void Main(string[] args) { OpenFileDialog OpenFile = new OpenFileDialog(); OpenFile.Multiselect = false; OpenFile.Title = "Cartridge"; OpenFile.Filter = "GBA Files (.gba)|*.gba"; OpenFile.FilterIndex = 1; string Cartridge; Console.WriteLine("Gneiss - Game Boy Advance Cartridge Reader."); Console.CursorVisible = false; if (OpenFile.ShowDialog() == DialogResult.OK) { Cartridge = OpenFile.FileName; BinaryReader BR = new BinaryReader(File.OpenRead(Cartridge)); BR.BaseStream.Seek(0xA0, SeekOrigin.Begin); Console.WriteLine("\n\nCartridge Name: {0}", Encoding.UTF8.GetString(BR.ReadBytes(12))); BR.BaseStream.Seek(0xAC, SeekOrigin.Begin); Console.WriteLine("Serial: {0}", Encoding.UTF8.GetString(BR.ReadBytes(4))); BR.BaseStream.Seek(0x108, SeekOrigin.Begin); Console.WriteLine("Name: {0}", Encoding.UTF8.GetString(BR.ReadBytes(24))); Console.Read(); } }
public static ConnectionSettings Read(byte[] data) { var cs = new ConnectionSettings(); using (var ms = new MemoryStream(data)) using (var br = new BinaryReader(ms)) { cs.Version = br.ReadInt32(); cs.Counter = br.ReadInt32(); cs.Autodetect = (Autodetect)br.ReadInt32(); var len = br.ReadInt32(); cs.ProxyServer = Utf8.GetString(br.ReadBytes(len)); len = br.ReadInt32(); cs.ExtraData = Utf8.GetString(br.ReadBytes(len)); len = br.ReadInt32(); cs.AutodetectScript = Utf8.GetString(br.ReadBytes(len)); // So damn lazy. using (var ms2 = new MemoryStream()) { var ba = new byte[Environment.SystemPageSize]; while ((len = br.Read(ba, 0, ba.Length)) != 0) { ms2.Write(ba, 0, len); } cs.Junk = ms2.ToArray(); } } return cs; }
public static bool ReadFile(string FileName) { LCMeshReader.OpenedFile = FileName; LCMeshReader.pMesh = new tMeshContainer(); BinaryReader b = new BinaryReader( new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)); LCMeshReader.pMesh.HeaderInfo = new tHeaderInfo(); LCMeshReader.pMesh.HeaderInfo.Format = b.ReadBytes(4); LCMeshReader.pMesh.HeaderInfo.Version = b.ReadInt32(); LCMeshReader.pMesh.HeaderInfo.MeshDataSize = b.ReadInt32(); LCMeshReader.pMesh.HeaderInfo.MeshCount = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.VertexCount = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.JointCount = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.TextureMaps = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.NormalCount = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.ObjCount = b.ReadUInt32(); LCMeshReader.pMesh.HeaderInfo.UnknownCount = b.ReadUInt32(); LCMeshReader.pMesh.FileName = b.ReadBytes(b.ReadInt32()); LCMeshReader.pMesh.Scale = b.ReadSingle(); LCMeshReader.pMesh.Value1 = b.ReadUInt32(); LCMeshReader.pMesh.FilePath = FileName; bool flag = false; if (LCMeshReader.pMesh.HeaderInfo.Version == 16) { if (LCMeshReader.ReadV10(b, b.BaseStream.Position)) flag = true; } else if (LCMeshReader.pMesh.HeaderInfo.Version == 17 && LCMeshReader.ReadV11(b, b.BaseStream.Position)) flag = true; b.Close(); return flag; }
public static void ReadBlendomatic(FileStream file) { BinaryReader reader = new BinaryReader(file); NumberOfBlendingModes = reader.ReadUInt32(); NumberOfTiles = reader.ReadUInt32(); BlendingModes = new Dictionary<byte, BlendingMode>(); Console.WriteLine("Number of blending modes: " + NumberOfBlendingModes); Console.WriteLine("Number of tiles: " + NumberOfTiles); for (var i = 0; i < NumberOfBlendingModes; i++ ) { BlendingMode mode; mode.TileSize = reader.ReadUInt32(); mode.Tiles = new Dictionary<byte, byte[]>(); var TileFlags = reader.ReadBytes(31); // all 1 wtf reader.ReadBytes((int)mode.TileSize * 4); for (var j = 0; j < NumberOfTiles; j++) { mode.Tiles[(byte)j] = reader.ReadBytes((int)mode.TileSize); } BlendingModes[(byte)i] = mode; } }
internal void Read(BinaryReader reader, float CoordZ, float scale) { SkinVertIndex = BitConverter.ToUInt32(reader.ReadBytes(4), 0); for (int i = 0; i < SkinVertPos.Length; i++) SkinVertPos[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0)* scale; SkinVertPos[2] *= CoordZ; }
public RPF7File(Stream inputStream, String filname = "") { this.Filename = filname; Stream = inputStream; Info = new Structs.RPF7Header(Stream); if (new string(Info.Magic) != "RPF7") { throw new Exception("Invalid RPF Magic"); } sixteenRoundsDecrypt = (Info.Flag >> 28) == 0xf; if (sixteenRoundsDecrypt) { throw new Exception("Needed to be tested first"); } using (BinaryReader binaryStream = new BinaryReader(AES.DecryptStream(new StreamKeeper(this.Stream), sixteenRoundsDecrypt))) { MemoryStream entriesInfo = new MemoryStream(binaryStream.ReadBytes(0x10 * Info.EntriesCount)); MemoryStream filenames = new MemoryStream(binaryStream.ReadBytes(Info.EntriesNamesLength)); this.Root = Entry.CreateFromHeader(new Structs.RPF7EntryInfoTemplate(entriesInfo), this, entriesInfo, filenames); } if (!(this.Root is DirectoryEntry)) { throw new Exception("Expected root to be directory"); } }
internal NameResolutionRecord(BinaryReader reader) { UInt16 type = reader.ReadUInt16(); int valueLength = reader.ReadUInt16(); if (type != EndRecordType) { int entriesLength = valueLength; if (type == Ip6RecordType) { this.IsIpVersion6 = true; this.IpAddress = reader.ReadBytes(Ip6Length); entriesLength -= Ip6Length; } else { this.IsIpVersion6 = false; this.IpAddress = reader.ReadBytes(Ip4Length); entriesLength -= Ip4Length; } this.DnsEntries = this.ReadDnsEntries(reader, entriesLength); int remainderLength = valueLength % ValueAlignmentBoundary; if (remainderLength > 0) { reader.ReadBytes(ValueAlignmentBoundary - remainderLength); // Read fill bytes to boundary. } } }
public static byte[] UncompressStream(Stream stream, int filesize, int memsize) { BinaryReader r = new BinaryReader(stream); long end = stream.Position + filesize; byte[] uncdata = new byte[memsize]; BinaryWriter bw = new BinaryWriter(new MemoryStream(uncdata)); byte[] data = r.ReadBytes(2); if (checking) if (data.Length != 2) throw new InvalidDataException("Hit unexpected end of file at " + stream.Position); int datalen = (((data[0] & 0x80) != 0) ? 4 : 3) * (((data[0] & 0x01) != 0) ? 2 : 1); data = r.ReadBytes(datalen); if (checking) if (data.Length != datalen) throw new InvalidDataException("Hit unexpected end of file at " + stream.Position); long realsize = 0; for (int i = 0; i < data.Length; i++) realsize = (realsize << 8) + data[i]; if (checking) if (realsize != memsize) throw new InvalidDataException(String.Format( "Resource data indicates size does not match index at 0x{0}. Read 0x{1}. Expected 0x{2}.", stream.Position.ToString("X8"), realsize.ToString("X8"), memsize.ToString("X8"))); while (stream.Position < end) { Dechunk(stream, bw); } if (checking) if (bw.BaseStream.Position != memsize) throw new InvalidDataException(String.Format("Read 0x{0:X8} bytes. Expected 0x{1:X8}.", bw.BaseStream.Position, memsize)); bw.Close(); return uncdata; }
/// <summary> /// Creates a new FAR3Archive instance from a path. /// </summary> /// <param name="Path">The path to the archive.</param> public FAR3Archive(string Path) { m_ArchivePath = Path; if (isReadingSomething == false) { isReadingSomething = true; try { m_Reader = new BinaryReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read)); } catch (Exception) { throw new FAR3Exception("Could not open the specified archive - " + Path + "! (FAR3Archive())"); } string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8)); uint Version = m_Reader.ReadUInt32(); if ((Header != "FAR!byAZ") || (Version != 3)) { throw new FAR3Exception("Archive wasn't a valid FAR V.3 archive! (FAR3Archive())"); } uint ManifestOffset = m_Reader.ReadUInt32(); m_ManifestOffset = ManifestOffset; m_Reader.BaseStream.Seek(ManifestOffset, SeekOrigin.Begin); uint NumFiles = m_Reader.ReadUInt32(); for (int i = 0; i < NumFiles; i++) { Far3Entry Entry = new Far3Entry(); Entry.DecompressedFileSize = m_Reader.ReadUInt32(); byte[] Dummy = m_Reader.ReadBytes(3); Entry.CompressedFileSize = (uint)((Dummy[0] << 0) | (Dummy[1] << 8) | (Dummy[2]) << 16); Entry.DataType = m_Reader.ReadByte(); Entry.DataOffset = m_Reader.ReadUInt32(); //Entry.HasFilename = m_Reader.ReadUInt16(); Entry.IsCompressed = m_Reader.ReadByte(); Entry.AccessNumber = m_Reader.ReadByte(); Entry.FilenameLength = m_Reader.ReadUInt16(); Entry.TypeID = m_Reader.ReadUInt32(); Entry.FileID = m_Reader.ReadUInt32(); Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength)); if (!m_Entries.ContainsKey(Entry.Filename)) m_Entries.Add(Entry.Filename, Entry); m_EntriesList.Add(Entry); m_EntryByID.Add(Entry.FileID, Entry); //isn't this a bad idea? i have a feeling this is a bad idea... } //Keep the stream open, it helps peformance. //m_Reader.Close(); isReadingSomething = false; } }
/// <summary> Parses the Replay.Messages.Events file. </summary> /// <param name="buffer"> Buffer containing the contents of the replay.messages.events file. </param> /// <returns> A list of chat messages parsed from the buffer. </returns> public static void Parse(Replay replay, byte[] buffer) { using (var stream = new MemoryStream(buffer)) { using (var reader = new BinaryReader(stream)) { int totalTime = 0; while (reader.BaseStream.Position < reader.BaseStream.Length) { // While not EOF var message = new ChatMessage(); var time = ParseTimestamp(reader); // sometimes we only have a header for the message if (reader.BaseStream.Position >= reader.BaseStream.Length) break; message.PlayerId = reader.ReadByte(); // I believe this 'PlayerId' is an index for this client list, which can include observers // var player = replay.ClientList[message.PlayerId]; totalTime += time; var opCode = reader.ReadByte(); if (opCode == 0x80) reader.ReadBytes(4); else if (opCode == 0x83) reader.ReadBytes(8); else if (opCode == 2 && message.PlayerId <= 10) { if (message.PlayerId == 80) continue; message.MessageTarget = (ChatMessageTarget)(opCode & 7); var length = reader.ReadByte(); if ((opCode & 8) == 8) length += 64; if ((opCode & 16) == 16) length += 128; message.Message = Encoding.UTF8.GetString(reader.ReadBytes(length)); } else { } if (message.Message != null) { message.Timestamp = new TimeSpan(0, 0, (int)Math.Round(totalTime / 16.0)); replay.ChatMessages.Add(message); } } } } }
public FDSFile(BinaryReader r) { byte[] tmp = r.ReadBytes(4); int numdisks; if (tmp.SequenceEqual(Check)) { numdisks = r.ReadByte(); ExtraData = r.ReadBytes(11); } else if (tmp.SequenceEqual(CheckAlt)) { // compensate (won't write identically) r.BaseStream.Seek(0, SeekOrigin.Begin); numdisks = (int)(r.BaseStream.Length / 65500); ExtraData = new byte[11]; } else { throw new InvalidOperationException("Bad Header!"); } if (r.BaseStream.Length - r.BaseStream.Position != numdisks * 65500) throw new InvalidOperationException("Bad File Length!"); while (numdisks > 0) { Disks.Add(new FDSDisk(r)); numdisks--; } }
public void Deserialize(byte[] buffer) { if (buffer.Length == 240) { MemoryStream MS = new MemoryStream(buffer); BinaryReader BR = new BinaryReader(MS); ushort length = BR.ReadUInt16(); if (length == 240) { ushort type = BR.ReadUInt16(); if (type == 1124) { Username = Encoding.ASCII.GetString(BR.ReadBytes(16)); Username = Username.Replace("\0", ""); BR.ReadBytes(112); Password = Encoding.ASCII.GetString(BR.ReadBytes(16)); BR.ReadBytes(112); Server = Encoding.ASCII.GetString(BR.ReadBytes(16)); Server = Server.Replace("\0", ""); } } BR.Close(); MS.Close(); } }
public void Read(BinaryReader reader, float CoordZ, float scale) { Position = new float[3]; for (int i = 0; i < Position.Length; i++) { Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } NormalVector = new float[3]; for (int i = 0; i < NormalVector.Length; i++) { NormalVector[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } UV = new float[2]; for (int i = 0; i < UV.Length; i++) { UV[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } BoneNum = new WORD[2]; for (int i = 0; i < BoneNum.Length; i++) { BoneNum[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0); } BoneWeight = reader.ReadByte(); NonEdgeFlag = reader.ReadByte(); Position[2] *= CoordZ; NormalVector[2] *= CoordZ; }
public void UOExtPacket(IClientPeer peer, byte header, byte[] buffer, int offset, short length) { MemoryStream ms = new MemoryStream(buffer, offset, length); BinaryReader br = new BinaryReader(ms); byte sequence = br.ReadByte(); switch (sequence) { case (0x00): byte version = br.ReadByte(); byte[] uoextmd5 = br.ReadBytes(16); byte[] uoextguimd5 = br.ReadBytes(16); if (version != 0) { peer.Close(); } else { if (!ByteArrayCompare(uoextmd5, Dll.UOExt.MD5)) { peer.Send(new Handshake(0x01)); peer.Send(Dll.UOExt.SimpleHeader); foreach (DllContent dc in Dll.UOExt.Content) { peer.Send(dc); } return; } else if (!ByteArrayCompare(uoextguimd5, Dll.UOExtGUI.MD5)) { peer.Send(new Handshake(0x02)); peer.Send(Dll.UOExtGUI.SimpleHeader); foreach (DllContent dc in Dll.UOExtGUI.Content) { peer.Send(dc); } } else { peer.Send(new Handshake(0x00)); } peer.Send(m_libraryList); peer.Send(m_pluginsList); } break; case (0x03): for (short i = 0; i < Dll.Dlls.Length; i++) { peer.Send(Dll.Dlls[i].Header); foreach (DllContent dc in Dll.Dlls[i].Content) { peer.Send(dc); } } peer.Send(m_initComplete); break; } }
public InstallShieldPackage(string filename, int priority) { this.priority = priority; s = FileSystem.Open(filename); // Parse package header BinaryReader reader = new BinaryReader(s); uint signature = reader.ReadUInt32(); if (signature != 0x8C655D13) throw new InvalidDataException("Not an Installshield package"); reader.ReadBytes(8); /*var FileCount = */reader.ReadUInt16(); reader.ReadBytes(4); /*var ArchiveSize = */reader.ReadUInt32(); reader.ReadBytes(19); var TOCAddress = reader.ReadInt32(); reader.ReadBytes(4); var DirCount = reader.ReadUInt16(); // Parse the directory list s.Seek(TOCAddress, SeekOrigin.Begin); BinaryReader TOCreader = new BinaryReader(s); for (var i = 0; i < DirCount; i++) ParseDirectory(TOCreader); }
private static Model LoadFromBIN(string pModelFile) { BinaryReader reader = new BinaryReader(new FileStream(pModelFile, FileMode.Open)); int numberOfVertices = reader.ReadInt32(); int floatsPerVertex = 6; Vertices = new float[numberOfVertices * floatsPerVertex]; byte[] byteArray = new byte[Vertices.Length * sizeof(float)]; byteArray = reader.ReadBytes(byteArray.Length); Buffer.BlockCopy(byteArray, 0, Vertices, 0, byteArray.Length); int numberOfTriangles = reader.ReadInt32(); Indices = new int[numberOfTriangles * 3]; byteArray = new byte[Indices.Length * sizeof(int)]; byteArray = reader.ReadBytes(Indices.Length * sizeof(int)); Buffer.BlockCopy(byteArray, 0, Indices, 0, byteArray.Length); reader.Close(); ModelMesh mesh = new ModelMesh(Vertices, Indices, false); List<ModelMesh> meshes = new List<ModelMesh>(); meshes.Add(mesh); return new Model(meshes); }
private static AntiForgeryToken DeserializeImpl(BinaryReader reader) { byte b = reader.ReadByte(); if (b != 1) { return null; } AntiForgeryToken antiForgeryToken = new AntiForgeryToken(); byte[] data = reader.ReadBytes(16); antiForgeryToken.SecurityToken = new BinaryBlob(128, data); antiForgeryToken.IsSessionToken = reader.ReadBoolean(); if (!antiForgeryToken.IsSessionToken) { bool flag = reader.ReadBoolean(); if (flag) { byte[] data2 = reader.ReadBytes(32); antiForgeryToken.ClaimUid = new BinaryBlob(256, data2); } else { antiForgeryToken.Username = reader.ReadString(); } antiForgeryToken.AdditionalData = reader.ReadString(); } if (reader.BaseStream.ReadByte() != -1) { return null; } return antiForgeryToken; }
public RegistryHive(string file) { if (!File.Exists(file)) throw new FileNotFoundException(); using (FileStream stream = File.OpenRead(file)) { using (BinaryReader reader = new BinaryReader(stream)) { byte[] buf = reader.ReadBytes(4); if (buf[0] != 'r' || buf[1] != 'e' || buf[2] != 'g' || buf[3] != 'f') throw new NotSupportedException(); reader.ReadBytes(8); buf = reader.ReadBytes(8); long timestamp = BitConverter.ToInt64(buf, 0); this.WasExported = (timestamp == 0) ? true : false; //fast-forward reader.BaseStream.Position += (0x1000 + 0x20 + 4)-reader.BaseStream.Position; this.RootKey = new NodeKey(reader); } } }
public void ByteArraySegmentedStream_ReadBytesTest() { var arr = new byte[100]; for (byte i = 0; i < 100; i++) arr[i] = i; var stream = new ByteArraySegmentedStream(true); stream.AddSegment(new ArraySegment<byte>(arr, 0, 10)); stream.AddSegment(new ArraySegment<byte>(arr, 10, 25)); stream.AddSegment(new ArraySegment<byte>(arr, 5, 10)); var reader = new BinaryReader(stream); var bs = reader.ReadBytes(5); Assert.AreEqual(bs.Length, 5); for (byte i = 0; i < 5; i++) Assert.AreEqual(i, bs[i]); bs = reader.ReadBytes(10); Assert.AreEqual(bs.Length, 10); for (byte i = 0; i < 10; i++) Assert.AreEqual(i + 5, bs[i]); bs = reader.ReadBytes(100); Assert.AreEqual(bs.Length, 30); for (byte i = 0; i < 20; i++) Assert.AreEqual(i + 15, bs[i]); for (byte i = 0; i < 10; i++) Assert.AreEqual(i + 5, bs[i + 20]); }
public FAR1Archive(string Path) { m_Path = Path; m_Reader = new BinaryReader(File.Open(Path, FileMode.Open)); string Header = Encoding.ASCII.GetString(m_Reader.ReadBytes(8)); uint Version = m_Reader.ReadUInt32(); if ((Header != "FAR!byAZ") || (Version != 1)) { throw(new Exception("Archive wasn't a valid FAR V.1 archive!")); } m_ManifestOffset = m_Reader.ReadUInt32(); m_Reader.BaseStream.Seek(m_ManifestOffset, SeekOrigin.Begin); m_NumFiles = m_Reader.ReadUInt32(); for (int i = 0; i < m_NumFiles; i++) { FarEntry Entry = new FarEntry(); Entry.DataLength = m_Reader.ReadInt32(); Entry.DataLength2 = m_Reader.ReadInt32(); Entry.DataOffset = m_Reader.ReadInt32(); Entry.FilenameLength = m_Reader.ReadInt16(); Entry.Filename = Encoding.ASCII.GetString(m_Reader.ReadBytes(Entry.FilenameLength)); m_Entries.Add(Entry); } m_Reader.Close(); }
/// <summary> /// Creatis this object and sets all it properties /// </summary> /// <param name="binaryReader"></param> internal CLSID(BinaryReader binaryReader) { Data1 = binaryReader.ReadBytes(4).Reverse().ToArray(); Data2 = binaryReader.ReadBytes(2).Reverse().ToArray(); Data3 = binaryReader.ReadBytes(2).Reverse().ToArray(); Data4 = binaryReader.ReadBytes(8).Reverse().ToArray(); }
public static byte[] GetWaveData(BinaryReader file, ref WaveInfo waveInfo) { byte[] returnData; //Read the wave file header from the buffer. waveInfo.ChunkID = file.ReadInt32(); waveInfo.FileSize = file.ReadInt32(); waveInfo.RiffType = file.ReadInt32(); waveInfo.FormatID = file.ReadInt32(); waveInfo.FormatSize = file.ReadInt32(); waveInfo.FormatCode = file.ReadInt16(); waveInfo.Channels = file.ReadInt16(); waveInfo.SampleRate = file.ReadInt32(); waveInfo.FormatAverageBps = file.ReadInt32(); waveInfo.FormatBlockAlign = file.ReadInt16(); waveInfo.BitDepth = file.ReadInt16(); if (waveInfo.FormatSize == 18) { // Read any extra values waveInfo.FormatExtraSize = file.ReadInt16(); file.ReadBytes(waveInfo.FormatExtraSize); } waveInfo.DataID = file.ReadInt32(); waveInfo.DataSize = file.ReadInt32(); // Store the audio data of the wave file to a byte array. returnData = file.ReadBytes(waveInfo.DataSize); return returnData; }
/// <summary> /// The read. /// </summary> /// <param name="client"> /// </param> /// <param name="packet"> /// </param> public static void Read(Client client, byte[] packet) { LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(packet)); MemoryStream m_stream = new MemoryStream(packet); BinaryReader m_reader = new BinaryReader(m_stream); // now we should do password check and then send OK or Error // sending OK now m_stream.Position = 8; short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength)); short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength)); LoginEncryption loginEncryption = new LoginEncryption(); if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName)) { client.IsBot = true; byte[] chars = AccountCharacterList.Create(userName); LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(chars)); client.Send(chars); } else { byte[] loginerr = LoginError.Create(); client.Send(loginerr); client.Server.DisconnectClient(client); } }
public ITI(string filename) { impi fil = new impi(); // FIXME: Possible re-use this.noteName = MidiHelper.OctaveMacro(); using (FileStream rop = new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (BinaryReader bob = new BinaryReader(rop)) { byte[] mal = bob.ReadBytes(Marshal.SizeOf(fil)); this.iti_instrument = IOHelper.xread<impi>(fil,mal); // Get Samples { impx[] samp = new impx[iti_instrument.impNumberOfSamples]; for (int i = 0; i < iti_instrument.impNumberOfSamples;i++) samp[i] = IOHelper.xread<impx>( samp[i], bob.ReadBytes(Marshal.SizeOf(samp[i])) ); this.ITI_SMPH = samp; } bob.Close(); rop.Close(); mal = null; } }
public BAR(Stream file) { if (!file.CanRead || !file.CanSeek) { throw new NotSupportedException("Cannot read or seek in stream"); } using (var br = new BinaryReader(file)) { if (file.Length < 16 || br.ReadUInt32() != 0x01524142) { throw new InvalidDataException("Invalid signature"); } int fileC = br.ReadInt32(); fileList = new List<BARFile>(fileC); Debug.WriteLine("Loading BAR with " + fileC + " files"); file.Position = 16; for (int i = 0; i < fileC; i++) { var bf = new BARFile(); bf.type = br.ReadUInt32(); { byte[] b = br.ReadBytes(4); Buffer.BlockCopy(b, 0, bf._id, 0, 4); } long lpos = file.Position + 8; uint pos = br.ReadUInt32(); int len = br.ReadInt32(); file.Position = pos; bf.data = br.ReadBytes(len); fileList.Add(bf); file.Position = lpos; } } //BinaryReader should close file }
private void TransformToPNG() { using (MemoryStream ms = new MemoryStream(this.rawData)) { BinaryReader r = new BinaryReader(ms); Bitmap colorImage = new Bitmap(ms); ms.Position = 0; r.ReadBytes(24); if (r.ReadUInt32() == 0x41464C41U) { int length = r.ReadInt32(); length = (int)((length & 0xFF000000) >> 24) | (int)((length & 0x00FF0000) >> 8) | (int)((length & 0x0000FF00) << 8) | (int)((length & 0x000000FF) << 24); using (MemoryStream alphaStream = new MemoryStream(r.ReadBytes(length))) { Bitmap alphaImage = new Bitmap(alphaStream); if (colorImage.Width != alphaImage.Width || colorImage.Height != alphaImage.Height) throw new InvalidDataException("Not a proper TS4 Thumbnail image"); //int[,] rawImage = new int[colorImage.Width, colorImage.Height]; //for (int y = 0; y < colorImage.Height; y++) //{ // for (int x = 0; x < colorImage.Width; x++) // { // Color color = colorImage.GetPixel(x, y); // byte alpha = alphaImage.GetPixel(x, y).R; // rawImage[x, y] = Color.FromArgb(alpha, color).ToArgb(); // } //} colorImage = UpdateAlpha(colorImage, alphaImage); this.Image = colorImage; } } this.Image = colorImage; } }
public bool Load(string path) { using (FileStream fs = new FileStream(path, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(fs)) { for (int i = 0; i < 8; ++i) { reader.ReadBytes(4); } uint count = reader.ReadUInt32(); uint offset = reader.ReadUInt32(); fs.Position = (long)offset; try { for (int i = 0; i < count; ++i) { ulong ext = reader.ReadUInt64(); ulong fpath = reader.ReadUInt64(); uint language = reader.ReadUInt32(); reader.ReadBytes(4); uint id = reader.ReadUInt32(); reader.ReadBytes(4); this.Add(ext, fpath, language, id); } } catch (Exception) { return false; } } } return true; }
public static Certificate GetSignedCertificate(Uri apiUri, CertificateStore certStore) { using (WebClient client = new WebClient()) { client.Headers.Add("User-Agent", GetUserAgent()); byte[] data = client.DownloadData(apiUri.AbsoluteUri + "?cmd=dlc&email=" + certStore.Certificate.IssuedTo.EmailAddress.Address); using (BinaryReader bR = new BinaryReader(new MemoryStream(data))) { int errorCode = bR.ReadInt32(); if (errorCode != 0) { string message = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32())); string remoteStackTrace = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadInt32())); throw new BitChatException(message); } Certificate cert = new Certificate(bR); if (!cert.IssuedTo.EmailAddress.Equals(certStore.Certificate.IssuedTo.EmailAddress) || (cert.PublicKeyEncryptionAlgorithm != certStore.PrivateKey.Algorithm) || (cert.PublicKeyXML != certStore.PrivateKey.GetPublicKey())) throw new BitChatException("Invalid signed certificate received. Please try again."); return cert; } } }