mirror of
https://github.com/upx/upx.git
synced 2025-08-07 22:46:51 +08:00
OutputFile::unset_extent(); endianness in Mach_fat_* and PackMachBase::b_info
This commit is contained in:
@ -407,11 +407,10 @@ void OutputFile::set_extent(off_t offset, off_t length)
|
||||
}
|
||||
}
|
||||
|
||||
off_t OutputFile::clear_offset()
|
||||
off_t OutputFile::unset_extent()
|
||||
{
|
||||
_offset = 0;
|
||||
::lseek(_fd, 0, SEEK_END);
|
||||
_length = tell();
|
||||
_length = ::lseek(_fd, 0, SEEK_END);
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,6 @@ public:
|
||||
const char *getName() const { return _name; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
virtual off_t tell() const;
|
||||
|
||||
protected:
|
||||
void sopen();
|
||||
@ -69,6 +68,7 @@ protected:
|
||||
virtual int readx(void *buf, int len);
|
||||
virtual void write(const void *buf, int len);
|
||||
virtual void seek(off_t off, int whence);
|
||||
virtual off_t tell() const;
|
||||
|
||||
int _fd;
|
||||
int _flags;
|
||||
@ -133,7 +133,7 @@ public:
|
||||
virtual void write(const MemBuffer *buf, int len);
|
||||
virtual void write(const MemBuffer &buf, int len);
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
virtual off_t clear_offset(); // returns actual length
|
||||
virtual off_t unset_extent(); // returns actual length
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
|
@ -648,7 +648,7 @@ void PackMachFat::pack(OutputFile *fo)
|
||||
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
|
||||
unsigned length;
|
||||
for (unsigned j=0; j < fat_head.fat.nfat_arch; ++j) {
|
||||
unsigned base = fo->clear_offset(); // actual length
|
||||
unsigned base = fo->unset_extent(); // actual length
|
||||
base += ~(~0u<<fat_head.arch[j].align) & -base; // align up
|
||||
fo->seek(base, SEEK_SET);
|
||||
fo->set_extent(base, ~0u);
|
||||
@ -672,10 +672,10 @@ void PackMachFat::pack(OutputFile *fo)
|
||||
} break;
|
||||
} // switch cputype
|
||||
fat_head.arch[j].offset = base;
|
||||
length = fo->clear_offset();
|
||||
length = fo->unset_extent();
|
||||
fat_head.arch[j].size = length - base;
|
||||
}
|
||||
ph.u_file_size = in_size;;
|
||||
ph.u_file_size = in_size;
|
||||
fi->set_extent(0, in_size);
|
||||
|
||||
fo->seek(0, SEEK_SET);
|
||||
@ -694,12 +694,6 @@ bool PackMachFat::canPack()
|
||||
struct Mach_fat_arch *arch = &fat_head.arch[0];
|
||||
|
||||
fi->readx(&fat_head, sizeof(fat_head));
|
||||
if (Mach_fat_header::FAT_MAGIC_SWAB==fat_head.fat.magic) {
|
||||
unsigned *const p = &fat_head.fat.magic;
|
||||
for (unsigned j = 0; j < sizeof(fat_head)/sizeof(unsigned); ++j) {
|
||||
p[j] = acc_swab32(p[j]);
|
||||
}
|
||||
}
|
||||
if (Mach_fat_header::FAT_MAGIC!=fat_head.fat.magic
|
||||
|| N_FAT_ARCH < fat_head.fat.nfat_arch) {
|
||||
return false;
|
||||
|
46
src/p_mach.h
46
src/p_mach.h
@ -29,22 +29,20 @@
|
||||
#ifndef __UPX_P_MACHO_H
|
||||
#define __UPX_P_MACHO_H
|
||||
|
||||
// Apparently, Mach_fat_header and Mach_fat_arch have the endianness
|
||||
// of the machine on which they were created. We must deal with both kinds.
|
||||
struct Mach_fat_header {
|
||||
unsigned magic;
|
||||
BE32 magic;
|
||||
enum e8 { // note conflict with java bytecode PackLinuxI386
|
||||
FAT_MAGIC = 0xcafebabe,
|
||||
FAT_MAGIC_SWAB = 0xbebafeca,
|
||||
};
|
||||
unsigned nfat_arch; // Number of Mach_fat_arch which follow.
|
||||
BE32 nfat_arch; // Number of Mach_fat_arch which follow.
|
||||
};
|
||||
struct Mach_fat_arch {
|
||||
unsigned cputype;
|
||||
unsigned cpusubtype;
|
||||
unsigned offset;
|
||||
unsigned size;
|
||||
unsigned align; /* shift count; log base 2 */
|
||||
BE32 cputype;
|
||||
BE32 cpusubtype;
|
||||
BE32 offset;
|
||||
BE32 size;
|
||||
BE32 align; /* shift count; log base 2 */
|
||||
};
|
||||
|
||||
/*************************************************************************
|
||||
@ -281,8 +279,6 @@ typedef N_Mach::MachClass_64<N_BELE_CTP::LEPolicy> MachClass_LE64;
|
||||
// shortcuts
|
||||
typedef MachClass_Host32::Mach_segment_command Mach32_segment_command;
|
||||
typedef MachClass_Host32::Mach_section_command Mach32_section_command;
|
||||
typedef MachClass_Host32::Mach_ppc_thread_state Mach_ppc_thread_state;
|
||||
typedef MachClass_Host32::Mach_i386_thread_state Mach_i386_thread_state;
|
||||
|
||||
typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
|
||||
typedef MachClass_Host64::Mach_section_command Mach64_section_command;
|
||||
@ -299,6 +295,8 @@ typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
|
||||
typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
|
||||
typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
|
||||
|
||||
typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
|
||||
typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
|
||||
#include "p_unix.h"
|
||||
|
||||
|
||||
@ -367,6 +365,32 @@ protected:
|
||||
|
||||
Mach_header mhdro;
|
||||
Mach_segment_command segcmdo;
|
||||
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
U32 sz_unc; // uncompressed_size
|
||||
U32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
U32 l_checksum;
|
||||
LE32 l_magic;
|
||||
U16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
U32 p_progid;
|
||||
U32 p_filesize;
|
||||
U32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
struct l_info linfo;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user