private void ReadTXFNChunk(BinaryReader bin, BlizzHeader chunk) { //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { if (str.Length > 1) { str.Replace("..", "."); str.Append(".blp"); //Filenames in TEX dont have have BLP extensions if (!CASC.FileExists(str.ToString())) { new WoWFormatLib.Utils.MissingFile(str.ToString()); } } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } }
protected byte[] GetImageBytes() { Stream fs = FileUpload.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); return bytes; }
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); }
private void ReadTEX(string filename, Stream tex) { var bin = new BinaryReader(tex); BlizzHeader chunk; long position = 0; while (position < tex.Length) { tex.Position = position; chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32()); chunk.Flip(); position = tex.Position + chunk.Size; switch (chunk.ToString()) { case "TXVR": ReadTXVRChunk(bin); continue; case "TXFN": ReadTXFNChunk(bin, chunk); continue; case "TXBT": case "TXMD": continue; default: throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename)); } } }
public MDBlob(BinaryReader reader) { //read length indicator _length = MModule.DecodeInt32(reader); _data = reader.ReadBytes(_length); }
internal BFCodeLabel(BinaryReader reader) { _name = reader.ReadCString(24); _offset = reader.ReadUInt32(); int unused = reader.ReadInt32(); _opcodeIndex = (int)_offset; }
static RadarColorData() { using (FileStream index = new FileStream(FileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader bin = new BinaryReader(index); // Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors. int colorCount = (int)index.Length / 2; for (int i = 0; i < colorCount; i++) { uint c = bin.ReadUInt16(); Colors[i] = 0xFF000000 | ( ((((c >> 10) & 0x1F) * multiplier)) | ((((c >> 5) & 0x1F) * multiplier) << 8) | (((c & 0x1F) * multiplier) << 16) ); } // fill the remainder of the color table with non-transparent magenta. for (int i = colorCount; i < Colors.Length; i++) { Colors[i] = 0xFFFF00FF; } Metrics.ReportDataRead((int)bin.BaseStream.Position); } }
public ServerConnection(TcpClient client, SslStream stream, BinaryReader binaryReader, BinaryWriter binaryWriter) { _client = client; _stream = stream; _binaryReader = binaryReader; _binaryWriter = binaryWriter; }
public void Load(BinaryReader br, FileStream fs) { Offset = br.ReadInt32(); Offset += 16; FrameCount = br.ReadInt32(); MipWidth = br.ReadInt32(); MipHeight = br.ReadInt32(); StartX = br.ReadInt32(); StartY = br.ReadInt32(); TileCount = br.ReadUInt16(); TotalCount = br.ReadUInt16(); CellWidth = br.ReadUInt16(); CellHeight = br.ReadUInt16(); Frames = new EanFrame[TotalCount]; long curPos = fs.Position; fs.Seek((long)Offset, SeekOrigin.Begin); for (int i = 0; i < TotalCount; i++) { Frames[i].X = br.ReadUInt16(); Frames[i].Y = br.ReadUInt16(); Frames[i].Width = br.ReadUInt16(); Frames[i].Height = br.ReadUInt16(); } fs.Seek((long)curPos, SeekOrigin.Begin); }
public static MessageBase Deserialize(byte[] data) { using (MemoryStream stream = new MemoryStream(data)) using (BinaryReader reader = new BinaryReader(stream)) { // Ignore initial key reader.ReadByte(); byte payloadLength = reader.ReadByte(); byte packageSequence = reader.ReadByte(); byte systemId = reader.ReadByte(); byte componentId = reader.ReadByte(); byte messageId = reader.ReadByte(); // Create instance based on message id MessageBase message = null; Type messageType; if (_messageTypes.TryGetValue(messageId, out messageType)) { message = (MessageBase)Activator.CreateInstance(messageType); message._fields = new object[message._fieldTypes.Length]; for (int i = 0; i < message._fieldTypes.Length; ++i) { message.ReadField(reader, i); } // TODO: Verify CRC byte LSBCRC = reader.ReadByte(); byte MSBCRC = reader.ReadByte(); } return message; } }
// // Un-marshal an object instance from the data input stream // public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs) { base.TightUnmarshal(wireFormat, o, dataIn, bs); ConsumerInfo info = (ConsumerInfo)o; info.ConsumerId = (ConsumerId) TightUnmarshalCachedObject(wireFormat, dataIn, bs); info.Browser = bs.ReadBoolean(); info.Destination = (ActiveMQDestination) TightUnmarshalCachedObject(wireFormat, dataIn, bs); info.PrefetchSize = dataIn.ReadInt32(); info.MaximumPendingMessageLimit = dataIn.ReadInt32(); info.DispatchAsync = bs.ReadBoolean(); info.Selector = TightUnmarshalString(dataIn, bs); info.SubscriptionName = TightUnmarshalString(dataIn, bs); info.NoLocal = bs.ReadBoolean(); info.Exclusive = bs.ReadBoolean(); info.Retroactive = bs.ReadBoolean(); info.Priority = dataIn.ReadByte(); if (bs.ReadBoolean()) { short size = dataIn.ReadInt16(); BrokerId[] value = new BrokerId[size]; for( int i=0; i < size; i++ ) { value[i] = (BrokerId) TightUnmarshalNestedObject(wireFormat,dataIn, bs); } info.BrokerPath = value; } else { info.BrokerPath = null; } info.AdditionalPredicate = (BooleanExpression) TightUnmarshalNestedObject(wireFormat, dataIn, bs); info.NetworkSubscription = bs.ReadBoolean(); info.OptimizedAcknowledge = bs.ReadBoolean(); info.NoRangeAcks = bs.ReadBoolean(); }
private static string DeCrypting() { var res = string.Empty; var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan); var reader = new BinaryReader(file); var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write, FileShare.None, 32, FileOptions.WriteThrough)); try { var pos = 0; while (pos < file.Length) { var c = reader.ReadUInt16(); //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR()); var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR()); if (pos < 256) res += pow + " "; writer.Write((byte)(pow)); pos += 2; } } finally { writer.Close(); reader.Close(); } return "Decoding Complete!\n" + res; }
public RespawnInfo(BinaryReader reader, int Version, int Customversion) { MonsterIndex = reader.ReadInt32(); Location = new Point(reader.ReadInt32(), reader.ReadInt32()); Count = reader.ReadUInt16(); Spread = reader.ReadUInt16(); Delay = reader.ReadUInt16(); Direction = reader.ReadByte(); if (Envir.LoadVersion >= 36) { RoutePath = reader.ReadString(); } if (Version > 67) { RandomDelay = reader.ReadUInt16(); RespawnIndex = reader.ReadInt32(); SaveRespawnTime = reader.ReadBoolean(); RespawnTicks = reader.ReadUInt16(); } else { RespawnIndex = ++SMain.Envir.RespawnIndex; } }
public void TestIncompleteRewind() { MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); bw.Write(1); bw.Write(2); bw.Write(3); bw.Write(4); bw.Write(5); bw.Write(6); bw.Write(7); bw.Flush(); ms.Position = 0; RewindableStream stream = new RewindableStream(ms); stream.StartRecording(); BinaryReader br = new BinaryReader(stream); Assert.AreEqual(br.ReadInt32(), 1); Assert.AreEqual(br.ReadInt32(), 2); Assert.AreEqual(br.ReadInt32(), 3); Assert.AreEqual(br.ReadInt32(), 4); stream.Rewind(true); Assert.AreEqual(br.ReadInt32(), 1); Assert.AreEqual(br.ReadInt32(), 2); stream.StartRecording(); Assert.AreEqual(br.ReadInt32(), 3); Assert.AreEqual(br.ReadInt32(), 4); Assert.AreEqual(br.ReadInt32(), 5); stream.Rewind(true); Assert.AreEqual(br.ReadInt32(), 3); Assert.AreEqual(br.ReadInt32(), 4); Assert.AreEqual(br.ReadInt32(), 5); Assert.AreEqual(br.ReadInt32(), 6); Assert.AreEqual(br.ReadInt32(), 7); }
public KinectReader(Stream fileStream, int width, int height) { this.Width = width; this.Height = height; this.reader = new BinaryReader(fileStream); this.createIndexes(); }
public IDictionary<byte[], IList<long>> Read(BinaryReader reader, int keyWidth) { var indexWidth = reader.ReadInt64(); var buckets = new Dictionary<byte[], IList<long>>(new ByteArrayComparer()); while (reader.BaseStream.Position < reader.BaseStream.Length) { var bucket = new List<long>(); var index = reader.ReadBytes(keyWidth); for (int i = 0; i < indexWidth - keyWidth; i += sizeof (long)) { var value = reader.ReadInt64(); if (value != long.MaxValue) { bucket.Add(value); } else { reader.BaseStream.Seek(indexWidth - keyWidth - i - sizeof (long), SeekOrigin.Current); break; } } buckets[index] = bucket; } return buckets; }
/// <summary> /// Creates texture atlas from stream. /// </summary> /// <param name="device"></param> public TextureAtlas ( RenderSystem rs, Stream stream, bool useSRgb = false ) { var device = rs.Game.GraphicsDevice; using ( var br = new BinaryReader(stream) ) { br.ExpectFourCC("ATLS", "texture atlas"); int count = br.ReadInt32(); for ( int i=0; i<count; i++ ) { var element = new Element(); element.Index = i; element.Name = br.ReadString(); element.X = br.ReadInt32(); element.Y = br.ReadInt32(); element.Width = br.ReadInt32(); element.Height = br.ReadInt32(); elements.Add( element ); } int ddsFileLength = br.ReadInt32(); var ddsImageBytes = br.ReadBytes( ddsFileLength ); texture = new UserTexture( rs, ddsImageBytes, useSRgb ); } dictionary = elements.ToDictionary( e => e.Name ); }
public void testWrite() { MemoryStream stream = new MemoryStream(); CollectionMetadataWriter writer = new CollectionMetadataWriter(stream); DocumentInfo doc1 = new DocumentInfo("http://www.google.com/index.html", "Google", 150, "#Section1", null); DocumentInfo doc2 = new DocumentInfo("http://www.google.com/index.html", "Google", 250, "#Section2", null); writer.AddDocumentInfo(0, doc1); writer.AddDocumentInfo(1, doc2); writer.WriteOut(); BinaryReader reader = new BinaryReader(stream); long collectionTokenCount = reader.ReadInt64(); Assert.AreEqual(400, collectionTokenCount); FileIndex<long, DocumentInfo> documentIndex = new FileIndex<long, DocumentInfo>( new LongEncoder(), new DocumentInfoEncoder(), stream); Assert.AreEqual(2, documentIndex.EntryCount); DocumentInfo docInfo; Assert.IsTrue(documentIndex.TryGet(0, out docInfo)); Assert.AreEqual(doc1, docInfo); Assert.IsTrue(documentIndex.TryGet(1, out docInfo)); Assert.AreEqual(doc2, docInfo); }
static Map LoadHeaderInternal( Stream stream ) { BinaryReader bs = new BinaryReader( stream ); byte version = bs.ReadByte(); if( version != 1 && version != 2 ) throw new MapFormatException(); Position spawn = new Position(); // Read in the spawn location spawn.X = (short)(IPAddress.NetworkToHostOrder( bs.ReadInt16() ) * 32); spawn.H = (short)(IPAddress.NetworkToHostOrder( bs.ReadInt16() ) * 32); spawn.Y = (short)(IPAddress.NetworkToHostOrder( bs.ReadInt16() ) * 32); // Read in the spawn orientation spawn.R = bs.ReadByte(); spawn.L = bs.ReadByte(); // Read in the map dimesions int widthX = IPAddress.NetworkToHostOrder( bs.ReadInt16() ); int widthY = IPAddress.NetworkToHostOrder( bs.ReadInt16() ); int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() ); Map map = new Map( null, widthX, widthY, height, false ); map.SetSpawn( spawn ); return map; }
public static PEType GetPEType(string path) { if (string.IsNullOrEmpty(path)) return PEType.Unknown; var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite )); br.BaseStream.Seek(0x3C, SeekOrigin.Begin); br.BaseStream.Seek(br.ReadInt32() + 4, SeekOrigin.Begin); ushort machine = br.ReadUInt16(); br.Close(); if (machine == 0x014C) return PEType.X32; if (machine == 0x8664) return PEType.X64; return PEType.Unknown; }
public byte[] FilenameToBytes(string filename) { byte[] data = null; // get the file information form the selected file FileInfo fInfo = new FileInfo(filename); // get the length of the file to see if it is possible // to upload it (with the standard 4 MB limit) long numBytes = fInfo.Length; double dLen = Convert.ToDouble(fInfo.Length / 1000000); // set up a file stream and binary reader for the // selected file FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); // convert the file to a byte array data = br.ReadBytes((int)numBytes); br.Close(); fStream.Close(); fStream.Dispose(); return data; }
//add near end of Terraria.IO.WorldFile.loadWorld before setting failure and success internal static void ReadModFile(string path, bool isCloudSave) { path = Path.ChangeExtension(path, ".twld"); if (!FileUtilities.Exists(path, isCloudSave)) { return; } byte[] buffer = FileUtilities.ReadAllBytes(path, isCloudSave); using (MemoryStream stream = new MemoryStream(buffer)) { using (BinaryReader reader = new BinaryReader(stream)) { byte limit = reader.ReadByte(); if (limit == 0) { return; } byte[] flags = reader.ReadBytes(limit); if (flags.Length < numByteFlags) { Array.Resize(ref flags, numByteFlags); } ReadModWorld(flags, reader); } } }
static Map LoadHeaderInternal( [NotNull] Stream stream ) { if( stream == null ) throw new ArgumentNullException( "stream" ); BinaryReader reader = new BinaryReader( stream ); // Read in the magic number if( reader.ReadUInt32() != Identifier ) { throw new MapFormatException(); } // Read in the map dimesions int width = reader.ReadInt16(); int length = reader.ReadInt16(); int height = reader.ReadInt16(); // ReSharper disable UseObjectOrCollectionInitializer Map map = new Map( null, width, length, height, false ); // ReSharper restore UseObjectOrCollectionInitializer // Read in the spawn location map.Spawn = new Position { X = reader.ReadInt16(), Y = reader.ReadInt16(), Z = reader.ReadInt16(), R = reader.ReadByte(), L = reader.ReadByte() }; return map; }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // Initialize ApplicationSprite sprite.AttachSpriteTo(page.Content); sprite.Invoke( base64 => { var bytes = Convert.FromBase64String(base64); new IHTMLPre { innerText = bytes.ToHexString() }.AttachToDocument(); var r = new BinaryReader(new MemoryStream(bytes)); var space = r.ReadByte(); new IHTMLPre { innerText = new { space }.ToString() }.AttachToDocument(); try { // implemented in Redux build configuration // script: error JSC1000: No implementation found for this native method, please implement [System.IO.BinaryReader.ReadSingle()] var f = r.ReadSingle(); new IHTMLPre { innerText = new { f }.ToString() }.AttachToDocument(); } catch (Exception ex) { new IHTMLPre { innerText = "error: " + new { ex.Message }.ToString() }.AttachToDocument(); } } ); }
public static Shape Load(string fn) { if (!System.IO.File.Exists(fn)) throw new System.Exception("File not found: " + fn); System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream(fn, System.IO.FileMode.Open)); Shape s = new Shape(); s.Width = br.ReadInt32(); s.Height = br.ReadInt32(); s.matrix = new bool[s.Width, s.Height]; try { for (int x = 0; x < s.Width; x++) for (int y = 0; y < s.Height; y++) s.notEmptyCellsCount += (s.matrix[x, y] = br.ReadBoolean()) ? 1 : 0; } catch (System.IO.EndOfStreamException) { throw new System.Exception("Invalid data for shape " + fn); } br.Close(); s.CreateTexture(); return s; }
/// <summary> /// Reads a *.anim file into this Anim instance. /// </summary> /// <param name="FileData">The filedata for the *.anim file.</param> public Anim(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_Name = Encoding.ASCII.GetString(Reader.ReadBytes(Endian.SwapInt16(Reader.ReadInt16()))); m_Duration = Reader.ReadSingle() / 1000; //Why does this have to be divided by 1000? o_O m_Distance = Reader.ReadSingle(); m_IsMoving = Reader.ReadByte(); m_NumTranslations = Endian.SwapUInt32(Reader.ReadUInt32()); m_TranslationsTableOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_TranslationsTableOffset + 12 * m_NumTranslations, SeekOrigin.Begin); m_NumRotations = Endian.SwapUInt32(Reader.ReadUInt32()); m_RotationsTableOffset = Reader.BaseStream.Position; Reader.BaseStream.Seek(m_RotationsTableOffset + 16 * m_NumRotations, SeekOrigin.Begin); m_MotionCount = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < m_MotionCount; i++) m_Motions.Add(ReadMotion(Reader)); }
public static bool RequestImageComparisonStatus(string testName = null) { if (!Connect()) throw new InvalidOperationException("Could not connect to image comparer server"); try { if (testName == null && NUnit.Framework.TestContext.CurrentContext == null) { testName = NUnit.Framework.TestContext.CurrentContext.Test.FullName; } var networkStream = ImageComparisonServer.GetStream(); var binaryWriter = new BinaryWriter(networkStream); var binaryReader = new BinaryReader(networkStream); // Header binaryWriter.Write((int)ImageServerMessageType.RequestImageComparisonStatus); binaryWriter.Write(testName); return binaryReader.ReadBoolean(); } catch (Exception) { throw; } }
private Frame[] GetAnimation() { if (_patch.length < 1) return null; MemoryStream ms = new MemoryStream(_patch.data); BinaryReader bin = new BinaryReader(ms); if (_patch.length < 1) return null; ushort[] palette = new ushort[0x100]; for( int i = 0; i < 0x100; ++i ) palette[i] = (ushort)( bin.ReadUInt16() ^ 0x8000 ); int start = (int)bin.BaseStream.Position; int frameCount = bin.ReadInt32(); int[] lookups = new int[frameCount]; for( int i = 0; i < frameCount; ++i ) lookups[i] = start + bin.ReadInt32(); Frame[] frames = new Frame[frameCount]; for( int i = 0; i < frameCount; ++i ) { bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin); frames[i] = new Frame(palette, bin, false); } return frames; }
public override void LoadData(BinaryReader reader, StructInstance instance) { int size = GetExpressionAttribute("size").EvaluateInt(instance); long baseOffset = reader.BaseStream.Position; uint baseValue; switch(size) { case 1: baseValue = reader.ReadByte(); break; case 2: baseValue = reader.ReadUInt16(); break; case 4: baseValue = reader.ReadUInt32(); break; default: throw new LoadDataException("Invalid bitfield size " + size); } BitfieldReader bitFieldReader = new BitfieldReader(baseValue, size, baseOffset); foreach(StructField field in ChildFields) { if (field is IntBasedField) { IntBasedField intBasedField = (IntBasedField) field; int? bit = intBasedField.GetIntAttribute("bit"); if (bit.HasValue) bitFieldReader.SetBits(bit.Value, bit.Value); else { int? fromBit = intBasedField.GetIntAttribute("frombit"); int? toBit = intBasedField.GetIntAttribute("tobit"); bitFieldReader.SetBits(fromBit.Value, toBit.Value); } } field.LoadData(bitFieldReader, instance); } }
public short[,] Read(string filePath) { short[,] imagePixels = null; FileStream fs = File.Open(filePath, FileMode.Open); using (BinaryReader reader = new BinaryReader(fs)) { if (ReadHeader(reader)) { int width, height; byte depth; if (ReadIHDR(reader, out width, out height, out depth)) { string chunkType = ""; while (chunkType != "IEND") { byte[] chunkData = ReadChunk(reader, out chunkType); // we only support image with one IDAT if (chunkType == "IDAT") { imagePixels = DecompressImageData(chunkData, width, height); } } } } } return imagePixels; }