Add decoding of Windows icons, panel for RT_ICON resources in NE, and detect Windows icon inside OS/2 RT_POINTER resources in NE.

This commit is contained in:
2018-03-06 15:48:43 +00:00
parent 54cc979d0e
commit 095221a349
8 changed files with 362 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ using System.Collections.Generic;
using System.Linq;
using exeinfogui.Os2;
using exeinfogui.Win16;
using exeinfogui.Windows;
using Eto.Forms;
using Eto.Serialization.Xaml;
@@ -41,6 +42,7 @@ namespace exeinfogui.NE
PanelNeStrings panelNeStrings;
PanelOs2Bitmap panelOs2Bitmap;
PanelWin16Version panelWin16Version;
PanelWindowsIcon panelWindowsIcon;
Panel pnlResource;
TreeGridItemCollection treeData;
TreeGridView treeResources;
@@ -61,6 +63,7 @@ namespace exeinfogui.NE
panelNeAccelerators = new PanelNeAccelerators();
panelHexDump = new PanelHexDump();
panelOs2Bitmap = new PanelOs2Bitmap();
panelWindowsIcon = new PanelWindowsIcon();
}
public void Update(IEnumerable<libexeinfo.NE.ResourceType> resourceTypes, libexeinfo.NE.TargetOS os)
@@ -131,6 +134,10 @@ namespace exeinfogui.NE
}
catch { goto default; }
break;
case "RT_ICON":
pnlResource.Content = panelWindowsIcon;
panelWindowsIcon.Update(data);
break;
default:
pnlResource.Content = panelHexDump;

View File

@@ -86,6 +86,35 @@ namespace exeinfogui.Os2
Bitmap.DecodedBitmap[] icons = Bitmap.DecodeBitmap(data);
if(icons == null || icons.Length == 0)
try
{
libexeinfo.Windows.Bitmap.DecodedBitmap winIcon = null;
if(BitConverter.ToUInt32(data, 4) == 40)
{
byte[] cursor = new byte[data.Length - 4];
Array.Copy(data, 4, cursor, 0, cursor.Length);
winIcon = libexeinfo.Windows.Bitmap.DecodeIcon(cursor);
}
else if(BitConverter.ToUInt32(data, 0) == 40)
winIcon = libexeinfo.Windows.Bitmap.DecodeIcon(data);
if(winIcon != null)
icons = new[]
{
new Bitmap.DecodedBitmap
{
BitsPerPixel = winIcon.BitsPerPixel,
Height = winIcon.Height,
Pixels = winIcon.Pixels,
Type = "Windows cursor",
Width = winIcon.Width
}
};
}
catch { icons = null; }
if(icons == null || icons.Length == 0)
{
imgIcon.Image = null;

View File

@@ -0,0 +1,27 @@
<?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="Vertical">
<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>
</Panel>

View File

@@ -0,0 +1,70 @@
using Eto.Drawing;
using Eto.Forms;
using Eto.Serialization.Xaml;
using Bitmap = libexeinfo.Windows.Bitmap;
namespace exeinfogui.Windows
{
public class PanelWindowsIcon : Panel
{
ImageView imgIcon;
Label lblColors;
Label lblSize;
PanelHexDump panelHexDump;
Panel pnlPanel;
TextBox txtColors;
TextBox txtSize;
public PanelWindowsIcon()
{
XamlReader.Load(this);
panelHexDump = new PanelHexDump();
pnlPanel.Content = panelHexDump;
}
public void Update(byte[] data)
{
if(data == null)
{
imgIcon.Image = null;
lblSize.Text = "No data";
lblColors.Visible = false;
lblSize.Visible = false;
txtColors.Visible = false;
txtSize.Visible = false;
pnlPanel.Visible = false;
return;
}
Bitmap.DecodedBitmap icon;
try { icon = Bitmap.DecodeIcon(data); }
catch { icon = null; }
if(icon == null)
{
imgIcon.Image = null;
lblSize.Text = "Undecoded";
lblColors.Visible = false;
lblSize.Visible = false;
txtColors.Visible = false;
txtSize.Visible = false;
pnlPanel.Visible = true;
panelHexDump.Update(data);
return;
}
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);
lblSize.Text = "Size";
lblColors.Visible = true;
lblSize.Visible = true;
txtColors.Visible = true;
txtSize.Visible = true;
pnlPanel.Visible = false;
}
}
}

View File

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