Major refactoring of src/stub directory.

This commit is contained in:
Markus F.X.J. Oberhumer
2006-06-15 08:17:50 +02:00
parent 72906cdc6a
commit d3323d6550
161 changed files with 24934 additions and 173 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
+145
View File
@@ -0,0 +1,145 @@
#! /usr/bin/env python
## 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
# 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, zlib
class opts:
dry_run = 0
ident = None
verbose = 0
def w_header(w, ifile, ofile, n):
w("/* %s -- created from %s, %d (0x%x) bytes\n" % (os.path.basename(ofile), os.path.basename(ifile), n, n))
w("""\n\
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>
*/\n\n\n""")
def w_checksum(w, s, data):
w("#define %s_SIZE %d\n" % (s, len(data)))
w("#define %s_ADLER32 0x%08x\n" % (s, 0xffffffffL & zlib.adler32(data)))
w("#define %s_CRC32 0x%08x\n" % (s, 0xffffffffL & zlib.crc32(data)))
w("\n")
def w_data(w, data):
def w_eol(w, i):
if i > 0:
w(" /* 0x%4x */" % (i - 16))
w("\n")
n = len(data)
for i in range(n):
if i % 16 == 0:
w_eol(w, i)
w("%3d" % ord(data[i]))
w(", " [i == n - 1])
i = n
while i % 16 != 0:
i += 1
w(" ")
w_eol(w, i)
def main(argv):
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)
assert len(args) == 2
ifile = args[0]
ofile = args[1]
# check file size
st = os.stat(ifile)
if 1 and st.st_size <= 0:
print >> sys.stderr, "%s: ERROR: emtpy file" % (ifile)
sys.exit(1)
if 1 and st.st_size > 64*1024:
print >> sys.stderr, "%s: ERROR: file is too big (%d bytes)" % (ifile, st.st_size)
if re.search(r"^fold", ifile):
print >> sys.stderr, " (please upgrade your binutils to 2.12.90.0.15 or better)"
sys.exit(1)
# read ifile
fp = open(ifile, "rb")
data = fp.read()
fp.close()
assert len(data) == st.st_size
# write ofile
fp = open(ofile, "wb")
w = fp.write
if opts.verbose >= 0:
w_header(w, ifile, ofile, 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)
if opts.ident:
w("};\n")
fp.close()
if __name__ == "__main__":
sys.exit(main(sys.argv))
+48
View File
@@ -0,0 +1,48 @@
#! /usr/bin/perl -w
#
# brandelf.pl -- brand an ELF binary as Linux or FreeBSD
#
# 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>
#
$fname = shift || die;
$sig = shift || "Linux";
die if length($sig) > 7;
sysopen (FH,$fname,2) || die;
binmode FH;
sysread (FH,$header,8) || die;
die if (substr($header, 0, 7) ne "\x7f\x45\x4c\x46\x01\x01\x01");
syswrite (FH,$sig,length($sig)) || die;
syswrite (FH,"\0\0\0\0\0\0\0\0",8-length($sig)) || die;
close (FH) || die;
exit (0);
# vi:ts=4:et
+133
View File
@@ -0,0 +1,133 @@
#! /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"
included_files = {}
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()
if len(s) < 3 or s[0] != s[-1]:
return not_found(l, s, state)
if s[0] == '<':
dirs = opts.includes
elif s[0] == '"':
dirs = [state[1]] + opts.includes
else:
assert 0
inc = s[1:-1]
for dir in dirs:
fn = os.path.join(dir, inc)
if os.path.isfile(fn):
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()
if len(s) < 3 or s[0] != s[-1]:
return not_found(l, s, state)
inc = s[1:-1]
# info: nasm simply does concat the includes
for prefix in opts.includes + [""]:
fn = prefix + inc
if os.path.isfile(fn):
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", "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()
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)
if __name__ == "__main__":
sys.exit(main(sys.argv))
+76
View File
@@ -0,0 +1,76 @@
#! /usr/bin/perl -w
#
# o2bin.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
# 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>
#
$delim = $/;
undef $/; # undef input record separator - read file as a whole
$ifile = shift || die;
$ofile = shift || die;
$x_start = shift || die;
$x_end = shift || die;
# read whole file
open(INFILE,$ifile) || die "$ifile\n";
binmode(INFILE);
$data = <INFILE>;
close(INFILE) || die;
# delete everything up to 'UPX1'
die if ($data =~ s/^.*${x_start}//s) != 1;
# delete everything from 'UPX9'
die if ($data =~ s/${x_end}.*$//s) != 1;
# write file
open(OUTFILE,">$ofile") || die "$ofile\n";
binmode(OUTFILE);
if ($ofile =~ /\.(db)$/i) {
# asm "db xx" output
$n = length($data);
$l = 16;
for ($i = 0; $i < $n; ) {
print OUTFILE "db " if ($i % $l == 0);
printf OUTFILE ("%d", ord(substr($data, $i, 1)));
++$i;
if ($i == $n || $i % $l == 0) {
print OUTFILE "\n";
} else {
print OUTFILE ",";
}
}
} else {
print OUTFILE $data;
}
close(OUTFILE) || die;
undef $delim;
exit(0);
# vi:ts=4:et