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 | #ifndef __BOOT_MODULES_H␊ |
11 | #define __BOOT_MODULES_H␊ |
12 | ␊ |
13 | extern unsigned long long textAddress;␊ |
14 | extern unsigned long long textSection;␊ |
15 | ␊ |
16 | ␊ |
17 | typedef struct symbolList_t␊ |
18 | {␊ |
19 | ␉char* symbol;␊ |
20 | ␉unsigned int addr;␊ |
21 | ␉struct symbolList_t* next;␊ |
22 | } symbolList_t;␊ |
23 | ␊ |
24 | typedef struct moduleList_t␊ |
25 | {␊ |
26 | ␉char* module;␊ |
27 | ␉unsigned int version;␊ |
28 | ␉unsigned int compat;␊ |
29 | ␉struct moduleList_t* next;␊ |
30 | } moduleList_t;␊ |
31 | ␊ |
32 | typedef struct callbackList_t␊ |
33 | {␊ |
34 | ␉void(*callback)(void*, void*, void*, void*);␊ |
35 | ␉struct callbackList_t* next;␊ |
36 | } callbackList_t;␊ |
37 | ␊ |
38 | typedef struct moduleHook_t␊ |
39 | {␊ |
40 | ␉const char* name;␊ |
41 | ␉callbackList_t* callbacks;␊ |
42 | ␉struct moduleHook_t* next;␊ |
43 | } moduleHook_t;␊ |
44 | ␊ |
45 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
46 | ␊ |
47 | #define SYMBOL_DYLD_STUB_BINDER␉"dyld_stub_binder"␊ |
48 | #define SYMBOL_LOOKUP_SYMBOL␉"_lookup_symbol"␊ |
49 | #define STUB_ENTRY_SIZE␉6␊ |
50 | ␊ |
51 | #define SECT_NON_LAZY_SYMBOL_PTR␉"__nl_symbol_ptr"␊ |
52 | #define SECT_SYMBOL_STUBS␉␉␉"__symbol_stub"␊ |
53 | ␊ |
54 | ␊ |
55 | ␊ |
56 | int init_module_system();␊ |
57 | void load_all_modules();␊ |
58 | ␊ |
59 | /*␊ |
60 | * Modules Interface␊ |
61 | * execute_hook␊ |
62 | *␉␉Exexutes a registered hook. All callbaks are␊ |
63 | *␉␉called in the same order that they were added␊ |
64 | *␊ |
65 | * register_hook_callback␊ |
66 | *␉␉registers a void function to be executed when a␊ |
67 | *␉␉hook is executed.␊ |
68 | */␊ |
69 | int execute_hook(const char* name, void*, void*, void*, void*);␊ |
70 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
71 | ␊ |
72 | inline void rebase_location(UInt32* location, char* base);␊ |
73 | void rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
74 | void bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
75 | ␊ |
76 | int load_module(char* module);␊ |
77 | int is_module_loaded(const char* name);␊ |
78 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
79 | ␊ |
80 | long long add_symbol(char* symbol, long long addr, char is64);␊ |
81 | ␊ |
82 | void* parse_mach(void* binary, ␊ |
83 | ␉␉␉␉ int(*dylib_loader)(char*),␊ |
84 | ␉␉␉␉ long long(*symbol_handler)(char*, long long, char)␊ |
85 | ␉␉␉␉ );␊ |
86 | ␊ |
87 | unsigned int handle_symtable(UInt32 base,␊ |
88 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
89 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
90 | ␉␉␉␉␉␉␉ char is64);␊ |
91 | ␉␉␉␉␉␉␉ ␊ |
92 | unsigned int lookup_all_symbols(const char* name);␊ |
93 | ␊ |
94 | extern unsigned int (*lookup_symbol)(const char*);␊ |
95 | ␊ |
96 | #endif /* __BOOT_MODULES_H */ |