off_t_upx_stub typedef enables easier use of native #include

... but requires  #define __WORDSIZE
	modified:   p_mach.h
	modified:   stub/amd64-darwin.macho-fold.h
	modified:   stub/src/amd64-darwin.macho-main.c
	modified:   stub/src/arm.v5a-darwin.macho-main.c
	modified:   stub/src/arm64-darwin.macho-main.c
	modified:   stub/src/i386-darwin.macho-main.c
	modified:   stub/src/include/darwin.h
	modified:   stub/src/powerpc-darwin.macho-main.c
	modified:   stub/src/powerpc64le-darwin.macho-main.c
	modified:   stub/tmp/amd64-darwin.macho-fold.map
This commit is contained in:
John Reiser 2017-11-28 14:49:46 -08:00
parent 143f0accef
commit e633c51b50
10 changed files with 87 additions and 75 deletions

View File

@ -29,6 +29,7 @@
#ifndef __UPX_P_MACHO_H
#define __UPX_P_MACHO_H 1
#include "conf.h"
__packed_struct(Mach_fat_header)
BE32 magic;

View File

@ -1,5 +1,5 @@
/* amd64-darwin.macho-fold.h
created from amd64-darwin.macho-fold.bin, 1398 (0x576) bytes
created from amd64-darwin.macho-fold.bin, 1400 (0x578) bytes
This file is part of the UPX executable compressor.
@ -31,11 +31,11 @@
*/
#define STUB_AMD64_DARWIN_MACHO_FOLD_SIZE 1398
#define STUB_AMD64_DARWIN_MACHO_FOLD_ADLER32 0xd4f15022
#define STUB_AMD64_DARWIN_MACHO_FOLD_CRC32 0xddc8ffe6
#define STUB_AMD64_DARWIN_MACHO_FOLD_SIZE 1400
#define STUB_AMD64_DARWIN_MACHO_FOLD_ADLER32 0x45325109
#define STUB_AMD64_DARWIN_MACHO_FOLD_CRC32 0x3fb2bf6b
unsigned char stub_amd64_darwin_macho_fold[1398] = {
unsigned char stub_amd64_darwin_macho_fold[1400] = {
/* 0x0000 */ 232, 74, 0, 0, 0,131,249, 73,117, 68, 83, 87, 72,141, 76, 55,
/* 0x0010 */ 253, 94, 86, 91,235, 47, 72, 57,206,115, 50, 86, 94,172, 60,128,
/* 0x0020 */ 114, 10, 60,143,119, 6,128,126,254, 15,116, 6, 44,232, 60, 1,
@ -75,9 +75,9 @@ unsigned char stub_amd64_darwin_macho_fold[1398] = {
/* 0x0240 */ 192, 59, 71, 16, 72,199, 68, 36, 16, 0, 0, 0, 0,199, 68, 36,
/* 0x0250 */ 12, 0, 0, 0, 0, 15,131,159, 1, 0, 0, 65,139, 69, 0,131,
/* 0x0260 */ 248, 25, 15,133, 81, 1, 0, 0, 73,139, 85, 32, 72,133,210, 15,
/* 0x0270 */ 132, 68, 1, 0, 0, 73,139,125, 24, 73,139, 69, 48, 72,137,251,
/* 0x0280 */ 72,137,253, 73,137,196,129,227,255, 15, 0, 0, 72,137, 68, 36,
/* 0x0290 */ 64, 72,137,124, 36, 72, 72, 41,221, 73, 1,220, 76,141, 52, 23,
/* 0x0270 */ 132, 68, 1, 0, 0, 73,139, 69, 48, 72,137, 68, 36, 64, 73,139,
/* 0x0280 */ 125, 24, 73,137,196, 72,137,251, 72,137,253, 72,137,124, 36, 72,
/* 0x0290 */ 129,227,255, 15, 0, 0, 76,141, 52, 23, 72, 41,221, 73, 1,220,
/* 0x02a0 */ 116, 70, 77,133,255, 76,137,230,116, 7, 73,141,116, 36, 3,235,
/* 0x02b0 */ 10, 72,133,192,185, 18, 0, 0, 0,117, 5,185, 18, 16, 0, 0,
/* 0x02c0 */ 65,131,200,255, 68,139, 76, 36, 52, 72,133,192, 68, 15, 69, 68,
@ -110,18 +110,18 @@ unsigned char stub_amd64_darwin_macho_fold[1398] = {
/* 0x0470 */ 83, 73,137,217,131,201,255, 49,246, 72,137,239, 72,141, 84, 36,
/* 0x0480 */ 8, 65, 84, 76,139,132, 36,128, 0, 0, 0,232,115,253,255,255,
/* 0x0490 */ 65, 89, 65, 90,139,117, 16, 72,141, 85, 32, 72,137,195, 49,201,
/* 0x04a0 */ 57,241, 15,131,190, 0, 0, 0,131, 58, 14, 15,133,168, 0, 0,
/* 0x04b0 */ 0,139,122, 8, 49,246, 72,141, 60, 58, 49,210,232,235,251,255,
/* 0x04c0 */ 255,133,192, 65,137,196,120, 22, 68,137,233, 76,137,242, 72,137,
/* 0x04d0 */ 238, 68,137,231,232,203,251,255,255, 73, 57,198,116, 16,191,127,
/* 0x04e0 */ 0, 0, 0,232,176,251,255,255, 68,139,107, 8,235,218,139, 69,
/* 0x04f0 */ 0, 61,202,254,186,190,116, 7, 61,190,186,254,202,117, 49, 72,
/* 0x0500 */ 15,182,117, 7, 72,137,239, 72,141, 93, 8, 72,107,246, 20,131,
/* 0x0510 */ 198, 8,232,109,251,255,255,139, 69, 4, 49,201, 57,193,115, 16,
/* 0x0520 */ 129, 59, 7, 0, 0, 1,116,192,255,193, 72,131,195, 20,235,236,
/* 0x0530 */ 65, 80, 68,137,238, 69, 49,201, 69, 49,192, 68,137,225,106, 0,
/* 0x0540 */ 49,210, 72,137,239,232,185,252,255,255, 68,137,231, 72,137,195,
/* 0x0550 */ 232, 83,251,255,255, 94, 95,235, 13,139, 66, 4,255,193, 72, 1,
/* 0x0560 */ 194,233, 58,255,255,255, 72,131,196, 64, 72,137,216, 91, 93, 65,
/* 0x0570 */ 92, 65, 93, 65, 94,195
/* 0x04a0 */ 57,241, 15,131,192, 0, 0, 0,131, 58, 14, 15,133,170, 0, 0,
/* 0x04b0 */ 0,139,122, 8, 49,246, 49,192, 72,141, 60, 58, 49,210,232,233,
/* 0x04c0 */ 251,255,255,133,192, 65,137,196,120, 22, 68,137,233, 76,137,242,
/* 0x04d0 */ 72,137,238, 68,137,231,232,201,251,255,255, 73, 57,198,116, 16,
/* 0x04e0 */ 191,127, 0, 0, 0,232,174,251,255,255, 68,139,107, 8,235,218,
/* 0x04f0 */ 139, 69, 0, 61,202,254,186,190,116, 7, 61,190,186,254,202,117,
/* 0x0500 */ 49, 72, 15,182,117, 7, 72,137,239, 72,141, 93, 8, 72,107,246,
/* 0x0510 */ 20,131,198, 8,232,107,251,255,255,139, 69, 4, 49,201, 57,193,
/* 0x0520 */ 115, 16,129, 59, 7, 0, 0, 1,116,192,255,193, 72,131,195, 20,
/* 0x0530 */ 235,236, 65, 80, 68,137,238, 69, 49,201, 69, 49,192, 68,137,225,
/* 0x0540 */ 106, 0, 49,210, 72,137,239,232,183,252,255,255, 68,137,231, 72,
/* 0x0550 */ 137,195,232, 81,251,255,255, 94, 95,235, 13,139, 66, 4,255,193,
/* 0x0560 */ 72, 1,194,233, 56,255,255,255, 72,131,196, 64, 72,137,216, 91,
/* 0x0570 */ 93, 65, 92, 65, 93, 65, 94,195
};

View File

@ -30,6 +30,7 @@
*/
#define __WORDSIZE 64
#include "include/darwin.h"
#ifndef DEBUG /*{*/
@ -466,8 +467,8 @@ typedef union {
#define PROT_EXEC 4
#define MAP_ANON_FD -1
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t_upx_stub);
ssize_t pread(int, void *, size_t, off_t_upx_stub);
extern void bswap(void *, unsigned);
DEBUG_STRCON(STR_mmap,
@ -478,7 +479,7 @@ DEBUG_STRCON(STR_do_xmap,
static Mach_AMD64_thread_state const *
do_xmap(
Mach_header64 const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header64 **mhdrpp,
@ -511,7 +512,7 @@ do_xmap(
unsigned const flags = MAP_FIXED | MAP_PRIVATE |
((xi || 0==sc->filesize) ? MAP_ANON : 0);
int const fdm = ((0==sc->filesize) ? MAP_ANON_FD : fdi);
off_t const offset = sc->fileoff + fat_offset;
off_t_upx_stub const offset = sc->fileoff + fat_offset;
DPRINTF((STR_mmap(), addr, mlen3, prot, flags, fdm, offset));
if (addr != mmap(addr, mlen3, prot, flags, fdm, offset)) {
@ -581,7 +582,7 @@ upx_main(
)
{
Mach_AMD64_thread_state const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(unsigned char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -33,6 +33,7 @@
//#define SIMULATE_ON_DEBIAN_EABI4 1
#undef SIMULATE_ON_DEBIAN_EABI4
#define __WORDSIZE 32
#include "include/darwin.h"
@ -309,14 +310,14 @@ typedef union {
#define MAP_ANON_FD -1
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t_upx_stub);
ssize_t pread(int, void *, size_t, off_t_upx_stub);
extern void bswap(void *, unsigned);
static Mach_ARM_thread_state const *
do_xmap(
Mach_header const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header **mhdrpp,
@ -400,7 +401,7 @@ upx_main(
)
{
Mach_ARM_thread_state const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(unsigned char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -33,6 +33,7 @@
//#define SIMULATE_ON_DEBIAN_EABI4 1
#undef SIMULATE_ON_DEBIAN_EABI4
#define __WORDSIZE 64
#include "include/darwin.h"
@ -315,14 +316,14 @@ typedef union {
#define MAP_ANON_FD -1
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t_upx_stub);
ssize_t pread(int, void *, size_t, off_t_upx_stub);
extern void bswap(void *, unsigned);
static Mach_ARM_thread_state const *
do_xmap(
Mach_header const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header **mhdrpp,
@ -406,7 +407,7 @@ upx_main(
)
{
Mach_ARM_thread_state const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(unsigned char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -30,6 +30,7 @@
*/
#define __WORDSIZE 32
#include "include/darwin.h"
#ifndef DEBUG /*{*/
@ -458,10 +459,10 @@ typedef union {
#define PROT_EXEC 4
#define MAP_ANON_FD -1
// We have off_t as 32 bits, but syscalls consider off_t as 64 bits.
// We have off_t_upx_stub as 32 bits, but syscalls consider off_t as 64 bits.
// Make the top 32 bits explicit, and pass a 0.
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t, unsigned);
extern ssize_t pread(int, void *, size_t, off_t, unsigned);
extern void *mmap(void *, size_t, unsigned, unsigned, int, off_t_upx_stub, unsigned);
extern ssize_t pread(int, void *, size_t, off_t_upx_stub, unsigned);
extern void bswap(void *, unsigned);
DEBUG_STRCON(STR_mmap,
@ -472,7 +473,7 @@ DEBUG_STRCON(STR_do_xmap,
static Mach_i386_thread_state const *
do_xmap(
Mach_header const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header **mhdrpp,
@ -505,7 +506,7 @@ do_xmap(
unsigned const flags = MAP_FIXED | MAP_PRIVATE |
((xi || 0==sc->filesize) ? MAP_ANON : 0);
int const fdm = ((0==sc->filesize) ? MAP_ANON_FD : fdi);
off_t const offset = sc->fileoff + fat_offset;
off_t_upx_stub const offset = sc->fileoff + fat_offset;
DPRINTF((STR_mmap(), addr, mlen3, prot, flags, fdm, offset));
if (addr != mmap(addr, mlen3, prot, flags, fdm, offset, 0)) {
@ -571,7 +572,7 @@ upx_main(
)
{
Mach_i386_thread_state const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(unsigned char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -33,9 +33,9 @@
#if defined(__GNUC__)
# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0))
# elif defined(__GNUC_MINOR__)
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
# define ACC_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100)
# else
# define ACC_CC_GNUC (__GNUC__ * 0x10000L)
# endif
@ -57,23 +57,28 @@ typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
#if (ACC_CC_GNUC >= 0x020800ul)
__extension__ typedef long long int64_t;
#if (ACC_CC_GNUC >= 0x020800ul) /*{*/
# if 64 == __WORDSIZE /*{*/
typedef long int64_t;
typedef unsigned long uint64_t;
# else /*}{*/
__extension__ typedef long long int64_t;
__extension__ typedef unsigned long long uint64_t;
#elif defined(_WIN32)
# endif /*}*/
#elif defined(_WIN32) /*}{*/
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#else /*}{*/
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif
#endif /*}*/
typedef size_t uintptr_t;
// XXX: restrict ourselves to 4GB for off_t. Some versions of gcc
// have bugs in handling 64-bit integers (such as passing as argument
// the wrong registers) and it takes more code anyway.
// Adjust in system call wrappers, particularly mmap() and pread().
typedef unsigned off_t;
typedef unsigned off_t_upx_stub;
// misc constants
@ -91,7 +96,7 @@ int close(int);
void exit(int) __attribute__((__noreturn__,__nothrow__));
int mprotect(void *, size_t, int);
extern int munmap(char *, size_t);
int open(char const *, unsigned, unsigned);
int open(char const *, int, ...);
/*************************************************************************

View File

@ -30,6 +30,7 @@
*/
#define __WORDSIZE 32
#include "include/darwin.h"
@ -315,13 +316,13 @@ typedef union {
unsigned long long off_t goes into registers (9,10) instead of (8,9).
Adjust in mmap(), pread(), and include/darwin.h .
*/
extern char *mmap(char *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern char *mmap(char *, size_t, unsigned, unsigned, int, off_t_upx_stub);
ssize_t pread(int, void *, size_t, off_t_upx_stub);
static Mach_ppc_thread_state const *
do_xmap(
Mach_header const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header **mhdrpp,
@ -399,7 +400,7 @@ upx_main(
)
{
Mach_ppc_thread_state const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -30,6 +30,7 @@
*/
#define __WORDSIZE 64
#include "include/darwin.h"
@ -315,13 +316,13 @@ typedef union {
unsigned long long off_t goes into registers (9,10) instead of (8,9).
Adjust in mmap(), pread(), and include/darwin.h .
*/
extern char *mmap(char *, size_t, unsigned, unsigned, int, off_t);
ssize_t pread(int, void *, size_t, off_t);
extern char *mmap(char *, size_t, unsigned, unsigned, int, off_t_upx_stub);
ssize_t pread(int, void *, size_t, off_t_upx_stub);
static Mach_ppcle_thread_state64 const *
do_xmap(
Mach_header const *const mhdr,
off_t const fat_offset,
off_t_upx_stub const fat_offset,
Extent *const xi,
int const fdi,
Mach_header **mhdrpp,
@ -399,7 +400,7 @@ upx_main(
)
{
Mach_ppcle_thread_state64 const *entry;
off_t fat_offset = 0;
off_t_upx_stub fat_offset = 0;
Extent xi, xo, xi0;
xi.buf = CONST_CAST(char *, 1+ (struct p_info const *)(1+ li)); // &b_info
xi.size = sz_compressed - (sizeof(struct l_info) + sizeof(struct p_info));

View File

@ -72,7 +72,7 @@ LOAD tmp/amd64-darwin.macho-main.o
.plt
*(.plt)
.text 0x0000000008048000 0x576
.text 0x0000000008048000 0x578
*(.text .stub .text.* .gnu.linkonce.t.*)
.text 0x0000000008048000 0xca tmp/amd64-darwin.macho-fold.o
0x00000000080480a0 munmap
@ -87,16 +87,16 @@ LOAD tmp/amd64-darwin.macho-main.o
0x000000000804809c mprotect
0x00000000080480a8 close
*fill* 0x00000000080480ca 0x2 90909090
.text 0x00000000080480cc 0x4aa tmp/amd64-darwin.macho-main.o
.text 0x00000000080480cc 0x4ac tmp/amd64-darwin.macho-main.o
0x000000000804840e upx_main
*(.text.*personality*)
*(.gnu.warning)
.fini
*(.fini)
0x0000000008048576 PROVIDE (__etext, .)
0x0000000008048576 PROVIDE (_etext, .)
0x0000000008048576 PROVIDE (etext, .)
0x0000000008048578 PROVIDE (__etext, .)
0x0000000008048578 PROVIDE (_etext, .)
0x0000000008048578 PROVIDE (etext, .)
.rodata
*(.rodata .rodata.* .gnu.linkonce.r.*)
@ -112,8 +112,8 @@ LOAD tmp/amd64-darwin.macho-main.o
.gcc_except_table
*(.gcc_except_table .gcc_except_table.*)
0x0000000008048576 . = (ALIGN (0x1000) - ((0x1000 - .) & 0xfff))
0x0000000008049576 . = (0x1000 DATA_SEGMENT_ALIGN 0x1000)
0x0000000008048578 . = (ALIGN (0x1000) - ((0x1000 - .) & 0xfff))
0x0000000008049578 . = (0x1000 DATA_SEGMENT_ALIGN 0x1000)
.eh_frame
*(.eh_frame)
@ -128,22 +128,22 @@ LOAD tmp/amd64-darwin.macho-main.o
*(.tbss .tbss.* .gnu.linkonce.tb.*)
*(.tcommon)
.preinit_array 0x0000000008049576 0x0
0x0000000008049576 PROVIDE (__preinit_array_start, .)
.preinit_array 0x0000000008049578 0x0
0x0000000008049578 PROVIDE (__preinit_array_start, .)
*(.preinit_array)
0x0000000008049576 PROVIDE (__preinit_array_end, .)
0x0000000008049578 PROVIDE (__preinit_array_end, .)
.init_array 0x0000000008049576 0x0
0x0000000008049576 PROVIDE (__init_array_start, .)
.init_array 0x0000000008049578 0x0
0x0000000008049578 PROVIDE (__init_array_start, .)
*(SORT(.init_array.*))
*(.init_array)
0x0000000008049576 PROVIDE (__init_array_end, .)
0x0000000008049578 PROVIDE (__init_array_end, .)
.fini_array 0x0000000008049576 0x0
0x0000000008049576 PROVIDE (__fini_array_start, .)
.fini_array 0x0000000008049578 0x0
0x0000000008049578 PROVIDE (__fini_array_start, .)
*(.fini_array)
*(SORT(.fini_array.*))
0x0000000008049576 PROVIDE (__fini_array_end, .)
0x0000000008049578 PROVIDE (__fini_array_end, .)
.ctors
*crtbegin*.o(.ctors)
@ -169,7 +169,7 @@ LOAD tmp/amd64-darwin.macho-main.o
.got
*(.got)
0x0000000008049576 . = (. DATA_SEGMENT_RELRO_END 0xc)
0x0000000008049578 . = (. DATA_SEGMENT_RELRO_END 0xc)
.got.plt
*(.got.plt)