1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #include <saio_types.h>␊ |
8 | #include <mach-o/loader.h>␊ |
9 | #include <mach-o/nlist.h>␊ |
10 | ␊ |
11 | ␊ |
12 | #ifndef __BOOT_MODULES_H␊ |
13 | #define __BOOT_MODULES_H␊ |
14 | ␊ |
15 | #define MODULE_PATH␉␉"/Extra/modules/"␊ |
16 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
17 | #define VOID_SYMBOL␉␉"dyld_void_start"␊ |
18 | extern unsigned long long textAddress;␊ |
19 | extern unsigned long long textSection;␊ |
20 | ␊ |
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 | ␊ |
31 | typedef struct callbackList_t␊ |
32 | {␊ |
33 | ␉void(*callback)(void*, void*, void*, void*);␊ |
34 | ␉struct callbackList_t* next;␊ |
35 | } callbackList_t;␊ |
36 | ␊ |
37 | typedef struct moduleHook_t␊ |
38 | {␊ |
39 | ␉const char* name;␊ |
40 | ␉callbackList_t* callbacks;␊ |
41 | ␉struct moduleHook_t* next;␊ |
42 | } moduleHook_t;␊ |
43 | ␊ |
44 | typedef struct modulesList_t␊ |
45 | {␊ |
46 | ␉char*␉␉␉␉␉name;␊ |
47 | //␉UInt32␉␉␉␉␉version;␊ |
48 | //␉UInt32␉␉␉␉␉compat;␊ |
49 | ␉struct modulesList_t* next;␊ |
50 | } moduleList_t;␊ |
51 | ␊ |
52 | ␊ |
53 | ␊ |
54 | int init_module_system();␊ |
55 | void load_all_modules();␊ |
56 | ␊ |
57 | void start_built_in_module(char* name, void(*start_function)(void));␊ |
58 | ␊ |
59 | ␊ |
60 | int load_module(char* module);␊ |
61 | int is_module_loaded(const char* name);␊ |
62 | void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/);␊ |
63 | ␊ |
64 | ␊ |
65 | ␊ |
66 | ␊ |
67 | /********************************************************************************/␊ |
68 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
69 | /********************************************************************************/␊ |
70 | long long␉␉add_symbol(char* symbol, long long addr, char is64);␊ |
71 | unsigned int␉lookup_all_symbols(const char* name);␊ |
72 | ␊ |
73 | ␊ |
74 | ␊ |
75 | /********************************************************************************/␊ |
76 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
77 | /********************************************************************************/␊ |
78 | void*␉␉␉parse_mach(void* binary, ␊ |
79 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
80 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char));␊ |
81 | unsigned int␉handle_symtable(UInt32 base,␊ |
82 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
83 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
84 | ␉␉␉␉␉␉␉ char is64);␊ |
85 | void␉␉␉rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
86 | inline void␉␉rebase_location(UInt32* location, char* base, int type);␊ |
87 | void␉␉␉bind_macho(void* base, char* bind_stream, UInt32 size);␊ |
88 | inline void␉␉bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
89 | ␊ |
90 | ␊ |
91 | ␊ |
92 | ␊ |
93 | /********************************************************************************/␊ |
94 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
95 | /********************************************************************************/␊ |
96 | int␉␉␉␉replace_function(const char* symbol, void* newAddress);␊ |
97 | int␉␉␉␉execute_hook(const char* name, void*, void*, void*, void*);␊ |
98 | void␉␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
99 | moduleHook_t*␉hook_exists(const char* name);␊ |
100 | ␊ |
101 | #if DEBUG_MODULES␊ |
102 | void␉␉␉print_hook_list();␊ |
103 | #endif␊ |
104 | ␊ |
105 | /********************************************************************************/␊ |
106 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
107 | /********************************************************************************/␊ |
108 | void dyld_stub_binder();␊ |
109 | ␊ |
110 | #endif /* __BOOT_MODULES_H */ |