void WriteResourceDirectoryTable(ResourceDirectoryTable rdt) { GotoOffset(rdt.Offset); m_writer.Write(rdt.Characteristics); m_writer.Write(rdt.TimeDateStamp); m_writer.Write(rdt.MajorVersion); m_writer.Write(rdt.MinorVersion); ResourceDirectoryEntry [] namedEntries = GetEntries(rdt, true); ResourceDirectoryEntry [] idEntries = GetEntries(rdt, false); m_writer.Write((ushort)namedEntries.Length); m_writer.Write((ushort)idEntries.Length); foreach (ResourceDirectoryEntry rde in namedEntries) { WriteResourceDirectoryEntry(rde); } foreach (ResourceDirectoryEntry rde in idEntries) { WriteResourceDirectoryEntry(rde); } RestoreOffset(); }
ResourceDirectoryEntry [] GetEntries(ResourceDirectoryTable rdt, bool identifiedByName) { ArrayList entries = new ArrayList(); foreach (ResourceDirectoryEntry rde in rdt.Entries) { if (rde.IdentifiedByName == identifiedByName) { entries.Add(rde); } } return(entries.ToArray(typeof(ResourceDirectoryEntry)) as ResourceDirectoryEntry []); }
void ComputeOffset(ResourceDirectoryTable root) { int offset = 0; Queue directoryTables = new Queue (); directoryTables.Enqueue (root); while (directoryTables.Count > 0) { ResourceDirectoryTable rdt = directoryTables.Dequeue () as ResourceDirectoryTable; rdt.Offset = offset; offset += 16; foreach (ResourceDirectoryEntry rde in rdt.Entries) { rde.Offset = offset; offset += 8; if (rde.IdentifiedByName) m_stringEntries.Add (rde.Name); if (rde.Child is ResourceDirectoryTable) directoryTables.Enqueue (rde.Child); else m_dataEntries.Add (rde.Child); } } foreach (ResourceDataEntry rde in m_dataEntries) { rde.Offset = offset; offset += 16; } foreach (ResourceDirectoryString rds in m_stringEntries) { rds.Offset = offset; byte [] str = Encoding.Unicode.GetBytes (rds.String); offset += 2 + str.Length; offset += 3; offset &= ~3; } foreach (ResourceDataEntry rde in m_dataEntries) { rde.Data = (uint) offset; offset += rde.ResourceData.Length; offset += 3; offset &= ~3; } m_writer.Write (new byte [offset]); }
ResourceDirectoryTable ReadDirectoryTable () { ResourceDirectoryTable rdt = new ResourceDirectoryTable (GetOffset ()); rdt.Characteristics = m_reader.ReadUInt32 (); rdt.TimeDateStamp = m_reader.ReadUInt32 (); rdt.MajorVersion = m_reader.ReadUInt16 (); rdt.MinorVersion = m_reader.ReadUInt16 (); ushort nameEntries = m_reader.ReadUInt16 (); ushort idEntries = m_reader.ReadUInt16 (); for (int i = 0; i < nameEntries; i++) rdt.Entries.Add (ReadDirectoryEntry ()); for (int i = 0; i < idEntries; i++) rdt.Entries.Add (ReadDirectoryEntry ()); return rdt; }
ResourceDirectoryTable ReadDirectoryTable() { ResourceDirectoryTable rdt = new ResourceDirectoryTable(GetOffset()); rdt.Characteristics = m_reader.ReadUInt32(); rdt.TimeDateStamp = m_reader.ReadUInt32(); rdt.MajorVersion = m_reader.ReadUInt16(); rdt.MinorVersion = m_reader.ReadUInt16(); ushort nameEntries = m_reader.ReadUInt16(); ushort idEntries = m_reader.ReadUInt16(); for (int i = 0; i < nameEntries; i++) { rdt.Entries.Add(ReadDirectoryEntry()); } for (int i = 0; i < idEntries; i++) { rdt.Entries.Add(ReadDirectoryEntry()); } return(rdt); }
void ComputeOffset(ResourceDirectoryTable root) { int offset = 0; Queue directoryTables = new Queue(); directoryTables.Enqueue(root); while (directoryTables.Count > 0) { ResourceDirectoryTable rdt = directoryTables.Dequeue() as ResourceDirectoryTable; rdt.Offset = offset; offset += 16; foreach (ResourceDirectoryEntry rde in rdt.Entries) { rde.Offset = offset; offset += 8; if (rde.IdentifiedByName) { m_stringEntries.Add(rde.Name); } if (rde.Child is ResourceDirectoryTable) { directoryTables.Enqueue(rde.Child); } else { m_dataEntries.Add(rde.Child); } } } foreach (ResourceDataEntry rde in m_dataEntries) { rde.Offset = offset; offset += 16; } foreach (ResourceDirectoryString rds in m_stringEntries) { rds.Offset = offset; byte [] str = Encoding.Unicode.GetBytes(rds.String); offset += 2 + str.Length; offset += 3; offset &= ~3; } foreach (ResourceDataEntry rde in m_dataEntries) { rde.Data = (uint)offset; offset += rde.ResourceData.Length; offset += 3; offset &= ~3; } m_writer.Write(new byte [offset]); }
void WriteResourceDirectoryTable(ResourceDirectoryTable rdt) { GotoOffset (rdt.Offset); m_writer.Write (rdt.Characteristics); m_writer.Write (rdt.TimeDateStamp); m_writer.Write (rdt.MajorVersion); m_writer.Write (rdt.MinorVersion); ResourceDirectoryEntry [] namedEntries = GetEntries (rdt, true); ResourceDirectoryEntry [] idEntries = GetEntries (rdt, false); m_writer.Write ((ushort) namedEntries.Length); m_writer.Write ((ushort) idEntries.Length); foreach (ResourceDirectoryEntry rde in namedEntries) WriteResourceDirectoryEntry (rde); foreach (ResourceDirectoryEntry rde in idEntries) WriteResourceDirectoryEntry (rde); RestoreOffset (); }
ResourceDirectoryEntry[] GetEntries(ResourceDirectoryTable rdt, bool identifiedByName) { ArrayList entries = new ArrayList (); foreach (ResourceDirectoryEntry rde in rdt.Entries) if (rde.IdentifiedByName == identifiedByName) entries.Add (rde); return entries.ToArray (typeof (ResourceDirectoryEntry)) as ResourceDirectoryEntry []; }