From 2b6ae3908c268cf41612ea19478cf92685dbeb61 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Sun, 30 Apr 2006 21:53:33 +0000 Subject: [PATCH] /usr/bin/dyld can be a "fat binary" [how stupid!] m_mac_mach32.c fold_machppc32.S fold_machppc32.h committer: jreiser 1146434013 +0000 --- src/stub/fold_machppc32.S | 4 + src/stub/fold_machppc32.h | 183 ++++++++++++++++++++------------------ src/stub/m_mac_mach32.c | 50 +++++++++-- 3 files changed, 141 insertions(+), 96 deletions(-) diff --git a/src/stub/fold_machppc32.S b/src/stub/fold_machppc32.S index 24de8845..9b0c57ca 100644 --- a/src/stub/fold_machppc32.S +++ b/src/stub/fold_machppc32.S @@ -96,6 +96,7 @@ SYS_write =4 SYS_open =5 SYS_close =6 +SYS_pread =153 SYS_mmap =197 SYS_mprotect= 74 @@ -103,6 +104,9 @@ SYS_mprotect= 74 in wrong registers. So change C interface to use size_t (32-bits) instead of off_t (64 bits), and convert here. */ +pread: .globl pread + movr a4,a3; li a3,0 # zero extend 4th arg size_t to off_t + li 0,SYS_pread; b sysgo mmap: .globl mmap movr a6,a5; li a5,0 # zero extend 6th arg size_t to off_t li 0,SYS_mmap diff --git a/src/stub/fold_machppc32.h b/src/stub/fold_machppc32.h index 34866ac2..8f71b789 100644 --- a/src/stub/fold_machppc32.h +++ b/src/stub/fold_machppc32.h @@ -1,4 +1,4 @@ -/* fold_machppc32.h -- created from fold_machppc32.bin, 1528 (0x5f8) bytes +/* fold_machppc32.h -- created from fold_machppc32.bin, 1648 (0x670) bytes This file is part of the UPX executable compressor. @@ -27,11 +27,11 @@ */ -#define FOLD_MACHPPC32_SIZE 1528 -#define FOLD_MACHPPC32_ADLER32 0xb665fdb7 -#define FOLD_MACHPPC32_CRC32 0x0feee296 +#define FOLD_MACHPPC32_SIZE 1648 +#define FOLD_MACHPPC32_ADLER32 0x16162538 +#define FOLD_MACHPPC32_CRC32 0x67f187d4 -unsigned char fold_machppc32[1528] = { +unsigned char fold_machppc32[1648] = { 72, 0, 0,105, 40, 6, 0,208, 76,130, 0, 32, 84,132,240,191, /* 0x 0 */ 77,130, 0, 32, 60, 0, 0, 16,124, 4, 0, 64, 65,128, 0, 8, /* 0x 10 */ 124, 4, 3,120, 56,165, 1, 32,124,103, 27,120, 56, 99,255,252, /* 0x 20 */ @@ -42,90 +42,97 @@ unsigned char fold_machppc32[1528] = { 124, 41, 11,120,125, 8, 2,166,128,159,255,248,124,100,248, 80, /* 0x 70 */ 128,195, 0, 24, 40, 6, 8, 0, 65,129, 0, 8, 56,192, 8, 0, /* 0x 80 */ 124, 61, 11,120,124, 38, 8, 80,124, 37, 11,120, 56, 33,255,232, /* 0x 90 */ -127,231,251,120, 72, 0, 4, 33,127,161,235,120,128, 67, 0, 0, /* 0x a0 */ +127,231,251,120, 72, 0, 4, 57,127,161,235,120,128, 67, 0, 0, /* 0x a0 */ 124, 73, 3,166,128, 67, 0,136,124, 79,241, 32,128, 67, 0,140, /* 0x b0 */ 124, 65, 3,166,128, 67, 0,144,124, 72, 3,166,184,131, 0, 24, /* 0x c0 */ 128, 3, 0, 8,128, 67, 0, 16,128, 99, 0, 20, 78,128, 4, 32, /* 0x d0 */ -125, 9, 67,120, 57, 0, 0, 0, 56, 0, 0,197, 68, 0, 0, 2, /* 0x e0 */ - 56, 96,255,255, 78,128, 0, 32, 56, 0, 0, 1, 75,255,255,240, /* 0x f0 */ - 56, 0, 0, 3, 75,255,255,232, 56, 0, 0, 5, 75,255,255,224, /* 0x 100 */ - 56, 0, 0, 6, 75,255,255,216, 56, 0, 0, 74, 75,255,255,208, /* 0x 110 */ -124, 8, 2,166,148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0, /* 0x 120 */ -129, 35, 0, 4,127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, /* 0x 130 */ - 75,255,255,185, 47,133, 0, 0, 65,158, 0, 28,124,169, 3,166, /* 0x 140 */ -136, 9, 0, 0, 57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, /* 0x 150 */ - 66, 0,255,240,128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80, /* 0x 160 */ -144, 3, 0, 0,125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16, /* 0x 170 */ -145, 35, 0, 4,124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166, /* 0x 180 */ -148, 33,255,192,191,129, 0, 48,124,159, 35,120,124,126, 27,120, /* 0x 190 */ -124,188, 43,120,144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, /* 0x 1a0 */ - 47,128, 0, 0, 65,158, 1, 32, 56,160, 0, 12,127,195,243,120, /* 0x 1b0 */ - 56,129, 0, 16, 75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, /* 0x 1c0 */ - 47,137, 0, 0, 64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85, /* 0x 1d0 */ -127,133, 0, 0, 64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, /* 0x 1e0 */ - 65,190, 0,228, 72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, /* 0x 1f0 */ - 56, 96, 0,127, 75,255,254,245,127, 5, 72, 64, 65,185,255,244, /* 0x 200 */ -128, 31, 0, 0,127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, /* 0x 210 */ - 64,152, 0,132,124,164, 43,120,128,126, 0, 4,124, 5, 3,120, /* 0x 220 */ - 56,193, 0, 32,136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, /* 0x 230 */ - 47,131, 0, 0, 64,190,255,188,128,129, 0, 32,128, 1, 0, 16, /* 0x 240 */ -127,132, 0, 0, 64,190,255,172,136,193, 0, 25, 49, 61,255,255, /* 0x 250 */ -124, 9,233, 16,125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, /* 0x 260 */ - 65,162, 0, 20,128,127, 0, 4,127,168, 3,166,136,161, 0, 26, /* 0x 270 */ - 78,128, 0, 33,128, 30, 0, 4,129, 97, 0, 20,129, 62, 0, 0, /* 0x 280 */ -124, 0, 90, 20,125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, /* 0x 290 */ - 72, 0, 0, 16,124, 4, 3,120,127,195,243,120, 75,255,254,117, /* 0x 2a0 */ -129, 97, 0, 16,129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, /* 0x 2b0 */ - 47,137, 0, 0,124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, /* 0x 2c0 */ - 75,255,254,228,128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64, /* 0x 2d0 */ -124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,176, /* 0x 2e0 */ -190, 97, 0, 28,125,128, 0, 38, 58,224, 0, 0,124,122, 27,120, /* 0x 2f0 */ -144, 1, 0, 84,124,155, 35,120,128, 3, 0, 16,124,179, 43,120, /* 0x 300 */ -145,129, 0, 24,124,212, 51,120,127,151, 0, 64,124,245, 59,120, /* 0x 310 */ -125, 22, 67,120, 59,195, 0, 28, 59, 0, 0, 0, 64,156, 1,120, /* 0x 320 */ -129, 62, 0, 0, 47,137, 0, 1, 64,190, 1, 44,129, 62, 0, 24, /* 0x 330 */ -129,126, 0, 36, 85, 61, 5, 62,128, 30, 0, 28,127,139,234, 20, /* 0x 340 */ -145, 97, 0, 8, 46, 28, 0, 0,127, 41, 2, 20,145, 33, 0, 12, /* 0x 350 */ -127,253, 72, 80, 65,146, 0, 72, 47,155, 0, 0, 64,190, 0, 16, /* 0x 360 */ - 47,139, 0, 0, 56,192, 0, 18, 64,158, 0, 8, 56,192, 16, 18, /* 0x 370 */ - 47,139, 0, 0,126,103,155,120, 64,158, 0, 8, 56,224,255,255, /* 0x 380 */ -129, 30, 0, 32,127,227,251,120,127,132,227,120, 56,160, 0, 3, /* 0x 390 */ - 75,255,253, 65,127,159, 24, 0, 64,158, 0,124, 47,155, 0, 0, /* 0x 3a0 */ - 65,158, 0, 52,128, 30, 0, 36, 47,128, 0, 0, 65,158, 0, 40, /* 0x 3b0 */ -128, 30, 0, 32, 47,128, 0, 0, 64,158, 0, 8,147,244, 0, 0, /* 0x 3c0 */ -127, 99,219,120, 56,129, 0, 8,126,165,171,120,126,198,179,120, /* 0x 3d0 */ - 75,255,253,173,124, 28, 0,208,125, 63,226, 20,112, 29, 15,255, /* 0x 3e0 */ - 65,130, 0, 24,127,169, 3,166, 56, 0, 0, 0,152, 9, 0, 0, /* 0x 3f0 */ - 57, 41, 0, 1, 66, 0,255,248, 65,178, 0, 36,128,190, 0, 44, /* 0x 400 */ -127,227,251,120,127,132,227,120, 75,255,253, 1, 47,131, 0, 0, /* 0x 410 */ - 65,190, 0, 12, 56, 96, 0,127, 75,255,252,209,124, 28,234, 20, /* 0x 420 */ -127,255, 2, 20,127,159,200, 64, 64,188, 0, 84,128,190, 0, 44, /* 0x 430 */ -124,159,200, 80,127,227,251,120, 56,192, 16, 18, 56,224,255,255, /* 0x 440 */ - 57, 0, 0, 0, 75,255,252,141,127,159, 24, 0, 65,190, 0, 48, /* 0x 450 */ - 75,255,255,196, 56, 9,255,252, 43,128, 0, 1, 65,157, 0, 32, /* 0x 460 */ -128, 30, 0, 8, 47,128, 0, 1, 64,190, 0, 20,128, 30, 0, 12, /* 0x 470 */ - 47,128, 0, 40, 64,190, 0, 8, 58,254, 0, 16,128, 26, 0, 16, /* 0x 480 */ - 59, 24, 0, 1,127,152, 0, 64,128, 30, 0, 4,127,222, 2, 20, /* 0x 490 */ - 75,255,254,140,128, 1, 0, 84,126,227,187,120,129,129, 0, 24, /* 0x 4a0 */ -186, 97, 0, 28,124, 8, 3,166, 56, 33, 0, 80,125,128,129, 32, /* 0x 4b0 */ - 78,128, 0, 32,148, 33,255,192,124, 8, 2,166,144,129, 0, 8, /* 0x 4c0 */ -191, 65, 0, 40,129, 97, 0, 8,124,191, 43,120,144, 1, 0, 68, /* 0x 4d0 */ - 56, 3, 0, 24, 57,107,255,232,144, 1, 0, 20,145, 97, 0, 16, /* 0x 4e0 */ -124,253, 59,120,128, 3, 0, 24,125, 60, 75,120,200, 1, 0, 16, /* 0x 4f0 */ -125, 27, 67,120,124,229, 59,120, 56, 97, 0, 16, 56,129, 0, 24, /* 0x 500 */ -124,218, 51,120, 56,192, 0, 0,144, 1, 0, 24,216, 1, 0, 32, /* 0x 510 */ - 59,192, 0, 0,147,225, 0, 28, 75,255,252,101,127,167,235,120, /* 0x 520 */ -127,104,219,120,127,227,251,120,127,134,227,120, 56,129, 0, 32, /* 0x 530 */ - 56,160,255,255, 75,255,253,165,128, 31, 0, 16,124,123, 27,120, /* 0x 540 */ - 59,191, 0, 28,127,158, 0, 64, 64,156, 0,136,128, 29, 0, 0, /* 0x 550 */ - 59,222, 0, 1, 56,128, 0, 0, 56,160, 0, 0, 47,128, 0, 14, /* 0x 560 */ - 64,190, 0, 92,128,125, 0, 8,124,125, 26, 20, 75,255,251,141, /* 0x 570 */ -127,228,251,120,124,124, 27,121,127, 69,211,120, 65,128, 0, 40, /* 0x 580 */ - 75,255,251,113, 56,128, 0, 0,127,154, 24, 0,127,133,227,120, /* 0x 590 */ -127,227,251,120, 56,192, 0, 0, 56,224, 0, 0, 57, 0, 0, 0, /* 0x 5a0 */ - 65,190, 0, 12, 56, 96, 0,127, 75,255,251, 65, 75,255,253, 45, /* 0x 5b0 */ -124,123, 27,120,127,131,227,120, 75,255,251, 73,128, 31, 0, 16, /* 0x 5c0 */ -129, 61, 0, 4,127,158, 0, 64,127,189, 74, 20, 75,255,255,124, /* 0x 5d0 */ -128, 1, 0, 68,127, 99,219,120,187, 65, 0, 40, 56, 33, 0, 64, /* 0x 5e0 */ -124, 8, 3,166, 78,128, 0, 32 /* 0x 5f0 */ +124,199, 51,120, 56,192, 0, 0, 56, 0, 0,153, 72, 0, 0, 16, /* 0x e0 */ +125, 9, 67,120, 57, 0, 0, 0, 56, 0, 0,197, 68, 0, 0, 2, /* 0x f0 */ + 56, 96,255,255, 78,128, 0, 32, 56, 0, 0, 1, 75,255,255,240, /* 0x 100 */ + 56, 0, 0, 3, 75,255,255,232, 56, 0, 0, 5, 75,255,255,224, /* 0x 110 */ + 56, 0, 0, 6, 75,255,255,216, 56, 0, 0, 74, 75,255,255,208, /* 0x 120 */ +124, 8, 2,166,148, 33,255,240,144, 1, 0, 20,128, 3, 0, 0, /* 0x 130 */ +129, 35, 0, 4,127,128, 40, 64, 64,188, 0, 12, 56, 96, 0,127, /* 0x 140 */ + 75,255,255,185, 47,133, 0, 0, 65,158, 0, 28,124,169, 3,166, /* 0x 150 */ +136, 9, 0, 0, 57, 41, 0, 1,152, 4, 0, 0, 56,132, 0, 1, /* 0x 160 */ + 66, 0,255,240,128, 3, 0, 0,129, 35, 0, 4,124, 5, 0, 80, /* 0x 170 */ +144, 3, 0, 0,125, 41, 42, 20,128, 1, 0, 20, 56, 33, 0, 16, /* 0x 180 */ +145, 35, 0, 4,124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166, /* 0x 190 */ +148, 33,255,192,191,129, 0, 48,124,159, 35,120,124,126, 27,120, /* 0x 1a0 */ +124,188, 43,120,144, 1, 0, 68,124,221, 51,120,128, 4, 0, 0, /* 0x 1b0 */ + 47,128, 0, 0, 65,158, 1, 32, 56,160, 0, 12,127,195,243,120, /* 0x 1c0 */ + 56,129, 0, 16, 75,255,255, 93,129, 33, 0, 16,128,161, 0, 20, /* 0x 1d0 */ + 47,137, 0, 0, 64,190, 0, 36, 60, 0, 33, 88, 96, 0, 80, 85, /* 0x 1e0 */ +127,133, 0, 0, 64,190, 0, 28,128, 30, 0, 0, 47,128, 0, 0, /* 0x 1f0 */ + 65,190, 0,228, 72, 0, 0, 12, 47,133, 0, 0, 64,190, 0, 12, /* 0x 200 */ + 56, 96, 0,127, 75,255,254,245,127, 5, 72, 64, 65,185,255,244, /* 0x 210 */ +128, 31, 0, 0,127,137, 0, 64, 65,189,255,232,128, 31, 0, 4, /* 0x 220 */ + 64,152, 0,132,124,164, 43,120,128,126, 0, 4,124, 5, 3,120, /* 0x 230 */ + 56,193, 0, 32,136,225, 0, 24,127,136, 3,166, 78,128, 0, 33, /* 0x 240 */ + 47,131, 0, 0, 64,190,255,188,128,129, 0, 32,128, 1, 0, 16, /* 0x 250 */ +127,132, 0, 0, 64,190,255,172,136,193, 0, 25, 49, 61,255,255, /* 0x 260 */ +124, 9,233, 16,125, 38, 0,208, 85, 41, 15,254,125, 43, 0, 57, /* 0x 270 */ + 65,162, 0, 20,128,127, 0, 4,127,168, 3,166,136,161, 0, 26, /* 0x 280 */ + 78,128, 0, 33,128, 30, 0, 4,129, 97, 0, 20,129, 62, 0, 0, /* 0x 290 */ +124, 0, 90, 20,125, 43, 72, 80,144, 30, 0, 4,145, 62, 0, 0, /* 0x 2a0 */ + 72, 0, 0, 16,124, 4, 3,120,127,195,243,120, 75,255,254,117, /* 0x 2b0 */ +129, 97, 0, 16,129, 63, 0, 0,128, 31, 0, 4,125, 43, 72, 80, /* 0x 2c0 */ + 47,137, 0, 0,124, 0, 90, 20,144, 31, 0, 4,145, 63, 0, 0, /* 0x 2d0 */ + 75,255,254,228,128, 1, 0, 68,187,129, 0, 48, 56, 33, 0, 64, /* 0x 2e0 */ +124, 8, 3,166, 78,128, 0, 32,124, 8, 2,166,148, 33,255,176, /* 0x 2f0 */ +190, 65, 0, 24,125,128, 0, 38, 58,224, 0, 0,124,122, 27,120, /* 0x 300 */ +144, 1, 0, 84,124,146, 35,120,128, 3, 0, 16,124,187, 43,120, /* 0x 310 */ +145,129, 0, 20,124,211, 51,120,127,151, 0, 64,124,244, 59,120, /* 0x 320 */ +125, 21, 67,120,125, 54, 75,120, 59,195, 0, 28, 59, 0, 0, 0, /* 0x 330 */ + 64,156, 1,124,129, 62, 0, 0, 47,137, 0, 1, 64,190, 1, 48, /* 0x 340 */ +129, 62, 0, 24,129,126, 0, 36, 85, 61, 5, 62,128, 30, 0, 28, /* 0x 350 */ +127,139,234, 20,145, 97, 0, 8, 46, 28, 0, 0,127, 41, 2, 20, /* 0x 360 */ +145, 33, 0, 12,127,253, 72, 80, 65,146, 0, 76, 47,155, 0, 0, /* 0x 370 */ + 64,190, 0, 16, 47,139, 0, 0, 56,192, 0, 18, 64,158, 0, 8, /* 0x 380 */ + 56,192, 16, 18, 47,139, 0, 0,126,103,155,120, 64,158, 0, 8, /* 0x 390 */ + 56,224,255,255,129, 30, 0, 32,127,227,251,120,127,132,227,120, /* 0x 3a0 */ + 56,160, 0, 3,125, 8,146, 20, 75,255,253, 57,127,159, 24, 0, /* 0x 3b0 */ + 64,158, 0,124, 47,155, 0, 0, 65,158, 0, 52,128, 30, 0, 36, /* 0x 3c0 */ + 47,128, 0, 0, 65,158, 0, 40,128, 30, 0, 32, 47,128, 0, 0, /* 0x 3d0 */ + 64,158, 0, 8,147,244, 0, 0,127, 99,219,120, 56,129, 0, 8, /* 0x 3e0 */ +126,165,171,120,126,198,179,120, 75,255,253,165,124, 28, 0,208, /* 0x 3f0 */ +125, 63,226, 20,112, 29, 15,255, 65,130, 0, 24,127,169, 3,166, /* 0x 400 */ + 56, 0, 0, 0,152, 9, 0, 0, 57, 41, 0, 1, 66, 0,255,248, /* 0x 410 */ + 65,178, 0, 36,128,190, 0, 44,127,227,251,120,127,132,227,120, /* 0x 420 */ + 75,255,252,249, 47,131, 0, 0, 65,190, 0, 12, 56, 96, 0,127, /* 0x 430 */ + 75,255,252,201,124, 28,234, 20,127,255, 2, 20,127,159,200, 64, /* 0x 440 */ + 64,188, 0, 84,128,190, 0, 44,124,159,200, 80,127,227,251,120, /* 0x 450 */ + 56,192, 16, 18, 56,224,255,255, 57, 0, 0, 0, 75,255,252,133, /* 0x 460 */ +127,159, 24, 0, 65,190, 0, 48, 75,255,255,196, 56, 9,255,252, /* 0x 470 */ + 43,128, 0, 1, 65,157, 0, 32,128, 30, 0, 8, 47,128, 0, 1, /* 0x 480 */ + 64,190, 0, 20,128, 30, 0, 12, 47,128, 0, 40, 64,190, 0, 8, /* 0x 490 */ + 58,254, 0, 16,128, 26, 0, 16, 59, 24, 0, 1,127,152, 0, 64, /* 0x 4a0 */ +128, 30, 0, 4,127,222, 2, 20, 75,255,254,136,128, 1, 0, 84, /* 0x 4b0 */ +126,227,187,120,129,129, 0, 20,186, 65, 0, 24,124, 8, 3,166, /* 0x 4c0 */ + 56, 33, 0, 80,125,128,129, 32, 78,128, 0, 32,148, 33,255,192, /* 0x 4d0 */ +124, 8, 2,166,144,129, 0, 8,191, 97, 0, 44,129, 97, 0, 8, /* 0x 4e0 */ +124,191, 43,120,144, 1, 0, 68, 56, 3, 0, 24, 57,107,255,232, /* 0x 4f0 */ +144, 1, 0, 20,145, 97, 0, 16,125, 27, 67,120,128, 3, 0, 24, /* 0x 500 */ +125, 60, 75,120,200, 1, 0, 16,124,253, 59,120,124,229, 59,120, /* 0x 510 */ + 56, 97, 0, 16, 56,129, 0, 24,124,222, 51,120, 56,192, 0, 0, /* 0x 520 */ +144, 1, 0, 24,216, 1, 0, 32,147,225, 0, 28, 75,255,252, 97, /* 0x 530 */ +127,105,219,120,127,135,227,120,127,227,251,120,127,168,235,120, /* 0x 540 */ + 56,128, 0, 0, 56,161, 0, 32, 56,192,255,255, 59, 96, 0, 0, /* 0x 550 */ + 75,255,253,153,129, 95, 0, 16, 57, 96, 0, 0,124,124, 27,120, /* 0x 560 */ +127,139, 80, 64, 57, 63, 0, 28, 64,156, 0,224,128, 9, 0, 0, /* 0x 570 */ + 57,107, 0, 1,127, 11, 80, 64, 47,128, 0, 14, 64,190, 0,192, /* 0x 580 */ +128,105, 0, 8, 56,128, 0, 0, 56,160, 0, 0,124,105, 26, 20, /* 0x 590 */ + 75,255,251,121,124,125, 27,121, 65,128, 0, 32,127,163,235,120, /* 0x 5a0 */ +127,228,251,120,127,197,243,120,127,102,219,120, 75,255,251, 37, /* 0x 5b0 */ +127,158, 24, 0, 65,190, 0, 20, 56, 96, 0,127, 75,255,251, 61, /* 0x 5c0 */ +131,105, 0, 8, 75,255,255,216,128, 31, 0, 0, 61, 32,202,254, /* 0x 5d0 */ + 97, 41,186,190,127,128, 72, 0, 64,158, 0, 52,129, 95, 0, 4, /* 0x 5e0 */ + 57, 96, 0, 0, 57, 63, 0, 8,127,139, 80, 64, 64,156, 0, 32, /* 0x 5f0 */ +128, 9, 0, 0, 57,107, 0, 1,127, 11, 80, 64, 47,128, 0, 18, /* 0x 600 */ + 65,190,255,192, 57, 41, 0, 20, 65,152,255,232,127,227,251,120, /* 0x 610 */ +127,100,219,120, 56,160, 0, 0,127,166,235,120, 56,224, 0, 0, /* 0x 620 */ + 57, 0, 0, 0, 57, 32, 0, 0, 75,255,252,193,124,124, 27,120, /* 0x 630 */ +127,163,235,120, 75,255,250,221, 72, 0, 0, 16,128, 9, 0, 4, /* 0x 640 */ +125, 41, 2, 20, 65,152,255, 40,128, 1, 0, 68,127,131,227,120, /* 0x 650 */ +187, 97, 0, 44, 56, 33, 0, 64,124, 8, 3,166, 78,128, 0, 32 /* 0x 660 */ }; diff --git a/src/stub/m_mac_mach32.c b/src/stub/m_mac_mach32.c index 37020403..5ff236a3 100644 --- a/src/stub/m_mac_mach32.c +++ b/src/stub/m_mac_mach32.c @@ -45,7 +45,7 @@ int close(int); void exit(int) __attribute__((__noreturn__)); int mprotect(void *, size_t, int); int open(char const *, unsigned, unsigned); -ssize_t read(int, void *, size_t); +ssize_t pread(int, void *, size_t, unsigned); #define CONST_CAST(type, var) \ ((type) ((uintptr_t) (var))) @@ -215,6 +215,25 @@ upx_bzero(char *p, size_t len) |(REP8(PROT_WRITE) & EXP8(PF_W)) \ ) >> ((pf & (PF_R|PF_W|PF_X))<<2) )) +typedef struct { + unsigned magic; + unsigned nfat_arch; +} Fat_header; +typedef struct { + unsigned cputype; + unsigned cpusubtype; + unsigned offset; + unsigned size; + unsigned align; /* power of 2 */ +} Fat_arch; + enum e8 { + FAT_MAGIC = 0xcafebabe + }; + enum e9 { + CPU_TYPE_POWERPC = 0x00000012, + CPU_TYPE_POWERPC64 = 0x01000012 + }; + typedef struct { unsigned magic; unsigned cputype; @@ -227,9 +246,6 @@ typedef struct { enum e0 { MH_MAGIC = 0xfeedface }; - enum e1 { - CPU_TYPE_POWERPC = 18 - }; enum e2 { MH_EXECUTE = 2 }; @@ -319,6 +335,7 @@ extern char *mmap(char *, size_t, unsigned, unsigned, int, /*off_t*/size_t); static Mach_ppc_thread_state const * do_xmap( Mach_header const *const mhdr, + unsigned const fat_offset, Extent *const xi, int const fdi, Mach_header **mhdrpp, @@ -344,7 +361,7 @@ do_xmap( if (0!=mlen && addr != mmap(addr, mlen, VM_PROT_READ | VM_PROT_WRITE, MAP_FIXED | MAP_PRIVATE | ((xi || 0==sc->filesize) ? MAP_ANON : 0), - ((0==sc->filesize) ? -1 : fdi), sc->fileoff) ) { + ((0==sc->filesize) ? -1 : fdi), sc->fileoff + fat_offset) ) { err_exit(8); } if (xi && 0!=sc->filesize) { @@ -396,6 +413,7 @@ upx_main( ) { Mach_ppc_thread_state const *entry; + unsigned 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)); @@ -406,7 +424,7 @@ upx_main( // Uncompress Macho headers unpackExtent(&xi, &xo, f_decompress, 0); // never filtered? - entry = do_xmap(mhdr, &xi0, -1, mhdrpp, f_decompress, f_unf); + entry = do_xmap(mhdr, fat_offset, &xi0, -1, mhdrpp, f_decompress, f_unf); { // Map dyld dynamic loader Mach_load_command const *lc = (Mach_load_command const *)(1+ mhdr); @@ -421,12 +439,28 @@ upx_main( if (0 > fdi) { err_exit(18); } - if ((ssize_t)sz_mhdr!=read(fdi, (void *)mhdr, sz_mhdr)) { +fat: + if ((ssize_t)sz_mhdr!=pread(fdi, (void *)mhdr, sz_mhdr, fat_offset)) { ERR_LAB err_exit(19); } - entry = do_xmap(mhdr, 0, fdi, 0, 0, 0); + switch (mhdr->magic) { + case MH_MAGIC: break; + case FAT_MAGIC: { + // stupid Apple: waste code and a page fault on EVERY execve + Fat_header const *const fh = (Fat_header const *)mhdr; + Fat_arch const *fa = (Fat_arch const *)(1+ fh); + for (j= 0; j < fh->nfat_arch; ++j, ++fa) { + if (CPU_TYPE_POWERPC==fa->cputype) { + fat_offset= fa->offset; + goto fat; + } + } + } break; + } // switch + entry = do_xmap(mhdr, fat_offset, 0, fdi, 0, 0, 0); close(fdi); + break; } }