Initial commit (from git)
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# app.pl -- assembly preprocessor for upx
|
||||
#
|
||||
# This file is part of the UPX executable compressor.
|
||||
#
|
||||
# Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
#
|
||||
# usage: app.pl infile outfile
|
||||
#
|
||||
|
||||
$in = shift || die;
|
||||
$ou = shift || die;
|
||||
|
||||
open (IN,"<$in") or die;
|
||||
open (OU,">$ou") or die;
|
||||
binmode IN;
|
||||
binmode OU;
|
||||
|
||||
@lines = <IN>;
|
||||
|
||||
%labels = ();
|
||||
$i = 0;
|
||||
$cs = "";
|
||||
|
||||
($ilabel = $in) =~ s,^.*[\/\\],,; # get basename
|
||||
$ilabel =~ s/\W//g;
|
||||
|
||||
# 1st pass
|
||||
for $line (@lines)
|
||||
{
|
||||
$labels{$1} = "$cs" if ($line =~ /^(\w+):/ && $cs);
|
||||
if ($line =~ /__([A-Z0-9]{8})__/) {
|
||||
$cs = $1;
|
||||
# verify the line
|
||||
if ($line =~ /^\%ifdef/) {
|
||||
# ok
|
||||
} elsif ($line =~ /^(\%\w+)?\s*;/) {
|
||||
# ok
|
||||
} else {
|
||||
print STDERR "$in:$i:warning:$line"
|
||||
}
|
||||
}
|
||||
|
||||
if ($line =~ /^\%(if|el|endi)/)
|
||||
{
|
||||
if ($line =~ /__([A-Z0-9]{8})__/)
|
||||
{
|
||||
$line=";$line";
|
||||
}
|
||||
else
|
||||
{
|
||||
print STDERR "$in:$i:warning:$line";
|
||||
}
|
||||
}
|
||||
$line =~ s/\.ash/\.asy/ if ($line =~ /^\s*\%include/);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$cs = "";
|
||||
$i = 0;
|
||||
|
||||
# 2nd pass
|
||||
for $line (@lines)
|
||||
{
|
||||
if ($line =~ /^\s+(j\w+|loop|call)\s+(\w*)/)
|
||||
{
|
||||
$label = $2;
|
||||
die "$line" if ($label =~ /(\bnear\b|\bshort\b)/);
|
||||
if (defined $labels{$label})
|
||||
{
|
||||
$ts = $labels{$label};
|
||||
if ($ts ne $cs)
|
||||
{
|
||||
$line =~ s/$label/J$i$ilabel/;
|
||||
print OU $line;
|
||||
print OU "J$i$ilabel:\n";
|
||||
print OU "\t\tsection\t.data\n\t\tdd\t";
|
||||
print OU "0,J$i$ilabel,\'$ts\',$label - S$ts$ilabel\n";
|
||||
print OU "\t\tsection\t.text\n\n";
|
||||
$line = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$line = ";$line" if ($line =~ /^\s+align\s/);
|
||||
|
||||
print OU $line;
|
||||
if ($line =~ /__([A-Z0-9]{8})__/)
|
||||
{
|
||||
print OU "S$1$ilabel:\n";
|
||||
print OU "\t\tsection\t.data\n\t\tdd\t\'$1\',S$1$ilabel\n";
|
||||
print OU "\t\tsection\t.text\n\n";
|
||||
$cs = $1;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# vi:ts=4:et
|
||||
@@ -0,0 +1,100 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# bin2h.pl --
|
||||
#
|
||||
# This file is part of the UPX executable compressor.
|
||||
#
|
||||
# Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
|
||||
$delim = $/;
|
||||
undef $/; # undef input record separator - read file as a whole
|
||||
|
||||
$ifile = shift || die;
|
||||
$ident = shift || die;
|
||||
$ofile = shift || die;
|
||||
|
||||
open(INFILE,$ifile) || die "$ifile\n";
|
||||
binmode(INFILE);
|
||||
open(OUTFILE,">$ofile") || die "$ofile\n";
|
||||
binmode(OUTFILE);
|
||||
|
||||
# read whole file
|
||||
$data = <INFILE>;
|
||||
close(INFILE);
|
||||
$n = length($data);
|
||||
|
||||
# print
|
||||
select(OUTFILE);
|
||||
|
||||
$o = $ofile;
|
||||
$o =~ s/.*[\/\\]//;
|
||||
|
||||
print <<"EOF";
|
||||
/* $o -- created from $ifile, $n bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2000 Laszlo Molnar
|
||||
|
||||
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
|
||||
markus.oberhumer\@jk.uni-linz.ac.at ml1050\@cdata.tvnet.hu
|
||||
*/
|
||||
|
||||
|
||||
EOF
|
||||
|
||||
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);
|
||||
}
|
||||
print "\n};\n";
|
||||
|
||||
close(OUTFILE) || die;
|
||||
select(STDOUT);
|
||||
|
||||
undef $delim;
|
||||
exit(0);
|
||||
|
||||
# vi:ts=4:et
|
||||
@@ -0,0 +1,47 @@
|
||||
#! /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-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
|
||||
$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
|
||||
@@ -0,0 +1,75 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# o2bin.pl --
|
||||
#
|
||||
# This file is part of the UPX executable compressor.
|
||||
#
|
||||
# Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
|
||||
$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
|
||||
@@ -0,0 +1,45 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# setfold.pl -- set Elf32_Phdr[1].p_offset
|
||||
#
|
||||
# This file is part of the UPX executable compressor.
|
||||
#
|
||||
# Copyright (C) 2000 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.
|
||||
#
|
||||
# John Reiser
|
||||
# jreiser@BitWagon.com
|
||||
#
|
||||
|
||||
$fname = shift || die;
|
||||
sysopen (FH,$fname,2) || die;
|
||||
binmode FH;
|
||||
|
||||
$val = oct shift || die;
|
||||
$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
|
||||
@@ -0,0 +1,77 @@
|
||||
#! /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-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
#
|
||||
# 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
|
||||
@@ -0,0 +1,40 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# version.pl -- convert version.h into version.asy
|
||||
#
|
||||
# This file is part of the UPX executable compressor.
|
||||
#
|
||||
# Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||
# Copyright (C) 1996-2000 Laszlo Molnar
|
||||
#
|
||||
# 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
|
||||
# markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||
#
|
||||
|
||||
$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
|
||||
Reference in New Issue
Block a user