1 | /*******************************************************************************
|
---|
2 | mach_inject.h
|
---|
3 | Copyright (c) 2003-2005 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
|
---|
4 | Some rights reserved: <http://creativecommons.org/licenses/by/2.0/>
|
---|
5 |
|
---|
6 | ***************************************************************************/
|
---|
7 |
|
---|
8 | /***************************************************************************//**
|
---|
9 | @mainpage mach_inject
|
---|
10 | @author Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
|
---|
11 |
|
---|
12 | This package, coded in C to the Mach API, allows you to "inject" code into
|
---|
13 | an arbitrary process. "Injection" means both 1) copying over the necessary
|
---|
14 | code into the target's address space and 2) remotely creating a new thread
|
---|
15 | to execute the code.
|
---|
16 |
|
---|
17 | ***************************************************************************/
|
---|
18 |
|
---|
19 | #ifndef _mach_inject_
|
---|
20 | #define _mach_inject_
|
---|
21 | #define __DARWIN_UNIX03 0
|
---|
22 | #include <sys/types.h>
|
---|
23 | #include <mach/error.h>
|
---|
24 | #include <mach/vm_types.h>
|
---|
25 | #include <stddef.h> // for ptrdiff_t
|
---|
26 |
|
---|
27 | #ifdef __cplusplus
|
---|
28 | extern "C" {
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #define err_threadEntry_image_not_found (err_local|1)
|
---|
32 |
|
---|
33 | #define INJECT_ENTRY injectEntry
|
---|
34 | #define INJECT_ENTRY_SYMBOL "injectEntry"
|
---|
35 |
|
---|
36 | typedef void (*mach_inject_entry)( ptrdiff_t codeOffset, void *paramBlock,
|
---|
37 | size_t paramSize, void* dummy_pthread_data );
|
---|
38 |
|
---|
39 | /***************************************************************************//**
|
---|
40 | Starts executing threadEntry in a new thread in the process specified by
|
---|
41 | targetProcess.
|
---|
42 |
|
---|
43 | @param threadEntry -> Required pointer to injected thread's entry
|
---|
44 | point.
|
---|
45 | @param paramBlock -> Optional pointer to block of memory to pass to
|
---|
46 | the injected thread.
|
---|
47 | @param paramSize -> Optional size of paramBlock.
|
---|
48 | @param targetProcess -> Required target process ID.
|
---|
49 | @param stackSize -> Optional stack size of threadEntry's thread. Set
|
---|
50 | to zero for default (currently 8K usable).
|
---|
51 | @result <- mach_error_t
|
---|
52 |
|
---|
53 | ***************************************************************************/
|
---|
54 |
|
---|
55 | mach_error_t
|
---|
56 | mach_inject(
|
---|
57 | const mach_inject_entry threadEntry,
|
---|
58 | const void *paramBlock,
|
---|
59 | size_t paramSize,
|
---|
60 | pid_t targetProcess,
|
---|
61 | vm_size_t stackSize );
|
---|
62 |
|
---|
63 | /***************************************************************************//**
|
---|
64 | Given a pointer, returns its Mach-O image and image size.
|
---|
65 |
|
---|
66 | @param pointer -> Required pointer.
|
---|
67 | @param image <- Optional returned pointer to image (really a
|
---|
68 | mach_header).
|
---|
69 | @param size <- Optional returned size of the image.
|
---|
70 | @param jumpTableOffset <- Optional returned offset of jump table within image (useful on intel)
|
---|
71 | @param jumpTableSize <- Optional returned size of jump table (useful on intel)
|
---|
72 | @result <- mach_error_t
|
---|
73 |
|
---|
74 | ***************************************************************************/
|
---|
75 |
|
---|
76 | mach_error_t
|
---|
77 | machImageForPointer(
|
---|
78 | const void *pointer,
|
---|
79 | const void **image,
|
---|
80 | unsigned long *size,
|
---|
81 | unsigned int *jumpTableOffset,
|
---|
82 | unsigned int *jumpTableSize );
|
---|
83 |
|
---|
84 | #ifdef __cplusplus
|
---|
85 | }
|
---|
86 | #endif
|
---|
87 | #endif // _mach_inject_ |
---|