mirror of
https://github.com/upx/upx
synced 2025-10-05 19:20:23 +08:00
Silence some compiler warnings.
This commit is contained in:
parent
b72e0f3060
commit
ef8a7f330d
|
@ -577,8 +577,8 @@ void PackLinuxElf32::defineSymbols(Filter const *ft)
|
||||||
upx_uint32_t lo_va_stub = get_te32(&elfout.phdr[0].p_vaddr);
|
upx_uint32_t lo_va_stub = get_te32(&elfout.phdr[0].p_vaddr);
|
||||||
upx_uint32_t adrm;
|
upx_uint32_t adrm;
|
||||||
len += (7&-lsize) + lsize;
|
len += (7&-lsize) + lsize;
|
||||||
upx_uint32_t my_page_size = 4096u;
|
const upx_uint32_t my_page_size = 4096u;
|
||||||
upx_uint32_t my_page_mask = -my_page_size;
|
const upx_uint32_t my_page_mask = 0u - my_page_size;
|
||||||
is_big = (lo_va_user < (lo_va_stub + len + 2 * my_page_size));
|
is_big = (lo_va_user < (lo_va_stub + len + 2 * my_page_size));
|
||||||
if (is_pie || (is_big /*&& ehdri.ET_EXEC==get_te16(&ehdri.e_type)*/)) {
|
if (is_pie || (is_big /*&& ehdri.ET_EXEC==get_te16(&ehdri.e_type)*/)) {
|
||||||
// .e_entry is set later by PackLinuxElf32::updateLoader
|
// .e_entry is set later by PackLinuxElf32::updateLoader
|
||||||
|
@ -1192,8 +1192,8 @@ PackLinuxElf64amd::defineSymbols(Filter const *ft)
|
||||||
unsigned lenm;
|
unsigned lenm;
|
||||||
unsigned lenu;
|
unsigned lenu;
|
||||||
len += (7&-lsize) + lsize;
|
len += (7&-lsize) + lsize;
|
||||||
upx_uint64_t my_page_size = 4096u;
|
const upx_uint64_t my_page_size = 4096u;
|
||||||
upx_uint64_t my_page_mask = -my_page_size;
|
const upx_uint64_t my_page_mask = 0u - my_page_size;
|
||||||
is_big = (lo_va_user < (lo_va_stub + len + 2 * my_page_size));
|
is_big = (lo_va_user < (lo_va_stub + len + 2 * my_page_size));
|
||||||
if (is_pie || (is_big /*&& ehdri.ET_EXEC==get_te16(&ehdri.e_type)*/)) {
|
if (is_pie || (is_big /*&& ehdri.ET_EXEC==get_te16(&ehdri.e_type)*/)) {
|
||||||
// .e_entry is set later by PackLinuxElf64::updateLoader
|
// .e_entry is set later by PackLinuxElf64::updateLoader
|
||||||
|
|
|
@ -82,7 +82,7 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||||
assert(ehdri.e_phoff == sizeof(Elf32_Ehdr)); // checked by canPack()
|
assert(ehdri.e_phoff == sizeof(Elf32_Ehdr)); // checked by canPack()
|
||||||
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
sz_phdrs = ehdri.e_phnum * ehdri.e_phentsize;
|
||||||
|
|
||||||
phdri = new Elf32_Phdr[(unsigned)ehdri.e_phnum];
|
phdri = New(Elf32_Phdr, ehdri.e_phnum);
|
||||||
fi->seek(ehdri.e_phoff, SEEK_SET);
|
fi->seek(ehdri.e_phoff, SEEK_SET);
|
||||||
fi->readx(phdri, sz_phdrs);
|
fi->readx(phdri, sz_phdrs);
|
||||||
|
|
||||||
|
|
|
@ -93,11 +93,13 @@ static const unsigned lc_segment[2] = {
|
||||||
//Mach_command::LC_SEGMENT_64
|
//Mach_command::LC_SEGMENT_64
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0 // NOT USED
|
||||||
static const unsigned lc_routines[2] = {
|
static const unsigned lc_routines[2] = {
|
||||||
0x11, 0x1a
|
0x11, 0x1a
|
||||||
//Mach_command::LC_ROUTINES,
|
//Mach_command::LC_ROUTINES,
|
||||||
//Mach_command::LC_ROUTINES_64
|
//Mach_command::LC_ROUTINES_64
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
|
PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
|
||||||
|
@ -459,7 +461,7 @@ PackMachBase<T>::buildMachLoader(
|
||||||
}
|
}
|
||||||
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
unsigned char const *const uncLoader = fold_hdrlen + fold;
|
||||||
|
|
||||||
unsigned char *const cprLoader = new unsigned char[sizeof(h) + h.sz_unc];
|
unsigned char *const cprLoader = New(unsigned char, sizeof(h) + h.sz_unc);
|
||||||
if (0 < szfold) {
|
if (0 < szfold) {
|
||||||
unsigned sz_cpr = 0;
|
unsigned sz_cpr = 0;
|
||||||
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
|
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
|
||||||
|
@ -1509,7 +1511,7 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||||
if ((sizeof(mhdri) + sz_cmds) > (size_t)fi->st_size()) {
|
if ((sizeof(mhdri) + sz_cmds) > (size_t)fi->st_size()) {
|
||||||
throwCantUnpack("file header corrupted");
|
throwCantUnpack("file header corrupted");
|
||||||
}
|
}
|
||||||
rawmseg = (Mach_segment_command *)new char[sz_cmds];
|
rawmseg = (Mach_segment_command *) New(char, sz_cmds);
|
||||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||||
|
|
||||||
// FIXME forgot space left for LC_CODE_SIGNATURE;
|
// FIXME forgot space left for LC_CODE_SIGNATURE;
|
||||||
|
@ -1542,7 +1544,7 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||||
|
|
||||||
// Uncompress Macho headers
|
// Uncompress Macho headers
|
||||||
fi->readx(ibuf, ph.c_len);
|
fi->readx(ibuf, ph.c_len);
|
||||||
Mach_header *const mhdr = (Mach_header *)new upx_byte[ph.u_len];
|
Mach_header *const mhdr = (Mach_header *) New(upx_byte, ph.u_len);
|
||||||
decompress(ibuf, (upx_byte *)mhdr, false);
|
decompress(ibuf, (upx_byte *)mhdr, false);
|
||||||
if (mhdri.magic != mhdr->magic
|
if (mhdri.magic != mhdr->magic
|
||||||
|| mhdri.cputype != mhdr->cputype
|
|| mhdri.cputype != mhdr->cputype
|
||||||
|
@ -1551,13 +1553,13 @@ void PackMachBase<T>::unpack(OutputFile *fo)
|
||||||
throwCantUnpack("file header corrupted");
|
throwCantUnpack("file header corrupted");
|
||||||
unsigned const ncmds = mhdr->ncmds;
|
unsigned const ncmds = mhdr->ncmds;
|
||||||
|
|
||||||
msegcmd = new Mach_segment_command[ncmds];
|
msegcmd = New(Mach_segment_command, ncmds);
|
||||||
unsigned char const *ptr = (unsigned char const *)(1+mhdr);
|
unsigned char const *ptr = (unsigned char const *)(1+mhdr);
|
||||||
for (unsigned j= 0; j < ncmds; ++j) {
|
for (unsigned j= 0; j < ncmds; ++j) {
|
||||||
memcpy(&msegcmd[j], ptr, umin(sizeof(Mach_segment_command),
|
memcpy(&msegcmd[j], ptr, umin(sizeof(Mach_segment_command),
|
||||||
((Mach_command const *)ptr)->cmdsize));
|
((Mach_command const *)ptr)->cmdsize));
|
||||||
ptr += (unsigned) ((Mach_segment_command const *)ptr)->cmdsize;
|
ptr += (unsigned) ((Mach_segment_command const *)ptr)->cmdsize;
|
||||||
if ((unsigned)(ptr - (unsigned char const *)mhdr) > ph.u_len) {
|
if (ptr_udiff(ptr, mhdr) > ph.u_len) {
|
||||||
throwCantUnpack("cmdsize");
|
throwCantUnpack("cmdsize");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1643,7 +1645,7 @@ int PackMachBase<T>::canUnpack()
|
||||||
if (1024 < headway) {
|
if (1024 < headway) {
|
||||||
infoWarning("Mach_header.sizeofcmds(%d) > 1024", headway);
|
infoWarning("Mach_header.sizeofcmds(%d) > 1024", headway);
|
||||||
}
|
}
|
||||||
rawmseg = (Mach_segment_command *)new char[(unsigned) mhdri.sizeofcmds];
|
rawmseg = (Mach_segment_command *) New(char, mhdri.sizeofcmds);
|
||||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||||
|
|
||||||
Mach_segment_command const *ptrTEXT = 0;
|
Mach_segment_command const *ptrTEXT = 0;
|
||||||
|
@ -1680,7 +1682,7 @@ int PackMachBase<T>::canUnpack()
|
||||||
pos_next = segptr->filesize + segptr->fileoff;
|
pos_next = segptr->filesize + segptr->fileoff;
|
||||||
if ((headway -= ptr->cmdsize) < 0) {
|
if ((headway -= ptr->cmdsize) < 0) {
|
||||||
infoWarning("Mach_command[%u]{@%lu}.cmdsize = %u", j,
|
infoWarning("Mach_command[%u]{@%lu}.cmdsize = %u", j,
|
||||||
sizeof(mhdri) + mhdri.sizeofcmds - (headway + ptr->cmdsize),
|
(unsigned long) (sizeof(mhdri) + mhdri.sizeofcmds - (headway + ptr->cmdsize)),
|
||||||
(unsigned)ptr->cmdsize);
|
(unsigned)ptr->cmdsize);
|
||||||
throwCantUnpack("sum(.cmdsize) exceeds .sizeofcmds");
|
throwCantUnpack("sum(.cmdsize) exceeds .sizeofcmds");
|
||||||
}
|
}
|
||||||
|
@ -1837,14 +1839,14 @@ bool PackMachBase<T>::canPack()
|
||||||
if (16384 < sz_mhcmds) { // somewhat arbitrary, but amd64-darwin.macho-upxmain.c
|
if (16384 < sz_mhcmds) { // somewhat arbitrary, but amd64-darwin.macho-upxmain.c
|
||||||
throwCantPack("16384 < Mach_header.sizeofcmds");
|
throwCantPack("16384 < Mach_header.sizeofcmds");
|
||||||
}
|
}
|
||||||
rawmseg = (Mach_segment_command *)new char[sz_mhcmds];
|
rawmseg = (Mach_segment_command *) New(char, sz_mhcmds);
|
||||||
fi->readx(rawmseg, mhdri.sizeofcmds);
|
fi->readx(rawmseg, mhdri.sizeofcmds);
|
||||||
|
|
||||||
unsigned const ncmds = mhdri.ncmds;
|
unsigned const ncmds = mhdri.ncmds;
|
||||||
if (256 < ncmds) { // arbitrary, but guard against garbage
|
if (256 < ncmds) { // arbitrary, but guard against garbage
|
||||||
throwCantPack("256 < Mach_header.ncmds");
|
throwCantPack("256 < Mach_header.ncmds");
|
||||||
}
|
}
|
||||||
msegcmd = new Mach_segment_command[ncmds];
|
msegcmd = New(Mach_segment_command, ncmds);
|
||||||
unsigned char const *ptr = (unsigned char const *)rawmseg;
|
unsigned char const *ptr = (unsigned char const *)rawmseg;
|
||||||
for (unsigned j= 0; j < ncmds; ++j) {
|
for (unsigned j= 0; j < ncmds; ++j) {
|
||||||
Mach_segment_command const *segptr = (Mach_segment_command const *)ptr;
|
Mach_segment_command const *segptr = (Mach_segment_command const *)ptr;
|
||||||
|
@ -1852,7 +1854,7 @@ bool PackMachBase<T>::canPack()
|
||||||
msegcmd[j] = *segptr;
|
msegcmd[j] = *segptr;
|
||||||
if (!strcmp("__DATA", segptr->segname)) {
|
if (!strcmp("__DATA", segptr->segname)) {
|
||||||
for (Mach_section_command const *secptr = (Mach_section_command const *)(1+ segptr);
|
for (Mach_section_command const *secptr = (Mach_section_command const *)(1+ segptr);
|
||||||
((char const *)secptr - (char const *)segptr) < segptr->cmdsize;
|
ptr_udiff(secptr, segptr) < segptr->cmdsize;
|
||||||
++secptr
|
++secptr
|
||||||
) {
|
) {
|
||||||
if (sizeof(Addr) == secptr->size
|
if (sizeof(Addr) == secptr->size
|
||||||
|
|
|
@ -160,7 +160,7 @@ void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsign
|
||||||
|
|
||||||
if (src && dst)
|
if (src && dst)
|
||||||
{
|
{
|
||||||
unsigned char *cpr_bh = new unsigned char[sz_cbh];
|
unsigned char *cpr_bh = New(unsigned char, sz_cbh);
|
||||||
|
|
||||||
memset(cpr_bh, 0, sizeof(bh));
|
memset(cpr_bh, 0, sizeof(bh));
|
||||||
ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh;
|
ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh;
|
||||||
|
@ -189,7 +189,7 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
|
||||||
|
|
||||||
if (src && (src->id == '1' && src->len < SZ_IH_BKUP) && dst)
|
if (src && (src->id == '1' && src->len < SZ_IH_BKUP) && dst)
|
||||||
{
|
{
|
||||||
unsigned char *unc_bh = new unsigned char[MemBuffer::getSizeForUncompression(SZ_IH_BKUP)];
|
unsigned char *unc_bh = New(unsigned char, MemBuffer::getSizeForUncompression(SZ_IH_BKUP));
|
||||||
|
|
||||||
unsigned sz_bh = SZ_IH_BKUP;
|
unsigned sz_bh = SZ_IH_BKUP;
|
||||||
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
|
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
|
||||||
|
@ -338,7 +338,7 @@ void PackPs1::buildLoader(const Filter *)
|
||||||
if (M_IS_LZMA(ph.method) && buildPart2)
|
if (M_IS_LZMA(ph.method) && buildPart2)
|
||||||
{
|
{
|
||||||
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
|
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
|
||||||
unsigned char *cprLoader = new unsigned char[sz_lcpr];
|
unsigned char *cprLoader = New(unsigned char, sz_lcpr);
|
||||||
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr,
|
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr,
|
||||||
NULL, M_NRV2B_8, 10, NULL, NULL );
|
NULL, M_NRV2B_8, 10, NULL, NULL );
|
||||||
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
|
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user