Subject: | create_resource_section() fails |
For an executable without a resource section, create_resource_section()
fails to create one. The attached script prints:
Show quoted text
C>perl add-res.pl hello.exe
original exe = Win32::Exe::PE::Header::PE32=HASH(0xc4086c)
no resource section found, creating one ...
No resource section found in file hello.exe at
C:/strawberry/perl/site/lib/Win32/Exe.pm line 348.
modified exe = Win32::Exe::PE::Header::PE32=HASH(0x1eb02b4)
Not an ARRAY reference at C:/strawberry/perl/site/lib/Win32/Exe.pm line 521.
hello.exe originally doesn't have a resource section:
Show quoted textC>objdump -h hello-orig.exe
hello-orig.exe: file format pei-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00003b44 00401000 00401000 00000400 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
1 .data 00165300 00405000 00405000 00004000 2**5
CONTENTS, ALLOC, LOAD, DATA
2 .rdata 00000570 0056b000 0056b000 00169400 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .bss 00008440 0056c000 0056c000 00000000 2**5
ALLOC
4 .idata 0000090c 00575000 00575000 00169a00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .CRT 00000034 00576000 00576000 0016a400 2**2
CONTENTS, ALLOC, LOAD, DATA
6 .tls 00000020 00577000 00577000 0016a600 2**2
CONTENTS, ALLOC, LOAD, DATA
After the script runs there's a strange new section (7)
Show quoted textC>objdump -h hello.exe
hello.exe: file format pei-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00003b44 00401000 00401000 00000400 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
1 .data 00165300 00405000 00405000 00004000 2**5
CONTENTS, ALLOC, LOAD, DATA
2 .rdata 00000570 0056b000 0056b000 00169400 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .bss 00008440 0056c000 0056c000 00000000 2**5
ALLOC
4 .idata 0000090c 00575000 00575000 00169a00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .CRT 00000034 00576000 00576000 0016a400 2**2
CONTENTS, ALLOC, LOAD, DATA
6 .tls 00000020 00577000 00577000 0016a600 2**2
CONTENTS, ALLOC, LOAD, DATA
7 00000000 00000000 00000000 00000000 2**2
READONLY
This is on Windows XP with Strawberry Perl 5.12.3 and Win32::Exe 0.16.
Cheers, Roderich
Subject: | add-res.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Win32::Exe;
@ARGV == 1 or die "usage: $0 file.exe\n";
my ($file) = @ARGV;
my $exe = Win32::Exe->new($file);
print STDERR "original exe = $exe\n";
if (!$exe->has_resource_section)
{
print STDERR "no resource section found, creating one ...\n";
$exe = $exe->create_resource_section;
print STDERR "modified exe = $exe\n";
}
my $rc = $exe->update( info =>
{
ProductName => "HelloWorld",
ProductVersion => "42.0",
CompanyName => "Hulloh Inc",
} );
print STDERR "update => $rc\n";
exit(0);