public void AddEntry(CASResult blte) { if (blte == null) { return; } // create the entry var entry = new EncodingEntry() { DecompressedSize = blte.DecompressedSize, Hash = blte.DataHash, }; entry.Keys.Add(blte.Hash); if (Data.ContainsKey(blte.DataHash)) // check if it exists { var existing = Data[blte.DataHash]; if (Layout.ContainsKey(existing.Keys[0])) // remove old layout { Layout.Remove(existing.Keys[0]); } existing.Keys[0] = blte.Hash; // update existing entry } else { Data.Add(entry.Hash, entry); // new entry } AddLayoutEntry(blte); }
public static void ReadEncodingFile(Stream fs) { if (fs != null) { using (BinaryReader br = new BinaryReader(fs)) { br.ReadBytes(2); //byte b1 = br.ReadByte(); //byte b2 = br.ReadByte(); //byte b3 = br.ReadByte(); //ushort s1 = br.ReadUInt16(); //ushort s2 = br.ReadUInt16(); br.ReadBytes(7); int numEntries = ReadInt32BE(br); //int i1 = ReadInt32BE(br); //byte b4 = br.ReadByte(); br.ReadBytes(5); int entriesOfs = ReadInt32BE(br); fs.Position += entriesOfs; // skip strings fs.Position += numEntries * 32; for (int i = 0; i < numEntries; ++i) { ushort keysCount; while (true) { keysCount = br.ReadUInt16(); if (keysCount == 0) { break; } int fileSize = ReadInt32BE(br); byte[] md5 = br.ReadBytes(16); EncodingEntry entry = new EncodingEntry(); entry.EncodingEntryInit(); entry.Size = fileSize; List <byte[]> entryKeysList = new List <byte[]>(); for (int ki = 0; ki < keysCount; ++ki) { byte[] key = br.ReadBytes(16); entryKeysList.Add(key); } entry.Keys = entryKeysList; EncodingData.Add(ByteString(md5), entry); } while (br.PeekChar() == 0) { fs.Position++; } } fs.Close(); fs = null; } } else { Debug.Log("ReadEncodingFile null"); } }
public void LoadEntries(DataFile file, IndexEntry indexEntry) { var blteEntry = new BinaryReader(DataFile.LoadBLTEEntry(indexEntry, file.readStream)); blteEntry.BaseStream.Position = 9; var entries = blteEntry.ReadBEUInt32(); blteEntry.BaseStream.Position += 5; var offsetEntries = blteEntry.ReadBEUInt32(); blteEntry.BaseStream.Position += offsetEntries + (entries << 5); for (var i = 0; i < entries; i++) { var keys = blteEntry.ReadUInt16(); while (keys != 0) { var encodingEntry = new EncodingEntry { Keys = new byte[keys][], Size = blteEntry.ReadBEUInt32() }; var md5 = blteEntry.ReadBytes(16); for (var j = 0; j < keys; j++) { encodingEntry.Keys[j] = blteEntry.ReadBytes(16); } this.entries.Add(md5, encodingEntry); keys = blteEntry.ReadUInt16(); } while (blteEntry.ReadByte() == 0) { ; } blteEntry.BaseStream.Position -= 1; } }
bool IWizardPagePresenter.ExitPage(bool movingForward) { XmlNode patternsRoot = formatRoot.SelectSingleNode("patterns"); if (patternsRoot == null) { patternsRoot = formatRoot.AppendChild(formatRoot.OwnerDocument.CreateElement("patterns")); } patternsRoot.RemoveAll(); foreach (string e in patterns) { patternsRoot.AppendChild(patternsRoot.OwnerDocument.CreateElement("pattern")).InnerText = e; } EncodingEntry ee = encodings.ElementAtOrDefault(view.EncodingComboBoxSelection); string encodingXMLCode = (ee != null) ? ee.ToXMLString() : "ACP"; XmlNode encodingNode = formatRoot.SelectSingleNode("encoding"); if (encodingNode == null) { encodingNode = formatRoot.AppendChild(formatRoot.OwnerDocument.CreateElement("encoding")); } encodingNode.InnerText = encodingXMLCode; XmlNode dejitterNode = formatRoot.SelectSingleNode("dejitter"); if (view.EnableDejitterCheckBoxChecked) { if (dejitterNode == null) { dejitterNode = formatRoot.AppendChild(formatRoot.OwnerDocument.CreateElement("dejitter")); } ((XmlElement)dejitterNode).SetAttribute("jitter-buffer-size", dejitterBufferStepper.Value.ToString()); } else { if (dejitterNode != null) { dejitterNode.ParentNode.RemoveChild(dejitterNode); } } return(true); }
public EncodingHandler(BLTEStream blte) { if (blte.Length != long.Parse(CASContainer.BuildConfig["encoding-size"][0])) { CASContainer.Settings?.Logger.LogAndThrow(Logging.LogType.Critical, "Encoding File is corrupt."); } BinaryReader stream = new BinaryReader(blte); Header = new EncodingHeader() { Magic = stream.ReadBytes(2), Version = stream.ReadByte(), ChecksumSizeA = stream.ReadByte(), ChecksumSizeB = stream.ReadByte(), FlagsA = stream.ReadUInt16(), FlagsB = stream.ReadUInt16(), NumEntriesA = stream.ReadUInt32BE(), NumEntriesB = stream.ReadUInt32BE(), StringBlockSize = stream.ReadUInt40BE() }; // stringTableA LayoutStringTable.AddRange(Encoding.ASCII.GetString(stream.ReadBytes((int)Header.StringBlockSize)).Split('\0')); // skip header block A stream.ReadBytes((int)Header.NumEntriesA * 32); // encoding table entry block for (int i = 0; i < Header.NumEntriesA; i++) { long start = stream.BaseStream.Position; ushort keysCount; while ((keysCount = stream.ReadUInt16()) != 0) { EncodingEntry entry = new EncodingEntry() { DecompressedSize = stream.ReadUInt32BE(), Hash = new MD5Hash(stream) }; for (int ki = 0; ki < keysCount; ki++) { entry.Keys.Add(new MD5Hash(stream)); } Data.Add(entry.Hash, entry); } if (stream.BaseStream.Position % CHUNK_SIZE != 0) { stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE); } } // skip header block B stream.ReadBytes((int)Header.NumEntriesB * 32); // layout table entry block for (int i = 0; i < Header.NumEntriesB; i++) { long start = stream.BaseStream.Position; MD5Hash hash; while (!(hash = new MD5Hash(stream)).IsEmpty) { var entry = new EncodingLayout() { Hash = hash, StringIndex = stream.ReadUInt32BE(), Size = stream.ReadUInt40BE() }; Layout.Add(entry.Hash, entry); } if (stream.BaseStream.Position % CHUNK_SIZE != 0) { stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE); } } stream.ReadBytes((int)(stream.BaseStream.Length - stream.BaseStream.Position)); //EncodingStringTable EncodingMap = blte.EncodingMap.ToArray(); blte?.Dispose(); stream?.Dispose(); }