public StringTableEntry GetStringTableEntry(uint offset) { if (StringTableEntries.ContainsKey(offset)) { return(StringTableEntries[offset]); } var index = (int)offset + 4; //unknown bytes, so skip var hash = BitConverter.ToUInt16(ChunkBytes, index); index += 2; var stringLen = BitConverter.ToUInt16(ChunkBytes, index); index += 2; var stringVal = Encoding.Unicode.GetString(ChunkBytes, index, stringLen * 2); var entrySize = 4 + 2 + 2 + stringLen * 2 + 2; //unknown + hash + len + null StringTableEntries.Add(offset, new StringTableEntry(offset, hash, stringVal, entrySize)); return(new StringTableEntry(offset, hash, stringVal, entrySize)); }
public SdbFile(byte[] rawBytes, string sourceFile) { RawBytes = rawBytes; SourceFile = Path.GetFullPath(sourceFile); MajorVersion = BitConverter.ToInt32(rawBytes, 0); MinorVersion = BitConverter.ToInt32(rawBytes, 4); var logger = LogManager.GetCurrentClassLogger(); logger.Debug($"Major: {MajorVersion}, Minor: {MinorVersion}"); var index = 0xc; StringTableEntries.Clear(); Metrics.Clear(); Children = new List <ISdbEntry>(); while (index < rawBytes.Length) { var id = (TagValue)BitConverter.ToUInt16(rawBytes, index); index += 2; var tagType = (int)id & 0xF000; if (tagType == 0x7000) { //lists look like: //tag //length //data ('length' bytes long) var size = BitConverter.ToInt32(rawBytes, index); index += 4; var buff = new byte[size]; Buffer.BlockCopy(rawBytes, index, buff, 0, size); var c = new Chunk(id, buff, index - 2 - 4); var l = new SdbEntryList(id, buff, index - 2 - 4); foreach (var sdbEntry in c.Children) { if (!(sdbEntry is SdbEntryList)) { sdbEntry.Offset += 4; } l.Children.Add(sdbEntry); } Children.Add(l); index += size; } else { throw new Exception( $"Unexpected Tag type '0x{tagType:X4}'! Please send this sdb file to [email protected] so suppoprt can be added!"); } } }