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 moduleInfo_t␊ |
31 | {␊ |
32 | ␉char *name;␊ |
33 | ␉char *author;␊ |
34 | ␉char *date;␊ |
35 | ␉unsigned int *version;␊ |
36 | ␉unsigned int *compat;␊ |
37 | ␉char *licenseshort;␊ |
38 | ␉char *licenselong;␊ |
39 | ␉␊ |
40 | }moduleInfo_t;*/␊ |
41 | ␊ |
42 | typedef struct moduleList_t␊ |
43 | {␊ |
44 | ␉char* module;␉␊ |
45 | ␉//struct moduleInfo_t* info;␊ |
46 | ␉struct moduleList_t* next;␊ |
47 | } moduleList_t;␊ |
48 | ␊ |
49 | typedef struct callbackList_t␊ |
50 | {␊ |
51 | ␉void(*callback)(void*, void*, 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 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
63 | ␊ |
64 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
65 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
66 | #define STUB_ENTRY_SIZE␉6␊ |
67 | ␊ |
68 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
69 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
70 | ␊ |
71 | ␊ |
72 | ␊ |
73 | int init_module_system();␊ |
74 | void load_all_modules();␊ |
75 | ␊ |
76 | /*␊ |
77 | * Modules Interface␊ |
78 | * execute_hook␊ |
79 | *␉␉Exexutes a registered hook. All callbaks are␊ |
80 | *␉␉called in the same order that they were added␊ |
81 | *␊ |
82 | * register_hook_callback␊ |
83 | *␉␉registers a void function to be executed when a␊ |
84 | *␉␉hook is executed.␊ |
85 | */␊ |
86 | int execute_hook(const char* name, void*, void*, void*, void*, void*, void*);␊ |
87 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*));␊ |
88 | ␊ |
89 | inline void rebase_location(UInt32* location, char* base, int type);␊ |
90 | inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
91 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
92 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
93 | ␊ |
94 | int load_module(char* module);␊ |
95 | int is_module_loaded(const char* name);␊ |
96 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
97 | ␊ |
98 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
99 | ␊ |
100 | void* parse_mach(void* binary, ␊ |
101 | ␉␉␉␉ int(*dylib_loader)(char*),␊ |
102 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
103 | ␉␉␉␉ );␊ |
104 | ␊ |
105 | unsigned int handle_symtable(UInt32 base,␊ |
106 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
107 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
108 | ␉␉␉␉␉␉␉ char is64);␊ |
109 | ␉␉␉␉␉␉␉ ␊ |
110 | unsigned int lookup_all_symbols(const char* name);␊ |
111 | ␊ |
112 | int replace_function(const char* symbol, void* newAddress);␊ |
113 | ␊ |
114 | extern unsigned int (*lookup_symbol)(const char*);␊ |
115 | ␊ |
116 | #endif /* __BOOT_MODULES_H */ |