Example #1
0
        protected void OnBtnPathClick(object sender, EventArgs e)
        {
            OpenFileDialog dlgOpenFileDialog = new OpenFileDialog {
                MultiSelect = false
            };

            dlgOpenFileDialog.Filters.Add(new FileFilter {
                Extensions = new[] { ".ico", ".ptr", ".bmp" }
            });
            DialogResult result = dlgOpenFileDialog.ShowDialog(this);

            if (result != DialogResult.Ok)
            {
                txtPath.Text       = "";
                imgIcon.Image      = null;
                grdIcons.DataStore = null;
                return;
            }

            txtPath.Text = dlgOpenFileDialog.FileName;
            FileStream fstream = new FileStream(dlgOpenFileDialog.FileName, FileMode.Open);

            byte[] data = new byte[fstream.Length];
            fstream.Read(data, 0, data.Length);
            fstream.Dispose();

            DecodedBitmap[] icons = Bitmap.DecodeBitmap(data);
            imgIcon.Image = new Eto.Drawing.Bitmap((int)icons[0].Width, (int)icons[0].Height,
                                                   PixelFormat.Format32bppRgba, icons[0].Pixels);
            grdIcons.DataStore = icons;
            grdIcons.Visible   = icons.Length != 1;
        }
Example #2
0
        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;
            }

            DecodedBitmap[] icons = Bitmap.DecodeBitmap(data);

            if (icons == null || icons.Length == 0)
            {
                try
                {
                    libexeinfo.Windows.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 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;
                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;
        }