File: getpearch.pl

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (76 lines) | stat: -rw-r--r-- 1,760 bytes parent folder | download | duplicates (24)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
#
# Get the appropriate variables to make an NSIS installer file
# based on the PE architecture of a specific file
#

use strict;
use bytes;

my %archnames = (
    0x01de => 'am33',
    0x8664 => 'x64',
    0x01c0 => 'arm32',
    0x01c4 => 'thumb',
    0xaa64 => 'arm64',
    0x0ebc => 'efi',
    0x014c => 'x86',
    0x0200 => 'ia64',
    0x9041 => 'm32r',
    0x0266 => 'mips16',
    0x0366 => 'mips',
    0x0466 => 'mips16',
    0x01f0 => 'powerpc',
    0x01f1 => 'powerpc',
    0x0166 => 'mips',
    0x01a2 => 'sh3',
    0x01a3 => 'sh3',
    0x01a6 => 'sh4',
    0x01a8 => 'sh5',
    0x01c2 => 'arm32',
    0x0169 => 'wcemipsv2'
);

my ($file) = @ARGV;
open(my $fh, '<', $file)
    or die "$0: cannot open file: $file: $!\n";

read($fh, my $mz, 2);
exit 1 if ($mz ne 'MZ');

exit 0 unless (seek($fh, 0x3c, 0));
exit 0 unless (read($fh, my $pe_offset, 4) == 4);
$pe_offset = unpack("V", $pe_offset);

exit 1 unless (seek($fh, $pe_offset, 0));
read($fh, my $pe, 4);
exit 1 unless ($pe eq "PE\0\0");

exit 1 unless (read($fh, my $arch, 2) == 2);
$arch = $archnames{unpack("v", $arch)};
if (defined($arch)) {
    print "!define ARCH ${arch}\n";
}

exit 1 unless (seek($fh, 14, 1));
exit 1 unless (read($fh, my $auxheaderlen, 2) == 2);
exit 1 unless (unpack("v", $auxheaderlen) >= 2);

exit 1 unless (seek($fh, 2, 1));
exit 1 unless (read($fh, my $petype, 2) == 2);
$petype = unpack("v", $petype);
if ($petype == 0x010b) {
    # It is a 32-bit PE32 file
    print "!define BITS 32\n";
    print "!define GLOBALINSTDIR \$PROGRAMFILES\n";
} elsif ($petype == 0x020b) {
    # It is a 64-bit PE32+ file
    print "!define BITS 64\n";
    print "!define GLOBALINSTDIR \$PROGRAMFILES64\n";
} else {
    # No idea...
    exit 1;
}

close($fh);
exit 0;