nsis: error out if getpearch.pl can't figure out what we need

Error out instead of failing silently in getpearch.pl

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2017-04-06 17:12:48 -07:00
parent 79570527b3
commit cb8094a954

View File

@ -35,28 +35,28 @@ open(my $fh, '<', $file)
or die "$0: cannot open file: $file: $!\n"; or die "$0: cannot open file: $file: $!\n";
read($fh, my $mz, 2); read($fh, my $mz, 2);
exit 0 if ($mz ne 'MZ'); exit 1 if ($mz ne 'MZ');
exit 0 unless (seek($fh, 0x3c, 0)); exit 1 unless (seek($fh, 0x3c, 0));
exit 0 unless (read($fh, my $pe_offset, 1) == 1); exit 1 unless (read($fh, my $pe_offset, 1) == 1);
$pe_offset = unpack("C", $pe_offset); $pe_offset = unpack("C", $pe_offset);
exit 0 unless (seek($fh, $pe_offset, 0)); exit 1 unless (seek($fh, $pe_offset, 0));
read($fh, my $pe, 4); read($fh, my $pe, 4);
exit 0 unless ($pe eq "PE\0\0"); exit 1 unless ($pe eq "PE\0\0");
exit 0 unless (read($fh, my $arch, 2) == 2); exit 1 unless (read($fh, my $arch, 2) == 2);
$arch = $archnames{unpack("v", $arch)}; $arch = $archnames{unpack("v", $arch)};
if (defined($arch)) { if (defined($arch)) {
print "!define ARCH ${arch}\n"; print "!define ARCH ${arch}\n";
} }
exit 0 unless (seek($fh, 14, 1)); exit 1 unless (seek($fh, 14, 1));
exit 0 unless (read($fh, my $auxheaderlen, 2) == 2); exit 1 unless (read($fh, my $auxheaderlen, 2) == 2);
exit 0 unless (unpack("v", $auxheaderlen) >= 2); exit 1 unless (unpack("v", $auxheaderlen) >= 2);
exit 0 unless (seek($fh, 2, 1)); exit 1 unless (seek($fh, 2, 1));
exit 0 unless (read($fh, my $petype, 2) == 2); exit 1 unless (read($fh, my $petype, 2) == 2);
$petype = unpack("v", $petype); $petype = unpack("v", $petype);
if ($petype == 0x010b) { if ($petype == 0x010b) {
# It is a 32-bit PE32 file # It is a 32-bit PE32 file
@ -68,6 +68,7 @@ if ($petype == 0x010b) {
print "!define GLOBALINSTDIR \$PROGRAMFILES64\n"; print "!define GLOBALINSTDIR \$PROGRAMFILES64\n";
} else { } else {
# No idea... # No idea...
exit 1;
} }
close($fh); close($fh);