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_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
22 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
23 | #define STUB_ENTRY_SIZE␉6␊ |
24 | ␊ |
25 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
26 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
27 | ␊ |
28 | ␊ |
29 | #define VALID_FUNCTION(__x__)␉(__x__ && (void*)__x__ != (void*)0xFFFFFFFF)␊ |
30 | ␊ |
31 | extern unsigned long long textAddress;␊ |
32 | extern unsigned long long textSection;␊ |
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 | typedef struct moduleList_t␊ |
43 | {␊ |
44 | ␉char* module;␊ |
45 | ␉unsigned int version;␊ |
46 | ␉unsigned int compat;␊ |
47 | ␉struct moduleList_t* next;␊ |
48 | } moduleList_t;␊ |
49 | ␊ |
50 | typedef struct callbackList_t␊ |
51 | {␊ |
52 | ␉void(*callback)(void*, void*, void*, void*);␊ |
53 | ␉struct callbackList_t* next;␊ |
54 | } callbackList_t;␊ |
55 | ␊ |
56 | typedef struct moduleHook_t␊ |
57 | {␊ |
58 | ␉const char* name;␊ |
59 | ␉callbackList_t* callbacks;␊ |
60 | ␉struct moduleHook_t* next;␊ |
61 | } moduleHook_t;␊ |
62 | ␊ |
63 | ␊ |
64 | ␊ |
65 | int init_module_system();␊ |
66 | void load_all_modules();␊ |
67 | ␊ |
68 | /*␊ |
69 | * Modules Interface␊ |
70 | * execute_hook␊ |
71 | *␉␉Exexutes a registered hook. All callbaks are␊ |
72 | *␉␉called in the same order that they were added␊ |
73 | *␊ |
74 | * register_hook_callback␊ |
75 | *␉␉registers a void function to be executed when a␊ |
76 | *␉␉hook is executed.␊ |
77 | */␊ |
78 | int execute_hook(const char* name, void*, void*, void*, void*);␊ |
79 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
80 | ␊ |
81 | inline void rebase_location(UInt32* location, char* base, int type);␊ |
82 | inline void bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
83 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
84 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
85 | ␊ |
86 | int load_module(char* module);␊ |
87 | int is_module_loaded(const char* name);␊ |
88 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
89 | ␊ |
90 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
91 | ␊ |
92 | void* parse_mach(void* binary, ␊ |
93 | ␉␉␉␉ int(*dylib_loader)(char*),␊ |
94 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
95 | ␉␉␉␉ );␊ |
96 | ␊ |
97 | unsigned int handle_symtable(UInt32 base,␊ |
98 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
99 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
100 | ␉␉␉␉␉␉␉ char is64);␊ |
101 | ␉␉␉␉␉␉␉ ␊ |
102 | unsigned int lookup_all_symbols(const char* name);␊ |
103 | ␊ |
104 | int replace_function(const char* symbol, void* newAddress);␊ |
105 | ␊ |
106 | //extern unsigned int (*lookup_symbol)(const char*);␊ |
107 | ␊ |
108 | #endif /* __BOOT_MODULES_H */ |