1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

Added internal debugging options '--fake-stub-version=X.XX' and

'--fake-stub-year=XXXX'.

These might prove useful for building up a test suite which is able to
check binary identity of compressed executables between UPX releases
where the implementation of a specific format has not changed.

committer: mfx <mfx> 1138960010 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2006-02-03 09:46:50 +00:00
parent 8e2aa07747
commit 899e7d2f39
3 changed files with 60 additions and 8 deletions

View File

@ -551,6 +551,16 @@ static int do_option(int optc, const char *arg)
case 516:
opt->no_progress = true;
break;
case 542:
if (!mfx_optarg || strlen(mfx_optarg) != 4)
e_optarg(arg);
memcpy(opt->fake_stub_version, mfx_optarg, 4);
break;
case 543:
if (!mfx_optarg || strlen(mfx_optarg) != 4)
e_optarg(arg);
memcpy(opt->fake_stub_year, mfx_optarg, 4);
break;
case 519:
opt->no_env = true;
break;
@ -758,6 +768,8 @@ static const struct mfx_option longopts[] =
// options
{"debug", 0x10, 0, 'D'},
{"fake-stub-version",0x31, 0, 542}, // for internal debugging
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging
{"force", 0, 0, 'f'}, // force overwrite of output files
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
{"info", 0, 0, 'i'}, // info mode

View File

@ -57,6 +57,8 @@ struct options_t {
int backup;
int console;
int debug;
char fake_stub_version[4+1]; // for internal debugging
char fake_stub_year[4+1]; // for internal debugging
int force;
int info_mode;
bool ignorewarn;

View File

@ -2,8 +2,8 @@
This file is part of the UPX executable compressor.
Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2005 Laszlo Molnar
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2006 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
@ -812,7 +812,10 @@ int Packer::patchVersion(void *b, int blen)
checkPatch(b, blen, boff, 14);
unsigned char *p = (unsigned char *)b + boff + 9;
memcpy(p, UPX_VERSION_STRING4, 4);
if (opt->fake_stub_version[0])
memcpy(p, opt->fake_stub_version, 4);
else
memcpy(p, UPX_VERSION_STRING4, 4);
return boff;
}
@ -974,23 +977,58 @@ const int *Packer::getDefaultCompressionMethods_le32(int method, int level, int
// loader util
**************************************************************************/
static void str_replace(char *s, int size, const char *o, const char *n, int xlen)
{
int off;
for (off = 0; off + xlen <= size; off += xlen)
{
off = find(s + off, size - off, o, xlen);
if (off < 0)
break;
memcpy(s + off, n, xlen);
}
}
char const *Packer::getIdentstr(unsigned *size, int small)
{
static const char identbig[] =
static char identbig[] =
"\n\0"
"$Info: "
"This file is packed with the UPX executable packer http://upx.sf.net $"
"\n\0"
"$Id: UPX "
UPX_VERSION_STRING4
" Copyright (C) 1996-2005 the UPX Team. All Rights Reserved. $"
" Copyright (C) 1996-2006 the UPX Team. All Rights Reserved. $"
"\n";
static const char identsmall[] =
static char identsmall[] =
"\n"
"$Id: UPX "
"(C) 1996-2005 the UPX Team. All Rights Reserved. http://upx.sf.net $"
"(C) 1996-2006 the UPX Team. All Rights Reserved. http://upx.sf.net $"
"\n";
static const char identtiny[] = UPX_VERSION_STRING4;
static char identtiny[] = UPX_VERSION_STRING4;
static int done;
if (!done && (opt->fake_stub_version[0] || opt->fake_stub_year[0]))
{
struct strinfo_t { char *s; int size; };
static const strinfo_t strlist[] = {
{ identbig, (int)sizeof(identbig) },
{ identsmall, (int)sizeof(identsmall) },
{ identtiny, (int)sizeof(identtiny) },
{ NULL, 0 } };
const strinfo_t* iter;
for (iter = strlist; iter->s; ++iter)
{
if (opt->fake_stub_version[0])
str_replace(iter->s, iter->size, UPX_VERSION_STRING4, opt->fake_stub_version, 4);
if (opt->fake_stub_year[0])
str_replace(iter->s, iter->size, "2006", opt->fake_stub_year, 4);
}
done = 1;
}
if (small < 0)
small = opt->small;