Main Page | Class List | File List | Class Members | File Members | Related Pages

mach_override.c File Reference

#include "mach_override.h"
#include <mach-o/dyld.h>
#include <mach/mach_host.h>
#include <mach/mach_init.h>
#include <mach/vm_map.h>
#include <sys/mman.h>
#include <CoreServices/CoreServices.h>

Go to the source code of this file.

Classes

struct  BranchIsland

Defines

#define kAddressHi   3
#define kAddressLo   5
#define kInstructionHi   10
#define kInstructionLo   11
#define kAllocateHigh   1
#define kAllocateNormal   0
#define kMFCTRMask   0xfc1fffff
#define kMFCTRInstruction   0x7c0903a6

Functions

mach_error_t allocateBranchIsland (BranchIsland **island, int allocateHigh)
 Implementation: Allocates memory for a branch island.

mach_error_t freeBranchIsland (BranchIsland *island)
 Implementation: Deallocates memory for a branch island.

mach_error_t setBranchIslandTarget (BranchIsland *island, const void *branchTo, long instruction)
 Implementation: Sets the branch island's target, with an optional instruction.

mach_error_t mach_override (char *originalFunctionSymbolName, const char *originalFunctionLibraryNameHint, const void *overrideFunctionAddress, void **originalFunctionReentryIsland)
 Dynamically overrides the function implementation referenced by originalFunctionSymbolName with the implentation pointed to by overrideFunctionAddress.


Variables

long kIslandTemplate []


Define Documentation

#define kAddressHi   3
 

Definition at line 39 of file mach_override.c.

Referenced by setBranchIslandTarget().

#define kAddressLo   5
 

Definition at line 40 of file mach_override.c.

Referenced by setBranchIslandTarget().

#define kAllocateHigh   1
 

Definition at line 44 of file mach_override.c.

Referenced by mach_override().

#define kAllocateNormal   0
 

Definition at line 45 of file mach_override.c.

Referenced by mach_override().

#define kInstructionHi   10
 

Definition at line 41 of file mach_override.c.

Referenced by setBranchIslandTarget().

#define kInstructionLo   11
 

Definition at line 42 of file mach_override.c.

Referenced by setBranchIslandTarget().

#define kMFCTRInstruction   0x7c0903a6
 

#define kMFCTRMask   0xfc1fffff
 


Function Documentation

mach_error_t allocateBranchIsland BranchIsland **  island,
int  allocateHigh
 

Implementation: Allocates memory for a branch island.

Parameters:
island <- The allocated island.
allocateHigh -> Whether to allocate the island at the end of the address space (for use with the branch absolute instruction).
Returns:
<- mach_error_t

Definition at line 218 of file mach_override.c.

References BranchIsland::allocatedHigh.

Referenced by mach_override().

mach_error_t freeBranchIsland BranchIsland island  ) 
 

Implementation: Deallocates memory for a branch island.

Parameters:
island -> The island to deallocate.
Returns:
<- mach_error_t

Definition at line 273 of file mach_override.c.

References BranchIsland::allocatedHigh, BranchIsland::instructions, and kIslandTemplate.

Referenced by mach_override().

mach_error_t mach_override char *  originalFunctionSymbolName,
const char *  originalFunctionLibraryNameHint,
const void *  overrideFunctionAddress,
void **  originalFunctionReentryIsland
 

Dynamically overrides the function implementation referenced by originalFunctionSymbolName with the implentation pointed to by overrideFunctionAddress.

Optionally returns a pointer to a "reentry island" which, if jumped to, will resume the original implementation.

Parameters:
originalFunctionSymbolName -> Required symbol name of the function to override (with overrideFunctionAddress). Remember, C function name symbols are prepended with an underscore.
originalFunctionLibraryNameHint -> Optional name of the library which contains originalFunctionSymbolName. Can be NULL, but this may result in the wrong function being overridden and/or a crash.
overrideFunctionAddress -> Required address to the overriding function.
originalFunctionReentryIsland <- Optional pointer to pointer to the reentry island. Can be NULL.
Returns:
<- err_cannot_override if the original function's implementation begins with the 'mfctr' instruction.

Definition at line 92 of file mach_override.c.

References allocateBranchIsland(), err_cannot_override, freeBranchIsland(), kAllocateHigh, kAllocateNormal, and setBranchIslandTarget().

Referenced by main().

mach_error_t setBranchIslandTarget BranchIsland island,
const void *  branchTo,
long  instruction
 

Implementation: Sets the branch island's target, with an optional instruction.

Parameters:
island -> The branch island to insert target into.
branchTo -> The address of the target.
instruction -> Optional instruction to execute prior to branch. Set to zero for nop.
Returns:
<- mach_error_t

Definition at line 311 of file mach_override.c.

References BranchIsland::instructions, kAddressHi, kAddressLo, kInstructionHi, kInstructionLo, and kIslandTemplate.

Referenced by mach_override().


Variable Documentation

long kIslandTemplate[]
 

Initial value:

 {
    0x9001FFFC, 
    0x3C00DEAD, 
    0x6000BEEF, 
    0x7C0903A6, 
    0x8001FFFC, 
    0x60000000, 
    0x4E800420  
}

Definition at line 30 of file mach_override.c.

Referenced by freeBranchIsland(), and setBranchIslandTarget().


Generated on Sun Jun 12 22:09:33 2005 for mach_override by doxygen 1.3.4