public byte[] Export(string[] Strings) { BinStrTbl[] OutTbl = new BinStrTbl[Structs.Length]; Structs.CopyTo(OutTbl, 0); using (MemoryStream Output = new MemoryStream()) { uint BuffPos = 0; for (uint t = 0, x = 0; t < OutTbl.Length; t++) { BinStrTbl Table = OutTbl[t]; for (int i = 0; i < Table.Strings.Length; i++) { Table.Strings[i] = Strings[x++]; } for (uint i = BuffPos; i < Offsets[t]; i++) { Output.WriteByte(Data[i]); } BuffPos += Offsets[t]; BuffPos += Lengths[t]; byte[] Binary = Tools.BuildStruct(ref Table, false, Encoding); Output.Write(Binary, 0, Binary.Length); } for (uint i = BuffPos; i < Data.Length; i++) { Output.WriteByte(Data[i]); } return(Output.ToArray()); } }
public string[] Import() { Structs = new BinStrTbl[0]; Offsets = new uint[0]; Lengths = new uint[0]; string[] Result = new string[0]; for (uint i = 1; i < Data.Length; i++) { if (MatchAt(Data, i)) { while (Data[--i] == 0x00) { continue; } while (Data[i - 1] != 0x00) { i--; } while ((i - (Structs.Length != 0 ? Offsets.Last() + Lengths.Last() : 0)) % 4 != 0) { i--; } uint Cnt = BitConverter.ToUInt32(new byte[] { Data[i], Data[i + 1], Data[i + 2], Data[i + 3] }, 0); if (Cnt * 2 > Data.Length) { continue; } BinStrTbl StringData = new BinStrTbl(); try { uint Len = (uint)Tools.ReadStruct(Data, ref StringData, false, Encoding, i); AppendArray(ref Structs, new BinStrTbl[] { StringData }); AppendArray(ref Offsets, new uint[] { i }); AppendArray(ref Lengths, new uint[] { Len }); AppendArray(ref Result, StringData.Strings); i += Len - 1; } catch { continue; } } } return(Result); }