Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4192352025
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 87 lines (68 sloc) 2.976 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/*******************************************************************************
mach_inject.h
Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>

***************************************************************************/

/***************************************************************************//**
@mainpage mach_inject
@author Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
This package, coded in C to the Mach API, allows you to "inject" code into
an arbitrary process. "Injection" means both 1) copying over the necessary
code into the target's address space and 2) remotely creating a new thread
to execute the code.

***************************************************************************/

#ifndef _mach_inject_
#define _mach_inject_

#include <sys/types.h>
#include <mach/error.h>
#include <mach/vm_types.h>
#include <stddef.h> // for ptrdiff_t

#ifdef __cplusplus
extern "C" {
#endif

#define err_threadEntry_image_not_found (err_local|1)

#define INJECT_ENTRY injectEntry
#define INJECT_ENTRY_SYMBOL "injectEntry"

typedef void (*mach_inject_entry)( ptrdiff_t codeOffset, void *paramBlock,
size_t paramSize, void* dummy_pthread_data );

/***************************************************************************//**
Starts executing threadEntry in a new thread in the process specified by
targetProcess.
@param threadEntry -> Required pointer to injected thread's entry
point.
@param paramBlock -> Optional pointer to block of memory to pass to
the injected thread.
@param paramSize -> Optional size of paramBlock.
@param targetProcess -> Required target process ID.
@param stackSize -> Optional stack size of threadEntry's thread. Set
to zero for default (currently 8K usable).
@result <- mach_error_t

***************************************************************************/

mach_error_t
mach_inject(
const mach_inject_entry threadEntry,
const void *paramBlock,
size_t paramSize,
pid_t targetProcess,
vm_size_t stackSize );

/***************************************************************************//**
Given a pointer, returns its Mach-O image and image size.
@param pointer -> Required pointer.
@param image <- Optional returned pointer to image (really a
mach_header).
@param size <- Optional returned size of the image.
@param jumpTableOffset <- Optional returned offset of jump table within image (useful on intel)
@param jumpTableSize <- Optional returned size of jump table (useful on intel)
@result <- mach_error_t
***************************************************************************/

mach_error_t
machImageForPointer(
const void *pointer,
const void **image,
unsigned long *size,
unsigned int *jumpTableOffset,
unsigned int *jumpTableSize );

#ifdef __cplusplus
}
#endif
#endif // _mach_inject_
Something went wrong with that request. Please try again.