File: exetype

package info (click to toggle)
perl-tk 1:804.033-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 34,724 kB
  • ctags: 37,174
  • sloc: ansic: 349,541; perl: 52,192; sh: 17,904; makefile: 5,732; asm: 3,565; ada: 1,681; pascal: 1,089; cpp: 1,006; yacc: 883; cs: 879
file content (63 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!perl -w
use strict;
unless (@ARGV == 2) {
    print "Usage: $0 exefile [CONSOLE|WINDOWS]\n";
    exit;
}
unless ($ARGV[1] =~ /^(console|windows)$/i) {
    print "Invalid subsystem $ARGV[1], please use CONSOLE or WINDOWS\n";
    exit;
}
my ($record,$magic,$offset,$size);
open EXE, "+< $ARGV[0]" or die "Cannot open $ARGV[0]: $!";
binmode EXE;
read EXE, $record, 32*4;
($magic,$offset) = unpack "Sx58L", $record;
die "Not an MSDOS executable file" unless $magic == 0x5a4d;
seek EXE, $offset, 0;
read EXE, $record, 24;
($magic,$size) = unpack "Lx16S", $record;
die "PE header not found" unless $magic == 0x4550;
die "Optional header not in NT32 format" unless $size == 224;
seek EXE, $offset+24+68, 0;
print EXE pack "S", uc($ARGV[1]) eq 'CONSOLE' ? 3 : 2;
close EXE;
__END__

=head1 NAME

exetype - Change executable subsystem type between "Console" and "Windows"

=head1 SYNOPSIS

        C:\perl\bin> copy perl.exe guiperl.exe
        C:\perl\bin> exetype guiperl.exe windows

=head1 DESCRIPTION

This program edits an executable file to indicate which subsystem the
operating system must invoke for execution.

You can specify any of the following subsystems:

=over

=item CONSOLE

The CONSOLE subsystem handles a Win32 character-mode application that
use a console supplied by the operating system.

=item WINDOWS

The WINDOWS subsystem handles an application that does not require a
console and creates its own windows, if required.

=back

=head1 AUTHOR

Jan Dubois <jand@activestate.com>

=cut