Debian Codegraph @

exetype

raw
1 #!perl -w
2 use strict;
3 unless (@ARGV == 2) {
4 print "Usage: $0 exefile [CONSOLE|WINDOWS]\n";
5 exit;
6 }
7 unless ($ARGV[1] =~ /^(console|windows)$/i) {
8 print "Invalid subsystem $ARGV[1], please use CONSOLE or WINDOWS\n";
9 exit;
10 }
11 my ($record,$magic,$offset,$size);
12 open EXE, "+< $ARGV[0]" or die "Cannot open $ARGV[0]: $!";
13 binmode EXE;
14 read EXE, $record, 32*4;
15 ($magic,$offset) = unpack "Sx58L", $record;
16 die "Not an MSDOS executable file" unless $magic == 0x5a4d;
17 seek EXE, $offset, 0;
18 read EXE, $record, 24;
19 ($magic,$size) = unpack "Lx16S", $record;
20 die "PE header not found" unless $magic == 0x4550;
21 die "Optional header not in NT32 format" unless $size == 224;
22 seek EXE, $offset+24+68, 0;
23 print EXE pack "S", uc($ARGV[1]) eq 'CONSOLE' ? 3 : 2;
24 close EXE;
25 __END__
26
27 =head1 NAME
28
29 exetype - Change executable subsystem type between "Console" and "Windows"
30
31 =head1 SYNOPSIS
32
33 C:\perl\bin> copy perl.exe guiperl.exe
34 C:\perl\bin> exetype guiperl.exe windows
35
36 =head1 DESCRIPTION
37
38 This program edits an executable file to indicate which subsystem the
39 operating system must invoke for execution.
40
41 You can specify any of the following subsystems:
42
43 =over
44
45 =item CONSOLE
46
47 The CONSOLE subsystem handles a Win32 character-mode application that
48 use a console supplied by the operating system.
49
50 =item WINDOWS
51
52 The WINDOWS subsystem handles an application that does not require a
53 console and creates its own windows, if required.
54
55 =back
56
57 =head1 AUTHOR
58
59 Jan Dubois <[email protected]>
60
61 =cut
62
63