1 | /*␊ |
2 | * Module Loading functionality␊ |
3 | * Copyright 2009 Evan Lojewski. All rights reserved.␊ |
4 | *␊ |
5 | */␊ |
6 | ␊ |
7 | #ifndef __BOOT_MODULES_H␊ |
8 | #define __BOOT_MODULES_H␊ |
9 | ␊ |
10 | #include <saio_types.h>␊ |
11 | #include <mach-o/loader.h>␊ |
12 | #include <mach-o/nlist.h>␊ |
13 | ␊ |
14 | ␊ |
15 | #define MODULE_PATH␉␉"/Extra/modules/"␊ |
16 | ␊ |
17 | #define SYMBOLS_MODULE "Symbols.dylib"␊ |
18 | #define SYMBOLS_AUTHOR "Chameleon"␊ |
19 | #define SYMBOLS_DESCRIPTION "Chameleon symbols for linking"␊ |
20 | #define SYMBOLS_VERSION 0␊ |
21 | #define SYMBOLS_COMPAT 0␊ |
22 | ␊ |
23 | #define VOID_SYMBOL␉␉"dyld_void_start"␊ |
24 | extern UInt64 textAddress;␊ |
25 | extern UInt64 textSection;␊ |
26 | ␊ |
27 | ␊ |
28 | ␊ |
29 | typedef struct symbolList_t␊ |
30 | {␊ |
31 | ␉char* symbol;␊ |
32 | ␉UInt64 addr;␊ |
33 | ␉struct symbolList_t* next;␊ |
34 | } symbolList_t;␊ |
35 | ␊ |
36 | ␊ |
37 | typedef struct callbackList_t␊ |
38 | {␊ |
39 | ␉void(*callback)(void*, void*, void*, void*);␊ |
40 | ␉struct callbackList_t* next;␊ |
41 | } callbackList_t;␊ |
42 | ␊ |
43 | typedef struct moduleHook_t␊ |
44 | {␊ |
45 | ␉const char* name;␊ |
46 | ␉callbackList_t* callbacks;␊ |
47 | ␉struct moduleHook_t* next;␊ |
48 | } moduleHook_t;␊ |
49 | ␊ |
50 | /*typedef struct moduleList_t //Azi: modules or module? see modules/include/modules␊ |
51 | {␊ |
52 | ␉char*␉␉␉␉␉name;␊ |
53 | //␉UInt32␉␉␉␉␉version;␊ |
54 | //␉UInt32␉␉␉␉␉compat;␊ |
55 | ␉struct moduleList_t*␉next;␊ |
56 | } moduleList_t; */␊ |
57 | ␊ |
58 | typedef struct modulesList_t␊ |
59 | {␊ |
60 | ␉const char*␉␉␉␉name;␊ |
61 | const char* author;␊ |
62 | const char* description;␊ |
63 | ␉UInt32␉␉␉␉␉version;␊ |
64 | ␉UInt32␉␉␉␉␉compat;␊ |
65 | ␉struct modulesList_t* next;␊ |
66 | } moduleList_t;␊ |
67 | ␊ |
68 | ␊ |
69 | ␊ |
70 | int init_module_system();␊ |
71 | void load_all_modules();␊ |
72 | ␊ |
73 | void start_built_in_module(const char* name, ␊ |
74 | const char* author, ␊ |
75 | const char* description,␊ |
76 | UInt32 version,␊ |
77 | UInt32 compat,␊ |
78 | void(*start_function)(void));␊ |
79 | ␊ |
80 | int load_module(char* module);␊ |
81 | int is_module_loaded(const char* name);␊ |
82 | void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat);␊ |
83 | ␊ |
84 | ␊ |
85 | ␊ |
86 | ␊ |
87 | /********************************************************************************/␊ |
88 | /*␉Symbol Functions␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
89 | /********************************************************************************/␊ |
90 | long long␉␉add_symbol(char* symbol, long long addr, char is64);␊ |
91 | unsigned int␉lookup_all_symbols(const char* name);␊ |
92 | ␊ |
93 | ␊ |
94 | ␊ |
95 | /********************************************************************************/␊ |
96 | /*␉Macho Parser␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
97 | /********************************************************************************/␊ |
98 | void*␉␉␉parse_mach(void* binary, ␊ |
99 | ␉␉␉␉␉␉␉int(*dylib_loader)(char*),␊ |
100 | ␉␉␉␉␉␉␉long long(*symbol_handler)(char*, long long, char),␊ |
101 | void (*section_handler)(char* section, char* segment, long long offset, long long address)␊ |
102 | );␊ |
103 | unsigned int␉handle_symtable(UInt32 base,␊ |
104 | ␉␉␉␉␉␉␉ struct symtab_command* symtabCommand,␊ |
105 | ␉␉␉␉␉␉␉ long long(*symbol_handler)(char*, long long, char),␊ |
106 | ␉␉␉␉␉␉␉ char is64);␊ |
107 | void␉␉␉rebase_macho(void* base, char* rebase_stream, UInt32 size);␊ |
108 | inline void␉␉rebase_location(UInt32* location, char* base, int type);␊ |
109 | void␉␉␉bind_macho(void* base, UInt8* bind_stream, UInt32 size);␊ |
110 | inline void␉␉bind_location(UInt32* location, char* value, UInt32 addend, int type);␊ |
111 | ␊ |
112 | ␊ |
113 | ␊ |
114 | ␊ |
115 | /********************************************************************************/␊ |
116 | /*␉Module Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
117 | /********************************************************************************/␊ |
118 | int␉␉␉␉replace_function(const char* symbol, void* newAddress);␊ |
119 | int␉␉␉␉execute_hook(const char* name, void*, void*, void*, void*);␊ |
120 | void␉␉␉register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));␊ |
121 | moduleHook_t*␉hook_exists(const char* name);␊ |
122 | ␊ |
123 | #if DEBUG_MODULES␊ |
124 | void␉␉␉print_hook_list();␊ |
125 | #endif␊ |
126 | ␊ |
127 | /********************************************************************************/␊ |
128 | /*␉dyld Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
129 | /********************************************************************************/␊ |
130 | void dyld_stub_binder();␊ |
131 | ␊ |
132 | #endif /* __BOOT_MODULES_H */ |