1
/* ctsw.h -- call-/swaptrick filter
3
This file is part of the UPX executable compressor.
5
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
6
Copyright (C) 1996-2004 Laszlo Molnar
9
UPX and the UCL library are free software; you can redistribute them
10
and/or modify them under the terms of the GNU General Public License as
11
published by the Free Software Foundation; either version 2 of
12
the License, or (at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; see the file COPYING.
21
If not, write to the Free Software Foundation, Inc.,
22
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
Markus F.X.J. Oberhumer Laszlo Molnar
25
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
30
/*************************************************************************
31
// 16-bit call-/swaptrick ("naive")
32
**************************************************************************/
34
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
35
upx_byte *b = f->buf; \
36
upx_byte *b_end = b + f->buf_len - 3; \
41
unsigned a = (unsigned) (b - f->buf); \
43
set(b, get(b) + (addvalue)); \
50
unsigned a = (unsigned) (b - f->buf); \
56
} while (++b < b_end); \
57
if (f->lastcall) f->lastcall += 2; \
62
static int f_ctsw16_e8_e9(Filter *f)
64
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_be16)
67
static int f_ctsw16_e9_e8(Filter *f)
69
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_be16)
74
static int u_ctsw16_e8_e9(Filter *f)
76
CTSW16(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be16, set_le16)
79
static int u_ctsw16_e9_e8(Filter *f)
81
CTSW16(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be16, set_le16)
86
static int s_ctsw16_e8_e9(Filter *f)
88
CTSW16(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le16, set_dummy)
91
static int s_ctsw16_e9_e8(Filter *f)
93
CTSW16(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le16, set_dummy)
100
/*************************************************************************
101
// 32-bit call-/swaptrick ("naive")
102
**************************************************************************/
104
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
105
upx_byte *b = f->buf; \
106
upx_byte *b_end = b + f->buf_len - 5; \
111
unsigned a = (unsigned) (b - f->buf); \
113
set(b, get(b) + (addvalue)); \
120
unsigned a = (unsigned) (b - f->buf); \
126
} while (++b < b_end); \
127
if (f->lastcall) f->lastcall += 4; \
132
static int f_ctsw32_e8_e9(Filter *f)
134
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_be32)
137
static int f_ctsw32_e9_e8(Filter *f)
139
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_be32)
144
static int u_ctsw32_e8_e9(Filter *f)
146
CTSW32(f, (*b == 0xe8), (*b == 0xe9), 0 - a - f->addvalue, get_be32, set_le32)
149
static int u_ctsw32_e9_e8(Filter *f)
151
CTSW32(f, (*b == 0xe9), (*b == 0xe8), 0 - a - f->addvalue, get_be32, set_le32)
156
static int s_ctsw32_e8_e9(Filter *f)
158
CTSW32(f, (*b == 0xe8), (*b == 0xe9), a + f->addvalue, get_le32, set_dummy)
161
static int s_ctsw32_e9_e8(Filter *f)
163
CTSW32(f, (*b == 0xe9), (*b == 0xe8), a + f->addvalue, get_le32, set_dummy)