From 199e274cacda53652294db828074d9934d955a58 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 8 Jan 2001 17:05:15 +0000 Subject: [PATCH] Added a simple delta filter. committer: mfx 978973515 +0000 --- src/filter/ctoj.h | 2 +- src/filter/ctojr.h | 2 +- src/filter/sub.h | 151 +++++++++++++++++++++++++++++++++++++++++++++ src/filteri.cpp | 9 ++- 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 src/filter/sub.h diff --git a/src/filter/ctoj.h b/src/filter/ctoj.h index 40fa6222..5313a29c 100644 --- a/src/filter/ctoj.h +++ b/src/filter/ctoj.h @@ -64,7 +64,7 @@ static int F(Filter *f) } const unsigned char cto8 = f->cto; #ifdef U - const unsigned cto = (unsigned)cto8 << 24; + const unsigned cto = (unsigned)f->cto << 24; #endif for (ic = 0; ic < size - 5; ic++) diff --git a/src/filter/ctojr.h b/src/filter/ctojr.h index a155b54c..61e2a6b9 100644 --- a/src/filter/ctojr.h +++ b/src/filter/ctojr.h @@ -105,7 +105,7 @@ static int F(Filter *f) } const unsigned char cto8 = f->cto; #ifdef U - const unsigned cto = (unsigned)cto8 << 24; + const unsigned cto = (unsigned)f->cto << 24; #endif for (ic = 0; ic < size - 5; ic++) diff --git a/src/filter/sub.h b/src/filter/sub.h new file mode 100644 index 00000000..44268372 --- /dev/null +++ b/src/filter/sub.h @@ -0,0 +1,151 @@ +/* sub.h -- simple delta filter + + This file is part of the UPX executable compressor. + + Copyright (C) 1996-2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2001 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 + markus@oberhumer.com ml1050@cdata.tvnet.hu + */ + + + +/************************************************************************* +// +**************************************************************************/ + +#define SUB(f, N) \ + upx_byte *b = f->buf; \ + unsigned l = f->buf_len; \ + int i; \ + unsigned char d[N]; \ + \ + i = N - 1; do d[i] = 0; while (--i >= 0); \ + \ + i = N - 1; \ + do { \ + *b -= d[i]; \ + d[i] += *b++; \ + if (--i < 0) \ + i = N - 1; \ + } while (--l > 0); \ + f->calls = f->buf_len - 1; \ + return 0; + + +#define ADD(f, N) \ + upx_byte *b = f->buf; \ + unsigned l = f->buf_len; \ + int i; \ + unsigned char d[N]; \ + \ + i = N - 1; do d[i] = 0; while (--i >= 0); \ + \ + i = N - 1; \ + do { \ + d[i] += *b; \ + *b++ = d[i]; \ + if (--i < 0) \ + i = N - 1; \ + } while (--l > 0); \ + f->calls = f->buf_len - 1; \ + return 0; + + +#define SCAN(f, N) \ + f->calls = f->buf_len - 1; \ + return 0; + + +// filter +static int f_sub1(Filter *f) +{ + SUB(f, 1) +} + +static int f_sub2(Filter *f) +{ + SUB(f, 2) +} + +static int f_sub3(Filter *f) +{ + SUB(f, 3) +} + +static int f_sub4(Filter *f) +{ + SUB(f, 4) +} + + +// unfilter +static int u_sub1(Filter *f) +{ + ADD(f, 1) +} + +static int u_sub2(Filter *f) +{ + ADD(f, 2) +} + +static int u_sub3(Filter *f) +{ + ADD(f, 3) +} + +static int u_sub4(Filter *f) +{ + ADD(f, 4) +} + + +// scan +static int s_sub1(Filter *f) +{ + SCAN(f, 1) +} + +static int s_sub2(Filter *f) +{ + SCAN(f, 2) +} + +static int s_sub3(Filter *f) +{ + SCAN(f, 3) +} + +static int s_sub4(Filter *f) +{ + SCAN(f, 4) +} + + +#undef SUB +#undef ADD +#undef SCAN + + +/* +vi:ts=4:et:nowrap +*/ + diff --git a/src/filteri.cpp b/src/filteri.cpp index 6fe3a406..d98fd2bf 100644 --- a/src/filteri.cpp +++ b/src/filteri.cpp @@ -41,12 +41,13 @@ /************************************************************************* -// calltrick / swaptrick +// simple filters: calltrick / swaptrick / delta / ... **************************************************************************/ #include "filter/ct.h" #include "filter/sw.h" #include "filter/ctsw.h" +#include "filter/sub.h" /************************************************************************* @@ -174,6 +175,12 @@ const FilterImp::FilterEntry FilterImp::filters[] = { // 32-bit cto calltrick with jmp and relative renumbering { 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le }, + + // simple delta filter + { 0x90, 2, 0, f_sub1, u_sub1, s_sub1 }, + { 0x91, 3, 0, f_sub2, u_sub2, s_sub2 }, + { 0x92, 4, 0, f_sub3, u_sub3, s_sub3 }, + { 0x93, 5, 0, f_sub4, u_sub4, s_sub4 }, }; const int FilterImp::n_filters = HIGH(filters);