Add panel to view OS/2 icons, bitmaps and pointers in NE executables.

This commit is contained in:
2018-03-05 15:01:57 +00:00
parent 2c89daf694
commit 6b988e16fb
4 changed files with 182 additions and 2 deletions

View File

@@ -27,6 +27,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using exeinfogui.Os2;
using exeinfogui.Win16; using exeinfogui.Win16;
using Eto.Forms; using Eto.Forms;
using Eto.Serialization.Xaml; using Eto.Serialization.Xaml;
@@ -35,13 +36,14 @@ namespace exeinfogui.NE
{ {
public class TabNeResources : TabPage public class TabNeResources : TabPage
{ {
PanelHexDump panelHexDump;
PanelNeAccelerators panelNeAccelerators; PanelNeAccelerators panelNeAccelerators;
PanelNeStrings panelNeStrings; PanelNeStrings panelNeStrings;
PanelOs2Bitmap panelOs2Bitmap;
PanelWin16Version panelWin16Version; PanelWin16Version panelWin16Version;
Panel pnlResource; Panel pnlResource;
TreeGridItemCollection treeData; TreeGridItemCollection treeData;
TreeGridView treeResources; TreeGridView treeResources;
PanelHexDump panelHexDump;
public TabNeResources() public TabNeResources()
{ {
@@ -57,7 +59,8 @@ namespace exeinfogui.NE
panelWin16Version = new PanelWin16Version(); panelWin16Version = new PanelWin16Version();
panelNeStrings = new PanelNeStrings(); panelNeStrings = new PanelNeStrings();
panelNeAccelerators = new PanelNeAccelerators(); panelNeAccelerators = new PanelNeAccelerators();
panelHexDump=new PanelHexDump(); panelHexDump = new PanelHexDump();
panelOs2Bitmap = new PanelOs2Bitmap();
} }
public void Update(IEnumerable<libexeinfo.NE.ResourceType> resourceTypes, libexeinfo.NE.TargetOS os) public void Update(IEnumerable<libexeinfo.NE.ResourceType> resourceTypes, libexeinfo.NE.TargetOS os)
@@ -116,6 +119,18 @@ namespace exeinfogui.NE
case "RT_ACCELTABLE": case "RT_ACCELTABLE":
pnlResource.Content = panelNeAccelerators; pnlResource.Content = panelNeAccelerators;
panelNeAccelerators.Update(data, libexeinfo.NE.TargetOS.OS2); panelNeAccelerators.Update(data, libexeinfo.NE.TargetOS.OS2);
break;
case "RT_BITMAP" when (libexeinfo.NE.TargetOS)((TreeGridItem)treeResources.SelectedItem).Values[4] ==
libexeinfo.NE.TargetOS.OS2:
case "RT_POINTER":
// TODO: Some do not contain valid OS/2 bitmaps
try
{
pnlResource.Content = panelOs2Bitmap;
panelOs2Bitmap.Update(data);
}
catch { goto default; }
break; break;
default: default:
pnlResource.Content = panelHexDump; pnlResource.Content = panelHexDump;

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<Panel xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackLayout Orientation="Horizontal">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True" VerticalAlignment="Stretch">
<GridView ID="grdIcons"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Expand="True">
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Label ID="lblType">Type</Label>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<TextBox ID="txtType" ReadOnly="True"/>
</StackLayoutItem>
</StackLayout>
<StackLayout Orientation="Horizontal">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Label ID="lblSize">Size</Label>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<TextBox ID="txtSize" ReadOnly="True"/>
</StackLayoutItem>
</StackLayout>
<StackLayout Orientation="Horizontal">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Label ID="lblColors">Colors</Label>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<TextBox ID="txtColors" ReadOnly="True"/>
</StackLayoutItem>
</StackLayout>
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Expand="True">
<ImageView ID="imgIcon"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Expand="True">
<Panel ID="pnlPanel"/>
</StackLayoutItem>
</StackLayout>
</StackLayoutItem>
</StackLayout>
</Panel>

View File

@@ -0,0 +1,122 @@
using System;
using Eto.Drawing;
using Eto.Forms;
using Eto.Serialization.Xaml;
using Bitmap = libexeinfo.Os2.Bitmap;
namespace exeinfogui.Os2
{
public class PanelOs2Bitmap : Panel
{
GridView grdIcons;
ImageView imgIcon;
Label lblColors;
Label lblSize;
Label lblType;
PanelHexDump panelHexDump;
Panel pnlPanel;
TextBox txtColors;
TextBox txtSize;
TextBox txtType;
public PanelOs2Bitmap()
{
XamlReader.Load(this);
grdIcons.Columns.Add(new GridColumn
{
DataCell =
new TextBoxCell {Binding = Binding.Property<Bitmap.DecodedBitmap, string>(b => $"{b.Type}")},
HeaderText = "Command"
});
grdIcons.Columns.Add(new GridColumn
{
DataCell = new TextBoxCell
{
Binding = Binding.Property<Bitmap.DecodedBitmap, string>(b => $"{b.Width}x{b.Height}")
},
HeaderText = "Size"
});
grdIcons.Columns.Add(new GridColumn
{
DataCell = new TextBoxCell
{
Binding = Binding.Property<Bitmap.DecodedBitmap, string>(b => $"{1 << (int)b.BitsPerPixel}")
},
HeaderText = "Colors"
});
grdIcons.AllowMultipleSelection = false;
grdIcons.SelectionChanged += GrdIconsOnSelectionChanged;
panelHexDump = new PanelHexDump();
pnlPanel.Content = panelHexDump;
}
void GrdIconsOnSelectionChanged(object sender, EventArgs eventArgs)
{
if(!(grdIcons.SelectedItem is Bitmap.DecodedBitmap icon))
{
imgIcon.Image = null;
return;
}
txtType.Text = icon.Type;
txtSize.Text = $"{icon.Width}x{icon.Height} pixels";
txtColors.Text = $"{1 << (int)icon.BitsPerPixel} ({icon.BitsPerPixel} bpp)";
imgIcon.Image =
new Eto.Drawing.Bitmap((int)icon.Width, (int)icon.Height, PixelFormat.Format32bppRgba, icon.Pixels);
}
public void Update(byte[] data)
{
if(data == null)
{
imgIcon.Image = null;
grdIcons.Visible = false;
lblType.Text = "No data";
lblColors.Visible = false;
lblSize.Visible = false;
txtType.Visible = false;
txtColors.Visible = false;
txtSize.Visible = false;
pnlPanel.Visible = false;
return;
}
Bitmap.DecodedBitmap[] icons = Bitmap.DecodeBitmap(data);
if(icons == null || icons.Length == 0)
{
imgIcon.Image = null;
grdIcons.Visible = false;
lblType.Text = "Undecoded";
lblColors.Visible = false;
lblSize.Visible = false;
txtType.Visible = false;
txtColors.Visible = false;
txtSize.Visible = false;
pnlPanel.Visible = true;
panelHexDump.Update(data);
return;
}
txtType.Text = icons[0].Type;
txtSize.Text = $"{icons[0].Width}x{icons[0].Height} pixels";
txtColors.Text = $"{1 << (int)icons[0].BitsPerPixel} ({icons[0].BitsPerPixel} bpp)";
imgIcon.Image = new Eto.Drawing.Bitmap((int)icons[0].Width, (int)icons[0].Height,
PixelFormat.Format32bppRgba, icons[0].Pixels);
grdIcons.DataStore = icons;
grdIcons.SelectedRow = 0;
grdIcons.Visible = icons.Length != 1;
lblType.Text = "Type";
lblColors.Visible = true;
lblSize.Visible = true;
txtType.Visible = true;
txtColors.Visible = true;
txtSize.Visible = true;
pnlPanel.Visible = false;
}
}
}

View File

@@ -22,5 +22,6 @@
<Folder Include="NE" /> <Folder Include="NE" />
<Folder Include="NE\" /> <Folder Include="NE\" />
<Folder Include="Win16\" /> <Folder Include="Win16\" />
<Folder Include="Os2\" />
</ItemGroup> </ItemGroup>
</Project> </Project>