This commit is contained in:
John Reiser
2006-06-15 12:21:01 -07:00
174 changed files with 24710 additions and 715 deletions
+50
View File
@@ -0,0 +1,50 @@
#! /bin/sh
#
# asl_m68k.sh --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
set -e
# wrapper for the ASL cross-assembler (version 1.42bld43)
# http://john.ccac.rwth-aachen.de:8000/as/
# http://john.ccac.rwth-aachen.de:8000/ftp/as/source/c_version/
file="$1"
test -f "$file" || exit 1
ofile=`echo "$file" | sed 's/\.[a-z]*$/.o/'`
# convert ' to " in dc.x statements
perl -p -i -e '
s,\x27,",g if m,^\s*dc\.,;
' "$file"
echo asl -q -xC -U -cpu 68000 -o "$ofile" -L "$file"
asl -q -xC -U -cpu 68000 -o "$ofile" -L "$file"
exit 0
+143
View File
@@ -0,0 +1,143 @@
#! /usr/bin/perl -w
#
# bin2h.pl --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# Copyright (C) 2000-2006 John F. Reiser
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
use Compress::Zlib;
$delim = $/;
undef $/; # undef input record separator - read file as a whole
$ifile = shift || die;
$ident = shift || die;
$ofile = shift || die;
$opt_q = "";
$opt_q = shift if ($#ARGV >= 0);
# open ifile
open(INFILE,$ifile) || die "open $ifile\n";
binmode(INFILE);
# check file size
@st = stat($ifile);
if (1 && $st[7] <= 0) {
print STDERR "$ifile: ERROR: emtpy file\n";
exit(1);
}
if (1 && $st[7] > 64*1024) {
print STDERR "$ifile: ERROR: file is too big (${st[7]} bytes)\n";
if ($ifile =~ /^fold/) {
print STDERR " (please upgrade your binutils to 2.12.90.0.15 or better)\n";
}
exit(1);
}
# read whole file
$data = <INFILE>;
close(INFILE) || die;
$n = length($data);
die if ($n != $st[7]);
# open ofile
open(OUTFILE,">$ofile") || die "open $ofile\n";
binmode(OUTFILE);
select(OUTFILE);
$if = $ifile;
$if =~ s/.*[\/\\]//;
$of = $ofile;
$of =~ s/.*[\/\\]//;
if ($opt_q ne "-q") {
printf ("/* %s -- created from %s, %d (0x%x) bytes\n", $of, $if, $n, $n);
print <<"EOF";
This file is part of the UPX executable compressor.
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
Copyright (C) 2000-2006 John F. Reiser
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
<mfx\@users.sourceforge.net> <ml1050\@users.sourceforge.net>
*/
EOF
}
$s = $ident;
$s =~ tr/a-z/A-Z/;
printf("#define %s_SIZE %d\n", $s, $n);
printf("#define %s_ADLER32 0x%08x\n", $s, &adler32($data));
printf("#define %s_CRC32 0x%08x\n", $s, &crc32($data));
printf("\n");
printf("unsigned char %s[%d] = {", $ident, $n);
for ($i = 0; $i < $n; $i++) {
if ($i % 16 == 0) {
printf(" /* 0x%4x */", $i - 16) if $i > 0;
print "\n";
}
printf("%3d", ord(substr($data, $i, 1)));
print "," if ($i != $n - 1);
}
while (($i % 16) != 0) {
$i++;
print " ";
}
printf(" /* 0x%4x */", $i - 16);
print "\n};\n";
close(OUTFILE) || die;
select(STDOUT);
undef $delim;
exit(0);
# vi:ts=4:et
+58
View File
@@ -0,0 +1,58 @@
#! /usr/bin/perl -w
#
# setfold.pl -- set Elf32_Phdr[1].p_offset
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 2000-2006 John F. Reiser
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
# John F. Reiser
# <jreiser@users.sourceforge.net>
#
$fname = shift || die;
sysopen (FH,$fname,2) || die;
binmode FH;
$fsize = (stat($fname))[7];
$val = shift || die "$val";
###print STDERR "$val\n";
$val = oct($val); # acutally hex()
$val = $val & 0xfff;
printf STDERR "setfold info: $fname: setting fold to 0x%x, file size 0x%x\n", $val, $fsize;
die unless $val > 0;
die unless $val < $fsize;
$num = pack("V", $val);
# 0x34 = sizeof(Elf32_Ehdr)
# 0x20 = sizeof(Elf32_Phdr)
# 4 = offset(p_offset)
sysseek (FH,0x34+0x20+4,0) || die;
syswrite (FH,$num,4) || die;
close(FH) || die;
exit 0;
# vi:ts=4:et
+52
View File
@@ -0,0 +1,52 @@
#! /bin/sh
#
# setfold.sh --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
set -e
file="$1"
# get directory of this script
bindir=`echo "$0" | sed -e 's|[^/][^/]*$||'`
bindir=`cd "$bindir" && pwd`
sstrip="./util/sstrip/sstrip"
test -x "$sstrip" || sstrip="$bindir/../util/sstrip/sstrip"
# get address of symbol "fold_begin"
fold=`nm -f bsd "$file" | grep fold_begin | sed 's/^0*\([0-9a-fA-F]*\).*/0x\1/'`
# strip
objcopy -S -R .comment -R .note "$file"
"$sstrip" "$file"
# patch address
perl -w "$bindir/setfold.pl" "$file" "$fold"
exit 0
+78
View File
@@ -0,0 +1,78 @@
#! /usr/bin/perl -w
#
# stripelf.pl -- strip section headers from an ELF executable
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
#
# Strip section headers from the Linux stub. Section headers are
# optional for executables, but nevertheless binutils (2.9.1.0.25)
# complain with a "File format not recognized" error.
# Looks like a bug in binutils to me.
#
# A positive side effect of this is that `strip' cannot ruin an UPX
# compressed file any longer.
#
$fname = shift || die;
sysopen (FH,$fname,2) || die;
binmode FH;
sysseek (FH,0x20,0) || die;
sysread (FH,$num,4) || die;
$shpos = unpack ("V",$num); # e_shoff
sysseek (FH,0x2e,0) || die;
sysread (FH,$num,2) || die;
$ssize = unpack ("v",$num); # e_shentsize
sysseek (FH,0x32,0) || die;
sysread (FH,$num,2) || die;
$idx = unpack ("v",$num); # e_shstrndx
sysseek (FH,$shpos + $idx * $ssize + 16,0) || die;
sysread (FH,$num,4) || die;
$neweof = unpack ("V",$num); # sh_offset of the e_shstrndx section
$num = pack ("x6");
sysseek (FH,0x20,0) || die;
syswrite (FH,$num,4) || die; # clear e_shoff
if (1) {
sysseek (FH,0x2e,0) || die;
syswrite (FH,$num,6) || die; # clear e_shentsize, e_shnum & e_shstrndx
} else {
sysseek (FH,0x30,0) || die;
syswrite (FH,$num,4) || die; # clear e_shnum & e_shstrndx
}
truncate (FH,$neweof) || die;
close(FH) || die;
print STDOUT "$0: truncated $fname to $neweof bytes.\n";
exit 0;
# vi:ts=4:et
+42
View File
@@ -0,0 +1,42 @@
#! /usr/bin/perl -w
#
# version.pl -- convert version.h into version.asy
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
$mode = shift || "--nasm";
while (<>) {
chop;
s/\s+$//;
if (/^\s*\#\s*define\s+(.*)/) {
print "%define $1\n" if ($mode eq "--nasm");
}
}
exit (0);
# vi:ts=4:et
+26 -13
View File
@@ -1,14 +1,11 @@
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
# vi:ts=4:et
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
#
# bin2h.py --
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 1996-2006 Laszlo Molnar
# Copyright (C) 2000-2006 John F. Reiser
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
@@ -31,7 +28,13 @@
#
import os, sys, zlib
import getopt, os, re, sys, zlib
class opts:
dry_run = 0
ident = None
verbose = 0
def w_header(w, ifile, ofile, n):
@@ -91,11 +94,19 @@ def w_data(w, data):
def main(argv):
ifile = argv[1]
ident = argv[2]
ofile = argv[3]
shortopts, longopts = "qv", ["dry-run", "ident=", "quiet", "verbose"]
xopts, args = getopt.gnu_getopt(argv[1:], shortopts, longopts)
for opt, optarg in xopts:
if 0: pass
elif opt in ["-q", "--quiet"]: opts.verbose = opts.verbose - 1
elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1
elif opt in ["--dry-run"]: opts.dry_run = opts.dry_run + 1
elif opt in ["--ident"]: opts.ident = optarg
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
opt_q = len(argv) >= 5
assert len(args) == 2
ifile = args[0]
ofile = args[1]
# check file size
st = os.stat(ifile)
@@ -117,12 +128,14 @@ def main(argv):
# write ofile
fp = open(ofile, "wb")
w = fp.write
if not opt_q:
if opts.verbose >= 0:
w_header(w, ifile, ofile, len(data))
w_checksum(w, ident.upper(), data)
w("unsigned char %s[%d] = {\n" % (ident, len(data)))
if opts.ident:
w_checksum(w, opts.ident.upper(), data)
w("unsigned char %s[%d] = {\n" % (opts.ident, len(data)))
w_data(w, data)
w("};\n")
if opts.ident:
w("};\n")
fp.close()
+179
View File
@@ -0,0 +1,179 @@
#! /usr/bin/env python
## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
#
# gpp_inc.py -- Generic PreProcessor: include
#
# This file is part of the UPX executable compressor.
#
# Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
# All Rights Reserved.
#
# UPX and the UCL library are free software; you can redistribute them
# and/or modify them under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Markus F.X.J. Oberhumer Laszlo Molnar
# <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
#
import getopt, os, re, sys
class opts:
dry_run = 0
verbose = 0
fatal = 1
includes = []
mode = "c"
target_mf = None
target_mmd = None
files_md = []
files_mmd = []
files_st = {}
def add_dep(state, fn, mode):
if mode:
files = files_md
else:
files = files_mmd
fn = os.path.normpath(fn)
fn = os.path.normcase(fn)
if fn in files:
return
# FIXME: could use samestat() etc.
files.append(fn)
files_st[fn] = os.stat(fn)
def not_found(l, s, state):
if opts.fatal:
raise Exception, "%s:%d: include file %s not found" % (state[0], state[2], s)
return l
def handle_inc_c(l, state, ofp):
m = re.search(r"^\s*\#\s*include\s+([\"\<].+)", l)
if not m:
return l
s = m.group(1).strip()
# FIXME: strip comments ?
if len(s) < 3:
return not_found(l, s, state)
if s[0] == '<' and s[-1] == '>':
dirs = opts.includes
elif s[0] == '"' and s[-1] == '"':
dirs = [state[1]] + opts.includes
else:
raise Exception, "syntax error: include line " + l
inc = s[1:-1]
for dir in dirs:
fn = os.path.join(dir, inc)
if os.path.isfile(fn):
add_dep(state, fn, s[0] == '<')
handle_file(fn, ofp, state)
return None
return not_found(l, s, state)
def handle_inc_nasm(l, state, ofp):
m = re.search(r"^\s*\%\s*include\s+([\"\<].+)", l)
if not m:
return l
s = m.group(1).strip()
# FIXME: strip comments ?
if len(s) < 3:
return not_found(l, s, state)
if s[0] == '<' and s[-1] == '>':
pass
elif s[0] == '"' and s[-1] == '"':
pass
else:
raise Exception, "syntax error: include line " + l
inc = s[1:-1]
# info: nasm simply does concat the includes
for prefix in opts.includes + [""]:
fn = prefix + inc
if os.path.isfile(fn):
add_dep(state, fn, False)
handle_file(fn, ofp, state)
return None
return not_found(l, s, state)
def handle_file(ifn, ofp, parent_state=None):
state = [ifn, os.path.dirname(ifn) or ".", 0, parent_state]
ifp = open(ifn, "rb")
for l in ifp.readlines():
state[2] += 1 # line counter
l = l.rstrip("\n")
if opts.mode == "c":
l = handle_inc_c(l, state, ofp)
elif opts.mode == "nasm":
l = handle_inc_nasm(l, state, ofp)
if l is not None:
ofp.write(l + "\n")
def main(argv):
ofile = None
shortopts, longopts = "qvI:o:", ["dry-run", "MF=", "MMD=", "mode=", "quiet", "verbose"]
xopts, args = getopt.gnu_getopt(argv[1:], shortopts, longopts)
for opt, optarg in xopts:
if 0: pass
elif opt in ["-q", "--quiet"]: opts.verbose = opts.verbose - 1
elif opt in ["-v", "--verbose"]: opts.verbose = opts.verbose + 1
elif opt in ["--dry-run"]: opts.dry_run = opts.dry_run + 1
elif opt in ["-I"]: opts.includes.append(optarg)
elif opt in ["-o"]: ofile = optarg
elif opt in ["--mode"]: opts.mode = optarg.lower()
elif opt in ["--MF"]: opts.target_mf = optarg
elif opt in ["--MMD"]: opts.target_mmd = optarg
else: assert 0, ("getopt problem:", opt, optarg, xopts, args)
if ofile is None:
assert len(args) == 2
ifile = args[0]
ofile = args[1]
else:
assert len(args) == 1
ifile = args[0]
assert os.path.isfile(ifile)
ofp = open(ofile, "wb")
handle_file(ifile, ofp)
ofp.close()
if opts.target_mmd:
fn = ofile + ".d"
if opts.target_mf:
fn = opts.target_mf
if os.path.isfile(fn):
os.unlink(fn)
if files_mmd:
fp = open(fn, "wb")
fp.write("%s : \\\n" % opts.target_mmd)
for i, f in enumerate(files_mmd):
if i < len(files_mmd) - 1:
fp.write(" %s \\\n" % f)
else:
fp.write(" %s\n" % f)
fp.close()
if __name__ == "__main__":
sys.exit(main(sys.argv))