Skip Menu |

This queue is for tickets about the Win32-Exe CPAN distribution.

Report information
The Basics
Id: 56234
Status: rejected
Priority: 0/
Queue: Win32-Exe

People
Owner: Nobody in particular
Requestors: RPKELLY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.11
Fixed in: (no value)



Subject: Corruption of EXEs when setting Icons
Sometimes, Win32::Exe will write back a corrupted EXE which cannot be run when setting the icon files in the executable. Attached are two icon files, and an exe. Using an.ico will not corrupt the executable, but nm.ico will. Altering sub "set_icons" in Win32/Exe.pm to the following fixes the issue: sub set_icons { my ($self, $icons) = @_; my $rsrc = $self->resource_section; my @gicons = $rsrc->objects('GroupIcon'); foreach my $gicon (@gicons) { my $group = $self->require_class('Resource::GroupIcon')->new; $group->SetPathName($gicon->PathName); $group->set_parent($rsrc); $rsrc->insert($group->PathName, $group); $group->set_icons($icons); $group->refresh; } } Note that making this change will cause test #12 (line 41) in file 2-icon.t to fail because the size of the resulting executable is larger. Thanks, -Ryan Kelly
Subject: nm.ico
Download nm.ico
image/x-icon 42.3k
nm.ico
Subject: an.ico
Download an.ico
image/x-icon 97.3k
an.ico
Subject: runner.exe
Download runner.exe
application/octet-stream 91.5k

Message body not shown because it is not plain text.

Hi, The exec image produced by Win32::Exe using nm.ico and runner.exe is not corrupted. After updating you can see the icon images for the executable in explorer, you can view the version information etc etc. The issue is that originally, runner.exe has three icon resources named IDI_APPICON, IDI_DOCUMENT and #32512 Within the runner.exe code attempts are probably made to load the resource named IDI_APPICON, which fail and give the spurious 'not a valid application' messages. Your code change replaces all existing icon resources with a copy of nm.ico, but keeps the original names. This happens to work for runner.exe but is a big change in behaviour for the method set_icons. The Windows resource loading methods are inconsistent (clearly). It would appear that when a resource with id IDI_APPICON is requested, IF this is not present Windows defaults to the first GROUPICON and must find an icon of the requested type in there. If, however, IDI_APPICON is found, Windows is not so fussy about finding the exact type in it and will convert the nearest compatible type. Hence, existing Win32::Exe code works with an.ico, which has necessary 32 bit images, but not with nm.ico. If, however, a resource with IDI_APPICON is created, it apparently does not matter what gets stuffed in there. Anyhow, I would think if you are changing the icons of an application that expects certain things at certain id's, that is going to be application specific and not something that can or should be dealt with by the generic 'set_icons' method. I shall use your code as the basis for adding a few methods 'list_groupicon_names' 'replace_group_icon' (takes a groupicon name and an iconfile) 'remove_group_icon' ( takes a groupicon name ) so that if you know what you want to do, it is possible without having to write the raw code. Thanks Mark On Fri Apr 02 14:20:21 2010, RPKELLY wrote: Show quoted text
> Sometimes, Win32::Exe will write back a corrupted EXE which cannot be > run when setting the icon files in the executable. Attached are two
icon Show quoted text
> files, and an exe. Using an.ico will not corrupt the executable, but > nm.ico will. Altering sub "set_icons" in Win32/Exe.pm to the following > fixes the issue: > > sub set_icons { > my ($self, $icons) = @_; > > my $rsrc = $self->resource_section; > > my @gicons = $rsrc->objects('GroupIcon'); > foreach my $gicon (@gicons) { > my $group = $self->require_class('Resource::GroupIcon')->new; > $group->SetPathName($gicon->PathName); > $group->set_parent($rsrc); > $rsrc->insert($group->PathName, $group); > > $group->set_icons($icons); > $group->refresh; > } > } > > Note that making this change will cause test #12 (line 41) in file > 2-icon.t to fail because the size of the resulting executable is
larger. Show quoted text
> > Thanks, > -Ryan Kelly