Cleaned up the use of upx_compress(), use delete[] where needed.
committer: mfx <mfx> 977422374 +0000
This commit is contained in:
parent
e787805b81
commit
5d74b7252d
@ -1,6 +1,10 @@
|
|||||||
*.0??
|
*.0??
|
||||||
|
*.dat
|
||||||
*.idb
|
*.idb
|
||||||
|
*.img
|
||||||
*.map
|
*.map
|
||||||
|
*.raw
|
||||||
|
*.rel
|
||||||
*.pdb
|
*.pdb
|
||||||
*.upx
|
*.upx
|
||||||
.gdbinit
|
.gdbinit
|
||||||
|
|||||||
@ -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 \
|
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
|
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_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
|
stub/l_sh_n2b.h stub/l_sh_n2d.h
|
||||||
p_sys$o: packer.h p_sys.h p_com.h \
|
p_sys$o: packer.h p_sys.h p_com.h \
|
||||||
stub/l_sys.h
|
stub/l_sys.h
|
||||||
|
|||||||
@ -46,12 +46,12 @@ static const
|
|||||||
|
|
||||||
PackLinuxI386elf::~PackLinuxI386elf()
|
PackLinuxI386elf::~PackLinuxI386elf()
|
||||||
{
|
{
|
||||||
delete phdri;
|
delete[] phdri;
|
||||||
}
|
}
|
||||||
|
|
||||||
PackLinuxI386elf::PackLinuxI386elf(InputFile *f)
|
PackLinuxI386elf::PackLinuxI386elf(InputFile *f)
|
||||||
:super(f)
|
:super(f)
|
||||||
,phdri(0)
|
,phdri(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,19 +127,14 @@ void PackLinuxI386elf::patchLoader()
|
|||||||
MemBuffer cprLoader(lsize);
|
MemBuffer cprLoader(lsize);
|
||||||
|
|
||||||
// compress compiled C-code portion of loader
|
// compress compiled C-code portion of loader
|
||||||
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
|
upx_uint const uncLsize = lsize - fold_begin;
|
||||||
conf.c_flags = 0;
|
upx_uint cprLsize;
|
||||||
upx_uint result_buffer[16];
|
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
|
||||||
upx_uint cprLsize;
|
NULL, opt->method, 10, NULL, NULL);
|
||||||
upx_compress(
|
if (r != UPX_E_OK || cprLsize >= uncLsize)
|
||||||
loader + fold_begin, lsize - fold_begin,
|
throwInternalError("loaded compression failed");
|
||||||
cprLoader, &cprLsize,
|
|
||||||
0, // progress_callback_t ??
|
set_le32(0+fold_begin+loader, uncLsize);
|
||||||
getCompressionMethod(), 9,
|
|
||||||
&conf,
|
|
||||||
result_buffer
|
|
||||||
);
|
|
||||||
set_le32(0+fold_begin+loader, lsize - fold_begin);
|
|
||||||
set_le32(4+fold_begin+loader, cprLsize);
|
set_le32(4+fold_begin+loader, cprLsize);
|
||||||
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
|
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
|
||||||
lsize = 8 + fold_begin + 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
|
// 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
|
// two sections elf_phdr (2 * 32 byte), so we have 12 free bytes
|
||||||
// from offset 116 to the program start at offset 128.
|
// from offset 116 to the program start at offset 128.
|
||||||
assert(ehdr->e_phoff == sizeof(*ehdr));
|
assert(ehdr->e_phoff == sizeof(Elf_LE32_Ehdr));
|
||||||
assert(ehdr->e_ehsize == sizeof(*ehdr));
|
assert(ehdr->e_ehsize == sizeof(Elf_LE32_Ehdr));
|
||||||
assert(ehdr->e_phentsize == sizeof(Elf_LE32_Phdr));
|
assert(ehdr->e_phentsize == sizeof(Elf_LE32_Phdr));
|
||||||
assert(ehdr->e_phnum == 2);
|
assert(ehdr->e_phnum == 2);
|
||||||
assert(ehdr->e_shnum == 0);
|
assert(ehdr->e_shnum == 0);
|
||||||
|
|||||||
@ -94,52 +94,48 @@ static off_t getbrk(Elf_LE32_Phdr const *phdr, int e_phnum)
|
|||||||
void PackLinuxI386sh::patchLoader()
|
void PackLinuxI386sh::patchLoader()
|
||||||
{
|
{
|
||||||
lsize = getLoaderSize();
|
lsize = getLoaderSize();
|
||||||
ehdri = (Elf_LE32_Ehdr *)(void *)loader;
|
Elf_LE32_Ehdr *const ehdr = (Elf_LE32_Ehdr *)(void *)loader;
|
||||||
Elf_LE32_Phdr *const phdri = (Elf_LE32_Phdr *)(1+ehdri);
|
Elf_LE32_Phdr *const phdr = (Elf_LE32_Phdr *)(1+ehdr);
|
||||||
|
|
||||||
patch_le32(loader,lsize,"UPX3",l_shname);
|
patch_le32(loader,lsize,"UPX3",l_shname);
|
||||||
patch_le32(loader,lsize,"UPX2",o_shname);
|
patch_le32(loader,lsize,"UPX2",o_shname);
|
||||||
|
|
||||||
// stub/scripts/setfold.pl puts address of 'fold_begin' in phdr[1].p_offset
|
// 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 > 0);
|
||||||
assert(fold_begin < (off_t)lsize);
|
assert(fold_begin < (off_t)lsize);
|
||||||
MemBuffer cprLoader(lsize);
|
MemBuffer cprLoader(lsize);
|
||||||
|
|
||||||
// compress compiled C-code portion of loader
|
// compress compiled C-code portion of loader
|
||||||
upx_compress_config_t conf; memset(&conf, 0xff, sizeof(conf));
|
upx_uint const uncLsize = lsize - fold_begin;
|
||||||
conf.c_flags = 0;
|
upx_uint cprLsize;
|
||||||
upx_uint result_buffer[16];
|
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
|
||||||
upx_uint cprLsize;
|
NULL, opt->method, 10, NULL, NULL);
|
||||||
upx_compress(
|
if (r != UPX_E_OK || cprLsize >= uncLsize)
|
||||||
loader + fold_begin, lsize - fold_begin,
|
throwInternalError("loaded compression failed");
|
||||||
cprLoader, &cprLsize,
|
|
||||||
0, // progress_callback_t ??
|
set_le32(0+fold_begin+loader, uncLsize);
|
||||||
getCompressionMethod(), 9,
|
|
||||||
&conf,
|
|
||||||
result_buffer
|
|
||||||
);
|
|
||||||
set_le32(0+fold_begin+loader, lsize - fold_begin);
|
|
||||||
set_le32(4+fold_begin+loader, cprLsize);
|
set_le32(4+fold_begin+loader, cprLsize);
|
||||||
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
|
memcpy( 8+fold_begin+loader, cprLoader, cprLsize);
|
||||||
lsize = 8 + fold_begin + cprLsize;
|
lsize = 8 + fold_begin + cprLsize;
|
||||||
patchVersion(loader,lsize);
|
patchVersion(loader,lsize);
|
||||||
|
|
||||||
unsigned const brka = getbrk(phdri, ehdri->e_phnum);
|
// Info for OS kernel to set the brk()
|
||||||
phdri[1].p_offset = 0xfff&brka;
|
unsigned const brka = getbrk(phdr, ehdr->e_phnum);
|
||||||
phdri[1].p_vaddr = brka;
|
phdr[1].p_offset = 0xfff&brka;
|
||||||
phdri[1].p_paddr = brka;
|
phdr[1].p_vaddr = brka;
|
||||||
phdri[1].p_filesz = 0;
|
phdr[1].p_paddr = brka;
|
||||||
phdri[1].p_memsz = 0;
|
phdr[1].p_filesz = 0;
|
||||||
|
phdr[1].p_memsz = 0;
|
||||||
|
|
||||||
// The beginning of our loader consists of a elf_hdr (52 bytes) and
|
// 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
|
// two sections elf_phdr (2 * 32 byte), so we have 12 free bytes
|
||||||
// from offset 116 to the program start at offset 128.
|
// from offset 116 to the program start at offset 128.
|
||||||
assert(ehdri->e_phoff == sizeof(Elf_LE32_Ehdr));
|
assert(ehdr->e_phoff == sizeof(Elf_LE32_Ehdr));
|
||||||
assert(ehdri->e_ehsize == sizeof(Elf_LE32_Ehdr));
|
assert(ehdr->e_ehsize == sizeof(Elf_LE32_Ehdr));
|
||||||
assert(ehdri->e_phentsize == sizeof(Elf_LE32_Phdr));
|
assert(ehdr->e_phentsize == sizeof(Elf_LE32_Phdr));
|
||||||
assert(ehdri->e_phnum == 2);
|
assert(ehdr->e_phnum == 2);
|
||||||
assert(ehdri->e_shnum == 0);
|
assert(ehdr->e_shnum == 0);
|
||||||
assert(lsize > 128 && lsize < 4096);
|
assert(lsize > 128 && lsize < 4096);
|
||||||
|
|
||||||
patchLoaderChecksum();
|
patchLoaderChecksum();
|
||||||
|
|||||||
@ -62,8 +62,6 @@ protected:
|
|||||||
|
|
||||||
virtual void patchLoader();
|
virtual void patchLoader();
|
||||||
|
|
||||||
Elf_LE32_Ehdr *ehdri; // from input file
|
|
||||||
|
|
||||||
int o_shname; // offset to name_of_shell
|
int o_shname; // offset to name_of_shell
|
||||||
int l_shname; // length of name_of_shell
|
int l_shname; // length of name_of_shell
|
||||||
};
|
};
|
||||||
|
|||||||
@ -445,19 +445,13 @@ void PackLinuxI386::patchLoader()
|
|||||||
MemBuffer cprLoader(lsize);
|
MemBuffer cprLoader(lsize);
|
||||||
|
|
||||||
// compress compiled C-code portion of loader
|
// 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 const uncLsize = lsize - fold_begin;
|
||||||
upx_uint cprLsize;
|
upx_uint cprLsize;
|
||||||
upx_compress(
|
int r = upx_compress(loader + fold_begin, uncLsize, cprLoader, &cprLsize,
|
||||||
loader + fold_begin, uncLsize,
|
NULL, opt->method, 10, NULL, NULL);
|
||||||
cprLoader, &cprLsize,
|
if (r != UPX_E_OK || cprLsize >= uncLsize)
|
||||||
0, // progress_callback_t ??
|
throwInternalError("loaded compression failed");
|
||||||
getCompressionMethod(), 9,
|
|
||||||
&conf,
|
|
||||||
result_buffer
|
|
||||||
);
|
|
||||||
memcpy(fold_begin+loader, cprLoader, cprLsize);
|
memcpy(fold_begin+loader, cprLoader, cprLsize);
|
||||||
lsize = fold_begin + cprLsize;
|
lsize = fold_begin + cprLsize;
|
||||||
phdr->p_filesz = lsize;
|
phdr->p_filesz = lsize;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user