in reply to Re: Re: STDOUT and a PAR --gui executable
in thread STDOUT and a PAR --gui executable
sub _strip_console { my $file = shift; my $preoff = shift || 0; my ($record, $magic, $signature, $offset, $size); open my $exe, "+< $file" or die "Cannot open $file: $!\n"; binmode $exe; seek $exe, $preoff, 0; # read IMAGE_DOS_HEADER structure read $exe, $record, 64; ($magic, $offset) = unpack "Sx58L", $record; die "$file is not an MSDOS executable file.\n" unless $magic == 0x5a4d; # "MZ" # read signature, IMAGE_FILE_HEADER and first WORD of IMAGE_OPTION +AL_HEADER seek $exe, $preoff + $offset, 0; read $exe, $record, 4+20+2; ($signature,$size,$magic) = unpack "Lx16Sx2S", $record; die "PE header not found" unless $signature == 0x4550; # "PE\0\0" die "Optional header is neither in NT32 nor in NT64 format" unless ($size == 224 && $magic == 0x10b) || # IMAGE_NT_OPTIONA +L_HDR32_MAGIC ($size == 240 && $magic == 0x20b); # IMAGE_NT_OPTIONA +L_HDR64_MAGIC # Offset 68 in the IMAGE_OPTIONAL_HEADER(32|64) is the 16 bit subs +ystem code seek $exe, $preoff + $offset+4+20+68, 0; print $exe pack "S", 2; # IMAGE_WINDOWS close $exe; }
|
|---|