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

Cleaned up the use of upx_compress(), use delete[] where needed.

committer: mfx <mfx> 977422374 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2000-12-21 18:12:54 +00:00
parent e787805b81
commit 5d74b7252d
6 changed files with 45 additions and 58 deletions

View File

@ -1,6 +1,10 @@
*.0??
*.dat
*.idb
*.img
*.map
*.raw
*.rel
*.pdb
*.upx
.gdbinit

View File

@ -461,7 +461,7 @@ p_exe$o: packer.h p_exe.h \
p_lx_elf$o: packer.h p_lx_elf.h p_unix.h p_elf.h \
stub/l_le_n2b.h stub/l_le_n2d.h
p_lx_sep$o: packer.h p_lx_sep.h p_lx_elf.h p_unix.h p_elf.h
p_lx_sh$o: packer.h p_lx_sh.h p_lx_elf.h p_unix.h p_elf.h \
p_lx_sh$o: packer.h p_lx_sh.h p_unix.h p_elf.h \
stub/l_sh_n2b.h stub/l_sh_n2d.h
p_sys$o: packer.h p_sys.h p_com.h \
stub/l_sys.h

View File

@ -46,12 +46,12 @@ static const
PackLinuxI386elf::~PackLinuxI386elf()
{
delete phdri;
delete[] phdri;
}
PackLinuxI386elf::PackLinuxI386elf(InputFile *f)
:super(f)
,phdri(0)
,phdri(NULL)
{
}
@ -127,19 +127,14 @@ void PackLinuxI386elf::patchLoader()
MemBuffer cprLoader(lsize);
// compress compiled C-code portion of loader
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
conf.c_flags = 0;
upx_uint result_buffer[16];
upx_uint cprLsize;
upx_compress(
loader + fold_begin, lsize - fold_begin,
cprLoader, &cprLsize,
0, // progress_callback_t ??
getCompressionMethod(), 9,
&conf,
result_buffer
);
set_le32(0+fold_begin+loader, lsize - fold_begin);
upx_uint const uncLsize = lsize - fold_begin;
upx_uint cprLsize;
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
NULL, opt->method, 10, NULL, NULL);
if (r != UPX_E_OK || cprLsize >= uncLsize)
throwInternalError("loaded compression failed");
set_le32(0+fold_begin+loader, uncLsize);
set_le32(4+fold_begin+loader, cprLsize);
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
lsize = 8 + fold_begin + cprLsize;
@ -156,8 +151,8 @@ void PackLinuxI386elf::patchLoader()
// The beginning of our loader consists of a elf_hdr (52 bytes) and
// two sections elf_phdr (2 * 32 byte), so we have 12 free bytes
// from offset 116 to the program start at offset 128.
assert(ehdr->e_phoff == sizeof(*ehdr));
assert(ehdr->e_ehsize == sizeof(*ehdr));
assert(ehdr->e_phoff == sizeof(Elf_LE32_Ehdr));
assert(ehdr->e_ehsize == sizeof(Elf_LE32_Ehdr));
assert(ehdr->e_phentsize == sizeof(Elf_LE32_Phdr));
assert(ehdr->e_phnum == 2);
assert(ehdr->e_shnum == 0);

View File

@ -94,52 +94,48 @@ static off_t getbrk(Elf_LE32_Phdr const *phdr, int e_phnum)
void PackLinuxI386sh::patchLoader()
{
lsize = getLoaderSize();
ehdri = (Elf_LE32_Ehdr *)(void *)loader;
Elf_LE32_Phdr *const phdri = (Elf_LE32_Phdr *)(1+ehdri);
Elf_LE32_Ehdr *const ehdr = (Elf_LE32_Ehdr *)(void *)loader;
Elf_LE32_Phdr *const phdr = (Elf_LE32_Phdr *)(1+ehdr);
patch_le32(loader,lsize,"UPX3",l_shname);
patch_le32(loader,lsize,"UPX2",o_shname);
// stub/scripts/setfold.pl puts address of 'fold_begin' in phdr[1].p_offset
off_t const fold_begin = phdri[1].p_offset;
off_t const fold_begin = phdr[1].p_offset;
assert(fold_begin > 0);
assert(fold_begin < (off_t)lsize);
MemBuffer cprLoader(lsize);
// compress compiled C-code portion of loader
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
conf.c_flags = 0;
upx_uint result_buffer[16];
upx_uint cprLsize;
upx_compress(
loader + fold_begin, lsize - fold_begin,
cprLoader, &cprLsize,
0, // progress_callback_t ??
getCompressionMethod(), 9,
&conf,
result_buffer
);
set_le32(0+fold_begin+loader, lsize - fold_begin);
upx_uint const uncLsize = lsize - fold_begin;
upx_uint cprLsize;
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
NULL, opt->method, 10, NULL, NULL);
if (r != UPX_E_OK || cprLsize >= uncLsize)
throwInternalError("loaded compression failed");
set_le32(0+fold_begin+loader, uncLsize);
set_le32(4+fold_begin+loader, cprLsize);
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
lsize = 8 + fold_begin + cprLsize;
patchVersion(loader,lsize);
unsigned const brka = getbrk(phdri, ehdri->e_phnum);
phdri[1].p_offset = 0xfff&brka;
phdri[1].p_vaddr = brka;
phdri[1].p_paddr = brka;
phdri[1].p_filesz = 0;
phdri[1].p_memsz = 0;
// Info for OS kernel to set the brk()
unsigned const brka = getbrk(phdr, ehdr->e_phnum);
phdr[1].p_offset = 0xfff&brka;
phdr[1].p_vaddr = brka;
phdr[1].p_paddr = brka;
phdr[1].p_filesz = 0;
phdr[1].p_memsz = 0;
// The beginning of our loader consists of a elf_hdr (52 bytes) and
// two sections elf_phdr (2 * 32 byte), so we have 12 free bytes
// from offset 116 to the program start at offset 128.
assert(ehdri->e_phoff == sizeof(Elf_LE32_Ehdr));
assert(ehdri->e_ehsize == sizeof(Elf_LE32_Ehdr));
assert(ehdri->e_phentsize == sizeof(Elf_LE32_Phdr));
assert(ehdri->e_phnum == 2);
assert(ehdri->e_shnum == 0);
assert(ehdr->e_phoff == sizeof(Elf_LE32_Ehdr));
assert(ehdr->e_ehsize == sizeof(Elf_LE32_Ehdr));
assert(ehdr->e_phentsize == sizeof(Elf_LE32_Phdr));
assert(ehdr->e_phnum == 2);
assert(ehdr->e_shnum == 0);
assert(lsize > 128 && lsize < 4096);
patchLoaderChecksum();

View File

@ -62,8 +62,6 @@ protected:
virtual void patchLoader();
Elf_LE32_Ehdr *ehdri; // from input file
int o_shname; // offset to name_of_shell
int l_shname; // length of name_of_shell
};

View File

@ -445,19 +445,13 @@ void PackLinuxI386::patchLoader()
MemBuffer cprLoader(lsize);
// compress compiled C-code portion of loader
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
conf.c_flags = 0;
upx_uint result_buffer[16];
upx_uint const uncLsize = lsize - fold_begin;
upx_uint cprLsize;
upx_compress(
loader + fold_begin, uncLsize,
cprLoader, &cprLsize,
0, // progress_callback_t ??
getCompressionMethod(), 9,
&conf,
result_buffer
);
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
NULL, opt->method, 10, NULL, NULL);
if (r != UPX_E_OK || cprLsize >= uncLsize)
throwInternalError("loaded compression failed");
memcpy(fold_begin+loader, cprLoader, cprLsize);
lsize = fold_begin + cprLsize;
phdr->p_filesz = lsize;