Root/
Source at commit 735 created 13 years 2 months ago. By meklort, GUI module bugfixes. Kext Patcher additions. | |
---|---|
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 | ␊ |
35 | typedef struct symbolList_t␊ |
36 | {␊ |
37 | ␉char* symbol;␊ |
38 | ␉unsigned int addr;␊ |
39 | ␉struct symbolList_t* next;␊ |
40 | } symbolList_t;␊ |
41 | ␊ |
42 | ␊ |
43 | typedef struct callbackList_t␊ |
44 | {␊ |
45 | ␉void(*callback)(void*, void*, void*, void*);␊ |
46 | ␉struct callbackList_t* next;␊ |
47 | } callbackList_t;␊ |
48 | ␊ |
49 | typedef struct moduleHook_t␊ |
50 | {␊ |
51 | ␉const char* name;␊ |
52 | ␉callbackList_t* callbacks;␊ |
53 | ␉struct moduleHook_t* next;␊ |
54 | } moduleHook_t;␊ |
55 | ␊ |
56 | typedef struct modulesList_t␊ |
57 | {␊ |
58 | ␉char*␉␉␉␉␉name;␊ |
59 | ␉UInt32␉␉␉␉␉version;␊ |
60 | ␉UInt32␉␉␉␉␉compat;␊ |
61 | ␉␊ |
62 | ␉void*␉␉␉␉␉base_addr;␊ |
63 | ␊ |
64 | ␉symbolList_t*␉␉␉exported_symbols;␊ |
65 | ␉symbolList_t*␉␉␉udefined_symbols;␊ |
66 | ␉//moduleHook_t*␉␉␉defined_hooks;␊ |
67 | ␉struct modulesList_t* next;␊ |
68 | } moduleList_t;␊ |
69 | ␊ |
70 | ␊ |
71 | ␊ |
72 | int init_module_system();␊ |
73 | void load_all_modules();␊ |
74 | ␊ |
75 | ␊ |
76 | ␊ |
77 | int load_module(char* module);␊ |
78 | int is_module_loaded(const char* name);␊ |
79 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
80 | ␊ |
81 | ␊ |
82 | ␊ |
83 | ␊ |
84 | /********************************************************************************/␊ |
85 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
86 | /********************************************************************************/␊ |
87 | long long␉␉add_symbol(char* symbol, long long addr, char is64);␊ |
88 | unsigned int␉lookup_all_symbols(const char* name);␊ |
89 | ␊ |
90 | ␊ |
91 | ␊ |
92 | /********************************************************************************/␊ |
93 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
94 | /********************************************************************************/␊ |
95 | void*␉␉␉parse_mach(void* binary, ␊ |
96 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
97 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char));␊ |
98 | unsigned int␉handle_symtable(UInt32 base,␊ |
99 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
100 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
101 | ␉␉␉␉␉␉␉ char is64);␊ |
102 | void␉␉␉rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
103 | inline void␉␉rebase_location(UInt32* location, char* base, int type);␊ |
104 | void␉␉␉bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
105 | inline void␉␉bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
106 | ␊ |
107 | ␊ |
108 | ␊ |
109 | ␊ |
110 | /********************************************************************************/␊ |
111 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
112 | /********************************************************************************/␊ |
113 | int␉␉␉␉replace_function(const char* symbol, void* newAddress);␊ |
114 | int␉␉␉␉execute_hook(const char* name, void*, void*, void*, void*);␊ |
115 | void␉␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
116 | moduleHook_t*␉hook_exists(const char* name);␊ |
117 | ␊ |
118 | #if DEBUG_MODULES␊ |
119 | void␉␉␉print_hook_list();␊ |
120 | #endif␊ |
121 | ␊ |
122 | /********************************************************************************/␊ |
123 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
124 | /********************************************************************************/␊ |
125 | void dyld_stub_binder();␊ |
126 | ␊ |
127 | #endif /* __BOOT_MODULES_H */ |