public SOLFile(string location) { var bytes = File.ReadAllBytes(location); BigEndianReader br = new BigEndianReader(bytes); ///HEADER/// br.ReadInt16(); //sol_version br.ReadInt32(); //file length if (br.ReadInt32() != 0x5443534F) //TCSO { throw new Exception("Invalid magic number, maybe this isn't an SOL file?"); } br.ReadBytes(6); //padding RootObject.name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())); //shared object name if (RootObject.name != "savedLines") { throw new Exception("invalid root object"); } if (br.ReadInt32() != 0) { throw new Exception("Invalid AMF version");//amf version, we only support 0o } ///items/// Amf0 amf = new Amf0(br); RootObject.data = amf.ReadAmf0(true); }
protected override void Parse(BigEndianReader reader) { reader.ReadByte(); // ID Length = reader.ReadByte(); Length2 = reader.ReadByte(); if (Length != 0) { reader.ReadByte(); XML = Encoding.ASCII.GetString(reader.ReadBytes(Length - 5)); XDocument docXML = XDocument.Parse(XML); From = FindParameter(docXML, "presence", "from"); Id = FindParameter(docXML, "presence", "id"); Name = FindParameter(docXML, "presence", "name"); Show = FindParameter(docXML, "presence", "show"); Version = FindParameter(docXML, "presence", "version"); } else // client { reader.ReadByte(); XML = Encoding.ASCII.GetString(reader.ReadBytes(Length2 - 5)); XDocument docXML = XDocument.Parse(XML); From = FindParameter(docXML, "presence", "from"); Show = FindParameter(docXML, "presence", "show"); To = FindParameter(docXML, "iq", "to"); Type = FindParameter(docXML, "iq", "type"); } }
private bool Build() { if ((m_Header.HasValue) && (m_Length.HasValue) && (m_Length == m_Data.Length)) { return(true); } if ((m_Reader.BytesAvailable >= 2) && (!m_Header.HasValue)) { m_Header = m_Reader.ReadShort(); m_ProtocolID = m_Header >> 2; m_LenghtType = m_Header & 0x3; } if ((m_LenghtType.HasValue) && (m_Reader.BytesAvailable >= m_LenghtType) && (!m_Length.HasValue)) { if ((m_LenghtType < 0) || (m_LenghtType > 3)) { throw new Exception("Malformated Message Header, invalid bytes number to read message length (inferior to 0 or superior to 3)"); } m_Length = 0; for (int i = m_LenghtType.Value - 1; i >= 0; i--) { m_Length |= m_Reader.ReadByte() << (i * 8); } } if ((m_Data == null) && (m_Length.HasValue)) { if (m_Length == 0) { m_Data = new byte[0]; } if (m_Reader.BytesAvailable >= m_Length) { m_Data = m_Reader.ReadBytes(m_Length.Value); } else if (m_Length > m_Reader.BytesAvailable) { m_Data = m_Reader.ReadBytes((int)m_Reader.BytesAvailable); } } if ((m_Data != null) && (m_Length.HasValue) && (m_Data.Length < m_Length)) { int bytesToRead = 0; if (m_Data.Length + m_Reader.BytesAvailable < m_Length) { bytesToRead = (int)m_Reader.BytesAvailable; } else if (m_Data.Length + m_Reader.BytesAvailable >= m_Length) { bytesToRead = m_Length.Value - m_Data.Length; } if (bytesToRead != 0) { int oldLength = m_Data.Length; Array.Resize(ref m_Data, m_Data.Length + bytesToRead); Array.Copy(m_Reader.ReadBytes(bytesToRead), 0, m_Data, oldLength, bytesToRead); } } return(m_Data != null && ((m_Header.HasValue) && (m_Length.HasValue) && (m_Length == m_Data.Length))); }
private void ImportLOBJ_Click(object sender, EventArgs e) { OpenFileDialog o = new OpenFileDialog(); o.Filter = "Binary Light Object (*blobj)|*.blobj"; if (o.ShowDialog() == DialogResult.OK) { BigEndianReader Reader = new BigEndianReader(new MemoryStream(File.ReadAllBytes(o.FileName))); LOBJ.Magic = Encoding.ASCII.GetString(Reader.ReadBytes(0x04)); if (LOBJ.Magic != "LOBJ") { throw new WrongMagicException(LOBJ.Magic, "LOBJ", Reader.BaseStream.Position - 4); } LOBJ.SectionSize = Reader.ReadUInt32(); if (LOBJ.SectionSize != 0x50) { MessageBox.Show("Please give this file to Wexos!"); } LOBJ.Unknown1 = Reader.ReadUInt64(); LOBJ.Unknown2 = Reader.ReadUInt16(); LOBJ.LightType = Reader.ReadByte(); LOBJ.Unknown3 = Reader.ReadByte(); LOBJ.LightID = Reader.ReadUInt16(); LOBJ.Unknown4 = Reader.ReadUInt16(); LOBJ.OriginVector = Reader.ReadSingles(3); LOBJ.DestinationVector = Reader.ReadSingles(3); LOBJ.Scale = Reader.ReadSingle(); LOBJ.RGBA = Reader.ReadBytes(4); LOBJ.Unknown5 = Reader.ReadUInt32(); LOBJ.Unknown6 = Reader.ReadSingle(); LOBJ.Unknown7 = Reader.ReadSingle(); LOBJ.Unknown8 = Reader.ReadSingle(); LOBJ.Padding = Reader.ReadUInt64(); Reader.Close(); dgwLOBJ.Rows.Add(HexUtil.Hex8(Convert.ToByte(dgwLOBJ.Rows.Count)), HexUtil.Hex8(LOBJ.LightType), HexUtil.Hex8(LOBJ.Unknown3), LOBJ.OriginVector[0], LOBJ.OriginVector[1], LOBJ.OriginVector[2], LOBJ.DestinationVector[0], LOBJ.DestinationVector[1], LOBJ.DestinationVector[2], LOBJ.Scale, LOBJ.Unknown6, LOBJ.Unknown7, LOBJ.Unknown8, HexUtil.Hex16(LOBJ.LightID), HexUtil.Hex16(LOBJ.Unknown4), HexUtil.Hex32(LOBJ.Unknown5), HexUtil.Hex8(LOBJ.RGBA[0]), HexUtil.Hex8(LOBJ.RGBA[1]), HexUtil.Hex8(LOBJ.RGBA[2]), HexUtil.Hex8(LOBJ.RGBA[3]), HexUtil.Hex64(LOBJ.Unknown1), HexUtil.Hex16(LOBJ.Unknown2), HexUtil.Hex64(LOBJ.Padding)); } }
public bool Build(BigEndianReader reader) { if (IsValid) { return(true); } if (reader.BytesAvailable >= 2 && !Header.HasValue) { Header = reader.ReadShort(); } if (LengthBytesCount.HasValue && reader.BytesAvailable >= LengthBytesCount && !Length.HasValue) { Length = 0; for (int i = LengthBytesCount.Value - 1; i >= 0; i--) { Length |= reader.ReadByte() << (i * 8); } } if (Data == null && Length.HasValue) { if (Length == 0) { Data = new byte[0]; } if (reader.BytesAvailable >= Length) { Data = reader.ReadBytes(Length.Value); } else if (Length > reader.BytesAvailable) { Data = reader.ReadBytes((int)reader.BytesAvailable); } } if (Data != null && Length.HasValue && Data.Length < Length) { int bytesToRead = 0; if (Data.Length + reader.BytesAvailable < Length) { bytesToRead = (int)reader.BytesAvailable; } else if (Data.Length + reader.BytesAvailable >= Length) { bytesToRead = Length.Value - Data.Length; } if (bytesToRead != 0) { int oldLength = Data.Length; Array.Resize(ref m_data, (int)(Data.Length + bytesToRead)); Array.Copy(reader.ReadBytes(bytesToRead), 0, Data, oldLength, bytesToRead); } } return(IsValid); }
public List <Amf0Object> ReadAmf0(bool rootobject = false) { List <Amf0Object> retlist = new List <Amf0Object>(); while (true) { Amf0Object ret = new Amf0Object(); if (br.Remaining < 2 && rootobject) { return(retlist); } ret.name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())); //object name ret.type = (Amf0Object.Amf0Type)br.ReadByte(); //type switch (ret.type) { case Amf0Object.Amf0Type.AMF0_NUMBER: //NUMBER ret.data = br.ReadDouble(); break; case Amf0Object.Amf0Type.AMF0_BOOLEAN: //BOOLEAN ret.data = br.ReadBoolean(); break; case Amf0Object.Amf0Type.AMF0_STRING: ret.data = Encoding.UTF8.GetString(br.ReadBytes(br.ReadInt16())); break; case Amf0Object.Amf0Type.AMF0_OBJECT: //OBJECT { ret.data = ReadAmf0(); } break; case Amf0Object.Amf0Type.AMF0_NULL: case Amf0Object.Amf0Type.AMF0_UNDEFINED: ret.data = null; break; case Amf0Object.Amf0Type.AMF0_ECMA_ARRAY: //ecma array { br.ReadInt32(); var ecma = ReadAmf0(); ret.data = ecma; // if (ecma.Count != l) // throw new Exception("Corrupt ECMA array in SOL file"); } break; case Amf0Object.Amf0Type.AMF0_OBJECT_END: return(retlist); default: throw new Exception("Error reading SOL file (40)"); } retlist.Add(ret); } }
public void ReadBLIGHT(string FilePath) { FileName = FilePath; BigEndianReader Reader = new BigEndianReader(new MemoryStream(File.ReadAllBytes(FilePath))); BLIGHT.Magic = Encoding.ASCII.GetString(Reader.ReadBytes(0x04)); if (BLIGHT.Magic != "LGHT") { throw new WrongMagicException(BLIGHT.Magic, "LGHT", Reader.BaseStream.Position - 4); } BLIGHT.FileSize = Reader.ReadUInt32(); BLIGHT.Unknown1 = Reader.ReadUInt32(); BLIGHT.Unknown2 = Reader.ReadUInt32(); BLIGHT.NrLOBJ = Reader.ReadUInt16(); BLIGHT.NrAmbientLight = Reader.ReadUInt16(); BLIGHT.Unknown3 = Reader.ReadUInt32(); BLIGHT.Padding = Reader.ReadUInt64(); BLIGHT.Padding2 = Reader.ReadUInt64(); for (int i = 0; i < BLIGHT.NrLOBJ; i++) { LOBJ.Magic = Encoding.ASCII.GetString(Reader.ReadBytes(0x04)); if (LOBJ.Magic != "LOBJ") { throw new WrongMagicException(LOBJ.Magic, "LOBJ", Reader.BaseStream.Position - 4); } LOBJ.SectionSize = Reader.ReadUInt32(); if (LOBJ.SectionSize != 0x50) { MessageBox.Show("Please give this file to Wexos!"); } LOBJ.Unknown1 = Reader.ReadUInt64(); LOBJ.Unknown2 = Reader.ReadUInt16(); LOBJ.LightType = Reader.ReadByte(); LOBJ.Unknown3 = Reader.ReadByte(); LOBJ.LightID = Reader.ReadUInt16(); LOBJ.Unknown4 = Reader.ReadUInt16(); LOBJ.OriginVector = Reader.ReadSingles(3); LOBJ.DestinationVector = Reader.ReadSingles(3); LOBJ.Scale = Reader.ReadSingle(); LOBJ.RGBA = Reader.ReadBytes(4); LOBJ.Unknown5 = Reader.ReadUInt32(); LOBJ.Unknown6 = Reader.ReadSingle(); LOBJ.Unknown7 = Reader.ReadSingle(); LOBJ.Unknown8 = Reader.ReadSingle(); LOBJ.Padding = Reader.ReadUInt64(); dgwLOBJ.Rows.Add(HexUtil.Hex8(Convert.ToByte(i)), HexUtil.Hex8(LOBJ.LightType), HexUtil.Hex8(LOBJ.Unknown3), LOBJ.OriginVector[0], LOBJ.OriginVector[1], LOBJ.OriginVector[2], LOBJ.DestinationVector[0], LOBJ.DestinationVector[1], LOBJ.DestinationVector[2], LOBJ.Scale, LOBJ.Unknown6, LOBJ.Unknown7, LOBJ.Unknown8, HexUtil.Hex16(LOBJ.LightID), HexUtil.Hex16(LOBJ.Unknown4), HexUtil.Hex32(LOBJ.Unknown5), HexUtil.Hex8(LOBJ.RGBA[0]), HexUtil.Hex8(LOBJ.RGBA[1]), HexUtil.Hex8(LOBJ.RGBA[2]), HexUtil.Hex8(LOBJ.RGBA[3]), HexUtil.Hex64(LOBJ.Unknown1), HexUtil.Hex16(LOBJ.Unknown2), HexUtil.Hex64(LOBJ.Padding)); } for (int i = 0; i < BLIGHT.NrAmbientLight; i++) { Ambient.RGBALight = Reader.ReadBytes(4); Ambient.Padding = Reader.ReadUInt32(); dgwAmbient.Rows.Add(HexUtil.Hex8(Convert.ToByte(i)), HexUtil.Hex8(Ambient.RGBALight[0]), HexUtil.Hex8(Ambient.RGBALight[1]), HexUtil.Hex8(Ambient.RGBALight[2]), HexUtil.Hex8(Ambient.RGBALight[3]), HexUtil.Hex32(Ambient.Padding)); } LOBJColor.BackColor = Color.FromArgb(byte.Parse(dgwLOBJ.Rows[0].Cells[16].Value.ToString(), NumberStyles.HexNumber), byte.Parse(dgwLOBJ.Rows[0].Cells[17].Value.ToString(), NumberStyles.HexNumber), byte.Parse(dgwLOBJ.Rows[0].Cells[18].Value.ToString(), NumberStyles.HexNumber)); AmbientColor.BackColor = Color.FromArgb(byte.Parse(dgwAmbient.Rows[0].Cells[1].Value.ToString(), NumberStyles.HexNumber), byte.Parse(dgwAmbient.Rows[0].Cells[2].Value.ToString(), NumberStyles.HexNumber), byte.Parse(dgwAmbient.Rows[0].Cells[3].Value.ToString(), NumberStyles.HexNumber)); this.Show(); Reader.Close(); }
protected override void Parse(BigEndianReader reader) { reader.ReadByte(); // ID reader.ReadInt16(); // Size _Serial = reader.ReadUInt32(); _GumpID = reader.ReadInt32(); _X = reader.ReadInt32(); _Y = reader.ReadInt32(); int compressedEntriesLength = reader.ReadInt32() - 4; int decompressedEntriesLength = reader.ReadInt32(); byte[] compressedEntries = reader.ReadBytes(compressedEntriesLength); byte[] decompressedEntries = new byte[decompressedEntriesLength]; Ultima.Package.Zlib.Decompress(decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength); string entries = Encoding.ASCII.GetString(decompressedEntries); int lineCount = reader.ReadInt32(); int compressedStringsLength = reader.ReadInt32() - 4; int decompressedStringsLength = reader.ReadInt32(); byte[] compressedStrings = reader.ReadBytes(compressedStringsLength); byte[] decompressedStrings = new byte[decompressedStringsLength]; Ultima.Package.Zlib.Decompress(decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength); string strings = Encoding.ASCII.GetString(decompressedStrings); _Text = new List <string>(); int start = 0; for (int i = 0; i < strings.Length; i++) { if (strings[i] == 0) { if (i - start > 0) { _Text.Add(strings.Substring(start, i - start)); } else { _Text.Add(String.Empty); } start = i + 1; } } Parse(entries); }
public NbtTag Read(out string name) { name = null; NbtTagType type = (NbtTagType)_reader.ReadByte(); if (type == NbtTagType.End) { return(null); } short length = _reader.ReadInt16(); byte[] array = _reader.ReadBytes(length); name = Encoding.UTF8.GetString(array); return(Read(type)); }
protected override void Parse( BigEndianReader reader ) { reader.ReadByte(); // ID reader.ReadInt16(); // Size _Serial = reader.ReadUInt32(); _GumpID = reader.ReadInt32(); _X = reader.ReadInt32(); _Y = reader.ReadInt32(); int compressedEntriesLength = reader.ReadInt32() - 4; int decompressedEntriesLength = reader.ReadInt32(); byte[] compressedEntries = reader.ReadBytes( compressedEntriesLength ); byte[] decompressedEntries = new byte[ decompressedEntriesLength ]; Ultima.Package.Zlib.Decompress( decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength ); string entries = Encoding.ASCII.GetString( decompressedEntries ); int lineCount = reader.ReadInt32(); int compressedStringsLength = reader.ReadInt32() - 4; int decompressedStringsLength = reader.ReadInt32(); byte[] compressedStrings = reader.ReadBytes( compressedStringsLength ); byte[] decompressedStrings = new byte[ decompressedStringsLength ]; Ultima.Package.Zlib.Decompress( decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength ); string strings = Encoding.ASCII.GetString( decompressedStrings ); _Text = new List<string>(); int start = 0; for ( int i = 0; i < strings.Length; i++ ) { if ( strings[ i ] == 0 ) { if ( i - start > 0 ) _Text.Add( strings.Substring( start, i - start ) ); else _Text.Add( String.Empty ); start = i + 1; } } Parse( entries ); }
public DlmMap ReadMap() { m_reader.Seek(0, SeekOrigin.Begin); int header = m_reader.ReadByte(); if (header != 77) { try { m_reader.Seek(0, SeekOrigin.Begin); var output = new MemoryStream(); ZipHelper.Deflate(new MemoryStream(m_reader.ReadBytes((int)m_reader.BytesAvailable)), output); var uncompress = output.ToArray(); ChangeStream(new MemoryStream(uncompress)); header = m_reader.ReadByte(); if (header != 77) { throw new FileLoadException("Wrong header file"); } } catch (Exception ex) { throw new FileLoadException("Wrong header file"); } } var map = DlmMap.ReadFromStream(m_reader, this); return(map); }
public bool DecryptCredentials(out Account account, AuthClient client, IEnumerable <byte> credentials) { try { account = null; string login; string password; using (var reader = new BigEndianReader(credentials.ToArray())) { login = reader.ReadUTF(); password = reader.ReadUTF(); client.AesKey = reader.ReadBytes(32); } account = AccountManager.Instance.FindAccountByLogin(login); if (account != null) { return(account.PasswordHash == password.GetMD5()); } else { return(false); } } catch { account = null; return(false); } }
public static Variable DecodeVarBind(byte[] Data) { using (var stream = new MemoryStream(Data)) using (var read = new BigEndianReader(stream)) { var nameType = (FieldType)read.ReadByte(); if (nameType != FieldType.OID) { throw new Exception("Invalid OID type for varbind"); } var nameLen = read.ReadInt16(); var oidIntCount = nameLen / sizeof(Int32); var oidInts = new UInt32[oidIntCount]; for (int i = 0; i < oidIntCount; ++i) { oidInts[i] = (UInt32)read.ReadInt32(); } var oid = new ObjectIdentifier(oidInts); var valueType = (FieldType)read.ReadByte(); var valueLen = read.ReadUInt16(); switch (valueType) { default: break; case FieldType.Null: return(new Variable(oid)); case FieldType.Int32: return(new Variable(oid, new Integer32(read.ReadInt32()))); case FieldType.String: return(new Variable(oid, new OctetString(read.ReadBytes(valueLen)))); case FieldType.OID: oidIntCount = valueLen / sizeof(Int32); oidInts = new UInt32[oidIntCount]; for (int i = 0; i < oidIntCount; ++i) { oidInts[i] = (UInt32)read.ReadInt32(); } return(new Variable(oid, new ObjectIdentifier(oidInts))); case FieldType.IPAddress: if (valueLen != 4) { throw new Exception("Invalid IP Address length"); } return(new Variable(oid, new IP(read.ReadBytes(4)))); case FieldType.Counter32: return(new Variable(oid, new Counter32((UInt32)read.ReadInt32()))); case FieldType.Gauge32: return(new Variable(oid, new Gauge32((UInt32)read.ReadInt32()))); case FieldType.TimeTicks: return(new Variable(oid, new TimeTicks((UInt32)read.ReadInt32()))); } } return(null); }
public static NetworkMessage GetPacket(byte[] buffer) { BigEndianReader reader = new BigEndianReader(buffer); uint header = reader.ReadUShort(); uint id = header >> 2; int length = 0; switch (header & 3) { case 1: length = reader.ReadByte(); break; case 2: length = reader.ReadUShort(); break; case 3: length = (reader.ReadByte() << 16) + (reader.ReadByte() << 8) + reader.ReadByte(); break; } byte[] data = (length > 0) ? reader.ReadBytes(length) : new byte[] { }; return(GetPacket(data, (uint)id)); }
public static string DecodeWithAES(List <sbyte> ticket) { var dr = new BigEndianReader(new byte[32]); var aesAlg = new AesManaged(); var ticketbyte = new byte[ticket.Count]; for (var i = 0; i <= ticket.Count - 1; i++) { ticketbyte[i] = (byte)ticket[i]; } aesAlg.IV = dr.ReadBytes(16); aesAlg.Key = new byte[32]; aesAlg.Padding = PaddingMode.None; aesAlg.Mode = CipherMode.CBC; var decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); var msDecrypt = new MemoryStream(ticketbyte); var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); var srDecrypt = new StreamReader(csDecrypt); return(srDecrypt.ReadToEnd()); }
public GameDataFileAccessor(string Path, I18nFileAccessor I18nAcessor) { FilePath = Path; ClasseDefinitions = new Dictionary <int, GameDataClassDefiniton>(); stream = new FileStream(Path, FileMode.Open); reader = new BigEndianReader(stream); i18nAcessor = I18nAcessor; string header = Encoding.Default.GetString(reader.ReadBytes(3)); int indexPos = reader.ReadInt(); reader.SetPosition(indexPos); int indexCount = reader.ReadInt(); for (int i = 1; i < indexCount; i += 8) { int index = reader.ReadInt(); int pos = reader.ReadInt(); indexes.Add(index, pos); } int classesCount = reader.ReadInt(); for (int i = 0; i < classesCount; i++) { int classId = reader.ReadInt(); ClasseDefinitions.Add(classId, ReadClassDefinition()); } foreach (GameDataClassDefiniton def in ClasseDefinitions.Values) { def.SetField(ClasseDefinitions, i18nAcessor.FilePath); } }
// Methods internal D2oData(string D2oFile) { D2oFileStream = new FileStream(D2oFile, FileMode.Open, FileAccess.Read); dictionary_1 = new Dictionary <int, int>(); dictionary_0 = new Dictionary <int, Class16>(); Reader = new BigEndianReader(D2oFileStream); Encoding.Default.GetString(Reader.ReadBytes(3)); D2oFileStream.Position = Reader.ReadInt(); int num = Reader.ReadInt(); int i = 1; while ((i <= num)) { dictionary_1.Add(Reader.ReadInt(), Reader.ReadInt()); int_0 += 1; i = (i + 8); } int num3 = Reader.ReadInt(); int j = 1; while ((j <= num3)) { method_2(Reader.ReadInt()); j += 1; } }
public EleInstance ReadElements() { m_reader.Seek(0, SeekOrigin.Begin); int header = m_reader.ReadByte(); if (header != 69) { try { var uncompress = ZipHelper.Uncompress(m_reader.ReadBytes((int)m_reader.BytesAvailable)); if (uncompress.Length <= 0 || uncompress[0] != 69) { throw new FileLoadException("Wrong header file"); } ChangeStream(new MemoryStream(uncompress)); } catch (Exception) { throw new FileLoadException("Wrong header file"); } } var instance = EleInstance.ReadFromStream(m_reader); return(instance); }
private void Initializeraw(LoadedMap LoadedMap) { FileStream LoadedMapStream = new FileStream(LoadedMap.Path, FileMode.Open, FileAccess.Read); BigEndianReader LoadedMapraw = new BigEndianReader(LoadedMapStream); LoadedMapraw.BaseStream.Position = LoadedMap.offset; byte[] LoadedMapBuffer = LoadedMapraw.ReadBytes((int)LoadedMap.bytesCount); byte[] LoadedMapBufferWithoutHeader = new byte[LoadedMapBuffer.Length - 2]; Array.Copy(LoadedMapBuffer, 2, LoadedMapBufferWithoutHeader, 0, LoadedMapBuffer.Length - 2); StringBuilder mapHashCodeBuilder = new StringBuilder(); byte[] LoadedMapMd5Buffer = MD5.Create().ComputeHash(LoadedMapBufferWithoutHeader); for (int i = 0; i < LoadedMapMd5Buffer.Length; i++) { mapHashCodeBuilder.Append(LoadedMapMd5Buffer[i].ToString("X2")); } HashCode = mapHashCodeBuilder.ToString(); MemoryStream decompressMapStream = new MemoryStream(LoadedMapBufferWithoutHeader); DeflateStream mapDeflateStream = new DeflateStream(decompressMapStream, CompressionMode.Decompress); Raw = new BigEndianReader(mapDeflateStream); MemoryStream stream = new MemoryStream(); Raw.BaseStream.CopyTo(stream); data = stream.ToArray(); Raw = new BigEndianReader(data); LoadedMapStream.Close(); }
/// <summary> /// Creates <see cref="TtfFileInfo"/> from <see cref="System.IO.Stream"/>. /// </summary> /// <param name="stream">Stream to create the structure. Stream will be disposed after use.</param> /// <returns><see cref="TtfFileInfo"/> if successful, otherwise null.</returns> public static TtfFileInfo FromStream(Stream stream) { try { using (var reader = new BigEndianReader(stream)) { var ttfFile = new TtfFileInfo() { Version = reader.ReadInt32() }; if (ttfFile.Version != 0x74727565 && ttfFile.Version != 0x00010000) return null; ttfFile.TableCount = reader.ReadInt16(); reader.BaseStream.Seek(6, SeekOrigin.Current); for (var tableIndex = 0; tableIndex < ttfFile.TableCount; tableIndex++) { var tag = reader.ReadInt32(); reader.BaseStream.Seek(4, SeekOrigin.Current); var offset = reader.ReadInt32(); var length = reader.ReadInt32(); if (tag != 0x6E616D65) continue; reader.BaseStream.Seek(offset, SeekOrigin.Begin); var table = reader.ReadBytes(length); var count = GetInt16(table, 2); var stringOffset = GetInt16(table, 4); for (var record = 0; record < count; record++) { var nameidOffset = record*12 + 6; var platformId = GetInt16(table, nameidOffset); var nameidValue = GetInt16(table, nameidOffset + 6); if (nameidValue != 4 || platformId != 1) continue; var nameLength = GetInt16(table, nameidOffset + 8); var nameOffset = stringOffset + GetInt16(table, nameidOffset + 10); if (nameOffset < 0 || nameOffset + nameLength >= table.Length) continue; ttfFile.FontName = Encoding.UTF8.GetString(table, nameOffset, nameLength); return ttfFile; } } } } catch { return null; } return null; }
internal byte[] ReadFile(string fileName) { lock (CheckLock) { var numArray = FilenameDataDictionnary[fileName]; D2pFileStream.Position = numArray[0]; return(Reader.ReadBytes(numArray[1])); } }
protected override void Parse(BigEndianReader reader) { reader.ReadByte(); // ID reader.ReadInt16(); // Size CompressionType = reader.ReadByte(); EnableResponse = reader.ReadByte(); Serial = reader.ReadUInt32(); Revision = reader.ReadUInt32(); TileLength = reader.ReadInt16(); BufferLength = reader.ReadInt16(); PlaneCount = reader.ReadByte(); Items = new List <Item>(); for (int i = 0; i < PlaneCount; i++) { byte[] data = reader.ReadBytes(4); Index = data[0]; int uncompressedsize = data[1] + ((data[3] & 0xF0) << 4); int compressedLength = data[2] + ((data[3] & 0xF) << 8); ItemData = new byte[uncompressedsize]; Ultima.Package.Zlib64.Decompress(ItemData, ref uncompressedsize, reader.ReadBytes(compressedLength), compressedLength); IsFloor = ((Index & 0x20) == 0x20); Index &= 0x1F; int numTiles = ItemData.Length >> 1; if (i == PlaneCount - 1) { int index = 0; numTiles = ItemData.Length / 5; for (int j = 0; j < numTiles; j++) { Items.Add(new Item(ItemData, index)); } } } }
public static NetworkMessage Build(BigEndianReader stream) { ushort header = stream.ReadUShort(); uint id = (uint)header >> 2; int lenght = GetMessageLenght(stream, header); if (id > int.MinValue) { byte[] buffer = (lenght > 0) ? stream.ReadBytes(lenght) : new byte[] { }; return(Build(id, new BigEndianReader(buffer))); } throw new Exception("Invalid packet id : " + id); }
internal byte[] ReadFile(string fileName) { if (!isInitialized) { throw new Exception("D2PFileDlm Not initialized"); } lock (CheckLock) { var filePosition = FilePositionDictionary[fileName]; Reader.BaseStream.Seek(filePosition.offset + 2, SeekOrigin.Begin); // + 2 is that so we can remove the header return(Reader.ReadBytes(filePosition.length)); } }
public static List <Variable> DecodeVarBindList(byte[] Data) { List <Variable> ret = new List <Variable>(); using (var stream = new MemoryStream(Data)) using (var read = new BigEndianReader(stream)) { while (true) { byte fieldID = read.ReadByte(); if (fieldID == 255) { break; } ushort fieldLength = read.ReadUInt16(); switch (fieldID) { case 1: // Error status { var errorStatus = read.ReadUInt16(); Console.WriteLine($"Error status: {errorStatus}"); } break; case 2: // Error { var errorType = read.ReadUInt16() == 1; Console.WriteLine($"Error: {errorType}"); } break; case 3: // VarBind { var vb = DecodeVarBind(read.ReadBytes(fieldLength)); ret.Add(vb); } break; } if (fieldID == 255 || read.PeekChar() < 0) { break; } } } return(ret); }
// Methods internal D2PFileDlm(string D2pFilePath) { D2pFileStream = new FileStream(D2pFilePath, FileMode.Open, FileAccess.Read); Reader = new BigEndianReader(D2pFileStream); CheckLock = RuntimeHelpers.GetObjectValue(new object()); byte[] bytes_header = Reader.ReadBytes(2); if (bytes_header.SequenceEqual(Header)) { Reader.BaseStream.Seek(-24, SeekOrigin.End); uint BaseOffset = Reader.ReadUInt(); uint BaseLength = Reader.ReadUInt(); uint IndexesOffset = Reader.ReadUInt(); uint NumberIndexes = Reader.ReadUInt(); uint PropertiesOffset = Reader.ReadUInt(); uint NumberProperties = Reader.ReadUInt(); //if (BaseOffset == 0 || BaseLength == 0 || IndexesOffset == 0 || NumberIndexes == 0 || PropertiesOffset == 0 || NumberProperties == 0) //throw new Exception("The file doesn't match the D2P Pattern"); Reader.BaseStream.Seek(IndexesOffset, SeekOrigin.Begin); #region Read Indexers FilePositionDictionary = new Dictionary <string, FilePosition>(); var i = 0; while (i < NumberIndexes) { FilePositionDictionary.Add(Reader.ReadUTF(), new FilePosition(Reader.ReadInt(), Reader.ReadInt())); i++; } #endregion Reader.BaseStream.Seek(PropertiesOffset, SeekOrigin.Begin); #region Read Properties Properties = new Dictionary <string, string>(); i = 0; while (i < NumberProperties) { Properties.Add(Reader.ReadUTF(), Reader.ReadUTF()); i++; } #endregion isInitialized = true; } else { throw new Exception(string.Format("Header on file {0} not valid", D2pFilePath)); } }
public BuffItem(BigEndianReader reader) { _SourceType = (BuffSourceType)reader.ReadInt16(); reader.ReadInt16(); // unknown _IconID = reader.ReadInt16(); _QueueIndex = reader.ReadInt16(); reader.ReadInt32(); // unknown _Duration = reader.ReadInt16(); reader.ReadBytes(3); // unknown _TitleCliloc = reader.ReadInt32(); _SecondaryCliloc = reader.ReadInt32(); _TernaryCliloc = reader.ReadInt32(); _TitleArguments = reader.ReadUnicodeString(); _SecondaryArguments = reader.ReadUnicodeString(); _TernaryArguments = reader.ReadUnicodeString(); }
private void ImportAmbient_Click(object sender, EventArgs e) { OpenFileDialog o = new OpenFileDialog(); o.Filter = "Binary Ambient Light (*bambl)|*.bambl"; if (o.ShowDialog() == DialogResult.OK) { BigEndianReader Reader = new BigEndianReader(new MemoryStream(File.ReadAllBytes(o.FileName))); string Magic = Reader.ReadASCII(4); if (Magic != "BAML") { throw new WrongMagicException(Magic, "BAML", Reader.BaseStream.Position - 4); } Ambient.RGBALight = Reader.ReadBytes(4); Ambient.Padding = Reader.ReadUInt32(); Reader.Close(); dgwAmbient.Rows.Add(HexUtil.Hex8(Convert.ToByte(dgwAmbient.Rows.Count)), HexUtil.Hex8(Ambient.RGBALight[0]), HexUtil.Hex8(Ambient.RGBALight[1]), HexUtil.Hex8(Ambient.RGBALight[2]), HexUtil.Hex8(Ambient.RGBALight[3]), HexUtil.Hex32(Ambient.Padding)); } }
/// <summary> /// Procède a l'identification d'un client. /// </summary> /// <param name="client"></param> public static void ProcessIdentification(AuthClient client) { client.Send(new CredentialsAcknowledgementMessage()); if (!client.IsVersionUpToDate()) { client.Send(new IdentificationFailedForBadVersionMessage((sbyte)IdentificationFailureReasonEnum.BAD_VERSION, AuthConfiguration.Instance.GetVersionExtended())); return; } BigEndianReader reader = new BigEndianReader(client.IdentificationMessage.credentials.Select(x => (byte)x).ToArray()); string username = reader.ReadUTF(); string password = reader.ReadUTF(); client.AesKey = reader.ReadBytes(32); AccountData account = AccountRecord.GetAccountByUsername(username); if (account == null || account.Password != password) { client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.WRONG_CREDENTIALS)); return; } if (account.Banned || BanIpRecord.IsBanned(client.Ip)) { client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.BANNED)); return; } client.Account = account; if (client.Account.Nickname == null || client.Account.Nickname == string.Empty) { client.Send(new NicknameRegistrationMessage()); return; } Login(client, client.IdentificationMessage.autoconnect); }
private void ReadFile() { if (m_reader.ReadByte() != 76) { throw new Exception("Malformated swf file"); } Version = m_reader.ReadByte(); FrameRate = m_reader.ReadUInt(); var count = m_reader.ReadInt(); for (int i = 0; i < count; i++) { Classes.Add(m_reader.ReadUTF()); } SwfData = m_reader.ReadBytes((int)m_reader.BytesAvailable); }
/// <summary> /// ONLY CLIENT SIDE !!! /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public byte[] ReWriteInstanceId(uint instanceId) { using (BigEndianReader reader = new BigEndianReader(FullPacket)) { using (BigEndianWriter writer = new BigEndianWriter()) { // header writer.WriteShort(reader.ReadShort()); // instance id writer.WriteUnsignedInt(instanceId); // skip reader.ReadUnsignedInt(); // len + data writer.WriteBytes(reader.ReadBytes((int)reader.BytesAvailable)); return(writer.Data); } } }
protected override void Parse(BigEndianReader reader) { reader.ReadByte(); // ID _Size = reader.ReadUInt16(); _Unk1 = reader.ReadUInt32(); _CharSlot = reader.ReadUInt32(); _CharName = reader.ReadAsciiString(30); _Unk2 = reader.ReadAsciiString(30); _Profession = reader.ReadByte(); _Flags = reader.ReadByte(); _Gender = reader.ReadByte(); _Race = reader.ReadByte(); _Strength = reader.ReadByte(); _Dexterity = reader.ReadByte(); _Intelligence = reader.ReadByte(); _SkinColor = reader.ReadUInt16(); reader.ReadUInt32(); reader.ReadUInt32(); _Skill1 = reader.ReadByte(); _Skill1Amount = reader.ReadByte(); _Skill2 = reader.ReadByte(); _Skill2Amount = reader.ReadByte(); _Skill3 = reader.ReadByte(); _Skill3Amount = reader.ReadByte(); _Skill4 = reader.ReadByte(); _Skill4Amount = reader.ReadByte(); reader.ReadBytes(25); reader.ReadByte(); _HairHue = reader.ReadInt16(); _HairStyle = reader.ReadUInt16(); reader.ReadByte(); reader.ReadUInt32(); reader.ReadByte(); _ShirtColor = reader.ReadInt16(); _ShirtID = reader.ReadInt16(); reader.ReadByte(); _FaceColor = reader.ReadUInt16(); _FaceID = reader.ReadUInt16(); reader.ReadByte(); _BeardHue = reader.ReadInt16(); _BeardStyle = reader.ReadInt16(); }
public BuffItem( BigEndianReader reader ) { _SourceType = (BuffSourceType) reader.ReadInt16(); reader.ReadInt16(); // unknown _IconID = reader.ReadInt16(); _QueueIndex = reader.ReadInt16(); reader.ReadInt32(); // unknown _Duration = reader.ReadInt16(); reader.ReadBytes( 3 ); // unknown _TitleCliloc = reader.ReadInt32(); _SecondaryCliloc = reader.ReadInt32(); _TernaryCliloc = reader.ReadInt32(); _TitleArguments = reader.ReadUnicodeString(); _SecondaryArguments = reader.ReadUnicodeString(); _TernaryArguments = reader.ReadUnicodeString(); }