public List<ProgramResource> Load() { var rsrcSection = new LeImageReader(this.imgLoaded, rvaResources); var rdr = rsrcSection.Clone(); return ReadResourceDirectory(rdr); }
/// <summary> /// Reads in the NE image resources. /// </summary> //$REFACTOR: resource loading seems to want to belong in a separate file. private void LoadResources(List<ProgramResource> resources) { var rsrcTable = new LeImageReader(RawImage, this.lfaNew + offRsrcTable); var rdr = rsrcTable.Clone(); ushort size_shift = rdr.ReadLeUInt16(); ProgramResourceGroup bitmaps = null; ProgramResourceGroup iconGroups = null; ProgramResourceGroup icons = null; var iconIds = new Dictionary<ushort, ProgramResourceInstance>(); ushort rsrcType = rdr.ReadLeUInt16(); while (rsrcType != 0) { var resGrp = new ProgramResourceGroup { Name = GetResourceType(rsrcType) }; if (rsrcType == NE_RSCTYPE_GROUP_ICON) iconGroups = resGrp; else if (rsrcType == NE_RSCTYPE_ICON) icons = resGrp; else if (rsrcType == NE_RSCTYPE_BITMAP) bitmaps = resGrp; ushort typeCount = rdr.ReadLeUInt16(); uint resLoader = rdr.ReadLeUInt32(); for (int count = typeCount; count > 0; --count) { ushort nameOffset = rdr.ReadLeUInt16(); ushort nameLength = rdr.ReadLeUInt16(); ushort nameFlags = rdr.ReadLeUInt16(); ushort nameId = rdr.ReadLeUInt16(); ushort nameHandle = rdr.ReadLeUInt16(); ushort nameUsage = rdr.ReadLeUInt16(); string resname; if ((nameId & 0x8000) != 0) { resname = (nameId & ~0x8000).ToString(); } else { resname = ReadByteLengthString(rsrcTable, nameId); } var offset = (uint)nameOffset << size_shift; var rdrRsrc = new LeImageReader(base.RawImage, offset); var rsrc = rdrRsrc.ReadBytes((uint)nameLength << size_shift); var rsrcInstance = new ProgramResourceInstance { Name = resname, Type = "Win16_" + resGrp.Name, Bytes = rsrc, }; resGrp.Resources.Add(rsrcInstance); if (rsrcType == NE_RSCTYPE_ICON) iconIds[(ushort)(nameId & ~0x8000)] = rsrcInstance; } resources.Add(resGrp); rsrcType = rdr.ReadLeUInt16(); } PostProcessIcons(iconGroups, icons, iconIds, resources); PostProcessBitmaps(bitmaps); }