Update to the MIT licensed version of mach_star.

This commit is contained in:
Mikkel Krautz 2009-03-20 15:06:31 +01:00
parent 0bd7c1ca5e
commit ba56432497
7 changed files with 88 additions and 52 deletions

View File

@ -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://creativecommons.org/licenses/by/2.0/legalcode>.
(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.</pre>
</body>
</html>

View File

@ -1,7 +1,7 @@
/*******************************************************************************
mach_inject.c
Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
@ -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");

View File

@ -1,7 +1,7 @@
/*******************************************************************************
mach_inject.h
Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/

View File

@ -1,7 +1,7 @@
/*******************************************************************************
mach_override.c
Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
@ -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

View File

@ -1,7 +1,7 @@
/*******************************************************************************
mach_override.h
Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
@ -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

View File

@ -2,9 +2,9 @@
stub.c - Overlay stub for Mumble
Based on mach_inject_bundle_stub.c
Copyright (c) 2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software:
<http://www.stclairsoft.com>

View File

@ -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: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
Based on mach_inject_bundle_stub.h
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software:
<http://www.stclairsoft.com>
Design inspired by SCPatchLoader, by Jon Gotow of St. Clair Software:
<http://www.stclairsoft.com>
***************************************************************************/
***************************************************************************/
#ifndef __STUB_H__
#define __STUB_H__