public DictionaryNode(BinaryReader bin) { //Offset = (UInt32)bin.BaseStream.Position; NodeType = bin.ReadByte(); if (NodeType != 0xC1) { throw new Exception("Not a dictionary node !"); } List <byte> _count = new List <byte>(); _count.AddRange(bin.ReadBytes(3)); _count.Add(0x00); uint count = BitConverter.ToUInt32(_count.ToArray(), 0); if (count == 0) { return; } for (int i = 0; i < count; i++) { //Debug.Print("DICTIONARY SUBNODE AT: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); GenericNode g = new GenericNode(); List <byte> _stringIndex = new List <byte>(); _stringIndex.AddRange(bin.ReadBytes(3)); _stringIndex.Add(0x00); g.StringIndex = BitConverter.ToUInt32(_stringIndex.ToArray(), 0); g.NodeType = bin.ReadByte(); g.Value = bin.ReadBytes(4); if (g.Value == null) { throw new Exception("Value can't be null"); } if (g.NodeType == 0xC1) { long OldPos = bin.BaseStream.Position; bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0); //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); DictionaryNode dict = new DictionaryNode(bin); if (dict.SubNodes.Count != 0) { g.SubNodes = dict.SubNodes; } bin.BaseStream.Position = OldPos; } else if (g.NodeType == 0xC0) { long OldPos = bin.BaseStream.Position; bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0); //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); ArrayNode arr = new ArrayNode(bin); if (arr.SubNodes.Count != 0) { g.SubNodes = arr.SubNodes; } bin.BaseStream.Position = OldPos; }// else Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); SubNodes.Add(g); } }
public ArrayNode(BinaryReader bin) { //Offset = (UInt32)bin.BaseStream.Position; NodeType = bin.ReadByte(); if (NodeType != 0xC0) { throw new Exception("Not an array node !"); } List <byte> _count = new List <byte>(); _count.AddRange(bin.ReadBytes(3)); _count.Add(0x00); uint Count = BitConverter.ToUInt32(_count.ToArray(), 0); if (Count == 0) { return; } byte[] NodeTypes; NodeTypes = bin.ReadBytes((int)Count); if (bin is BigEndianReader) { Array.Reverse(NodeTypes); } while ((bin.BaseStream.Position % 4) != 0) { bin.ReadByte(); //Padding } for (int i = 0; i < Count; i++) { // Debug.Print("ARRAY SUBNODE AT: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); GenericNode g = new GenericNode(); g.NodeType = NodeTypes[i]; g.Value = bin.ReadBytes(4); if (g.NodeType == 0xC1) { long OldPos = bin.BaseStream.Position; bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0); //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); DictionaryNode dict = new DictionaryNode(bin); if (dict.SubNodes.Count != 0) { g.SubNodes = dict.SubNodes; } bin.BaseStream.Position = OldPos; } else if (g.NodeType == 0xC0) { long OldPos = bin.BaseStream.Position; bin.BaseStream.Position = BitConverter.ToUInt32(g.Value, 0); //Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); ArrayNode Arr = new ArrayNode(bin); if (Arr.SubNodes.Count != 0) { g.SubNodes = Arr.SubNodes; } bin.BaseStream.Position = OldPos; }//else Debug.Print(HelpFunctions.GetHexString(NodeType) + " node at: " + HelpFunctions.GetHexString((int)bin.BaseStream.Position)); SubNodes.Add(g); } }