From ba5643249737b9752f19a82ea175d82d755cc439 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Fri, 20 Mar 2009 15:06:31 +0100 Subject: [PATCH] Update to the MIT licensed version of mach_star. --- installer_macx/license.html | 7 ++-- overlay_macx/injector/mach_inject.c | 55 +++++++++++++++------------- overlay_macx/injector/mach_inject.h | 4 +- overlay_macx/overlay/mach_override.c | 16 +++----- overlay_macx/overlay/mach_override.h | 38 ++++++++++++++++++- overlay_macx/stub/stub.c | 6 +-- overlay_macx/stub/stub.h | 14 +++---- 7 files changed, 88 insertions(+), 52 deletions(-) diff --git a/installer_macx/license.html b/installer_macx/license.html index eb40d3288..8f7451f8b 100644 --- a/installer_macx/license.html +++ b/installer_macx/license.html @@ -57,9 +57,9 @@ license can be found in the Licenses folder on the disk image containing the Mumble installer. The Mumble OpenGL overlay on Mac OS X uses mach_star -(http://rentzsch.com/mach_star/), which is licensed under the Creative -Commons Attribution 2.0 Generic license. The mach_star license can be -found on the web at . +(http://github.com/rentzsch/mach_star/), which is licensed under the MIT +license. The mach_star license can be found on the disk image containing +the Mumble installer. Murmur (the server component of Mumble) makes use of ZeroC Ice. (http://www.zeroc.com/). Ice is licensed under the terms of the GPL v2. @@ -67,3 +67,4 @@ The ZeroC Ice license can be found in the Licenses folder on the disk image containing the Mumble installer. + diff --git a/overlay_macx/injector/mach_inject.c b/overlay_macx/injector/mach_inject.c index cd005c5e6..02f589624 100644 --- a/overlay_macx/injector/mach_inject.c +++ b/overlay_macx/injector/mach_inject.c @@ -1,7 +1,7 @@ /******************************************************************************* mach_inject.c - Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: ***************************************************************************/ @@ -28,6 +28,19 @@ #define ASSERT_CAST( CAST_TO, CAST_FROM ) \ COMPILE_TIME_ASSERT( sizeof(CAST_TO)==sizeof(CAST_FROM) ) +#if !__DARWIN_UNIX03 + /* ppc */ + #define __srr0 srr0 + #define __r1 r1 + #define __r3 r3 + #define __r4 r4 + #define __r5 r5 + #define __lr lr + /* i386 */ + #define __eip eip + #define __esp esp +#endif + #if defined(__i386__) void* fixedUpImageFromImage ( const void *image, @@ -63,7 +76,7 @@ mach_inject( unsigned int jumpTableOffset; unsigned int jumpTableSize; mach_error_t err = machImageForPointer( threadEntry, &image, &imageSize, &jumpTableOffset, &jumpTableSize ); - + // Initialize stackSize to default if requested. if( stackSize == 0 ) /** @bug @@ -145,29 +158,29 @@ mach_inject( bzero( &remoteThreadState, sizeof(remoteThreadState) ); ASSERT_CAST( unsigned int, remoteCode ); - remoteThreadState.srr0 = (unsigned int) remoteCode; - remoteThreadState.srr0 += threadEntryOffset; - assert( remoteThreadState.srr0 < (remoteCode + imageSize) ); + remoteThreadState.__srr0 = (unsigned int) remoteCode; + remoteThreadState.__srr0 += threadEntryOffset; + assert( remoteThreadState.__srr0 < (remoteCode + imageSize) ); ASSERT_CAST( unsigned int, remoteStack ); - remoteThreadState.r1 = (unsigned int) remoteStack; + remoteThreadState.__r1 = (unsigned int) remoteStack; ASSERT_CAST( unsigned int, imageOffset ); - remoteThreadState.r3 = (unsigned int) imageOffset; + remoteThreadState.__r3 = (unsigned int) imageOffset; ASSERT_CAST( unsigned int, remoteParamBlock ); - remoteThreadState.r4 = (unsigned int) remoteParamBlock; + remoteThreadState.__r4 = (unsigned int) remoteParamBlock; ASSERT_CAST( unsigned int, paramSize ); - remoteThreadState.r5 = (unsigned int) paramSize; + remoteThreadState.__r5 = (unsigned int) paramSize; ASSERT_CAST( unsigned int, 0xDEADBEEF ); - remoteThreadState.lr = (unsigned int) 0xDEADBEEF; + remoteThreadState.__lr = (unsigned int) 0xDEADBEEF; #if 0 printf( "remoteCode start: %p\n", (void*) remoteCode ); printf( "remoteCode size: %ld\n", imageSize ); - printf( "remoteCode pc: %p\n", (void*) remoteThreadState.srr0 ); + printf( "remoteCode pc: %p\n", (void*) remoteThreadState.__srr0 ); printf( "remoteCode end: %p\n", (void*) (((char*)remoteCode)+imageSize) ); fflush(0); @@ -182,7 +195,7 @@ mach_inject( i386_thread_state_t remoteThreadState; bzero( &remoteThreadState, sizeof(remoteThreadState) ); - + vm_address_t dummy_thread_struct = remoteStack; remoteStack += (stackSize / 2); // this is the real stack // (*) increase the stack, since we're simulating a CALL instruction, which normally pushes return address on the stack @@ -204,15 +217,10 @@ mach_inject( // push stackContents err = vm_write( remoteTask, remoteStack, (pointer_t) stackContents, STACK_CONTENTS_SIZE); - -#if !__DARWIN_UNIX03 - #define __eip eip - #define __esp esp -#endif - + // set remote Program Counter remoteThreadState.__eip = (unsigned int) (remoteCode); - remoteThreadState.__eip += threadEntryOffset; + remoteThreadState.__eip += threadEntryOffset; // set remote Stack Pointer ASSERT_CAST( unsigned int, remoteStack ); @@ -281,24 +289,21 @@ machImageForPointer( if( size ) { ;//assertUInt32( st_size ); *size = sb.st_size; - + // needed for Universal binaries. Check if file is fat and get image size from there. int fd = open (imageName, O_RDONLY); - if (fd == -1) { fprintf(stderr, "Unable to open() image. Error: %s\n", strerror(errno)); exit(1); } size_t mapSize = *size; - fprintf(stderr, "mapSize = %u\n", mapSize); char * fileImage = mmap (NULL, mapSize, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0); - if (fileImage == -1) { fprintf(stderr, "Unable to mmap() image. Error: %s\n", strerror(errno)); exit(1); } - + struct fat_header* fatHeader = (struct fat_header *)fileImage; if (fatHeader->magic == OSSwapBigToHostInt32(FAT_MAGIC)) { //printf("This is a fat binary\n"); diff --git a/overlay_macx/injector/mach_inject.h b/overlay_macx/injector/mach_inject.h index c002d101d..65b977e03 100644 --- a/overlay_macx/injector/mach_inject.h +++ b/overlay_macx/injector/mach_inject.h @@ -1,7 +1,7 @@ /******************************************************************************* mach_inject.h - Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: ***************************************************************************/ diff --git a/overlay_macx/overlay/mach_override.c b/overlay_macx/overlay/mach_override.c index c8cb2ef4f..0e03bfab9 100644 --- a/overlay_macx/overlay/mach_override.c +++ b/overlay_macx/overlay/mach_override.c @@ -1,7 +1,7 @@ /******************************************************************************* mach_override.c - Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: ***************************************************************************/ @@ -150,11 +150,10 @@ mach_override( originalFunctionSymbolName, (void*) &originalFunctionPtr, NULL ); - + printf ("In mach_override\n"); return mach_override_ptr( originalFunctionPtr, overrideFunctionAddress, originalFunctionReentryIsland ); - printf ("Out of mach_override_ptr\n"); } mach_error_t @@ -177,8 +176,6 @@ mach_override_ptr( long originalInstruction = *originalFunctionPtr; if( !err && ((originalInstruction & kMFCTRMask) == kMFCTRInstruction) ) err = err_cannot_override; - - printf("Here...\n"); #elif defined (__i386__) int eatenCount = 0; char originalInstructions[kOriginalInstructionsSize]; @@ -212,7 +209,7 @@ mach_override_ptr( #if defined(__ppc__) || defined(__POWERPC__) if( !err ) err = setBranchIslandTarget( escapeIsland, overrideFunctionAddress, 0 ); - + // Build the branch absolute instruction to the escape island. long branchAbsoluteInstruction = 0; // Set to 0 just to silence warning. if( !err ) { @@ -478,9 +475,8 @@ typedef struct { static AsmInstructionMatch possibleInstructions[] = { { 0x1, {0xFF}, {0x90} }, // nop - { 0x1, {0xFF}, {0x55} }, // push %esp + { 0x1, {0xF8}, {0x50} }, // push %eax | %ebx | %ecx | %edx | %ebp | %esp | %esi | %edi { 0x2, {0xFF, 0xFF}, {0x89, 0xE5} }, // mov %esp,%ebp - { 0x1, {0xFF}, {0x53} }, // push %ebx { 0x3, {0xFF, 0xFF, 0x00}, {0x83, 0xEC, 0x00} }, // sub 0x??, %esp { 0x0 } }; @@ -603,4 +599,4 @@ asm( " ret" ); -#endif +#endif \ No newline at end of file diff --git a/overlay_macx/overlay/mach_override.h b/overlay_macx/overlay/mach_override.h index c07a9afb1..8584fc387 100644 --- a/overlay_macx/overlay/mach_override.h +++ b/overlay_macx/overlay/mach_override.h @@ -1,7 +1,7 @@ /******************************************************************************* mach_override.h - Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: ***************************************************************************/ @@ -116,7 +116,41 @@ mach_override_ptr( void *originalFunctionAddress, const void *overrideFunctionAddress, void **originalFunctionReentryIsland ); + +/************************************************************************************//** + + + ************************************************************************************/ +#ifdef __cplusplus + +#define MACH_OVERRIDE( ORIGINAL_FUNCTION_RETURN_TYPE, ORIGINAL_FUNCTION_NAME, ORIGINAL_FUNCTION_ARGS, ERR ) \ + { \ + static ORIGINAL_FUNCTION_RETURN_TYPE (*ORIGINAL_FUNCTION_NAME##_reenter)ORIGINAL_FUNCTION_ARGS; \ + static bool ORIGINAL_FUNCTION_NAME##_overriden = false; \ + class mach_override_class__##ORIGINAL_FUNCTION_NAME { \ + public: \ + static kern_return_t override(void *originalFunctionPtr) { \ + kern_return_t result = err_none; \ + if (!ORIGINAL_FUNCTION_NAME##_overriden) { \ + ORIGINAL_FUNCTION_NAME##_overriden = true; \ + result = mach_override_ptr( (void*)originalFunctionPtr, \ + (void*)mach_override_class__##ORIGINAL_FUNCTION_NAME::replacement, \ + (void**)&ORIGINAL_FUNCTION_NAME##_reenter ); \ + } \ + return result; \ + } \ + static ORIGINAL_FUNCTION_RETURN_TYPE replacement ORIGINAL_FUNCTION_ARGS { + +#define END_MACH_OVERRIDE( ORIGINAL_FUNCTION_NAME ) \ + } \ + }; \ + \ + err = mach_override_class__##ORIGINAL_FUNCTION_NAME::override((void*)ORIGINAL_FUNCTION_NAME); \ + } + +#endif + #ifdef __cplusplus } #endif diff --git a/overlay_macx/stub/stub.c b/overlay_macx/stub/stub.c index 0dd8cc55f..8c52765ce 100644 --- a/overlay_macx/stub/stub.c +++ b/overlay_macx/stub/stub.c @@ -2,9 +2,9 @@ stub.c - Overlay stub for Mumble Based on mach_inject_bundle_stub.c - Copyright (c) 2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: - + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: + Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software: diff --git a/overlay_macx/stub/stub.h b/overlay_macx/stub/stub.h index 78e0789bc..02beab019 100644 --- a/overlay_macx/stub/stub.h +++ b/overlay_macx/stub/stub.h @@ -1,14 +1,14 @@ /******************************************************************************* - stub.h - Overlay stub for Mumble + stub.h - Overlay stub for Mumble - Based on mach_inject_bundle_stub.c - Copyright (c) 2005 Jonathan 'Wolf' Rentzsch: - Some rights reserved: + Based on mach_inject_bundle_stub.h + Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: + Some rights reserved: - Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software: - + Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software: + - ***************************************************************************/ + ***************************************************************************/ #ifndef __STUB_H__ #define __STUB_H__