public void Show(Program program, ProgramResourceInstance resource) { var uiSvc = services.RequireService <IDecompilerShellUiService>(); var rsrcToString = ResourceToString(resource); var wnd = uiSvc.FindDocumentWindow("resEdit", resource); if (wnd == null) { wnd = uiSvc.CreateDocumentWindow( "resEdit", resource, resource.Name, new ResourceEditorInteractor(program, resource)); } wnd.Show(); }
public ResourceEditorInteractor(Program program, ProgramResourceInstance resource) { this.program = program; this.resource = resource; }
/// <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); }
private string ResourceToString(ProgramResourceInstance resource) { return(string.Format("{0}:{1}", resource.Type, resource.Name)); }
/// <summary> /// Reads in the NE image resources. /// </summary> public List <ProgramResource> LoadResources() { List <ProgramResource> resources = new List <ProgramResource>(); var rsrcTable = new LeImageReader(RawImage, OffRsrcTable); var rdr = rsrcTable.Clone(); ushort size_shift = rdr.ReadLeUInt16(); var resourceGroups = new Dictionary <ResourceType, ProgramResourceGroup>(); var iconIds = new Dictionary <ushort, ProgramResourceInstance>(); ushort rsrcType = rdr.ReadLeUInt16(); while (rsrcType != 0) { var rt = Win16ResourceType.FromInt(rsrcType); if (!resourceGroups.TryGetValue(rt, out var resGrp)) { resGrp = new ProgramResourceGroup { Name = rt.Name }; resourceGroups.Add(rt, 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(RawImage, offset); var rsrc = rdrRsrc.ReadBytes((uint)nameLength << size_shift); var rsrcInstance = new ProgramResourceInstance { Name = resname, Type = resGrp.Name, Bytes = rsrc, FileExtension = rt.FileExtension, }; resGrp.Resources.Add(rsrcInstance); if (rt == Win16ResourceType.Icon) { iconIds[(ushort)(nameId & ~0x8000)] = rsrcInstance; } } resources.Add(resGrp); rsrcType = rdr.ReadLeUInt16(); } PostProcessIcons(resourceGroups, iconIds, resources); PostProcessBitmaps(resourceGroups); return(resources); }
/// <summary> /// Reads in the NE resources from OS/2. /// </summary> public List <ProgramResource> LoadOs2Resources(NeImageLoader.NeSegment[] segments, ushort segmentCount, ushort alignmentShift) { List <ProgramResource> resources = new List <ProgramResource>(); var rsrcTable = new LeImageReader(RawImage, OffRsrcTable); var rdr = rsrcTable.Clone(); ResourceTableEntry[] entries = new ResourceTableEntry[ResourceTableEntries]; for (int i = 0; i < entries.Length; i++) { entries[i].etype = rdr.ReadUInt16(); entries[i].ename = rdr.ReadUInt16(); } NeImageLoader.NeSegment[] resourceSegments = new NeImageLoader.NeSegment[ResourceTableEntries]; Array.Copy(segments, segmentCount - ResourceTableEntries, resourceSegments, 0, ResourceTableEntries); NeImageLoader.NeSegment[] realSegments = new NeImageLoader.NeSegment[segmentCount - ResourceTableEntries]; Array.Copy(segments, 0, realSegments, 0, realSegments.Length); segments = realSegments; var os2Resources = new SortedDictionary <ushort, ProgramResourceGroup>(); for (int i = 0; i < entries.Length; i++) { os2Resources.TryGetValue(entries[i].etype, out ProgramResourceGroup resGrp); var rt = Os2ResourceType.FromInt(entries[i].etype); if (resGrp == null) { resGrp = new ProgramResourceGroup { Name = rt.Name } } ; uint length = resourceSegments[i].DataLength; var dataOffset = (uint)(resourceSegments[i].DataOffset << alignmentShift); if (length == 0) { length = 65536; } if (dataOffset == 0) { dataOffset = 65536; } if ((resourceSegments[i].Flags & (ushort)0x4000) != 0) { length <<= alignmentShift; } var rdrRsrc = new LeImageReader(RawImage, dataOffset); var rsrc = rdrRsrc.ReadBytes(length); var rsrcInstance = new ProgramResourceInstance { Name = $"{entries[i].ename}", Type = "Os2_" + resGrp.Name, Bytes = rsrc, FileExtension = rt.FileExtension }; resGrp.Resources.Add(rsrcInstance); os2Resources.Remove(entries[i].etype); os2Resources[entries[i].etype] = resGrp; } foreach (var kvp in os2Resources) { resources.Add(kvp.Value); } return(resources); } string ReadByteLengthString(EndianImageReader rdr, int offset) { var clone = rdr.Clone(); clone.Offset = clone.Offset + offset; var len = clone.ReadByte(); var abStr = clone.ReadBytes(len); return(Encoding.ASCII.GetString(abStr)); }
private string ResourceToString(ProgramResourceInstance resource) { var items = new List <string>(); return(string.Format("{0}:{1}", resource.Type, resource.Name)); }