1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #include <mach-o/loader.h>␊ |
8 | #include <mach-o/nlist.h>␊ |
9 | ␊ |
10 | ␊ |
11 | // There is a bug with the module system / rebasing / binding␊ |
12 | // that causes static variables to be incorrectly rebased or bound␊ |
13 | // Disable static variables for the moment␊ |
14 | // #define static␊ |
15 | ␊ |
16 | #ifndef __BOOT_MODULES_H␊ |
17 | #define __BOOT_MODULES_H␊ |
18 | ␊ |
19 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
20 | ␊ |
21 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
22 | #define STUB_ENTRY_SIZE␉6␊ |
23 | ␊ |
24 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
25 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
26 | ␊ |
27 | ␊ |
28 | #define VALID_FUNCTION(__x__)␉(__x__ && (void*)__x__ != (void*)0xFFFFFFFF)␊ |
29 | ␊ |
30 | extern unsigned long long textAddress;␊ |
31 | extern unsigned long long textSection;␊ |
32 | ␊ |
33 | ␊ |
34 | typedef struct symbolList_t␊ |
35 | {␊ |
36 | ␉char* symbol;␊ |
37 | ␉unsigned int addr;␊ |
38 | ␉struct symbolList_t* next;␊ |
39 | } symbolList_t;␊ |
40 | ␊ |
41 | typedef struct moduleList_t␊ |
42 | {␊ |
43 | ␉char* module;␊ |
44 | ␉unsigned int version;␊ |
45 | ␉unsigned int compat;␊ |
46 | ␉struct moduleList_t* next;␊ |
47 | } moduleList_t;␊ |
48 | ␊ |
49 | typedef struct callbackList_t␊ |
50 | {␊ |
51 | ␉void(*callback)(void*, void*, void*, void*);␊ |
52 | ␉struct callbackList_t* next;␊ |
53 | } callbackList_t;␊ |
54 | ␊ |
55 | typedef struct moduleHook_t␊ |
56 | {␊ |
57 | ␉const char* name;␊ |
58 | ␉callbackList_t* callbacks;␊ |
59 | ␉struct moduleHook_t* next;␊ |
60 | } moduleHook_t;␊ |
61 | ␊ |
62 | ␊ |
63 | ␊ |
64 | int init_module_system();␊ |
65 | void load_all_modules();␊ |
66 | ␊ |
67 | ␊ |
68 | ␊ |
69 | int load_module(char* module);␊ |
70 | int is_module_loaded(const char* name);␊ |
71 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
72 | ␊ |
73 | ␊ |
74 | ␊ |
75 | ␊ |
76 | /********************************************************************************/␊ |
77 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
78 | /********************************************************************************/␊ |
79 | long long␉␉add_symbol(char* symbol, long long addr, char is64);␊ |
80 | unsigned int␉lookup_all_symbols(const char* name);␊ |
81 | ␊ |
82 | ␊ |
83 | ␊ |
84 | /********************************************************************************/␊ |
85 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
86 | /********************************************************************************/␊ |
87 | void*␉␉␉parse_mach(void* binary, ␊ |
88 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
89 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char));␊ |
90 | unsigned int␉handle_symtable(UInt32 base,␊ |
91 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
92 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
93 | ␉␉␉␉␉␉␉ char is64);␊ |
94 | void␉␉␉rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
95 | inline void␉␉rebase_location(UInt32* location, char* base, int type);␊ |
96 | void␉␉␉bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
97 | inline void␉␉bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
98 | ␊ |
99 | ␊ |
100 | ␊ |
101 | ␊ |
102 | /********************************************************************************/␊ |
103 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
104 | /********************************************************************************/␊ |
105 | int␉␉␉␉replace_function(const char* symbol, void* newAddress);␊ |
106 | int␉␉␉␉execute_hook(const char* name, void*, void*, void*, void*);␊ |
107 | void␉␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
108 | moduleHook_t*␉hook_exists(const char* name);␊ |
109 | ␊ |
110 | #if DEBUG_MODULES␊ |
111 | void␉␉␉print_hook_list();␊ |
112 | #endif␊ |
113 | ␊ |
114 | /********************************************************************************/␊ |
115 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
116 | /********************************************************************************/␊ |
117 | void dyld_stub_binder();␊ |
118 | ␊ |
119 | #endif /* __BOOT_MODULES_H */ |