Root/
Source at commit 607 created 13 years 7 months ago. By meklort, Kext patcher can now add BCM43xx devices to the wifi kext. Only patches the kexts if associated devices exist, otherwise doesn't touch the mkext. | |
---|---|
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 | extern unsigned long long textAddress;␊ |
20 | extern unsigned long long textSection;␊ |
21 | ␊ |
22 | ␊ |
23 | typedef struct symbolList_t␊ |
24 | {␊ |
25 | ␉char* symbol;␊ |
26 | ␉unsigned int addr;␊ |
27 | ␉struct symbolList_t* next;␊ |
28 | } symbolList_t;␊ |
29 | ␊ |
30 | typedef struct moduleList_t␊ |
31 | {␊ |
32 | ␉char* module;␊ |
33 | ␉unsigned int version;␊ |
34 | ␉unsigned int compat;␊ |
35 | ␉struct moduleList_t* next;␊ |
36 | } moduleList_t;␊ |
37 | ␊ |
38 | typedef struct callbackList_t␊ |
39 | {␊ |
40 | ␉void(*callback)(void*, void*, void*, void*);␊ |
41 | ␉struct callbackList_t* next;␊ |
42 | } callbackList_t;␊ |
43 | ␊ |
44 | typedef struct moduleHook_t␊ |
45 | {␊ |
46 | ␉const char* name;␊ |
47 | ␉callbackList_t* callbacks;␊ |
48 | ␉struct moduleHook_t* next;␊ |
49 | } moduleHook_t;␊ |
50 | ␊ |
51 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
52 | ␊ |
53 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
54 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
55 | #define STUB_ENTRY_SIZE␉6␊ |
56 | ␊ |
57 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
58 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
59 | ␊ |
60 | ␊ |
61 | ␊ |
62 | int init_module_system();␊ |
63 | void load_all_modules();␊ |
64 | ␊ |
65 | /*␊ |
66 | * Modules Interface␊ |
67 | * execute_hook␊ |
68 | *␉␉Exexutes a registered hook. All callbaks are␊ |
69 | *␉␉called in the same order that they were added␊ |
70 | *␊ |
71 | * register_hook_callback␊ |
72 | *␉␉registers a void function to be executed when a␊ |
73 | *␉␉hook is executed.␊ |
74 | */␊ |
75 | int execute_hook(const char* name, void*, void*, void*, void*);␊ |
76 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
77 | ␊ |
78 | inline void rebase_location(UInt32* location, char* base, int type);␊ |
79 | inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
80 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
81 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
82 | ␊ |
83 | int load_module(char* module);␊ |
84 | int is_module_loaded(const char* name);␊ |
85 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
86 | ␊ |
87 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
88 | ␊ |
89 | void* parse_mach(void* binary, ␊ |
90 | ␉␉␉␉ int(*dylib_loader)(char*),␊ |
91 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
92 | ␉␉␉␉ );␊ |
93 | ␊ |
94 | unsigned int handle_symtable(UInt32 base,␊ |
95 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
96 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
97 | ␉␉␉␉␉␉␉ char is64);␊ |
98 | ␉␉␉␉␉␉␉ ␊ |
99 | unsigned int lookup_all_symbols(const char* name);␊ |
100 | ␊ |
101 | int replace_function(const char* symbol, void* newAddress);␊ |
102 | ␊ |
103 | extern unsigned int (*lookup_symbol)(const char*);␊ |
104 | ␊ |
105 | #endif /* __BOOT_MODULES_H */ |