Refactored a new mem_replace() function.

committer: mfx <mfx> 1138984802 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2006-02-03 16:40:02 +00:00
parent 899e7d2f39
commit fbb60f5191
3 changed files with 24 additions and 15 deletions

View File

@ -977,19 +977,6 @@ 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 char identbig[] =
@ -1022,9 +1009,9 @@ char const *Packer::getIdentstr(unsigned *size, int small)
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);
mem_replace(iter->s, iter->size, UPX_VERSION_STRING4, 4, opt->fake_stub_version);
if (opt->fake_stub_year[0])
str_replace(iter->s, iter->size, "2006", opt->fake_stub_year, 4);
mem_replace(iter->s, iter->size, "2006", 4, opt->fake_stub_year);
}
done = 1;
}

View File

@ -203,6 +203,26 @@ int find_le64(const void *b, int blen, acc_uint64l_t what)
}
int mem_replace(void *bb, int blen, const void *what, int wlen, const void *r)
{
unsigned char *b = (unsigned char *) bb;
int boff = 0;
int n = 0;
while (blen - boff >= wlen)
{
int off = find(b + boff, blen - boff, what, wlen);
if (off < 0)
break;
boff += off;
memcpy(b + boff, r, wlen);
boff += wlen;
n++;
}
return n;
}
/*************************************************************************
// filename util
**************************************************************************/

View File

@ -58,6 +58,8 @@ int find_le16(const void *b, int blen, unsigned what);
int find_le32(const void *b, int blen, unsigned what);
int find_le64(const void *b, int blen, acc_uint64l_t what);
int mem_replace(void *b, int blen, const void *what, int wlen, const void *r);
#if (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0530))
#elif (ACC_CC_DMC && (__DMC__ < 0x830))