1
/* sw.h -- 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 swaptrick ("naive")
32
**************************************************************************/
34
#define SW16(f, cond, 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); \
47
} while (++b < b_end); \
48
if (f->lastcall) f->lastcall += 2; \
53
static int f_sw16_e8(Filter *f)
55
SW16(f, (*b == 0xe8), get_le16, set_be16)
58
static int f_sw16_e9(Filter *f)
60
SW16(f, (*b == 0xe9), get_le16, set_be16)
63
static int f_sw16_e8e9(Filter *f)
65
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_be16)
70
static int u_sw16_e8(Filter *f)
72
SW16(f, (*b == 0xe8), get_be16, set_le16)
75
static int u_sw16_e9(Filter *f)
77
SW16(f, (*b == 0xe9), get_be16, set_le16)
80
static int u_sw16_e8e9(Filter *f)
82
SW16(f, (*b == 0xe8 || *b == 0xe9), get_be16, set_le16)
87
static int s_sw16_e8(Filter *f)
89
SW16(f, (*b == 0xe8), get_le16, set_dummy)
92
static int s_sw16_e9(Filter *f)
94
SW16(f, (*b == 0xe9), get_le16, set_dummy)
97
static int s_sw16_e8e9(Filter *f)
99
SW16(f, (*b == 0xe8 || *b == 0xe9), get_le16, set_dummy)
108
/*************************************************************************
109
// 32-bit swaptrick ("naive")
110
**************************************************************************/
112
#define SW32(f, cond, get, set) \
113
upx_byte *b = f->buf; \
114
upx_byte *b_end = b + f->buf_len - 5; \
119
unsigned a = (unsigned) (b - f->buf); \
125
} while (++b < b_end); \
126
if (f->lastcall) f->lastcall += 4; \
131
static int f_sw32_e8(Filter *f)
133
SW32(f, (*b == 0xe8), get_le32, set_be32)
136
static int f_sw32_e9(Filter *f)
138
SW32(f, (*b == 0xe9), get_le32, set_be32)
141
static int f_sw32_e8e9(Filter *f)
143
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_be32)
148
static int u_sw32_e8(Filter *f)
150
SW32(f, (*b == 0xe8), get_be32, set_le32)
153
static int u_sw32_e9(Filter *f)
155
SW32(f, (*b == 0xe9), get_be32, set_le32)
158
static int u_sw32_e8e9(Filter *f)
160
SW32(f, (*b == 0xe8 || *b == 0xe9), get_be32, set_le32)
165
static int s_sw32_e8(Filter *f)
167
SW32(f, (*b == 0xe8), get_le32, set_dummy)
170
static int s_sw32_e9(Filter *f)
172
SW32(f, (*b == 0xe9), get_le32, set_dummy)
175
static int s_sw32_e8e9(Filter *f)
177
SW32(f, (*b == 0xe8 || *b == 0xe9), get_le32, set_dummy)