From 6c2c17492611d4671781e017dae96eee6b6f16a3 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Mon, 8 Jan 2001 18:49:17 +0000 Subject: [PATCH] Added a simple delta filter. committer: mfx 978979757 +0000 --- src/filter/sub.h | 151 --------------------------------------------- src/filter/sub16.h | 122 ++++++++++++++++++++++++++++++++++++ src/filter/sub32.h | 122 ++++++++++++++++++++++++++++++++++++ src/filter/sub8.h | 122 ++++++++++++++++++++++++++++++++++++ src/filteri.cpp | 25 ++++++-- 5 files changed, 386 insertions(+), 156 deletions(-) delete mode 100644 src/filter/sub.h create mode 100644 src/filter/sub16.h create mode 100644 src/filter/sub32.h create mode 100644 src/filter/sub8.h diff --git a/src/filter/sub.h b/src/filter/sub.h deleted file mode 100644 index 44268372..00000000 --- a/src/filter/sub.h +++ /dev/null @@ -1,151 +0,0 @@ -/* 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/filter/sub16.h b/src/filter/sub16.h new file mode 100644 index 00000000..75db923d --- /dev/null +++ b/src/filter/sub16.h @@ -0,0 +1,122 @@ +/* sub16.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 + */ + + + +/************************************************************************* +// +**************************************************************************/ + +#include "filter/sub.hh" + +#define SUB16(f, N) SUB(f, N, unsigned short, get_le16, set_le16) +#define ADD16(f, N) ADD(f, N, unsigned short, get_le16, set_le16) +#define SCAN16(f, N) SCAN(f, N, unsigned short, get_le16, set_le16) + + +/************************************************************************* +// +**************************************************************************/ + +// filter +static int f_sub16_1(Filter *f) +{ + SUB16(f, 1) +} + +static int f_sub16_2(Filter *f) +{ + SUB16(f, 2) +} + +static int f_sub16_3(Filter *f) +{ + SUB16(f, 3) +} + +static int f_sub16_4(Filter *f) +{ + SUB16(f, 4) +} + + +// unfilter +static int u_sub16_1(Filter *f) +{ + ADD16(f, 1) +} + +static int u_sub16_2(Filter *f) +{ + ADD16(f, 2) +} + +static int u_sub16_3(Filter *f) +{ + ADD16(f, 3) +} + +static int u_sub16_4(Filter *f) +{ + ADD16(f, 4) +} + + +// scan +static int s_sub16_1(Filter *f) +{ + SCAN16(f, 1) +} + +static int s_sub16_2(Filter *f) +{ + SCAN16(f, 2) +} + +static int s_sub16_3(Filter *f) +{ + SCAN16(f, 3) +} + +static int s_sub16_4(Filter *f) +{ + SCAN16(f, 4) +} + + +#undef SUB +#undef ADD +#undef SCAN +#undef SUB16 +#undef ADD16 +#undef SCAN16 + + +/* +vi:ts=4:et:nowrap +*/ + diff --git a/src/filter/sub32.h b/src/filter/sub32.h new file mode 100644 index 00000000..3643e436 --- /dev/null +++ b/src/filter/sub32.h @@ -0,0 +1,122 @@ +/* sub32.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 + */ + + + +/************************************************************************* +// +**************************************************************************/ + +#include "filter/sub.hh" + +#define SUB32(f, N) SUB(f, N, unsigned int, get_le32, set_le32) +#define ADD32(f, N) ADD(f, N, unsigned int, get_le32, set_le32) +#define SCAN32(f, N) SCAN(f, N, unsigned int, get_le32, set_le32) + + +/************************************************************************* +// +**************************************************************************/ + +// filter +static int f_sub32_1(Filter *f) +{ + SUB32(f, 1) +} + +static int f_sub32_2(Filter *f) +{ + SUB32(f, 2) +} + +static int f_sub32_3(Filter *f) +{ + SUB32(f, 3) +} + +static int f_sub32_4(Filter *f) +{ + SUB32(f, 4) +} + + +// unfilter +static int u_sub32_1(Filter *f) +{ + ADD32(f, 1) +} + +static int u_sub32_2(Filter *f) +{ + ADD32(f, 2) +} + +static int u_sub32_3(Filter *f) +{ + ADD32(f, 3) +} + +static int u_sub32_4(Filter *f) +{ + ADD32(f, 4) +} + + +// scan +static int s_sub32_1(Filter *f) +{ + SCAN32(f, 1) +} + +static int s_sub32_2(Filter *f) +{ + SCAN32(f, 2) +} + +static int s_sub32_3(Filter *f) +{ + SCAN32(f, 3) +} + +static int s_sub32_4(Filter *f) +{ + SCAN32(f, 4) +} + + +#undef SUB +#undef ADD +#undef SCAN +#undef SUB32 +#undef ADD32 +#undef SCAN32 + + +/* +vi:ts=4:et:nowrap +*/ + diff --git a/src/filter/sub8.h b/src/filter/sub8.h new file mode 100644 index 00000000..f4669850 --- /dev/null +++ b/src/filter/sub8.h @@ -0,0 +1,122 @@ +/* sub8.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 + */ + + + +/************************************************************************* +// +**************************************************************************/ + +#include "filter/sub.hh" + +#define SUB8(f, N) SUB(f, N, unsigned char, get_8, set_8) +#define ADD8(f, N) ADD(f, N, unsigned char, get_8, set_8) +#define SCAN8(f, N) SCAN(f, N, unsigned char, get_8, set_8) + + +/************************************************************************* +// +**************************************************************************/ + +// filter +static int f_sub8_1(Filter *f) +{ + SUB8(f, 1) +} + +static int f_sub8_2(Filter *f) +{ + SUB8(f, 2) +} + +static int f_sub8_3(Filter *f) +{ + SUB8(f, 3) +} + +static int f_sub8_4(Filter *f) +{ + SUB8(f, 4) +} + + +// unfilter +static int u_sub8_1(Filter *f) +{ + ADD8(f, 1) +} + +static int u_sub8_2(Filter *f) +{ + ADD8(f, 2) +} + +static int u_sub8_3(Filter *f) +{ + ADD8(f, 3) +} + +static int u_sub8_4(Filter *f) +{ + ADD8(f, 4) +} + + +// scan +static int s_sub8_1(Filter *f) +{ + SCAN8(f, 1) +} + +static int s_sub8_2(Filter *f) +{ + SCAN8(f, 2) +} + +static int s_sub8_3(Filter *f) +{ + SCAN8(f, 3) +} + +static int s_sub8_4(Filter *f) +{ + SCAN8(f, 4) +} + + +#undef SUB +#undef ADD +#undef SCAN +#undef SUB8 +#undef ADD8 +#undef SCAN8 + + +/* +vi:ts=4:et:nowrap +*/ + diff --git a/src/filteri.cpp b/src/filteri.cpp index d98fd2bf..6f6eb169 100644 --- a/src/filteri.cpp +++ b/src/filteri.cpp @@ -31,6 +31,8 @@ #define set_dummy(p, v) ((void)0) +#define get_8(p) (*(p)) +#define set_8(p, v) (*(p) = (v)) /************************************************************************* @@ -47,7 +49,10 @@ #include "filter/ct.h" #include "filter/sw.h" #include "filter/ctsw.h" -#include "filter/sub.h" + +#include "filter/sub8.h" +#include "filter/sub16.h" +#include "filter/sub32.h" /************************************************************************* @@ -177,10 +182,20 @@ const FilterImp::FilterEntry FilterImp::filters[] = { { 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 }, + { 0x90, 2, 0, f_sub8_1, u_sub8_1, s_sub8_1 }, + { 0x91, 3, 0, f_sub8_2, u_sub8_2, s_sub8_2 }, + { 0x92, 4, 0, f_sub8_3, u_sub8_3, s_sub8_3 }, + { 0x93, 5, 0, f_sub8_4, u_sub8_4, s_sub8_4 }, + + { 0xa0,99, 0, f_sub16_1, u_sub16_1, s_sub16_1 }, + { 0xa1,99, 0, f_sub16_2, u_sub16_2, s_sub16_2 }, + { 0xa2,99, 0, f_sub16_3, u_sub16_3, s_sub16_3 }, + { 0xa3,99, 0, f_sub16_4, u_sub16_4, s_sub16_4 }, + + { 0xb0,99, 0, f_sub32_1, u_sub32_1, s_sub32_1 }, + { 0xb1,99, 0, f_sub32_2, u_sub32_2, s_sub32_2 }, + { 0xb2,99, 0, f_sub32_3, u_sub32_3, s_sub32_3 }, + { 0xb3,99, 0, f_sub32_4, u_sub32_4, s_sub32_4 }, }; const int FilterImp::n_filters = HIGH(filters);