From 3e31560e7df7b07578366da7df58a8598271b482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Thu, 13 Apr 2006 12:23:42 +0000 Subject: [PATCH] added a new filter for ARM 24-bit naive calltrick committer: ml1050 1144931022 +0000 --- src/filter/ct.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/filteri.cpp | 3 +++ 2 files changed, 43 insertions(+) diff --git a/src/filter/ct.h b/src/filter/ct.h index 46d0bbec..53dbe4b7 100644 --- a/src/filter/ct.h +++ b/src/filter/ct.h @@ -383,6 +383,46 @@ static int s_ct32_e8e9_bswap_be(Filter *f) #undef CT32 +/************************************************************************* +// 24-bit ARM calltrick ("naive") +**************************************************************************/ + +#define CT24ARM(f, cond, addvalue, get, set) \ + upx_byte *b = f->buf; \ + upx_byte *b_end = b + f->buf_len - 4; \ + do { \ + if (cond) \ + { \ + unsigned a = (unsigned) (b - f->buf); \ + f->lastcall = a; \ + set(b, get(b) + (addvalue)); \ + f->calls++; \ + } \ + b += 4; \ + } while (b < b_end); \ + if (f->lastcall) f->lastcall += 4; \ + return 0; + + +#define ARMCT_COND (((b[3] & 0x0f) == 0x0b)) + +static int f_ct24arm_le(Filter *f) +{ + CT24ARM(f, ARMCT_COND, a / 4 + f->addvalue, get_le24, set_le24) +} + +static int u_ct24arm_le(Filter *f) +{ + CT24ARM(f, ARMCT_COND, 0 - a / 4 - f->addvalue, get_le24, set_le24) +} + +static int s_ct24arm_le(Filter *f) +{ + CT24ARM(f, ARMCT_COND, a + f->addvalue, get_le24, set_dummy) +} + +#undef CT24ARM +#undef ARMCT_COND /* vi:ts=4:et:nowrap diff --git a/src/filteri.cpp b/src/filteri.cpp index 10d19ff3..516f993c 100644 --- a/src/filteri.cpp +++ b/src/filteri.cpp @@ -224,6 +224,9 @@ const FilterImp::FilterEntry FilterImp::filters[] = { { 0x46, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le }, { 0x49, 6, 0x00ffffff, f_ctok32_e8e9_bswap_le, u_ctok32_e8e9_bswap_le, s_ctok32_e8e9_bswap_le }, + // 24-bit calltrick for arm + { 0x50, 8, 0x01ffffff, f_ct24arm_le, u_ct24arm_le, s_ct24arm_le }, + // 32-bit cto calltrick with jmp and jcc(swap 0x0f/0x8Y) and relative renumbering { 0x80, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le }, { 0x81, 8, 0x00ffffff, f_ctojr32_e8e9_bswap_le, u_ctojr32_e8e9_bswap_le, s_ctojr32_e8e9_bswap_le },